From 9a42e3c408be34df19c58735eea444d3b0ac37c9 Mon Sep 17 00:00:00 2001 From: camcam-lemon Date: Sat, 30 Nov 2024 17:13:11 +0900 Subject: [PATCH] refactor: create version file and delete loading package.json version Co-authored-by: camcam-lemon --- .github/workflows/release-publish.yml | 7 ++++++- src/index.js | 7 ++----- src/version.js | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 src/version.js diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index 4696779f..85d37209 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -42,7 +42,12 @@ jobs: - name: Prepare release run: npm version --no-git-tag-version --allow-same-version ${{env.RELEASE_VERSION}} - + + - name: Update version file + run: | + echo "export const version = '${{env.RELEASE_VERSION}}'" > src/version.js + git add src/version.js + - name: Convert repository name to lower case run: echo "GITHUB_REPOSITORY_LOWER_CASE=$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV diff --git a/src/index.js b/src/index.js index 407e9034..79944272 100644 --- a/src/index.js +++ b/src/index.js @@ -5,11 +5,8 @@ import { resolve } from 'import-meta-resolve' import path from 'path' import puppeteer from 'puppeteer' import url from 'url' +import { version } from './version.js' -// importing JSON is still experimental in Node.JS https://nodejs.org/docs/latest-v16.x/api/esm.html#json-modules -import { createRequire } from 'module' -const require = createRequire(import.meta.url) -const pkg = require('../package.json') // __dirname is not available in ESM modules by default const __dirname = url.fileURLToPath(new url.URL('.', import.meta.url)) @@ -108,7 +105,7 @@ function parseCommanderInt (value, _unused) { async function cli () { const commander = new Command() commander - .version(pkg.version) + .version(version) .addOption(new Option('-t, --theme [theme]', 'Theme of the chart').choices(['default', 'forest', 'dark', 'neutral']).default('default')) .addOption(new Option('-w, --width [width]', 'Width of the page').argParser(parseCommanderInt).default(800)) .addOption(new Option('-H, --height [height]', 'Height of the page').argParser(parseCommanderInt).default(600)) diff --git a/src/version.js b/src/version.js new file mode 100644 index 00000000..2be0992d --- /dev/null +++ b/src/version.js @@ -0,0 +1 @@ +export const version = '11.4.0'