Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npx @build-in-blocks/dev.setup@1.0.4 dev:internal:lint
blocks.pkg.dev.setup dev:internal:lint
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
# -------------------------------------------------
Expand Down
20 changes: 11 additions & 9 deletions bin/pkg.internal.cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -58,19 +58,20 @@
// husky folder, with content that includes pre-commit file.
// ---------------------------------------------------------
if (command === userAppArg.huskyGitSetup) {
console.log('[PREPARING] Setting up husky git hooks...');

Check warning on line 61 in bin/pkg.internal.cli.js

View workflow job for this annotation

GitHub Actions / validate (23.x)

Unexpected console statement

Check warning on line 61 in bin/pkg.internal.cli.js

View workflow job for this annotation

GitHub Actions / validate (20.x)

Unexpected console statement

Check warning on line 61 in bin/pkg.internal.cli.js

View workflow job for this annotation

GitHub Actions / validate (22.x)

Unexpected console statement

Check warning on line 61 in bin/pkg.internal.cli.js

View workflow job for this annotation

GitHub Actions / validate (24.x)

Unexpected console statement

Check warning on line 61 in bin/pkg.internal.cli.js

View workflow job for this annotation

GitHub Actions / validate (25.x)

Unexpected console statement
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 });

console.log('[SUCCESS] Husky git hooks integrated successfully.');

Check warning on line 74 in bin/pkg.internal.cli.js

View workflow job for this annotation

GitHub Actions / validate (23.x)

Unexpected console statement

Check warning on line 74 in bin/pkg.internal.cli.js

View workflow job for this annotation

GitHub Actions / validate (20.x)

Unexpected console statement

Check warning on line 74 in bin/pkg.internal.cli.js

View workflow job for this annotation

GitHub Actions / validate (22.x)

Unexpected console statement

Check warning on line 74 in bin/pkg.internal.cli.js

View workflow job for this annotation

GitHub Actions / validate (24.x)

Unexpected console statement

Check warning on line 74 in bin/pkg.internal.cli.js

View workflow job for this annotation

GitHub Actions / validate (25.x)

Unexpected console statement
} catch {
blocksTerminalLogger({
startLoggerMessageOnNewLine: true,
Expand Down Expand Up @@ -105,7 +106,7 @@
// 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,
Expand All @@ -119,7 +120,8 @@
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,
Expand Down
8 changes: 7 additions & 1 deletion config.root/root.js
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -30,4 +33,7 @@ export {
binPath,
//-
internalPkgJSON,
//-
isWindowsOS,
windowsCmdextension,
};
19 changes: 1 addition & 18 deletions docs.release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Loading