@programinglive/commiter 1.1.0 โ 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/bug_report.md +28 -28
- package/.github/ISSUE_TEMPLATE/config.yml +5 -5
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -20
- package/.github/PULL_REQUEST_TEMPLATE.md +24 -24
- package/CHANGELOG.md +59 -43
- package/CODE_OF_CONDUCT.md +36 -36
- package/LICENSE +21 -21
- package/PRD.md +86 -0
- package/PUBLISH.md +142 -142
- package/README.md +187 -187
- package/SECURITY.md +30 -30
- package/commitlint.config.cjs +4 -4
- package/docs/prd-fs-f-ok-warning.md +47 -0
- package/docs/release-notes/RELEASE_NOTES.md +52 -0
- package/docs/release-notes/fs-f-ok-warning.md +14 -0
- package/index.js +148 -148
- package/package.json +94 -94
- package/scripts/preload/fs-f-ok.cjs +23 -0
- package/scripts/release.js +127 -4
- package/scripts/update-release-notes.js +182 -0
package/SECURITY.md
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
# Security Policy
|
|
2
|
-
|
|
3
|
-
## Reporting a Vulnerability
|
|
4
|
-
|
|
5
|
-
If you discover a security vulnerability in `@programinglive/commiter`, please report it responsibly.
|
|
6
|
-
|
|
7
|
-
Send your report to: [security@programinglive.com](mailto:security@programinglive.com).
|
|
8
|
-
|
|
9
|
-
Please include:
|
|
10
|
-
- A detailed description of the vulnerability
|
|
11
|
-
- Steps to reproduce the issue
|
|
12
|
-
- Any potential impact
|
|
13
|
-
- Optional: Suggested mitigation or patch
|
|
14
|
-
|
|
15
|
-
We aim to respond within **48 hours** and will keep you informed of our progress.
|
|
16
|
-
|
|
17
|
-
## Supported Versions
|
|
18
|
-
|
|
19
|
-
We support the latest released version of the package. Please ensure you are running the most recent version before reporting issues.
|
|
20
|
-
|
|
21
|
-
## Disclosure Policy
|
|
22
|
-
|
|
23
|
-
We follow a coordinated disclosure process:
|
|
24
|
-
1. Acknowledge receipt of your report within 48 hours
|
|
25
|
-
2. Assess the vulnerability and determine severity
|
|
26
|
-
3. Fix the issue and prepare a release
|
|
27
|
-
4. Credit the reporter (if desired)
|
|
28
|
-
5. Publish a security advisory detailing the fix
|
|
29
|
-
|
|
30
|
-
Thank you for helping keep our project secure!
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting a Vulnerability
|
|
4
|
+
|
|
5
|
+
If you discover a security vulnerability in `@programinglive/commiter`, please report it responsibly.
|
|
6
|
+
|
|
7
|
+
Send your report to: [security@programinglive.com](mailto:security@programinglive.com).
|
|
8
|
+
|
|
9
|
+
Please include:
|
|
10
|
+
- A detailed description of the vulnerability
|
|
11
|
+
- Steps to reproduce the issue
|
|
12
|
+
- Any potential impact
|
|
13
|
+
- Optional: Suggested mitigation or patch
|
|
14
|
+
|
|
15
|
+
We aim to respond within **48 hours** and will keep you informed of our progress.
|
|
16
|
+
|
|
17
|
+
## Supported Versions
|
|
18
|
+
|
|
19
|
+
We support the latest released version of the package. Please ensure you are running the most recent version before reporting issues.
|
|
20
|
+
|
|
21
|
+
## Disclosure Policy
|
|
22
|
+
|
|
23
|
+
We follow a coordinated disclosure process:
|
|
24
|
+
1. Acknowledge receipt of your report within 48 hours
|
|
25
|
+
2. Assess the vulnerability and determine severity
|
|
26
|
+
3. Fix the issue and prepare a release
|
|
27
|
+
4. Credit the reporter (if desired)
|
|
28
|
+
5. Publish a security advisory detailing the fix
|
|
29
|
+
|
|
30
|
+
Thank you for helping keep our project secure!
|
package/commitlint.config.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
extends: ['@commitlint/config-conventional'],
|
|
3
|
-
ignores: [(message) => message.startsWith('chore(release):')]
|
|
4
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: ['@commitlint/config-conventional'],
|
|
3
|
+
ignores: [(message) => message.startsWith('chore(release):')]
|
|
4
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# PRD: Eliminate `fs.F_OK` Deprecation Warning During Releases
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
`standard-version@9.5.0` uses the deprecated `fs.F_OK` constant when ensuring the changelog file exists. When `scripts/release.js` executed, Node.js v20+ surfaced `[DEP0176]` warnings, creating noise in CI/CD logs and confusing maintainers about potential breakages.
|
|
5
|
+
|
|
6
|
+
## Goals
|
|
7
|
+
- Prevent the deprecation warning without forking or manually editing `node_modules`.
|
|
8
|
+
- Keep the mitigation self-contained within the Commiter codebase so dependency upgrades remain safe.
|
|
9
|
+
- Preserve existing release behaviour (tests, standard-version invocation, CLI API).
|
|
10
|
+
|
|
11
|
+
## Non-Goals
|
|
12
|
+
- Upgrading `standard-version` or other dependencies.
|
|
13
|
+
- Patching unrelated lifecycle scripts that do not trigger the warning.
|
|
14
|
+
- Changing user-facing configuration or CLI commands.
|
|
15
|
+
|
|
16
|
+
## Target Users
|
|
17
|
+
- Repository maintainers who run `npm run release*` scripts and expect clean logs.
|
|
18
|
+
- CI pipelines that rely on warning-free output to detect regressions.
|
|
19
|
+
|
|
20
|
+
## Functional Requirements
|
|
21
|
+
1. Release commands must execute without emitting the `fs.F_OK` deprecation warning.
|
|
22
|
+
2. The fix must apply automatically whenever the bundled release helper runs.
|
|
23
|
+
3. Commiter must continue to run project tests prior to executing `standard-version`.
|
|
24
|
+
4. All existing automated tests must remain green.
|
|
25
|
+
|
|
26
|
+
## Technical Approach
|
|
27
|
+
- Introduce `scripts/preload/fs-f-ok.cjs` that monkey patches Node's module loader for `standard-version/lib/lifecycles/changelog`, rewriting `fs.F_OK` to `fs.constants.F_OK` in-memory before the module executes.
|
|
28
|
+
- Ensure every Commiter-managed release process uses the preload script by appending `--require <preload>` to `NODE_OPTIONS` for the spawned `standard-version` child process.
|
|
29
|
+
- Retain a local require of the preload script in `scripts/release.js` so unit tests that run in-process also benefit.
|
|
30
|
+
|
|
31
|
+
## Success Metrics
|
|
32
|
+
- Running `node scripts/release.js --help` (or any release command) no longer emits `[DEP0176]`.
|
|
33
|
+
- Automated test suite (`npm test`) passes without new failures.
|
|
34
|
+
|
|
35
|
+
## Testing Plan
|
|
36
|
+
- Extend test coverage with `test/fs-f-ok-preload.test.js` to verify `fs.F_OK` is aligned with `fs.constants.F_OK` after loading the release helper.
|
|
37
|
+
- Update existing release unit tests to assert the spawn sequence now includes the `--require` preload flag.
|
|
38
|
+
- Execute `node --test` locally and in CI to validate.
|
|
39
|
+
|
|
40
|
+
## Risks & Mitigations
|
|
41
|
+
- **Upstream Changes**: Future `standard-version` versions may restructure files. Mitigate by scoping the preload to the exact module path and gracefully skipping if no replacement is required.
|
|
42
|
+
- **Environment Variable Collisions**: Appending to `NODE_OPTIONS` could conflict with user-provided values. Mitigate by concatenating (instead of overriding) existing options.
|
|
43
|
+
- **Windows Path Quoting**: Preload flag builder escapes quotes and wraps paths containing spaces to avoid spawn failures on Windows.
|
|
44
|
+
|
|
45
|
+
## Rollout Plan
|
|
46
|
+
- Ship change in the next patch release (v1.1.x).
|
|
47
|
+
- Communicate via release notes and CHANGELOG updates once published.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Commiter Release Notes
|
|
2
|
+
|
|
3
|
+
This document summarizes every published version of `@programinglive/commiter`. Refer to the generated [CHANGELOG](../../CHANGELOG.md) for commit-level details.
|
|
4
|
+
|
|
5
|
+
| Version | Date | Highlights |
|
|
6
|
+
|---------|------|------------|
|
|
7
|
+
| 1.1.3 | 2025-11-05 | See CHANGELOG for details. |
|
|
8
|
+
| 1.1.2 | 2025-11-05 | auto-update release notes during release (99d1043) |
|
|
9
|
+
| 1.1.1 | 2025-11-05 | ๐ Bug Fix โ removed the fs.F_OK deprecation warning from release runs. |
|
|
10
|
+
| 1.1.0 | 2025-10-29 | ๐ Documentation โ clarified release automation flow. |
|
|
11
|
+
| 1.0.12 | 2025-10-29 | โจ Feature โ autodetects project test command before releasing. |
|
|
12
|
+
| 1.0.11 | 2025-10-29 | ๐ Documentation โ added project status and download badges. |
|
|
13
|
+
| 1.0.10 | 2025-10-29 | Maintenance release; no additional notes provided. |
|
|
14
|
+
| 1.0.9 | 2025-10-29 | โจ Feature โ introduced a new capability (see changelog commit `e1603c1`). |
|
|
15
|
+
| 1.0.8 | 2025-10-29 | โจ Feature โ added release helper script and tests. |
|
|
16
|
+
| 1.0.7 | 2025-10-29 | โจ Feature โ added release helper script and tests. |
|
|
17
|
+
| 1.0.6 | 2025-10-19 | Maintenance release; no additional notes provided. |
|
|
18
|
+
| 1.0.5 | 2025-10-19 | ๐ Bug Fix โ allowed release commits to include emoji. |
|
|
19
|
+
| 1.0.4 | 2025-10-19 | ๐ Bug Fix โ ensured safe default test script for initial release. |
|
|
20
|
+
| 1.0.3 | 2025-10-19 | Maintenance release; no additional notes provided. |
|
|
21
|
+
| 1.0.2 | 2025-10-19 | Maintenance release; no additional notes provided. |
|
|
22
|
+
| 1.0.1 | 2025-10-18 | ๐ Bug Fix โ aligned commitlint config with project module type. |
|
|
23
|
+
| 1.0.0 | 2025-10-17 | โจ Initial release โ bootstrapped conventional release tooling; added community docs and metadata. |
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## 1.1.3
|
|
28
|
+
|
|
29
|
+
Released on **2025-11-05**.
|
|
30
|
+
|
|
31
|
+
- See CHANGELOG for details.
|
|
32
|
+
|
|
33
|
+
## 1.1.2 โ ๐งน Chores
|
|
34
|
+
|
|
35
|
+
Released on **2025-11-05**.
|
|
36
|
+
|
|
37
|
+
- auto-update release notes during release (99d1043)
|
|
38
|
+
|
|
39
|
+
## 1.1.1 โ fs.F_OK Deprecation Warning Fix
|
|
40
|
+
|
|
41
|
+
Released on **2025-11-05**.
|
|
42
|
+
- Eliminated the `[DEP0176] fs.F_OK` warning emitted during release commands by injecting a preload script that transparently rewrites `fs.F_OK` usage inside `standard-version`.
|
|
43
|
+
- Ensured the preload script runs for both in-process unit tests and the child process that executes `standard-version` by appending a `--require` flag to `NODE_OPTIONS`.
|
|
44
|
+
- Updated the test suite to cover the preload behaviour and the adjusted release workflow, switching the project to Nodeโs built-in test runner (`node --test`).
|
|
45
|
+
|
|
46
|
+
### Impact
|
|
47
|
+
- Release logs are now warning-free, reducing CI noise and operator confusion.
|
|
48
|
+
- Future dependency updates remain safe because no files under `node_modules` are modified.
|
|
49
|
+
- The new tests guard against regressions in the preload integration.
|
|
50
|
+
|
|
51
|
+
### Testing
|
|
52
|
+
- `node --test`
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Release Notes: Fix fs.F_OK Deprecation Warning
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
- Eliminated the `[DEP0176] fs.F_OK` warning emitted during release commands by injecting a preload script that transparently rewrites `fs.F_OK` usage inside `standard-version`.
|
|
5
|
+
- Ensured the preload script runs for both in-process unit tests and the child process that executes `standard-version` by appending a `--require` flag to `NODE_OPTIONS`.
|
|
6
|
+
- Updated the test suite to cover the preload behaviour and the adjusted release workflow, switching the project to Nodeโs built-in test runner (`node --test`).
|
|
7
|
+
|
|
8
|
+
## Impact
|
|
9
|
+
- Release logs are now warning-free, reducing CI noise and operator confusion.
|
|
10
|
+
- Future dependency updates remain safe because no files under `node_modules` are modified.
|
|
11
|
+
- The new tests guard against regressions in the preload integration.
|
|
12
|
+
|
|
13
|
+
## Testing
|
|
14
|
+
- `node --test`
|
package/index.js
CHANGED
|
@@ -1,148 +1,148 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Commiter - Commit convention tooling for standard-version releases
|
|
5
|
-
*
|
|
6
|
-
* This package helps enforce conventional commits and automate releases
|
|
7
|
-
* with beautiful changelogs featuring icons for each commit type.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const { execSync } = require('child_process');
|
|
11
|
-
const fs = require('fs');
|
|
12
|
-
const path = require('path');
|
|
13
|
-
|
|
14
|
-
function ensureSafeTestScript(scripts = {}) {
|
|
15
|
-
const defaultFailingTestScript = 'echo "Error: no test specified" && exit 1';
|
|
16
|
-
if (!scripts.test || scripts.test === defaultFailingTestScript) {
|
|
17
|
-
scripts.test = 'echo "No tests specified"';
|
|
18
|
-
}
|
|
19
|
-
return scripts;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function setupCommiter() {
|
|
23
|
-
console.log('๐ Setting up Commiter...\n');
|
|
24
|
-
|
|
25
|
-
// Check if package.json exists
|
|
26
|
-
if (!fs.existsSync('package.json')) {
|
|
27
|
-
console.error('โ Error: package.json not found. Please run this in a Node.js project directory.');
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
// Install dependencies
|
|
33
|
-
console.log('๐ฆ Installing dependencies...');
|
|
34
|
-
execSync('npm install --save-dev standard-version @commitlint/cli @commitlint/config-conventional husky', {
|
|
35
|
-
stdio: 'inherit'
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// Read package.json
|
|
39
|
-
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
40
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
41
|
-
|
|
42
|
-
packageJson.scripts = ensureSafeTestScript(packageJson.scripts || {});
|
|
43
|
-
// Add scripts
|
|
44
|
-
packageJson.scripts.prepare = 'husky';
|
|
45
|
-
packageJson.scripts.release = 'node scripts/release.js';
|
|
46
|
-
packageJson.scripts['release:major'] = 'node scripts/release.js major';
|
|
47
|
-
packageJson.scripts['release:minor'] = 'node scripts/release.js minor';
|
|
48
|
-
packageJson.scripts['release:patch'] = 'node scripts/release.js patch';
|
|
49
|
-
|
|
50
|
-
// Add standard-version config
|
|
51
|
-
packageJson['standard-version'] = {
|
|
52
|
-
releaseCommitMessageFormat: 'chore(release): {{currentTag}} ๐',
|
|
53
|
-
types: [
|
|
54
|
-
{ type: 'feat', section: 'โจ Features' },
|
|
55
|
-
{ type: 'fix', section: '๐ Bug Fixes' },
|
|
56
|
-
{ type: 'perf', section: 'โก Performance' },
|
|
57
|
-
{ type: 'refactor', section: 'โป๏ธ Refactors' },
|
|
58
|
-
{ type: 'docs', section: '๐ Documentation' },
|
|
59
|
-
{ type: 'style', section: '๐ Styles' },
|
|
60
|
-
{ type: 'test', section: 'โ
Tests' },
|
|
61
|
-
{ type: 'build', section: '๐๏ธ Build System' },
|
|
62
|
-
{ type: 'ci', section: '๐ท Continuous Integration' },
|
|
63
|
-
{ type: 'chore', section: '๐งน Chores' },
|
|
64
|
-
{ type: 'revert', section: 'โช Reverts' }
|
|
65
|
-
]
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// Write updated package.json
|
|
69
|
-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
|
|
70
|
-
|
|
71
|
-
// Create release helper script
|
|
72
|
-
console.log('๐ ๏ธ Creating release helper script...');
|
|
73
|
-
const releaseScriptDir = path.join(process.cwd(), 'scripts');
|
|
74
|
-
if (!fs.existsSync(releaseScriptDir)) {
|
|
75
|
-
fs.mkdirSync(releaseScriptDir, { recursive: true });
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const releaseScriptPath = path.join(releaseScriptDir, 'release.js');
|
|
79
|
-
const releaseScriptSource = path.join(__dirname, 'scripts', 'release.js');
|
|
80
|
-
const releaseScriptContent = fs.readFileSync(releaseScriptSource, 'utf8');
|
|
81
|
-
|
|
82
|
-
fs.writeFileSync(releaseScriptPath, releaseScriptContent + '\n');
|
|
83
|
-
try {
|
|
84
|
-
fs.chmodSync(releaseScriptPath, 0o755);
|
|
85
|
-
} catch (error) {
|
|
86
|
-
// Ignore chmod errors on non-POSIX systems
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Determine commitlint config format based on project module type
|
|
90
|
-
const isEsmProject = packageJson.type === 'module';
|
|
91
|
-
const commitlintConfigFile = isEsmProject ? 'commitlint.config.js' : 'commitlint.config.cjs';
|
|
92
|
-
const commitlintConfigContent = isEsmProject
|
|
93
|
-
? `export default {
|
|
94
|
-
extends: ['@commitlint/config-conventional'],
|
|
95
|
-
ignores: [(message) => message.startsWith('chore(release):')]
|
|
96
|
-
}\n`
|
|
97
|
-
: `module.exports = {
|
|
98
|
-
extends: ['@commitlint/config-conventional'],
|
|
99
|
-
ignores: [(message) => message.startsWith('chore(release):')]
|
|
100
|
-
}\n`;
|
|
101
|
-
|
|
102
|
-
const legacyCommitlintConfigFile = isEsmProject ? 'commitlint.config.cjs' : 'commitlint.config.js';
|
|
103
|
-
if (fs.existsSync(legacyCommitlintConfigFile)) {
|
|
104
|
-
fs.rmSync(legacyCommitlintConfigFile);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
console.log(`โ๏ธ Creating commitlint config (${commitlintConfigFile})...`);
|
|
108
|
-
fs.writeFileSync(commitlintConfigFile, commitlintConfigContent);
|
|
109
|
-
|
|
110
|
-
// Initialize Husky
|
|
111
|
-
console.log('๐ถ Setting up Husky...');
|
|
112
|
-
execSync('npx husky init', { stdio: 'inherit' });
|
|
113
|
-
|
|
114
|
-
// Create commit-msg hook
|
|
115
|
-
const huskyDir = path.join(process.cwd(), '.husky');
|
|
116
|
-
if (!fs.existsSync(huskyDir)) {
|
|
117
|
-
fs.mkdirSync(huskyDir, { recursive: true });
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const commitMsgHook = `#!/usr/bin/env sh
|
|
121
|
-
|
|
122
|
-
npx --no -- commitlint --edit "$1"
|
|
123
|
-
`;
|
|
124
|
-
fs.writeFileSync(path.join(huskyDir, 'commit-msg'), commitMsgHook);
|
|
125
|
-
fs.chmodSync(path.join(huskyDir, 'commit-msg'), 0o755);
|
|
126
|
-
|
|
127
|
-
console.log('\nโ
Commiter setup complete!\n');
|
|
128
|
-
console.log('๐ Available commands:');
|
|
129
|
-
console.log(' npm run release major - Create a major release (1.0.0 โ 2.0.0)');
|
|
130
|
-
console.log(' npm run release minor - Create a minor release (1.0.0 โ 1.1.0)');
|
|
131
|
-
console.log(' npm run release patch - Create a patch release (1.0.0 โ 1.0.1)');
|
|
132
|
-
console.log(' npm run release - Auto-detect version bump');
|
|
133
|
-
console.log(' npm run release -- --prerelease beta - Create a beta prerelease\n');
|
|
134
|
-
console.log('๐ฏ Commit format: type(scope): subject');
|
|
135
|
-
console.log(' Example: feat(auth): add user login\n');
|
|
136
|
-
|
|
137
|
-
} catch (error) {
|
|
138
|
-
console.error('โ Error during setup:', error.message);
|
|
139
|
-
process.exit(1);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Run setup if called directly
|
|
144
|
-
if (require.main === module) {
|
|
145
|
-
setupCommiter();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
module.exports = { setupCommiter, ensureSafeTestScript };
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Commiter - Commit convention tooling for standard-version releases
|
|
5
|
+
*
|
|
6
|
+
* This package helps enforce conventional commits and automate releases
|
|
7
|
+
* with beautiful changelogs featuring icons for each commit type.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const { execSync } = require('child_process');
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
|
|
14
|
+
function ensureSafeTestScript(scripts = {}) {
|
|
15
|
+
const defaultFailingTestScript = 'echo "Error: no test specified" && exit 1';
|
|
16
|
+
if (!scripts.test || scripts.test === defaultFailingTestScript) {
|
|
17
|
+
scripts.test = 'echo "No tests specified"';
|
|
18
|
+
}
|
|
19
|
+
return scripts;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function setupCommiter() {
|
|
23
|
+
console.log('๐ Setting up Commiter...\n');
|
|
24
|
+
|
|
25
|
+
// Check if package.json exists
|
|
26
|
+
if (!fs.existsSync('package.json')) {
|
|
27
|
+
console.error('โ Error: package.json not found. Please run this in a Node.js project directory.');
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// Install dependencies
|
|
33
|
+
console.log('๐ฆ Installing dependencies...');
|
|
34
|
+
execSync('npm install --save-dev standard-version @commitlint/cli @commitlint/config-conventional husky', {
|
|
35
|
+
stdio: 'inherit'
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Read package.json
|
|
39
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
40
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
41
|
+
|
|
42
|
+
packageJson.scripts = ensureSafeTestScript(packageJson.scripts || {});
|
|
43
|
+
// Add scripts
|
|
44
|
+
packageJson.scripts.prepare = 'husky';
|
|
45
|
+
packageJson.scripts.release = 'node scripts/release.js';
|
|
46
|
+
packageJson.scripts['release:major'] = 'node scripts/release.js major';
|
|
47
|
+
packageJson.scripts['release:minor'] = 'node scripts/release.js minor';
|
|
48
|
+
packageJson.scripts['release:patch'] = 'node scripts/release.js patch';
|
|
49
|
+
|
|
50
|
+
// Add standard-version config
|
|
51
|
+
packageJson['standard-version'] = {
|
|
52
|
+
releaseCommitMessageFormat: 'chore(release): {{currentTag}} ๐',
|
|
53
|
+
types: [
|
|
54
|
+
{ type: 'feat', section: 'โจ Features' },
|
|
55
|
+
{ type: 'fix', section: '๐ Bug Fixes' },
|
|
56
|
+
{ type: 'perf', section: 'โก Performance' },
|
|
57
|
+
{ type: 'refactor', section: 'โป๏ธ Refactors' },
|
|
58
|
+
{ type: 'docs', section: '๐ Documentation' },
|
|
59
|
+
{ type: 'style', section: '๐ Styles' },
|
|
60
|
+
{ type: 'test', section: 'โ
Tests' },
|
|
61
|
+
{ type: 'build', section: '๐๏ธ Build System' },
|
|
62
|
+
{ type: 'ci', section: '๐ท Continuous Integration' },
|
|
63
|
+
{ type: 'chore', section: '๐งน Chores' },
|
|
64
|
+
{ type: 'revert', section: 'โช Reverts' }
|
|
65
|
+
]
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// Write updated package.json
|
|
69
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
|
|
70
|
+
|
|
71
|
+
// Create release helper script
|
|
72
|
+
console.log('๐ ๏ธ Creating release helper script...');
|
|
73
|
+
const releaseScriptDir = path.join(process.cwd(), 'scripts');
|
|
74
|
+
if (!fs.existsSync(releaseScriptDir)) {
|
|
75
|
+
fs.mkdirSync(releaseScriptDir, { recursive: true });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const releaseScriptPath = path.join(releaseScriptDir, 'release.js');
|
|
79
|
+
const releaseScriptSource = path.join(__dirname, 'scripts', 'release.js');
|
|
80
|
+
const releaseScriptContent = fs.readFileSync(releaseScriptSource, 'utf8');
|
|
81
|
+
|
|
82
|
+
fs.writeFileSync(releaseScriptPath, releaseScriptContent + '\n');
|
|
83
|
+
try {
|
|
84
|
+
fs.chmodSync(releaseScriptPath, 0o755);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
// Ignore chmod errors on non-POSIX systems
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Determine commitlint config format based on project module type
|
|
90
|
+
const isEsmProject = packageJson.type === 'module';
|
|
91
|
+
const commitlintConfigFile = isEsmProject ? 'commitlint.config.js' : 'commitlint.config.cjs';
|
|
92
|
+
const commitlintConfigContent = isEsmProject
|
|
93
|
+
? `export default {
|
|
94
|
+
extends: ['@commitlint/config-conventional'],
|
|
95
|
+
ignores: [(message) => message.startsWith('chore(release):')]
|
|
96
|
+
}\n`
|
|
97
|
+
: `module.exports = {
|
|
98
|
+
extends: ['@commitlint/config-conventional'],
|
|
99
|
+
ignores: [(message) => message.startsWith('chore(release):')]
|
|
100
|
+
}\n`;
|
|
101
|
+
|
|
102
|
+
const legacyCommitlintConfigFile = isEsmProject ? 'commitlint.config.cjs' : 'commitlint.config.js';
|
|
103
|
+
if (fs.existsSync(legacyCommitlintConfigFile)) {
|
|
104
|
+
fs.rmSync(legacyCommitlintConfigFile);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
console.log(`โ๏ธ Creating commitlint config (${commitlintConfigFile})...`);
|
|
108
|
+
fs.writeFileSync(commitlintConfigFile, commitlintConfigContent);
|
|
109
|
+
|
|
110
|
+
// Initialize Husky
|
|
111
|
+
console.log('๐ถ Setting up Husky...');
|
|
112
|
+
execSync('npx husky init', { stdio: 'inherit' });
|
|
113
|
+
|
|
114
|
+
// Create commit-msg hook
|
|
115
|
+
const huskyDir = path.join(process.cwd(), '.husky');
|
|
116
|
+
if (!fs.existsSync(huskyDir)) {
|
|
117
|
+
fs.mkdirSync(huskyDir, { recursive: true });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const commitMsgHook = `#!/usr/bin/env sh
|
|
121
|
+
|
|
122
|
+
npx --no -- commitlint --edit "$1"
|
|
123
|
+
`;
|
|
124
|
+
fs.writeFileSync(path.join(huskyDir, 'commit-msg'), commitMsgHook);
|
|
125
|
+
fs.chmodSync(path.join(huskyDir, 'commit-msg'), 0o755);
|
|
126
|
+
|
|
127
|
+
console.log('\nโ
Commiter setup complete!\n');
|
|
128
|
+
console.log('๐ Available commands:');
|
|
129
|
+
console.log(' npm run release major - Create a major release (1.0.0 โ 2.0.0)');
|
|
130
|
+
console.log(' npm run release minor - Create a minor release (1.0.0 โ 1.1.0)');
|
|
131
|
+
console.log(' npm run release patch - Create a patch release (1.0.0 โ 1.0.1)');
|
|
132
|
+
console.log(' npm run release - Auto-detect version bump');
|
|
133
|
+
console.log(' npm run release -- --prerelease beta - Create a beta prerelease\n');
|
|
134
|
+
console.log('๐ฏ Commit format: type(scope): subject');
|
|
135
|
+
console.log(' Example: feat(auth): add user login\n');
|
|
136
|
+
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.error('โ Error during setup:', error.message);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Run setup if called directly
|
|
144
|
+
if (require.main === module) {
|
|
145
|
+
setupCommiter();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
module.exports = { setupCommiter, ensureSafeTestScript };
|