diff --git a/.husky/pre-commit b/.husky/pre-commit index 863fe55..2312dc5 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,2 +1 @@ -npx ts-node ./check-version.ts npx lint-staged diff --git a/check-version.ts b/check-version.ts deleted file mode 100644 index f993d4c..0000000 --- a/check-version.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { version as hardCodedVersion } from './lib/version'; -import packageJson from './package.json'; - -if (packageJson.version !== hardCodedVersion) { - console.error(`You need to update \`./lib/version.ts\` to match the version in package.json before committing! - -package.json version: \x1B[1;32m${packageJson.version}\x1B[m -hard coded version: \x1B[1;31m${hardCodedVersion}\x1B[m`); - process.exit(1); -} - -process.exit(0); diff --git a/eslint.config.mjs b/eslint.config.mjs index 26cc72c..9950ca5 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -12,7 +12,7 @@ export default [ ignores: ['coverage/**', 'dist/**', 'examples/**', 'node_modules/**'], }, { - files: ['index.ts', 'lib/**/*.ts', 'check-version.ts'], + files: ['index.ts', 'lib/**/*.ts'], languageOptions: { parser: tsParser, parserOptions: { diff --git a/package.json b/package.json index cd90b52..1f5806a 100644 --- a/package.json +++ b/package.json @@ -82,13 +82,14 @@ "repository": "customerio/customerio-node", "scripts": { "test": "nyc ava", + "prebuild": "node scripts/sync-version.js", "build": "tsc -p tsconfig.json", "lint": "eslint .", "lint:fix": "eslint . --fix", "format": "prettier --write .", "prepublishOnly": "npm run build", "prepare": "husky", - "version": "node update-version.js" + "version": "node scripts/sync-version.js && git add lib/version.ts" }, "lint-staged": { "*.{js,json,md,ts,yml,yaml}": "prettier --write", diff --git a/scripts/sync-version.js b/scripts/sync-version.js new file mode 100644 index 0000000..6414f46 --- /dev/null +++ b/scripts/sync-version.js @@ -0,0 +1,5 @@ +const { version } = require('../package.json'); +const { resolve } = require('path'); +const { writeFileSync } = require('fs'); + +writeFileSync(resolve(__dirname, '..', 'lib', 'version.ts'), `export const version = '${version}';\n`); diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 4192953..c5151a7 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -3,5 +3,5 @@ "compilerOptions": { "noEmit": true }, - "include": ["index.ts", "lib/**/*.ts", "test/**/*.ts", "check-version.ts"] + "include": ["index.ts", "lib/**/*.ts", "test/**/*.ts"] } diff --git a/update-version.js b/update-version.js deleted file mode 100644 index 8fed619..0000000 --- a/update-version.js +++ /dev/null @@ -1,5 +0,0 @@ -const packageJson = require('./package.json'); -const { resolve } = require('path'); -const { writeFileSync } = require('fs'); - -writeFileSync(resolve(__dirname, 'lib/version.ts'), `export const version = '${packageJson.version}';\n`);