@programinglive/commiter 1.0.6 → 1.0.10
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/workflows/publish.yml +34 -0
- package/CHANGELOG.md +23 -0
- package/PUBLISH.md +26 -0
- package/index.js +27 -8
- package/package.json +5 -5
- package/scripts/release.js +97 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: Publish to NPM
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
id-token: write
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout code
|
|
17
|
+
uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Setup Node.js
|
|
20
|
+
uses: actions/setup-node@v4
|
|
21
|
+
with:
|
|
22
|
+
node-version: '18'
|
|
23
|
+
registry-url: 'https://registry.npmjs.org'
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: npm ci
|
|
27
|
+
|
|
28
|
+
- name: Run tests
|
|
29
|
+
run: npm test
|
|
30
|
+
|
|
31
|
+
- name: Publish to NPM
|
|
32
|
+
run: npm publish --access public
|
|
33
|
+
env:
|
|
34
|
+
NODE_AUTH_TOKEN: ${{ secrets.COMMITER_TOKEN }}
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.0.10](https://github.com/programinglive/commiter/compare/v1.0.9...v1.0.10) (2025-10-29)
|
|
6
|
+
|
|
7
|
+
### [1.0.9](https://github.com/programinglive/commiter/compare/v1.0.8...v1.0.9) (2025-10-29)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### ✨ Features
|
|
11
|
+
|
|
12
|
+
* add new feature ([e1603c1](https://github.com/programinglive/commiter/commit/e1603c144823dd54f077de3f16c5c764d2066fe7))
|
|
13
|
+
|
|
14
|
+
### [1.0.8](https://github.com/programinglive/commiter/compare/v1.0.7...v1.0.8) (2025-10-29)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### ✨ Features
|
|
18
|
+
|
|
19
|
+
* add release helper script and tests ([085af63](https://github.com/programinglive/commiter/commit/085af631d2c53725f125d0f48b1221bc81830288))
|
|
20
|
+
|
|
21
|
+
### [1.0.7](https://github.com/programinglive/commiter/compare/v1.0.6...v1.0.7) (2025-10-29)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### ✨ Features
|
|
25
|
+
|
|
26
|
+
* add release helper script and tests ([93f4235](https://github.com/programinglive/commiter/commit/93f4235c3cf2e34b77b78ba51c0337cf89e564df))
|
|
27
|
+
|
|
5
28
|
### [1.0.6](https://github.com/programinglive/commiter/compare/v1.0.5...v1.0.6) (2025-10-19)
|
|
6
29
|
|
|
7
30
|
### [1.0.5](https://github.com/programinglive/commiter/compare/v1.0.4...v1.0.5) (2025-10-19)
|
package/PUBLISH.md
CHANGED
|
@@ -72,6 +72,7 @@ npm publish
|
|
|
72
72
|
|
|
73
73
|
## Automated Release Workflow
|
|
74
74
|
|
|
75
|
+
### Option 1: Manual Publishing (Traditional)
|
|
75
76
|
1. Make changes and commit using conventional commits
|
|
76
77
|
2. Run the appropriate release command
|
|
77
78
|
3. Push to GitHub with tags
|
|
@@ -93,6 +94,31 @@ git push --follow-tags origin main
|
|
|
93
94
|
npm publish
|
|
94
95
|
```
|
|
95
96
|
|
|
97
|
+
### Option 2: Automated Publishing (Recommended)
|
|
98
|
+
1. Make changes and commit using conventional commits
|
|
99
|
+
2. Run the appropriate release command
|
|
100
|
+
3. Push to GitHub with tags - **npm publishing happens automatically**
|
|
101
|
+
|
|
102
|
+
Example:
|
|
103
|
+
```bash
|
|
104
|
+
# Make changes
|
|
105
|
+
git add .
|
|
106
|
+
git commit -m "feat(cli): add interactive setup wizard"
|
|
107
|
+
|
|
108
|
+
# Create release
|
|
109
|
+
npm run release:minor
|
|
110
|
+
|
|
111
|
+
# Push to GitHub (triggers automatic npm publish)
|
|
112
|
+
git push --follow-tags origin main
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Setup Required for Automated Publishing:**
|
|
116
|
+
1. Add `NPM_TOKEN` secret to your GitHub repository
|
|
117
|
+
2. The GitHub Actions workflow (`.github/workflows/publish.yml`) will automatically:
|
|
118
|
+
- Run tests
|
|
119
|
+
- Publish to npm when a tag starting with `v` is pushed
|
|
120
|
+
- Use the `--access public` flag for scoped packages
|
|
121
|
+
|
|
96
122
|
## Unpublishing (Emergency Only)
|
|
97
123
|
|
|
98
124
|
If you need to unpublish a version within 72 hours:
|
package/index.js
CHANGED
|
@@ -42,10 +42,10 @@ function setupCommiter() {
|
|
|
42
42
|
packageJson.scripts = ensureSafeTestScript(packageJson.scripts || {});
|
|
43
43
|
// Add scripts
|
|
44
44
|
packageJson.scripts.prepare = 'husky';
|
|
45
|
-
packageJson.scripts.release = '
|
|
46
|
-
packageJson.scripts['release:major'] = '
|
|
47
|
-
packageJson.scripts['release:minor'] = '
|
|
48
|
-
packageJson.scripts['release:patch'] = '
|
|
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
49
|
|
|
50
50
|
// Add standard-version config
|
|
51
51
|
packageJson['standard-version'] = {
|
|
@@ -68,6 +68,24 @@ function setupCommiter() {
|
|
|
68
68
|
// Write updated package.json
|
|
69
69
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
|
|
70
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
|
+
|
|
71
89
|
// Determine commitlint config format based on project module type
|
|
72
90
|
const isEsmProject = packageJson.type === 'module';
|
|
73
91
|
const commitlintConfigFile = isEsmProject ? 'commitlint.config.js' : 'commitlint.config.cjs';
|
|
@@ -108,10 +126,11 @@ npx --no -- commitlint --edit "$1"
|
|
|
108
126
|
|
|
109
127
|
console.log('\n✅ Commiter setup complete!\n');
|
|
110
128
|
console.log('📚 Available commands:');
|
|
111
|
-
console.log(' npm run release
|
|
112
|
-
console.log(' npm run release
|
|
113
|
-
console.log(' npm run release
|
|
114
|
-
console.log(' npm run release - Auto-detect version bump
|
|
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');
|
|
115
134
|
console.log('🎯 Commit format: type(scope): subject');
|
|
116
135
|
console.log(' Example: feat(auth): add user login\n');
|
|
117
136
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@programinglive/commiter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "Commit convention tooling for standard-version releases with beautiful changelogs",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "node test/ensureSafeTestScript.test.js",
|
|
11
11
|
"prepare": "husky",
|
|
12
|
-
"release": "
|
|
13
|
-
"release:major": "
|
|
14
|
-
"release:minor": "
|
|
15
|
-
"release:patch": "
|
|
12
|
+
"release": "node scripts/release.js",
|
|
13
|
+
"release:major": "node scripts/release.js major",
|
|
14
|
+
"release:minor": "node scripts/release.js minor",
|
|
15
|
+
"release:patch": "node scripts/release.js patch"
|
|
16
16
|
},
|
|
17
17
|
"keywords": [
|
|
18
18
|
"commit",
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawnSync } = require('child_process');
|
|
4
|
+
|
|
5
|
+
const VALID_RELEASE_TYPES = new Set([
|
|
6
|
+
'major',
|
|
7
|
+
'minor',
|
|
8
|
+
'patch',
|
|
9
|
+
'premajor',
|
|
10
|
+
'preminor',
|
|
11
|
+
'prepatch',
|
|
12
|
+
'prerelease'
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
const SEMVER_REGEX = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
16
|
+
|
|
17
|
+
function getCliArguments(argv = process.argv) {
|
|
18
|
+
const rawArgs = argv.slice(2);
|
|
19
|
+
if (rawArgs.length === 0) {
|
|
20
|
+
return { releaseType: undefined, extraArgs: [] };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (rawArgs[0].startsWith('-')) {
|
|
24
|
+
return { releaseType: undefined, extraArgs: rawArgs };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const [firstArg, ...rest] = rawArgs;
|
|
28
|
+
return { releaseType: firstArg, extraArgs: rest };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getNpmRunArgument(env = process.env) {
|
|
32
|
+
try {
|
|
33
|
+
const npmArgs = JSON.parse(env.npm_config_argv || '{}');
|
|
34
|
+
const original = npmArgs.original || [];
|
|
35
|
+
const releaseIndex = original.lastIndexOf('release');
|
|
36
|
+
if (releaseIndex !== -1) {
|
|
37
|
+
return original[releaseIndex + 1];
|
|
38
|
+
}
|
|
39
|
+
} catch (error) {
|
|
40
|
+
// Ignore JSON parsing issues and fall back to defaults
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function buildStandardVersionArgs({ releaseType, extraArgs }) {
|
|
46
|
+
const args = [];
|
|
47
|
+
if (releaseType) {
|
|
48
|
+
const normalized = releaseType.trim();
|
|
49
|
+
const isValid = VALID_RELEASE_TYPES.has(normalized) || SEMVER_REGEX.test(normalized);
|
|
50
|
+
if (!isValid) {
|
|
51
|
+
const allowed = Array.from(VALID_RELEASE_TYPES).join(', ');
|
|
52
|
+
throw new Error(`Unknown release type "${normalized}". Use one of ${allowed} or a valid semver version.`);
|
|
53
|
+
}
|
|
54
|
+
args.push('--release-as', normalized);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (Array.isArray(extraArgs) && extraArgs.length > 0) {
|
|
58
|
+
args.push(...extraArgs);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return args;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function runRelease({ argv = process.argv, env = process.env, spawn = spawnSync } = {}) {
|
|
65
|
+
const { releaseType: cliReleaseType, extraArgs } = getCliArguments(argv);
|
|
66
|
+
const inferredReleaseType = cliReleaseType || getNpmRunArgument(env);
|
|
67
|
+
const standardVersionArgs = buildStandardVersionArgs({
|
|
68
|
+
releaseType: inferredReleaseType,
|
|
69
|
+
extraArgs
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const standardVersionBin = require.resolve('standard-version/bin/cli.js');
|
|
73
|
+
return spawn(process.execPath, [standardVersionBin, ...standardVersionArgs], {
|
|
74
|
+
stdio: 'inherit'
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (require.main === module) {
|
|
79
|
+
try {
|
|
80
|
+
const result = runRelease();
|
|
81
|
+
if (result.status !== 0) {
|
|
82
|
+
process.exit(result.status ?? 1);
|
|
83
|
+
}
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error(`❌ ${error.message}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = {
|
|
91
|
+
VALID_RELEASE_TYPES,
|
|
92
|
+
SEMVER_REGEX,
|
|
93
|
+
getCliArguments,
|
|
94
|
+
getNpmRunArgument,
|
|
95
|
+
buildStandardVersionArgs,
|
|
96
|
+
runRelease
|
|
97
|
+
};
|