Skip to content

Commit

Permalink
Updated esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
TfTHacker committed Nov 4, 2023
1 parent 7b31212 commit 788dfb1
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 0.7.1 (Pending)
- New: Can now force a reinstall of a beta plugin. This might be useful when a local file gets corrupted and you want to replace it with the current file in the release. Addresses https://github.com/TfTHacker/obsidian42-brat/issues/62)
- Fix: if the url ends with .git, the Add New Plugin form will strip the .git extension. This makes it easier to sue the github copy code button url with BRAT (fix for https://github.com/TfTHacker/obsidian42-brat/issues/55)
- Updates: updated to newest esbuild and also all project dependenices

# 0.7.0
## Major updates to **THEMES** support
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 TfTHacker
Copyright (c) 2023 TfTHacker

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
61 changes: 34 additions & 27 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
import fs from "fs";
import { ESLint } from "eslint";

const prod = (process.argv[2] === "production");

esbuild.build({
entryPoints: ["src/main.ts"],
bundle: true,
external: ["obsidian"],
format: "cjs",
watch: !prod,
target: "es2016",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
minify: true,
outfile: "build/main.js",
}).catch(() => process.exit(1));
import console from "console";

fs.copyFile("manifest.json", "build/manifest.json", (err) => {if(err) console.log(err)} );
fs.copyFile("styles.css", "build/styles.css", (err) => {if(err) console.log(err)} );

// eslint won't slow down the build process, just runs after the build finishes
(async function eslintTest() {
const eslint = new ESLint();
const results = await eslint.lintFiles(["src/**/*.ts"]);
const formatter = await eslint.loadFormatter("stylish");
const resultText = formatter.format(results);
console.log(resultText);
})().catch((error) => {
process.exitCode = 1;
console.error(error);
const prod = (process.argv[2] === "production");

const context = await esbuild.context({
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: prod ? false : "inline",
treeShaking: true,
outfile: "build/main.js",
});

if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"description": "Easily install a beta version of a plugin for testing.",
"author": "TfTHacker",
"authorUrl": "https://github.com/TfTHacker/obsidian42-brat",
"helpUrl": "https://tfthacker.com/BRAT",
"isDesktopOnly": false,
"fundingUrl": {
"Buy Me a Coffee": "https://bit.ly/o42-kofi",
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "node esbuild.config.mjs production",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"lint": "eslint . --ext .ts"
},
"author": "TfT Hacker",
Expand All @@ -18,8 +18,9 @@
"@types/node": "^20.8.10",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"esbuild": "0.16.7",
"eslint": "^8.52.0",
"builtin-modules": "3.3.0",
"eslint": "^8.53.0",
"esbuild": "0.19.5",
"obsidian": "latest",
"tslib": "^2.6.2",
"typescript": "5.2.2"
Expand Down
10 changes: 5 additions & 5 deletions src/features/BetaPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ export default class BetaPlugins {
// if plugin folder doesnt exist or manifest.json doesn't exist, create it and save the plugin files
await adapter.mkdir(pluginTargetFolderPath);
}
await adapter.write(pluginTargetFolderPath + "main.js", relFiles.mainJs);
await adapter.write(pluginTargetFolderPath + "manifest.json", relFiles.manifest);
await adapter.write(pluginTargetFolderPath + "main.js", relFiles.mainJs!);
await adapter.write(pluginTargetFolderPath + "manifest.json", relFiles.manifest!);
if (relFiles.styles) await adapter.write(pluginTargetFolderPath + "styles.css", relFiles.styles);
}

Expand Down Expand Up @@ -223,7 +223,7 @@ export default class BetaPlugins {
if (seeIfUpdatedOnly) { // dont update, just report it
const msg = `There is an update available for ${primaryManifest.id} from version ${localManifestJSON.version} to ${primaryManifest.version}. `;
this.plugin.log(msg + `[Release Info](https://github.com/${repositoryPath}/releases/tag/${primaryManifest.version})`, false);
ToastMessage(this.plugin, msg, 30, async () => { window.open(`https://github.com/${repositoryPath}/releases/tag/${primaryManifest.version}`)});
ToastMessage(this.plugin, msg, 30, async () => { window.open(`https://github.com/${repositoryPath}/releases/tag/${primaryManifest!.version}`)});
} else {
await this.writeReleaseFilesToPluginFolder(primaryManifest.id, releaseFiles);
//@ts-ignore
Expand All @@ -232,7 +232,7 @@ export default class BetaPlugins {
if (this.plugin.app.plugins.plugins[primaryManifest.id]?.manifest) await this.reloadPlugin(primaryManifest.id); //reload if enabled
const msg = `${primaryManifest.id}\nPlugin has been updated from version ${localManifestJSON.version} to ${primaryManifest.version}. `;
this.plugin.log(msg + `[Release Info](https://github.com/${repositoryPath}/releases/tag/${primaryManifest.version})`, false);
ToastMessage(this.plugin, msg, 30, async () => { window.open(`https://github.com/${repositoryPath}/releases/tag/${primaryManifest.version}`) } );
ToastMessage(this.plugin, msg, 30, async () => { window.open(`https://github.com/${repositoryPath}/releases/tag/${primaryManifest!.version}`) } );
}
} else
if (reportIfNotUpdted) ToastMessage(this.plugin, `No update available for ${repositoryPath}`, 3);
Expand Down Expand Up @@ -301,7 +301,7 @@ export default class BetaPlugins {
const msg2 = `Checking for plugin updates COMPLETED`;
this.plugin.log(msg2, true);
if (showInfo) {
newNotice.hide();
newNotice!.hide();
ToastMessage(this.plugin, msg2, 10);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/features/githubUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const grabCommmunityThemesList = async (debugLogging = true): Promise<JSO
}


export const grabCommmunityThemeCssFile = async (repositoryPath: string, betaVersion = false, debugLogging): Promise<string|null> => {
export const grabCommmunityThemeCssFile = async (repositoryPath: string, betaVersion = false, debugLogging: boolean): Promise<string|null> => {
const themesURL = `https://github.com/raw/${repositoryPath}/HEAD/theme${betaVersion ? "-beta" : ""}.css`;
try {
const response = await request({ url: themesURL });
Expand Down Expand Up @@ -102,7 +102,7 @@ export const checksumForString = (str: string): string => {
return checksum(str).toString();
}

export const grabChecksumOfThemeCssFile = async (repositoryPath: string, betaVersion, debugLogging): Promise<string> =>{
export const grabChecksumOfThemeCssFile = async (repositoryPath: string, betaVersion: boolean, debugLogging: boolean): Promise<string> =>{
const themeCSS = await grabCommmunityThemeCssFile(repositoryPath, betaVersion, debugLogging)
return themeCSS ? checksumForString(themeCSS) : "0";
}
Expand Down
2 changes: 1 addition & 1 deletion src/features/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const themesCheckAndUpdates = async (plugin: ThePlugin, showInfo: boolean
const msg2 = `Checking for beta theme updates COMPLETED`;
plugin.log(msg2, true);
if (showInfo) {
if(plugin.settings.notificationsEnabled) newNotice.hide();
if(plugin.settings.notificationsEnabled) newNotice!.hide();
ToastMessage(plugin, msg2);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ export default class ThePlugin extends Plugin {
}
setTimeout(async () => {
this.bratAPI = new BratAPI(this);
globalThis.bratAPI = this.bratAPI;
(globalThis as any).bratAPI = this.bratAPI;
}, 500);
});
}

showRibbonButton(): void { this.ribbonIcon = this.addRibbonIcon("BratIcon", "BRAT", async () => this.commands.ribbonDisplayCommands()) }

log(textToLog: string, verbose = false): void { logger(this, textToLog, verbose) }
Expand Down
2 changes: 1 addition & 1 deletion src/ui/GenericFuzzySuggester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class GenericFuzzySuggester extends FuzzySuggestModal<SuggesterItem>{
renderSuggestion(item: FuzzyMatch<SuggesterItem>, el: HTMLElement): void { el.createEl('div', { text: item.item.display }) }

enterTrigger(evt: KeyboardEvent): void {
const selectedText = document.querySelector(".suggestion-item.is-selected div").textContent;
const selectedText = document.querySelector(".suggestion-item.is-selected div")!.textContent;
const item = this.data.find(i => i.display === selectedText);
if (item) {
this.invokeCallback(item, evt);
Expand Down
5 changes: 2 additions & 3 deletions src/ui/PluginCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export default class PluginCommands {
const gfs = new GenericFuzzySuggester(this.plugin);
gfs.setSuggesterData(pluginList);
await gfs.display(async (results) => {
console.log(results)
const msg = `Reinstalling ${results.info}`;
ToastMessage(this.plugin, `\n${msg}`, 3);
this.plugin.log(msg, true);
Expand Down Expand Up @@ -139,7 +138,7 @@ export default class PluginCommands {
showInRibbon: true,
callback: async () => {
const communityPlugins = await grabCommmunityPluginList(this.plugin.settings.debuggingMode);
const communityPluginList: SuggesterItem[] = Object.values(communityPlugins).map((p) => { return { display: `Plugin: ${p.name} (${p.repo})`, info: p.repo } });
const communityPluginList: SuggesterItem[] = Object.values(communityPlugins!).map((p) => { return { display: `Plugin: ${p.name} (${p.repo})`, info: p.repo } });
const bratList: SuggesterItem[] = Object.values(this.plugin.settings.pluginList).map((p) => { return { display: "BRAT: " + p, info: p } });
communityPluginList.forEach(si => bratList.push(si));
const gfs = new GenericFuzzySuggester(this.plugin);
Expand All @@ -156,7 +155,7 @@ export default class PluginCommands {
showInRibbon: true,
callback: async () => {
const communityTheme = await grabCommmunityThemesList(this.plugin.settings.debuggingMode);
const communityThemeList: SuggesterItem[] = Object.values(communityTheme).map((p) => { return { display: `Theme: ${p.name} (${p.repo})`, info: p.repo } });
const communityThemeList: SuggesterItem[] = Object.values(communityTheme!).map((p) => { return { display: `Theme: ${p.name} (${p.repo})`, info: p.repo } });
const gfs = new GenericFuzzySuggester(this.plugin);
gfs.setSuggesterData(communityThemeList);
await gfs.display(async (results) => {
Expand Down
6 changes: 3 additions & 3 deletions src/ui/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class BratSettingsTab extends PluginSettingTab {
if (btn.buttonEl.textContent === "")
btn.setButtonText("Click once more to confirm removal");
else {
btn.buttonEl.parentElement.parentElement.remove();
btn.buttonEl.parentElement!.parentElement!.remove();
await this.plugin.betaPlugins.deletePlugin(bp)
}
});
Expand All @@ -123,7 +123,7 @@ export class BratSettingsTab extends PluginSettingTab {
if (btn.buttonEl.textContent === "")
btn.setButtonText("Click once more to confirm removal");
else {
btn.buttonEl.parentElement.parentElement.remove();
btn.buttonEl.parentElement!.parentElement!.remove();
await this.plugin.betaPlugins.deletePlugin(bp.repo);
}
});
Expand Down Expand Up @@ -154,7 +154,7 @@ export class BratSettingsTab extends PluginSettingTab {
if (btn.buttonEl.textContent === "")
btn.setButtonText("Click once more to confirm removal");
else {
btn.buttonEl.parentElement.parentElement.remove();
btn.buttonEl.parentElement!.parentElement!.remove();
await themeDelete(this.plugin, bp.repo);
}
});
Expand Down
24 changes: 24 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"baseUrl": ".",
"inlineSourceMap": true,
"inlineSources": true,
"module": "ESNext",
"target": "ES6",
"allowJs": true,
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"isolatedModules": true,
"strictNullChecks": true,
"lib": [
"DOM",
"ES5",
"ES6",
"ES7"
]
},
"include": [
"**/*.ts"
]
}

0 comments on commit 788dfb1

Please sign in to comment.