From dc0916ddda0543511d2ba9361ebc44ba303ac8b1 Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Wed, 7 Dec 2022 19:56:31 +1100 Subject: [PATCH] chore: move extension manifest to src/, add build script --- .gitignore | 3 +++ dep/.github/workflows/update-parents.yml | 29 ---------------------- package.json | 3 +++ scripts/build-browser-extension.sh | 8 ++++++ scripts/enhance-desktop-app.mjs | 13 +++++----- scripts/patch-desktop-app.mjs | 0 {dep => src/dep}/README.md | 0 {dep => src/dep}/feather-sprite.svg | 0 {dep => src/dep}/jscolor.min.js | 0 {dep => src/dep}/markdown-it.min.js | 0 {dep => src/dep}/mime-db.json | 0 {dep => src/dep}/style-vendorizer.mjs | 0 {dep => src/dep}/twind-content.mjs | 0 {dep => src/dep}/twind-css.mjs | 0 {dep => src/dep}/twind.mjs | 0 src/{desktop => electron}/client.mjs | 0 src/{desktop => electron}/electronApi.cjs | 0 src/{desktop => electron}/env/env.mjs | 0 src/{desktop => electron}/env/fs.mjs | 0 src/{desktop => electron}/env/storage.mjs | 0 src/{desktop => electron}/frame.mjs | 0 src/{desktop => electron}/init.cjs | 0 src/{desktop => electron}/worker.cjs | 0 src/{browser => }/manifest.json | 6 ++--- {media => src/media}/animated.gif | Bin {media => src/media}/blackwhite-x128.png | Bin {media => src/media}/blackwhite-x16.png | Bin {media => src/media}/blackwhite-x256.png | Bin {media => src/media}/blackwhite-x32.png | Bin {media => src/media}/blackwhite-x48.png | Bin {media => src/media}/blackwhite-x512.png | Bin {media => src/media}/blackwhite.svg | 0 {media => src/media}/colour-x128.png | Bin {media => src/media}/colour-x16.png | Bin {media => src/media}/colour-x256.png | Bin {media => src/media}/colour-x32.png | Bin {media => src/media}/colour-x48.png | Bin {media => src/media}/colour-x512.png | Bin {media => src/media}/colour.svg | 0 {media => src/media}/promo-large.jpg | Bin {media => src/media}/promo-marquee.jpg | Bin {media => src/media}/promo-small.jpg | Bin 42 files changed, 24 insertions(+), 38 deletions(-) delete mode 100644 dep/.github/workflows/update-parents.yml create mode 100755 scripts/build-browser-extension.sh mode change 100644 => 100755 scripts/enhance-desktop-app.mjs mode change 100644 => 100755 scripts/patch-desktop-app.mjs rename {dep => src/dep}/README.md (100%) rename {dep => src/dep}/feather-sprite.svg (100%) rename {dep => src/dep}/jscolor.min.js (100%) rename {dep => src/dep}/markdown-it.min.js (100%) rename {dep => src/dep}/mime-db.json (100%) rename {dep => src/dep}/style-vendorizer.mjs (100%) rename {dep => src/dep}/twind-content.mjs (100%) rename {dep => src/dep}/twind-css.mjs (100%) rename {dep => src/dep}/twind.mjs (100%) rename src/{desktop => electron}/client.mjs (100%) rename src/{desktop => electron}/electronApi.cjs (100%) rename src/{desktop => electron}/env/env.mjs (100%) rename src/{desktop => electron}/env/fs.mjs (100%) rename src/{desktop => electron}/env/storage.mjs (100%) rename src/{desktop => electron}/frame.mjs (100%) rename src/{desktop => electron}/init.cjs (100%) rename src/{desktop => electron}/worker.cjs (100%) rename src/{browser => }/manifest.json (84%) rename {media => src/media}/animated.gif (100%) rename {media => src/media}/blackwhite-x128.png (100%) rename {media => src/media}/blackwhite-x16.png (100%) rename {media => src/media}/blackwhite-x256.png (100%) rename {media => src/media}/blackwhite-x32.png (100%) rename {media => src/media}/blackwhite-x48.png (100%) rename {media => src/media}/blackwhite-x512.png (100%) rename {media => src/media}/blackwhite.svg (100%) rename {media => src/media}/colour-x128.png (100%) rename {media => src/media}/colour-x16.png (100%) rename {media => src/media}/colour-x256.png (100%) rename {media => src/media}/colour-x32.png (100%) rename {media => src/media}/colour-x48.png (100%) rename {media => src/media}/colour-x512.png (100%) rename {media => src/media}/colour.svg (100%) rename {media => src/media}/promo-large.jpg (100%) rename {media => src/media}/promo-marquee.jpg (100%) rename {media => src/media}/promo-small.jpg (100%) diff --git a/.gitignore b/.gitignore index 424379b..6ea139f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# builds +dist/ + # dependencies node_modules/ diff --git a/dep/.github/workflows/update-parents.yml b/dep/.github/workflows/update-parents.yml deleted file mode 100644 index 75094a7..0000000 --- a/dep/.github/workflows/update-parents.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: 'update parent repositories' - -on: - push: - branches: - - main - -jobs: - sync: - name: update parent - runs-on: ubuntu-latest - strategy: - matrix: - repo: ['notion-enhancer/extension', 'notion-enhancer/desktop'] - steps: - - name: checkout repo - uses: actions/checkout@v2 - with: - token: ${{ secrets.CI_TOKEN }} - submodules: true - repository: ${{ matrix.repo }} - - name: pull updates - run: | - git pull --recurse-submodules - git submodule update --remote --recursive - - name: commit changes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: '[${{ github.event.repository.name }}] ${{ github.event.head_commit.message }}' diff --git a/package.json b/package.json index 74e3398..4052aa9 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,9 @@ "license": "MIT", "bin": "bin.mjs", "type": "module", + "scripts": { + "build-ext": "./scripts/build-browser-extension.sh" + }, "engines": { "node": ">=16.x.x" }, diff --git a/scripts/build-browser-extension.sh b/scripts/build-browser-extension.sh new file mode 100755 index 0000000..0150883 --- /dev/null +++ b/scripts/build-browser-extension.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +version=$(node -p "require('./package.json').version") + +cd src +mkdir -p ../dist +rm -f "../dist/notion-enhancer-$version.zip" +zip -r9 "../dist/notion-enhancer-$version.zip" . -x electron/\* \ No newline at end of file diff --git a/scripts/enhance-desktop-app.mjs b/scripts/enhance-desktop-app.mjs old mode 100644 new mode 100755 index a90a154..f95bbdb --- a/scripts/enhance-desktop-app.mjs +++ b/scripts/enhance-desktop-app.mjs @@ -115,13 +115,14 @@ const unpackApp = () => { insertPath = getResourcePath("app/node_modules/notion-enhancer"); if (existsSync(insertPath)) await fsp.rm(insertPath, { recursive: true }); // insert the notion-enhancer/src folder into notion's node_modules folder + const excludedDests = [ + getResourcePath("app/node_modules/notion-enhancer/browser"), + getResourcePath("app/node_modules/notion-enhancer/manifest.json"), + ]; await fsp.cp(srcPath, insertPath, { recursive: true, - filter: (_, dest) => { - // exclude browser-specific files - const browserDest = getResourcePath("app/node_modules/notion-enhancer/browser"); - return dest !== browserDest; - }, + // exclude browser-specific files + filter: (_, dest) => !excludedDests.includes(dest), }); // call patch-desktop-app.mjs on each file const notionScripts = (await readdirDeep(appPath)).filter((file) => file.endsWith(".js")), @@ -135,7 +136,7 @@ const unpackApp = () => { } // create package.json const manifestPath = getResourcePath("app/node_modules/notion-enhancer/package.json"), - insertManifest = { ...manifest, main: "desktop/init.cjs" }; + insertManifest = { ...manifest, main: "electron/init.cjs" }; // remove cli-specific fields delete insertManifest.bin; delete insertManifest.type; diff --git a/scripts/patch-desktop-app.mjs b/scripts/patch-desktop-app.mjs old mode 100644 new mode 100755 diff --git a/dep/README.md b/src/dep/README.md similarity index 100% rename from dep/README.md rename to src/dep/README.md diff --git a/dep/feather-sprite.svg b/src/dep/feather-sprite.svg similarity index 100% rename from dep/feather-sprite.svg rename to src/dep/feather-sprite.svg diff --git a/dep/jscolor.min.js b/src/dep/jscolor.min.js similarity index 100% rename from dep/jscolor.min.js rename to src/dep/jscolor.min.js diff --git a/dep/markdown-it.min.js b/src/dep/markdown-it.min.js similarity index 100% rename from dep/markdown-it.min.js rename to src/dep/markdown-it.min.js diff --git a/dep/mime-db.json b/src/dep/mime-db.json similarity index 100% rename from dep/mime-db.json rename to src/dep/mime-db.json diff --git a/dep/style-vendorizer.mjs b/src/dep/style-vendorizer.mjs similarity index 100% rename from dep/style-vendorizer.mjs rename to src/dep/style-vendorizer.mjs diff --git a/dep/twind-content.mjs b/src/dep/twind-content.mjs similarity index 100% rename from dep/twind-content.mjs rename to src/dep/twind-content.mjs diff --git a/dep/twind-css.mjs b/src/dep/twind-css.mjs similarity index 100% rename from dep/twind-css.mjs rename to src/dep/twind-css.mjs diff --git a/dep/twind.mjs b/src/dep/twind.mjs similarity index 100% rename from dep/twind.mjs rename to src/dep/twind.mjs diff --git a/src/desktop/client.mjs b/src/electron/client.mjs similarity index 100% rename from src/desktop/client.mjs rename to src/electron/client.mjs diff --git a/src/desktop/electronApi.cjs b/src/electron/electronApi.cjs similarity index 100% rename from src/desktop/electronApi.cjs rename to src/electron/electronApi.cjs diff --git a/src/desktop/env/env.mjs b/src/electron/env/env.mjs similarity index 100% rename from src/desktop/env/env.mjs rename to src/electron/env/env.mjs diff --git a/src/desktop/env/fs.mjs b/src/electron/env/fs.mjs similarity index 100% rename from src/desktop/env/fs.mjs rename to src/electron/env/fs.mjs diff --git a/src/desktop/env/storage.mjs b/src/electron/env/storage.mjs similarity index 100% rename from src/desktop/env/storage.mjs rename to src/electron/env/storage.mjs diff --git a/src/desktop/frame.mjs b/src/electron/frame.mjs similarity index 100% rename from src/desktop/frame.mjs rename to src/electron/frame.mjs diff --git a/src/desktop/init.cjs b/src/electron/init.cjs similarity index 100% rename from src/desktop/init.cjs rename to src/electron/init.cjs diff --git a/src/desktop/worker.cjs b/src/electron/worker.cjs similarity index 100% rename from src/desktop/worker.cjs rename to src/electron/worker.cjs diff --git a/src/browser/manifest.json b/src/manifest.json similarity index 84% rename from src/browser/manifest.json rename to src/manifest.json index 4d4d969..36abd33 100644 --- a/src/browser/manifest.json +++ b/src/manifest.json @@ -16,14 +16,14 @@ "browser_action": {}, "background": { "scripts": ["worker.js"] }, "options_ui": { - "page": "repo/menu/menu.html", + "page": "mods/menu/menu.html", "open_in_tab": true }, - "web_accessible_resources": ["env/*", "api/*", "dep/*", "media/*", "repo/*"], + "web_accessible_resources": ["browser/*", "common/*", "dep/*", "media/*", "mods/*"], "content_scripts": [ { "matches": ["https://*.notion.so/*", "https://*.notion.site/*"], - "js": ["init.js"] + "js": ["browser/init.js"] } ], "permissions": ["tabs", "storage", "clipboardRead", "clipboardWrite", "unlimitedStorage"] diff --git a/media/animated.gif b/src/media/animated.gif similarity index 100% rename from media/animated.gif rename to src/media/animated.gif diff --git a/media/blackwhite-x128.png b/src/media/blackwhite-x128.png similarity index 100% rename from media/blackwhite-x128.png rename to src/media/blackwhite-x128.png diff --git a/media/blackwhite-x16.png b/src/media/blackwhite-x16.png similarity index 100% rename from media/blackwhite-x16.png rename to src/media/blackwhite-x16.png diff --git a/media/blackwhite-x256.png b/src/media/blackwhite-x256.png similarity index 100% rename from media/blackwhite-x256.png rename to src/media/blackwhite-x256.png diff --git a/media/blackwhite-x32.png b/src/media/blackwhite-x32.png similarity index 100% rename from media/blackwhite-x32.png rename to src/media/blackwhite-x32.png diff --git a/media/blackwhite-x48.png b/src/media/blackwhite-x48.png similarity index 100% rename from media/blackwhite-x48.png rename to src/media/blackwhite-x48.png diff --git a/media/blackwhite-x512.png b/src/media/blackwhite-x512.png similarity index 100% rename from media/blackwhite-x512.png rename to src/media/blackwhite-x512.png diff --git a/media/blackwhite.svg b/src/media/blackwhite.svg similarity index 100% rename from media/blackwhite.svg rename to src/media/blackwhite.svg diff --git a/media/colour-x128.png b/src/media/colour-x128.png similarity index 100% rename from media/colour-x128.png rename to src/media/colour-x128.png diff --git a/media/colour-x16.png b/src/media/colour-x16.png similarity index 100% rename from media/colour-x16.png rename to src/media/colour-x16.png diff --git a/media/colour-x256.png b/src/media/colour-x256.png similarity index 100% rename from media/colour-x256.png rename to src/media/colour-x256.png diff --git a/media/colour-x32.png b/src/media/colour-x32.png similarity index 100% rename from media/colour-x32.png rename to src/media/colour-x32.png diff --git a/media/colour-x48.png b/src/media/colour-x48.png similarity index 100% rename from media/colour-x48.png rename to src/media/colour-x48.png diff --git a/media/colour-x512.png b/src/media/colour-x512.png similarity index 100% rename from media/colour-x512.png rename to src/media/colour-x512.png diff --git a/media/colour.svg b/src/media/colour.svg similarity index 100% rename from media/colour.svg rename to src/media/colour.svg diff --git a/media/promo-large.jpg b/src/media/promo-large.jpg similarity index 100% rename from media/promo-large.jpg rename to src/media/promo-large.jpg diff --git a/media/promo-marquee.jpg b/src/media/promo-marquee.jpg similarity index 100% rename from media/promo-marquee.jpg rename to src/media/promo-marquee.jpg diff --git a/media/promo-small.jpg b/src/media/promo-small.jpg similarity index 100% rename from media/promo-small.jpg rename to src/media/promo-small.jpg