From 6d69a5172903241ba5d042f47a010feaa8322437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Thu, 14 Sep 2023 17:58:13 +0200 Subject: [PATCH] chore(cli): inline version --- .gitignore | 1 + package.json | 5 +++-- packages/cli/package.json | 2 ++ packages/cli/scripts/inline-version.mjs | 9 +++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 packages/cli/scripts/inline-version.mjs diff --git a/.gitignore b/.gitignore index e796c1f4b..66c869471 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ node_modules packages/formatters/src/html/templates.ts packages/cli/binaries +packages/cli/src/version.ts /test-harness/tmp/ /test-harness/tests/ packages/*/dist diff --git a/package.json b/package.json index 6cb5dda0f..86c3c9cf7 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "scripts": { "clean": "rimraf .cache packages/*/{dist,.cache}", "prebuild": "yarn workspaces foreach run prebuild", - "build": "yarn prebuild && tsc --build ./tsconfig.build.json", + "build": "yarn prebuild && tsc --build ./tsconfig.build.json && yarn postbuild", + "postbuild": "yarn workspaces foreach run postbuild", "prelint": "yarn workspaces foreach run prelint", "lint": "yarn prelint && yarn lint.prettier && yarn lint.eslint", "lint.fix": "yarn lint.prettier --write && yarn lint.eslint --fix", @@ -37,7 +38,7 @@ "test.harness": "yarn pretest.harness && jest -c test-harness/jest.config.mjs", "test.jest": "jest --silent --cacheDirectory=.cache/.jest", "test.karma": "karma start", - "prepare": "husky install", + "prepare": "husky install && yarn workspaces foreach run prepare", "prerelease": "patch-package", "release": "yarn prerelease && multi-semantic-release --deps.bump=satisfy", "jest": "jest" diff --git a/packages/cli/package.json b/packages/cli/package.json index c174dbd1d..d67f46570 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -24,6 +24,8 @@ "url": "https://github.com/stoplightio/spectral.git" }, "scripts": { + "prepare": "node scripts/inline-version.mjs", + "postbuild": "node scripts/inline-version.mjs", "build.binary": "pkg . --output ./binaries/spectral", "build.windows": "pkg . --targets windows --out-path ./binaries", "build.nix": "pkg . --targets linux-x64,linux-arm64,macos-x64,macos-arm64,alpine-x64,alpine-arm64 --out-path ./binaries", diff --git a/packages/cli/scripts/inline-version.mjs b/packages/cli/scripts/inline-version.mjs new file mode 100644 index 000000000..0f809a8d6 --- /dev/null +++ b/packages/cli/scripts/inline-version.mjs @@ -0,0 +1,9 @@ +import * as fs from 'node:fs/promises'; +import { fileURLToPath } from 'node:url'; +import { join } from 'node:path'; + +const cwd = join(fileURLToPath(import.meta.url), '../..'); + +const { version } = JSON.parse(await fs.readFile(join(cwd, 'package.json'), 'utf8')); + +await fs.writeFile(join(cwd, 'src/version.ts'), `export const VERSION = '${version}';\n`);