update deps; fix preview modal

This commit is contained in:
mProjectsCode 2023-12-12 21:07:49 +01:00
parent 26cf166a54
commit 5125e73cb4
19 changed files with 1365 additions and 1302 deletions

View file

@ -1,62 +1,60 @@
import esbuild from 'esbuild';
import process from 'process';
import builtins from 'builtin-modules';
import esbuildSvelte from 'esbuild-svelte';
import sveltePreprocess from 'svelte-preprocess';
import manifest from './manifest.json' assert { type: 'json' };
const banner = `/*
-------------------------------------------
${manifest.name} - Release Build
-------------------------------------------
By: ${manifest.author} (${manifest.authorUrl})
Time: ${new Date().toUTCString()}
Version: ${manifest.version}
-------------------------------------------
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;
const prod = process.argv[2] === 'production';
esbuild
.build({
banner: {
js: banner,
},
entryPoints: ['src/main.ts'],
bundle: true,
external: [
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/closebrackets',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/comment',
'@codemirror/fold',
'@codemirror/gutter',
'@codemirror/highlight',
'@codemirror/history',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/matchbrackets',
'@codemirror/panel',
'@codemirror/rangeset',
'@codemirror/rectangular-selection',
'@codemirror/search',
'@codemirror/state',
'@codemirror/stream-parser',
'@codemirror/text',
'@codemirror/tooltip',
'@codemirror/view',
...builtins,
],
format: 'cjs',
watch: !prod,
target: 'es2018',
logLevel: 'info',
sourcemap: prod ? false : 'inline',
treeShaking: true,
outfile: 'main.js',
plugins: [
esbuildSvelte({
compilerOptions: { css: true },
preprocess: sveltePreprocess(),
}),
],
})
.catch(() => process.exit(1));
const build = await esbuild.build({
banner: {
js: banner,
},
entryPoints: ['src/main.ts'],
bundle: true,
external: [
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/search',
'@codemirror/state',
'@codemirror/view',
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
...builtins,
],
format: 'cjs',
target: 'es2018',
logLevel: 'info',
sourcemap: false,
treeShaking: true,
outfile: 'main.js',
minify: true,
metafile: true,
plugins: [
esbuildSvelte({
compilerOptions: { css: 'injected' },
preprocess: sveltePreprocess(),
filterWarnings: warning => {
// we don't want warnings from node modules that we can do nothing about
return !warning.filename.includes('node_modules');
},
}),
],
});

63
esbuild.dev.config.mjs Normal file
View file

@ -0,0 +1,63 @@
import esbuild from 'esbuild';
import process from 'process';
import builtins from 'builtin-modules';
import esbuildSvelte from 'esbuild-svelte';
import sveltePreprocess from 'svelte-preprocess';
import manifest from './manifest.json' assert { type: 'json' };
const banner = `/*
-------------------------------------------
${manifest.name} - Dev Build
-------------------------------------------
By: ${manifest.author} (${manifest.authorUrl})
Time: ${new Date().toUTCString()}
Version: Dev Build
-------------------------------------------
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;
const context = await esbuild
.context({
banner: {
js: banner,
},
entryPoints: ['src/main.ts'],
bundle: true,
external: [
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/search',
'@codemirror/state',
'@codemirror/view',
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
...builtins,
],
format: 'cjs',
target: 'es2018',
logLevel: 'info',
sourcemap: 'inline',
treeShaking: true,
outfile: 'main.js',
plugins: [
esbuildSvelte({
compilerOptions: { css: 'injected' },
preprocess: sveltePreprocess(),
filterWarnings: warning => {
// we don't want warnings from node modules that we can do nothing about
return !warning.filename.includes('node_modules');
},
}),
],
})
.catch(() => process.exit(1));
await context.watch();

2401
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@
"description": "A plugin that can query multiple APIs for movies, series, anime, games, music and wiki articles, and import them into your vault.",
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
"dev": "node esbuild.dev.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json",
"test": "jest",
@ -14,25 +14,24 @@
"author": "Moritz Jung",
"license": "GPL-3.0",
"devDependencies": {
"@popperjs/core": "^2.11.5",
"@tsconfig/svelte": "^3.0.0",
"@types/jest": "^29.5.3",
"@types/node": "^18.16.20",
"@typescript-eslint/eslint-plugin": "^5.30.0",
"@typescript-eslint/parser": "^5.30.0",
"@popperjs/core": "^2.11.8",
"@tsconfig/svelte": "^5.0.2",
"@types/jest": "^29.5.11",
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"builtin-modules": "^3.3.0",
"esbuild": "^0.14.47",
"esbuild-svelte": "^0.7.1",
"eslint-plugin-only-warn": "^1.0.3",
"jest": "^29.6.1",
"esbuild": "^0.19.9",
"esbuild-svelte": "^0.8.0",
"eslint-plugin-only-warn": "^1.1.0",
"jest": "^29.7.0",
"jest-fetch-mock": "^3.0.3",
"obsidian": "latest",
"svelte": "^3.53.1",
"svelte-preprocess": "^4.10.7",
"obsidian": "^1.4.11",
"prettier": "3.1.1",
"svelte": "^4.2.8",
"svelte-preprocess": "^5.1.2",
"ts-jest": "^29.1.1",
"tslib": "2.4.0",
"typescript": "^4.9.5",
"prettier": "2.7.1"
},
"dependencies": {}
"tslib": "2.6.2",
"typescript": "^5.3.3"
}
}

View file

@ -49,7 +49,7 @@ export class BoardGameGeekAPI extends APIModel {
title,
englishTitle: title,
year,
} as BoardGameModel)
} as BoardGameModel),
);
}

View file

@ -52,7 +52,7 @@ export class MALAPI extends APIModel {
year: result.year ?? result.aired?.prop?.from?.year ?? '',
dataSource: this.apiName,
id: result.mal_id,
} as MovieModel)
} as MovieModel),
);
}
if (type === 'movie' || type === 'special') {
@ -64,7 +64,7 @@ export class MALAPI extends APIModel {
year: result.year ?? result.aired?.prop?.from?.year ?? '',
dataSource: this.apiName,
id: result.mal_id,
} as MovieModel)
} as MovieModel),
);
} else if (type === 'series' || type === 'ova') {
ret.push(
@ -75,7 +75,7 @@ export class MALAPI extends APIModel {
year: result.year ?? result.aired?.prop?.from?.year ?? '',
dataSource: this.apiName,
id: result.mal_id,
} as SeriesModel)
} as SeriesModel),
);
}
}

View file

@ -73,7 +73,7 @@ export class MALAPIManga extends APIModel {
lastWatched: '',
personalRating: 0,
},
} as MangaModel)
} as MangaModel),
);
}

View file

@ -55,7 +55,7 @@ export class MusicBrainzAPI extends APIModel {
artists: result['artist-credit'].map((a: any) => a.name),
subType: result['primary-type'],
} as MusicReleaseModel)
} as MusicReleaseModel),
);
}

View file

@ -69,7 +69,7 @@ export class OMDbAPI extends APIModel {
year: result.Year,
dataSource: this.apiName,
id: result.imdbID,
} as MovieModel)
} as MovieModel),
);
} else if (type === 'series') {
ret.push(
@ -80,7 +80,7 @@ export class OMDbAPI extends APIModel {
year: result.Year,
dataSource: this.apiName,
id: result.imdbID,
} as SeriesModel)
} as SeriesModel),
);
} else if (type === 'game') {
ret.push(
@ -91,7 +91,7 @@ export class OMDbAPI extends APIModel {
year: result.Year,
dataSource: this.apiName,
id: result.imdbID,
} as GameModel)
} as GameModel),
);
}
}

View file

@ -41,7 +41,7 @@ export class OpenLibraryAPI extends APIModel {
year: result.first_publish_year,
dataSource: this.apiName,
id: result.key,
} as BookModel)
} as BookModel),
);
}
@ -75,7 +75,7 @@ export class OpenLibraryAPI extends APIModel {
plot: result.description ?? 'unknown',
pages: result.number_of_pages_median ?? 'unknown',
onlineRating: Number.parseFloat(Number(result.ratings_average ?? 0).toFixed(2)),
image: `https://covers.openlibrary.org/b/OLID/` + result.cover_edition_key + `-L.jpg` ?? '',
image: `https://covers.openlibrary.org/b/OLID/` + result.cover_edition_key + `-L.jpg`,
released: true,

View file

@ -60,7 +60,7 @@ export class SteamAPI extends APIModel {
year: '',
dataSource: this.apiName,
id: result.appid,
} as GameModel)
} as GameModel),
);
}

View file

@ -42,7 +42,7 @@ export class WikipediaAPI extends APIModel {
year: '',
dataSource: this.apiName,
id: result.pageid,
} as WikiModel)
} as WikiModel),
);
}

View file

@ -68,7 +68,7 @@ export default class MediaDbPlugin extends Plugin {
.onClick(() => this.createEntriesFromFolder(file));
});
}
})
}),
);
// register command to open search modal
@ -291,6 +291,11 @@ export default class MediaDbPlugin extends Plugin {
}
}
generateMediaDbNoteFrontmatterPreview(mediaTypeModel: MediaTypeModel): string {
const fileMetadata = this.modelPropertyMapper.convertObject(mediaTypeModel.toMetaDataObject());
return this.settings.useCustomYamlStringifier ? YAMLConverter.toYaml(fileMetadata) : stringifyYaml(fileMetadata);
}
async generateMediaDbNoteContents(mediaTypeModel: MediaTypeModel, options: CreateNoteOptions): Promise<string> {
let fileMetadata = this.modelPropertyMapper.convertObject(mediaTypeModel.toMetaDataObject());
let fileContent = '';

View file

@ -26,7 +26,6 @@ export class MediaDbPreviewModal extends Modal {
this.plugin = plugin;
this.title = previewModalOptions.modalTitle;
this.elements = previewModalOptions.elements;
this.createNoteOptions = previewModalOptions.createNoteOptions;
this.markdownComponent = new Component();
}
@ -53,8 +52,8 @@ export class MediaDbPreviewModal extends Modal {
previewWrapper.createEl('h3', { text: result.englishTitle });
const fileDiv = previewWrapper.createDiv({ cls: 'media-db-plugin-preview' });
let fileContent = await this.plugin.generateMediaDbNoteContents(result, this.createNoteOptions);
fileContent = `\n${fileContent}\n`;
let fileContent = this.plugin.generateMediaDbNoteFrontmatterPreview(result);
fileContent = `\`\`\`yaml\n${fileContent}\`\`\``;
try {
// TODO: fix this not rendering the frontmatter any more
@ -83,7 +82,7 @@ export class MediaDbPreviewModal extends Modal {
}
onOpen(): void {
this.preview();
void this.preview();
}
onClose(): void {

View file

@ -44,7 +44,7 @@ export class PropertyMappingModel {
return {
res: false,
err: new PropertyMappingNameConflictError(
`Multiple remapped properties (${propertiesWithSameTarget.map(x => x.toString()).toString()}) may not share the same name.`
`Multiple remapped properties (${propertiesWithSameTarget.map(x => x.toString()).toString()}) may not share the same name.`,
),
};
}

View file

@ -192,8 +192,8 @@ export class MediaDbSettingTab extends PluginSettingTab {
"For more syntax, refer to <a href='https://momentjs.com/docs/#/displaying/format/'>format reference</a>.<br>" +
"Your current syntax looks like this: <b><a id='media-db-dateformat-preview' style='pointer-events: none; cursor: default; text-decoration: none;'>" +
this.plugin.dateFormatter.getPreview() +
'</a></b>'
)
'</a></b>',
),
)
.addText(cb => {
cb.setPlaceholder(DEFAULT_SETTINGS.customDateFormat)

View file

@ -100,5 +100,5 @@ describe.each([{ name: OMDbAPI }, { name: MALAPI }, { name: LocGovAPI }, { name:
await expect(apiMock.searchByTitle('Hooking Season Playtest')).resolves.toEqual(ret);
expect(fetchMock).toHaveBeenCalledTimes(1);
});
}
},
);

View file

@ -21,7 +21,7 @@ export function setWikipediaResponseMock() {
year: '',
dataSource: apiMock.apiName,
id: wikiresponse.pageid,
})
}),
);
return ret;
}
@ -37,7 +37,7 @@ export function setOMDbResponseMock() {
year: omdbresponse.Year,
dataSource: apiMock.apiName,
id: omdbresponse.imdbID,
})
}),
);
return ret;
}
@ -53,7 +53,7 @@ export function setMALResponseMock() {
year: result.aired.prop.from.year,
dataSource: apiMock.apiName,
id: result.mal_id,
})
}),
);
return ret;
}
@ -69,7 +69,7 @@ export function setSteamResponseMock() {
year: '',
dataSource: apiMock.apiName,
id: steamResponse.appid,
})
}),
);
return ret;
}
@ -89,7 +89,7 @@ export function setMusicBrainzResponseMock() {
artists: result['artist-credit'].map((a: any) => a.name),
subType: result['primary-type'],
} as MusicReleaseModel)
} as MusicReleaseModel),
);
return ret;
}

View file

@ -175,7 +175,6 @@ export interface SelectModalOptions {
export interface PreviewModalOptions {
modalTitle?: string;
elements?: MediaTypeModel[];
createNoteOptions?: CreateNoteOptions;
}
export const SEARCH_MODAL_DEFAULT_OPTIONS: SearchModalOptions = {
@ -206,7 +205,6 @@ export const SELECT_MODAL_OPTIONS_DEFAULT: SelectModalOptions = {
export const PREVIEW_MODAL_DEFAULT_OPTIONS: PreviewModalOptions = {
modalTitle: 'Media DB Preview',
elements: [],
createNoteOptions: { attachTemplate: true },
};
/**
@ -289,7 +287,7 @@ export class ModalHelper {
* @returns the user input or nothing and a reference to the modal.
*/
async createAdvancedSearchModal(
advancedSearchModalOptions: AdvancedSearchModalOptions
advancedSearchModalOptions: AdvancedSearchModalOptions,
): Promise<{ advancedSearchModalResult: AdvancedSearchModalResult; advancedSearchModal: MediaDbAdvancedSearchModal }> {
const modal = new MediaDbAdvancedSearchModal(this.plugin, advancedSearchModalOptions);
const res: AdvancedSearchModalResult = await new Promise(resolve => {
@ -316,7 +314,7 @@ export class ModalHelper {
*/
async openAdvancedSearchModal(
advancedSearchModalOptions: AdvancedSearchModalOptions,
submitCallback: (advancedSearchModalData: AdvancedSearchModalData) => Promise<MediaTypeModel[]>
submitCallback: (advancedSearchModalData: AdvancedSearchModalData) => Promise<MediaTypeModel[]>,
): Promise<MediaTypeModel[]> {
const { advancedSearchModalResult, advancedSearchModal } = await this.createAdvancedSearchModal(advancedSearchModalOptions);
console.debug(`MDB | advencedSearchModal closed with code ${advancedSearchModalResult.code}`);
@ -380,7 +378,7 @@ export class ModalHelper {
*/
async openIdSearchModal(
idSearchModalOptions: IdSearchModalOptions,
submitCallback: (idSearchModalData: IdSearchModalData) => Promise<MediaTypeModel>
submitCallback: (idSearchModalData: IdSearchModalData) => Promise<MediaTypeModel>,
): Promise<MediaTypeModel> {
const { idSearchModalResult, idSearchModal } = await this.createIdSearchModal(idSearchModalOptions);
console.debug(`MDB | idSearchModal closed with code ${idSearchModalResult.code}`);