diff --git a/.husky/pre-commit b/.husky/pre-commit index e5f6132..d76502e 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1 @@ -npx @build-in-blocks/dev.setup@1.0.4 dev:internal:lint \ No newline at end of file +blocks.pkg.dev.setup dev:internal:lint \ No newline at end of file diff --git a/README.md b/README.md index c3d2fa6..20409a4 100644 --- a/README.md +++ b/README.md @@ -107,19 +107,27 @@ export default { > [!NOTE] > **Before you proceed with husky setup:** Your project must be a git repository, and you must have made at least one commit to git. If you have done that already, then proceed to follow the husky-related step below. If it's not a git repository, first run the `git init` command at the root of your project to initialize it as a git repository, add and commit one or more files to git as needed, then proceed to follow the husky-related steps below. -- Add this prepare script to your `package.json` scripts: +- **Add the prepare script:** In your web project's `package.json` file, add the `prepare` script. - ```` - "scripts": { - "prepare": "npx @build-in-blocks/dev.setup@1.0.4 dev:husky:setup:git", - // your other npm scripts in your project goes here as usual - }, - ```` + - For `macOS` and `linux`, use: - > [!IMPORTANT] - > About `@build-in-blocks/dev.setup@[VERSION_NUMBER_HERE]` in the script: Make sure the version number used your in your `prepare` script is the same as the version of the `@build-in-blocks/dev.setup` package in your `package.json` file's `devDependencies`. + ```` + "scripts": { + "prepare": "blocks.pkg.dev.setup dev:husky:setup:git" + // your other npm scripts in your project goes here as usual + }, + ```` + + - For `windows OS`, use: + + ```` + "scripts": { + "prepare": "blocks.pkg.dev.setup.cmd dev:husky:setup:git" + // your other npm scripts in your project goes here as usual + }, + ```` -- Initialize husky and lint-staged by running this script command: +- **Init git hooks:** Initialize `husky` and `lint-staged` git hooks by running this script command: ```` npm run prepare @@ -206,7 +214,7 @@ export default { # ----------------------------------------------------------------- # This points to the shared library repository's "central" workflow # ----------------------------------------------------------------- - uses: build-in-blocks/dev.setup/.github/workflows/central-blocks-ci.yml@v1.0.4 + uses: build-in-blocks/dev.setup/.github/workflows/central-blocks-ci.yml@v1.0.5 with: run_tests: true # ------------------------------------------------- diff --git a/bin/pkg.internal.cli.js b/bin/pkg.internal.cli.js index b8b189d..7af99ba 100755 --- a/bin/pkg.internal.cli.js +++ b/bin/pkg.internal.cli.js @@ -4,9 +4,9 @@ import { fs, path, execSync, process } from '../config.root/external.packages.js'; import { blocksTerminalLogger } from '../config.root/blocks.packages.js'; -import { internalPkgJSON, __dirname } from '../config.root/root.js'; +import { internalPkgJSON, __dirname, isWindowsOS, windowsCmdextension } from '../config.root/root.js'; -const internalCommand = '@build-in-blocks/dev.setup@1.0.4'; +const internalCommand = 'blocks.pkg.dev.setup'; const userAppArg = { huskyGitSetup: 'dev:husky:setup:git', @@ -60,13 +60,14 @@ if (pkgArgDetected) { if (command === userAppArg.huskyGitSetup) { console.log('[PREPARING] Setting up husky git hooks...'); try { - execSync(`node "${huskyBin}"`, { stdio: 'inherit' }); + const huskyInitCmd = isWindowsOS ? `husky${windowsCmdextension}` : `node "${huskyBin}"`; // This check makes it compatible with Windows OS (in production) + execSync(huskyInitCmd, { stdio: 'inherit' }); const preCommitPath = path.join(userAppRoot, '.husky/pre-commit'); - //------------------------------------------------------------------------------------- - // Use 'npx @build-in-blocks/[library] [command]' to ensure portability in the User App - //------------------------------------------------------------------------------------- - const hookContent = `npx ${internalCommand} ${userAppArg.internalLint}`; + //------------------------------------------------------------------------- + // Use the (original) internalCommand to ensure portability in the User App + //------------------------------------------------------------------------- + const hookContent = `${internalCommand} ${userAppArg.internalLint}`; fs.writeFileSync(preCommitPath, hookContent, { mode: 0o755 }); @@ -105,7 +106,7 @@ if (pkgArgDetected) { // Check to detect the correct PATH key. Treat the PATH // difference between windows OS and other OS. //----------------------------------------------------- - const pathKey = process.platform === 'win32' ? Object.keys(process.env).find((k) => k.toUpperCase() === 'PATH') || 'PATH' : 'PATH'; + const pathKey = isWindowsOS ? Object.keys(process.env).find((k) => k.toUpperCase() === 'PATH') || 'PATH' : 'PATH'; const env = { ...process.env, @@ -119,7 +120,8 @@ if (pkgArgDetected) { LINT_STAGED_BACKUP: '0', }; - execSync(`node "${lintStagedBin}" --config "${configPath}"`, { + const lintStagedBinCmd = isWindowsOS ? `lint-staged${windowsCmdextension}` : `node "${lintStagedBin}"`; // This check makes it compatible with Windows OS (in production) + execSync(`${lintStagedBinCmd} --config "${configPath}"`, { stdio: 'inherit', cwd: userAppRoot, env, diff --git a/config.root/root.js b/config.root/root.js index b3d4dbb..2dc25a9 100644 --- a/config.root/root.js +++ b/config.root/root.js @@ -1,4 +1,4 @@ -import { fs, path, fileURLToPath, createRequire } from './external.packages.js'; +import { fs, path, fileURLToPath, createRequire, process } from './external.packages.js'; // ------------------------------------------------ // ESM & Resolution Helpers: @@ -19,6 +19,9 @@ const binPath = ({ pkgName, binSubPath }) => { const internalProjectRoot = path.join(__dirname, '../', 'package.json'); const internalPkgJSON = JSON.parse(fs.readFileSync(internalProjectRoot, 'utf-8')); +const isWindowsOS = process.platform === 'win32'; +const windowsCmdextension = '.cmd'; + export { //------------------------------- // Export global access variables @@ -30,4 +33,7 @@ export { binPath, //- internalPkgJSON, + //- + isWindowsOS, + windowsCmdextension, }; diff --git a/docs.release/README.md b/docs.release/README.md index d7f0be2..bb2c7ba 100644 --- a/docs.release/README.md +++ b/docs.release/README.md @@ -13,26 +13,9 @@ #### This library -- Change version number in `pkg.internal.cli.js` and `pre-commit` files. -- In the **root README** always remember to change version number: - - In `@build-in-blocks/dev.setup@[VERSION_NUMBER]` for the npm scripts part of the docs too, as you bump up the `package.json` version. - - For the .yml file's `call-shared-logic` in `uses: build-in-blocks/dev.setup/.github/workflows/central-blocks-ci.yml@v[VERSION_NUMBER_HERE]`. +- In the **root README** always remember to change version number for the .yml file's `call-shared-logic` in `uses: build-in-blocks/dev.setup/.github/workflows/central-blocks-ci.yml@v[VERSION_NUMBER_HERE]`, to match with that the version bump for `package.json`. - You may want to use your code editor's global search to ensure that there are no other places that need this version number change. - -# - -#### Connected user apps - -- Before release (of your "user app" i.e. especially if it's a web library to be published), you always have to check that npx is referencing the correct/updated version in the scripts section of the package.json e.g. @1.0.0 in this case. - - ```` - "scripts": { - "prepare": "npx @build-in-blocks/dev.setup@1.0.0 dev:husky:setup:git" - // your other npm scripts in your project goes here as usual - }, - ```` - # #### Build in blocks libraries in general diff --git a/package-lock.json b/package-lock.json index cf30998..4953d3f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@build-in-blocks/dev.setup", - "version": "1.0.4", + "version": "1.0.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@build-in-blocks/dev.setup", - "version": "1.0.4", + "version": "1.0.5", "license": "AGPL-3.0", "dependencies": { "@eslint/js": "^10.0.1", @@ -1266,9 +1266,9 @@ } }, "node_modules/prettier": { - "version": "3.8.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.8.1.tgz", - "integrity": "sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg==", + "version": "3.8.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.8.2.tgz", + "integrity": "sha512-8c3mgTe0ASwWAJK+78dpviD+A8EqhndQPUBpNUIPt6+xWlIigCwfN01lWr9MAede4uqXGTEKeQWTvzb3vjia0Q==", "license": "MIT", "bin": { "prettier": "bin/prettier.cjs" diff --git a/package.json b/package.json index 50f46d9..b904559 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@build-in-blocks/dev.setup", - "version": "1.0.4", + "version": "1.0.5", "description": "Code linting, formatting, pre-commit hook and GitHub Actions Continuous Integration (CI) (including node version compatiblity check) development environment setup for your typescript code repository", "type": "module", "main": "config.programmed/eslint.helper.mjs",