diff options
| author | Darius Jahandarie <djahandarie@gmail.com> | 2023-09-23 18:05:33 +0900 | 
|---|---|---|
| committer | Darius Jahandarie <djahandarie@gmail.com> | 2023-09-23 23:18:52 +0900 | 
| commit | 6f24ac4e2a1ee8928e0be69bea774bcade28f2a9 (patch) | |
| tree | 0f3cdca6bef987b55559a166fa55cb79fa13598b | |
| parent | 94ccff4c790ae8c2ef301bdb4e593f51436b3c8e (diff) | |
Remove hardcoded version from manifest
* Dynamically set version as argument to build script
* Set version using tag ref_name in CI
* [Cleanup] gitignore ext/manifest.json as it's dynamically generated
| -rw-r--r-- | .github/workflows/ci.yml | 9 | ||||
| -rw-r--r-- | .github/workflows/create-prerelease-on-tag.yml | 2 | ||||
| -rw-r--r-- | .github/workflows/playwright.yml | 9 | ||||
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | CONTRIBUTING.md | 10 | ||||
| -rw-r--r-- | dev/build.js | 12 | ||||
| -rw-r--r-- | dev/data/manifest-variants.json | 2 | ||||
| -rw-r--r-- | ext/manifest.json | 131 | 
8 files changed, 23 insertions, 153 deletions
| diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c62c9893..1b81df2f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,16 +41,11 @@ jobs:          env:            CI: true -      - name: Manifest -        run: npm run test-manifest -        env: -          CI: true +      - name: Build +        run: npm run build        - name: Validate manifest.json of the extension          uses: cardinalby/schema-validator-action@c2da05377e89dd0c9b7be9420da0b3534b1efcce # pin@v1          with:            file: ext/manifest.json            schema: "https://json.schemastore.org/chrome-manifest.json" - -      - name: Build -        run: npm run test-build diff --git a/.github/workflows/create-prerelease-on-tag.yml b/.github/workflows/create-prerelease-on-tag.yml index 06cb8c7e..0999c5ec 100644 --- a/.github/workflows/create-prerelease-on-tag.yml +++ b/.github/workflows/create-prerelease-on-tag.yml @@ -21,7 +21,7 @@ jobs:            node-version-file: ".node-version"        - name: Lint -        run: npm run-script build +        run: npm run-script build -- --yomitan-version ${{ github.ref_name }}          shell: bash        - name: Release diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index a1135157..8efc184a 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -14,13 +14,13 @@ jobs:          run: rm -rf /usr/share/fonts        - uses: actions/checkout@v3 -       +        - name: Install CJK fonts          uses: awalsh128/cache-apt-pkgs-action@1850ee53f6e706525805321a3f2f863dcf73c962 # v1.3.0          with:            packages: fonts-ipafont-mincho            execute_install_scripts: true -         +        - uses: actions/setup-node@v3          with:            cache: "npm" @@ -29,6 +29,9 @@ jobs:        - name: Install dependencies          run: npm ci +      - name: Build +        run: npm run build +        - name: Cache playwright browsers          id: cache-playwright          uses: actions/cache@v3 @@ -40,7 +43,7 @@ jobs:        - if: ${{ steps.cache-playwright.outputs.cache-hit != 'true' }}          name: Install Playwright Browsers          run: npx playwright install chromium -         +        - name: Grab latest dictionaries from dictionaries branch          uses: actions/checkout@v3          with: @@ -6,3 +6,4 @@ dictionaries/  /playwright-report/  /playwright/.cache/  /test/playwright/__screenshots__/ +ext/manifest.json diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ffc76b74..b67f6092 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,9 +50,10 @@ Several command line arguments are available for these scripts:  * `[target]` - Builds a specific target.  * `--all` - Builds all targets specified in [manifest-variants.json](dev/data/manifest-variants.json).  * `--default` - Restores the default manifest file. -* `--manifest <target>` - Overwrites [ext/manifest.json](ext/manifest.json) with the manifest variant for the specified build target. +* `--manifest <target>` - Overwrites `ext/manifest.json` with the manifest variant for the specified build target.  * `--dry-run` - Runs the full build process (excluding zip building), checking that the configuration is valid.  * `--dry-run-build-zip` - If `--dry-run` is also specified, zip building will also be performed in memory; no files are created. +* `--yomitan-version <version>` - Sets the version number in the extension manifest. Defaults to 0.0.0.0 if not set.  If no arguments are specified, the command is equivalent to `build.bat --all`. @@ -66,11 +67,8 @@ Otherwise, the [JSZip](https://stuk.github.io/jszip/) API is used to generate th  ## Manifest  Manifest variants for different build targets are specified in [manifest-variants.json](dev/data/manifest-variants.json). -This file is used to overwrite the [manfiest.json](ext/manifest.json) file included in the extension. -By default, this manifest should be the default `chrome` manifest, and changes to [manfiest.json](ext/manifest.json) should not be committed -unless there is a corresponding change in [manifest-variants.json](dev/data/manifest-variants.json). -There is a continuous integration test which validates this, and the default manifest can be restored by running -`build.bat --default`. +This file is used to generate the `ext/manifest.json` file included in the extension. +The generated `ext/manfiest.json` should not be committed.  ## Style diff --git a/dev/build.js b/dev/build.js index 5222c4c8..24b1e2d0 100644 --- a/dev/build.js +++ b/dev/build.js @@ -108,7 +108,7 @@ function getIndexOfFilePath(array, item) {      return -1;  } -async function build(buildDir, extDir, manifestUtil, variantNames, manifestPath, dryRun, dryRunBuildZip) { +async function build(buildDir, extDir, manifestUtil, variantNames, manifestPath, dryRun, dryRunBuildZip, yomitanVersion) {      const sevenZipExes = ['7za', '7z'];      // Create build directory @@ -130,6 +130,8 @@ async function build(buildDir, extDir, manifestUtil, variantNames, manifestPath,          process.stdout.write(message);      }; +    process.stdout.write(`Version: ${yomitanVersion}...\n`); +      for (const variantName of variantNames) {          const variant = manifestUtil.getVariant(variantName);          if (typeof variant === 'undefined' || variant.buildable === false) { continue; } @@ -148,7 +150,7 @@ async function build(buildDir, extDir, manifestUtil, variantNames, manifestPath,              const fileNameSafe = path.basename(fileName);              const fullFileName = path.join(buildDir, fileNameSafe);              if (!dryRun) { -                fs.writeFileSync(manifestPath, ManifestUtil.createManifestString(modifiedManifest)); +                fs.writeFileSync(manifestPath, ManifestUtil.createManifestString(modifiedManifest).replace('$YOMITAN_VERSION', yomitanVersion));              }              if (!dryRun || dryRunBuildZip) { @@ -183,11 +185,13 @@ async function main(argv) {          ['manifest', null],          ['dry-run', false],          ['dry-run-build-zip', false], +        ['yomitan-version', '0.0.0.0'],          [null, []]      ]));      const dryRun = args.get('dry-run');      const dryRunBuildZip = args.get('dry-run-build-zip'); +    const yomitanVersion = args.get('yomitan-version');      const manifestUtil = new ManifestUtil(); @@ -202,14 +206,14 @@ async function main(argv) {              manifestUtil.getVariants().filter(({buildable}) => buildable !== false).map(({name}) => name) :              args.get(null)          ); -        await build(buildDir, extDir, manifestUtil, variantNames, manifestPath, dryRun, dryRunBuildZip); +        await build(buildDir, extDir, manifestUtil, variantNames, manifestPath, dryRun, dryRunBuildZip, yomitanVersion);      } finally {          // Restore manifest          const manifestName = (!args.get('default') && args.get('manifest') !== null) ? args.get('manifest') : null;          const restoreManifest = manifestUtil.getManifest(manifestName);          process.stdout.write('Restoring manifest...\n');          if (!dryRun) { -            fs.writeFileSync(manifestPath, ManifestUtil.createManifestString(restoreManifest)); +            fs.writeFileSync(manifestPath, ManifestUtil.createManifestString(restoreManifest).replace('$YOMITAN_VERSION', yomitanVersion));          }      }  } diff --git a/dev/data/manifest-variants.json b/dev/data/manifest-variants.json index 304a3a0e..26d91d26 100644 --- a/dev/data/manifest-variants.json +++ b/dev/data/manifest-variants.json @@ -2,7 +2,7 @@      "manifest": {          "manifest_version": 3,          "name": "Yomitan", -        "version": "23.4.7.0", +        "version": "$YOMITAN_VERSION",          "description": "Japanese dictionary with Anki integration",          "author": "TheMoeWay",          "icons": { diff --git a/ext/manifest.json b/ext/manifest.json deleted file mode 100644 index 018a4a0b..00000000 --- a/ext/manifest.json +++ /dev/null @@ -1,131 +0,0 @@ -{ -    "manifest_version": 3, -    "name": "Yomitan", -    "version": "23.4.7.0", -    "description": "Japanese dictionary with Anki integration", -    "author": "TheMoeWay", -    "icons": { -        "16": "images/icon16.png", -        "19": "images/icon19.png", -        "32": "images/icon32.png", -        "38": "images/icon38.png", -        "48": "images/icon48.png", -        "64": "images/icon64.png", -        "128": "images/icon128.png" -    }, -    "action": { -        "default_icon": { -            "16": "images/icon16.png", -            "19": "images/icon19.png", -            "32": "images/icon32.png", -            "38": "images/icon38.png", -            "48": "images/icon48.png", -            "64": "images/icon64.png", -            "128": "images/icon128.png" -        }, -        "default_title": "Yomitan", -        "default_popup": "action-popup.html" -    }, -    "background": { -        "service_worker": "sw.js" -    }, -    "content_scripts": [ -        { -            "run_at": "document_idle", -            "matches": [ -                "http://*/*", -                "https://*/*", -                "file://*/*" -            ], -            "match_about_blank": true, -            "all_frames": true, -            "js": [ -                "js/core.js", -                "js/yomichan.js", -                "js/app/frontend.js", -                "js/app/popup.js", -                "js/app/popup-factory.js", -                "js/app/popup-proxy.js", -                "js/app/popup-window.js", -                "js/app/theme-controller.js", -                "js/comm/api.js", -                "js/comm/cross-frame-api.js", -                "js/comm/frame-ancestry-handler.js", -                "js/comm/frame-client.js", -                "js/comm/frame-offset-forwarder.js", -                "js/data/sandbox/string-util.js", -                "js/dom/dom-text-scanner.js", -                "js/dom/document-util.js", -                "js/dom/text-source-element.js", -                "js/dom/text-source-range.js", -                "js/input/hotkey-handler.js", -                "js/language/text-scanner.js", -                "js/script/dynamic-loader.js", -                "js/app/content-script-main.js" -            ] -        } -    ], -    "minimum_chrome_version": "96.0.0.0", -    "options_ui": { -        "page": "settings.html", -        "open_in_tab": true -    }, -    "sandbox": { -        "pages": [ -            "template-renderer.html" -        ] -    }, -    "permissions": [ -        "storage", -        "clipboardWrite", -        "unlimitedStorage", -        "webRequest", -        "declarativeNetRequest", -        "scripting" -    ], -    "optional_permissions": [ -        "clipboardRead", -        "nativeMessaging" -    ], -    "host_permissions": [ -        "<all_urls>" -    ], -    "commands": { -        "toggleTextScanning": { -            "suggested_key": { -                "default": "Alt+Delete" -            }, -            "description": "Toggle text scanning on/off" -        }, -        "openInfoPage": { -            "description": "Open the info page" -        }, -        "openSettingsPage": { -            "description": "Open the settings page" -        }, -        "openSearchPage": { -            "suggested_key": { -                "default": "Alt+Insert" -            }, -            "description": "Open the search page" -        }, -        "openPopupWindow": { -            "description": "Open the popup window" -        } -    }, -    "web_accessible_resources": [ -        { -            "resources": [ -                "popup.html", -                "template-renderer.html" -            ], -            "matches": [ -                "<all_urls>" -            ] -        } -    ], -    "content_security_policy": { -        "extension_pages": "default-src 'self'; img-src blob: 'self'; style-src 'self' 'unsafe-inline'; media-src *; connect-src *", -        "sandbox": "sandbox allow-scripts; default-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'unsafe-inline'" -    } -} |