start-command 0.3.1
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/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.changeset/isolation-support.md +30 -0
- package/.github/workflows/release.yml +292 -0
- package/.husky/pre-commit +1 -0
- package/.prettierignore +6 -0
- package/.prettierrc +10 -0
- package/CHANGELOG.md +24 -0
- package/LICENSE +24 -0
- package/README.md +249 -0
- package/REQUIREMENTS.md +229 -0
- package/bun.lock +453 -0
- package/bunfig.toml +3 -0
- package/eslint.config.mjs +122 -0
- package/experiments/debug-regex.js +49 -0
- package/experiments/isolation-design.md +142 -0
- package/experiments/test-cli.sh +42 -0
- package/experiments/test-substitution.js +143 -0
- package/package.json +63 -0
- package/scripts/changeset-version.mjs +38 -0
- package/scripts/check-file-size.mjs +103 -0
- package/scripts/create-github-release.mjs +93 -0
- package/scripts/create-manual-changeset.mjs +89 -0
- package/scripts/format-github-release.mjs +83 -0
- package/scripts/format-release-notes.mjs +219 -0
- package/scripts/instant-version-bump.mjs +121 -0
- package/scripts/publish-to-npm.mjs +129 -0
- package/scripts/setup-npm.mjs +37 -0
- package/scripts/validate-changeset.mjs +107 -0
- package/scripts/version-and-commit.mjs +237 -0
- package/src/bin/cli.js +670 -0
- package/src/lib/args-parser.js +259 -0
- package/src/lib/isolation.js +419 -0
- package/src/lib/substitution.js +323 -0
- package/src/lib/substitutions.lino +308 -0
- package/test/args-parser.test.js +389 -0
- package/test/isolation.test.js +248 -0
- package/test/substitution.test.js +236 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create GitHub Release from CHANGELOG.md
|
|
5
|
+
* Usage: node scripts/create-github-release.mjs --release-version <version> --repository <repository>
|
|
6
|
+
* release-version: Version number (e.g., 1.0.0)
|
|
7
|
+
* repository: GitHub repository (e.g., owner/repo)
|
|
8
|
+
*
|
|
9
|
+
* Uses link-foundation libraries:
|
|
10
|
+
* - use-m: Dynamic package loading without package.json dependencies
|
|
11
|
+
* - command-stream: Modern shell command execution with streaming support
|
|
12
|
+
* - lino-arguments: Unified configuration from CLI args, env vars, and .lenv files
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { readFileSync } from 'fs';
|
|
16
|
+
|
|
17
|
+
// Load use-m dynamically
|
|
18
|
+
const { use } = eval(
|
|
19
|
+
await (await fetch('https://unpkg.com/use-m/use.js')).text()
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// Import link-foundation libraries
|
|
23
|
+
const { $ } = await use('command-stream');
|
|
24
|
+
const { makeConfig } = await use('lino-arguments');
|
|
25
|
+
|
|
26
|
+
// Parse CLI arguments using lino-arguments
|
|
27
|
+
// Note: Using --release-version instead of --version to avoid conflict with yargs' built-in --version flag
|
|
28
|
+
const config = makeConfig({
|
|
29
|
+
yargs: ({ yargs, getenv }) =>
|
|
30
|
+
yargs
|
|
31
|
+
.option('release-version', {
|
|
32
|
+
type: 'string',
|
|
33
|
+
default: getenv('VERSION', ''),
|
|
34
|
+
describe: 'Version number (e.g., 1.0.0)',
|
|
35
|
+
})
|
|
36
|
+
.option('repository', {
|
|
37
|
+
type: 'string',
|
|
38
|
+
default: getenv('REPOSITORY', ''),
|
|
39
|
+
describe: 'GitHub repository (e.g., owner/repo)',
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const { releaseVersion: version, repository } = config;
|
|
44
|
+
|
|
45
|
+
if (!version || !repository) {
|
|
46
|
+
console.error('Error: Missing required arguments');
|
|
47
|
+
console.error(
|
|
48
|
+
'Usage: node scripts/create-github-release.mjs --release-version <version> --repository <repository>'
|
|
49
|
+
);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const tag = `v${version}`;
|
|
54
|
+
|
|
55
|
+
console.log(`Creating GitHub release for ${tag}...`);
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
// Read CHANGELOG.md
|
|
59
|
+
const changelog = readFileSync('./CHANGELOG.md', 'utf8');
|
|
60
|
+
|
|
61
|
+
// Extract changelog entry for this version
|
|
62
|
+
// Read from CHANGELOG.md between this version header and the next version header
|
|
63
|
+
const versionHeaderRegex = new RegExp(`## ${version}[\\s\\S]*?(?=## \\d|$)`);
|
|
64
|
+
const match = changelog.match(versionHeaderRegex);
|
|
65
|
+
|
|
66
|
+
let releaseNotes = '';
|
|
67
|
+
if (match) {
|
|
68
|
+
// Remove the version header itself and trim
|
|
69
|
+
releaseNotes = match[0].replace(`## ${version}`, '').trim();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!releaseNotes) {
|
|
73
|
+
releaseNotes = `Release ${version}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Create release using GitHub API with JSON input
|
|
77
|
+
// This avoids shell escaping issues that occur when passing text via command-line arguments
|
|
78
|
+
// (Previously caused apostrophes like "didn't" to appear as "didn'''" in releases)
|
|
79
|
+
const payload = JSON.stringify({
|
|
80
|
+
tag_name: tag,
|
|
81
|
+
name: version,
|
|
82
|
+
body: releaseNotes,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
await $`gh api repos/${repository}/releases -X POST --input -`.run({
|
|
86
|
+
stdin: payload,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
console.log(`\u2705 Created GitHub release: ${tag}`);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error('Error creating release:', error.message);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create a changeset file for manual releases
|
|
5
|
+
* Usage: node scripts/create-manual-changeset.mjs --bump-type <major|minor|patch> [--description <description>]
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: Update the PACKAGE_NAME constant below to match your package.json
|
|
8
|
+
*
|
|
9
|
+
* Uses link-foundation libraries:
|
|
10
|
+
* - use-m: Dynamic package loading without package.json dependencies
|
|
11
|
+
* - command-stream: Modern shell command execution with streaming support
|
|
12
|
+
* - lino-arguments: Unified configuration from CLI args, env vars, and .lenv files
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { writeFileSync } from 'fs';
|
|
16
|
+
import { randomBytes } from 'crypto';
|
|
17
|
+
|
|
18
|
+
// TODO: Update this to match your package name in package.json
|
|
19
|
+
const PACKAGE_NAME = 'start-command';
|
|
20
|
+
|
|
21
|
+
// Load use-m dynamically
|
|
22
|
+
const { use } = eval(
|
|
23
|
+
await (await fetch('https://unpkg.com/use-m/use.js')).text()
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// Import link-foundation libraries
|
|
27
|
+
const { $ } = await use('command-stream');
|
|
28
|
+
const { makeConfig } = await use('lino-arguments');
|
|
29
|
+
|
|
30
|
+
// Parse CLI arguments using lino-arguments
|
|
31
|
+
const config = makeConfig({
|
|
32
|
+
yargs: ({ yargs, getenv }) =>
|
|
33
|
+
yargs
|
|
34
|
+
.option('bump-type', {
|
|
35
|
+
type: 'string',
|
|
36
|
+
default: getenv('BUMP_TYPE', ''),
|
|
37
|
+
describe: 'Version bump type: major, minor, or patch',
|
|
38
|
+
choices: ['major', 'minor', 'patch'],
|
|
39
|
+
})
|
|
40
|
+
.option('description', {
|
|
41
|
+
type: 'string',
|
|
42
|
+
default: getenv('DESCRIPTION', ''),
|
|
43
|
+
describe: 'Description for the changeset',
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const { bumpType, description: descriptionArg } = config;
|
|
49
|
+
|
|
50
|
+
// Use provided description or default based on bump type
|
|
51
|
+
const description = descriptionArg || `Manual ${bumpType} release`;
|
|
52
|
+
|
|
53
|
+
if (!bumpType || !['major', 'minor', 'patch'].includes(bumpType)) {
|
|
54
|
+
console.error(
|
|
55
|
+
'Usage: node scripts/create-manual-changeset.mjs --bump-type <major|minor|patch> [--description <description>]'
|
|
56
|
+
);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Generate a random changeset ID
|
|
61
|
+
const changesetId = randomBytes(4).toString('hex');
|
|
62
|
+
const changesetFile = `.changeset/manual-release-${changesetId}.md`;
|
|
63
|
+
|
|
64
|
+
// Create the changeset file with single quotes to match Prettier config
|
|
65
|
+
const content = `---
|
|
66
|
+
'${PACKAGE_NAME}': ${bumpType}
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
${description}
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
writeFileSync(changesetFile, content, 'utf-8');
|
|
73
|
+
|
|
74
|
+
console.log(`Created changeset: ${changesetFile}`);
|
|
75
|
+
console.log('Content:');
|
|
76
|
+
console.log(content);
|
|
77
|
+
|
|
78
|
+
// Format with Prettier
|
|
79
|
+
console.log('\nFormatting with Prettier...');
|
|
80
|
+
await $`npx prettier --write "${changesetFile}"`;
|
|
81
|
+
|
|
82
|
+
console.log('\n✅ Changeset created and formatted successfully');
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error('Error creating changeset:', error.message);
|
|
85
|
+
if (process.env.DEBUG) {
|
|
86
|
+
console.error('Stack trace:', error.stack);
|
|
87
|
+
}
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Format GitHub release notes using the format-release-notes.mjs script
|
|
5
|
+
* Usage: node scripts/format-github-release.mjs --release-version <version> --repository <repository> --commit-sha <commit_sha>
|
|
6
|
+
* release-version: Version number (e.g., 1.0.0)
|
|
7
|
+
* repository: GitHub repository (e.g., owner/repo)
|
|
8
|
+
* commit_sha: Commit SHA for PR detection
|
|
9
|
+
*
|
|
10
|
+
* Uses link-foundation libraries:
|
|
11
|
+
* - use-m: Dynamic package loading without package.json dependencies
|
|
12
|
+
* - command-stream: Modern shell command execution with streaming support
|
|
13
|
+
* - lino-arguments: Unified configuration from CLI args, env vars, and .lenv files
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// Load use-m dynamically
|
|
17
|
+
const { use } = eval(
|
|
18
|
+
await (await fetch('https://unpkg.com/use-m/use.js')).text()
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
// Import link-foundation libraries
|
|
22
|
+
const { $ } = await use('command-stream');
|
|
23
|
+
const { makeConfig } = await use('lino-arguments');
|
|
24
|
+
|
|
25
|
+
// Parse CLI arguments using lino-arguments
|
|
26
|
+
// Note: Using --release-version instead of --version to avoid conflict with yargs' built-in --version flag
|
|
27
|
+
const config = makeConfig({
|
|
28
|
+
yargs: ({ yargs, getenv }) =>
|
|
29
|
+
yargs
|
|
30
|
+
.option('release-version', {
|
|
31
|
+
type: 'string',
|
|
32
|
+
default: getenv('VERSION', ''),
|
|
33
|
+
describe: 'Version number (e.g., 1.0.0)',
|
|
34
|
+
})
|
|
35
|
+
.option('repository', {
|
|
36
|
+
type: 'string',
|
|
37
|
+
default: getenv('REPOSITORY', ''),
|
|
38
|
+
describe: 'GitHub repository (e.g., owner/repo)',
|
|
39
|
+
})
|
|
40
|
+
.option('commit-sha', {
|
|
41
|
+
type: 'string',
|
|
42
|
+
default: getenv('COMMIT_SHA', ''),
|
|
43
|
+
describe: 'Commit SHA for PR detection',
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const { releaseVersion: version, repository, commitSha } = config;
|
|
48
|
+
|
|
49
|
+
if (!version || !repository || !commitSha) {
|
|
50
|
+
console.error('Error: Missing required arguments');
|
|
51
|
+
console.error(
|
|
52
|
+
'Usage: node scripts/format-github-release.mjs --release-version <version> --repository <repository> --commit-sha <commit_sha>'
|
|
53
|
+
);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const tag = `v${version}`;
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
// Get the release ID for this version
|
|
61
|
+
let releaseId = '';
|
|
62
|
+
try {
|
|
63
|
+
const result =
|
|
64
|
+
await $`gh api "repos/${repository}/releases/tags/${tag}" --jq '.id'`.run(
|
|
65
|
+
{ capture: true }
|
|
66
|
+
);
|
|
67
|
+
releaseId = result.stdout.trim();
|
|
68
|
+
} catch {
|
|
69
|
+
console.log(`\u26A0\uFE0F Could not find release for ${tag}`);
|
|
70
|
+
process.exit(0);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (releaseId) {
|
|
74
|
+
console.log(`Formatting release notes for ${tag}...`);
|
|
75
|
+
// Pass the trigger commit SHA for PR detection
|
|
76
|
+
// This allows proper PR lookup even if the changelog doesn't have a commit hash
|
|
77
|
+
await $`node scripts/format-release-notes.mjs --release-id "${releaseId}" --release-version "${tag}" --repository "${repository}" --commit-sha "${commitSha}"`;
|
|
78
|
+
console.log(`\u2705 Formatted release notes for ${tag}`);
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('Error formatting release:', error.message);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Script to format GitHub release notes with proper formatting:
|
|
5
|
+
* - Fix special characters like \n
|
|
6
|
+
* - Add link to PR that contains the release commit (if found)
|
|
7
|
+
* - Add shields.io NPM version badge
|
|
8
|
+
* - Format nicely with proper markdown
|
|
9
|
+
*
|
|
10
|
+
* IMPORTANT: Update the PACKAGE_NAME constant below to match your package.json
|
|
11
|
+
*
|
|
12
|
+
* PR Detection Logic:
|
|
13
|
+
* 1. Extract commit hash from changelog entry (if present)
|
|
14
|
+
* 2. Fall back to --commit-sha argument (passed from workflow)
|
|
15
|
+
* 3. Look up PRs that contain the commit via GitHub API
|
|
16
|
+
* 4. If no PR found, simply don't display any PR link (no guessing)
|
|
17
|
+
*
|
|
18
|
+
* Uses link-foundation libraries:
|
|
19
|
+
* - use-m: Dynamic package loading without package.json dependencies
|
|
20
|
+
* - command-stream: Modern shell command execution with streaming support
|
|
21
|
+
* - lino-arguments: Unified configuration from CLI args, env vars, and .lenv files
|
|
22
|
+
*
|
|
23
|
+
* Note: Uses --release-version instead of --version to avoid conflict with yargs' built-in --version flag.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
// TODO: Update this to match your package name in package.json
|
|
27
|
+
const PACKAGE_NAME = 'start-command';
|
|
28
|
+
|
|
29
|
+
// Load use-m dynamically
|
|
30
|
+
const { use } = eval(
|
|
31
|
+
await (await fetch('https://unpkg.com/use-m/use.js')).text()
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// Import link-foundation libraries
|
|
35
|
+
const { $ } = await use('command-stream');
|
|
36
|
+
const { makeConfig } = await use('lino-arguments');
|
|
37
|
+
|
|
38
|
+
// Parse CLI arguments using lino-arguments
|
|
39
|
+
// Note: Using --release-version instead of --version to avoid conflict with yargs' built-in --version flag
|
|
40
|
+
const config = makeConfig({
|
|
41
|
+
yargs: ({ yargs, getenv }) =>
|
|
42
|
+
yargs
|
|
43
|
+
.option('release-version', {
|
|
44
|
+
type: 'string',
|
|
45
|
+
default: getenv('VERSION', ''),
|
|
46
|
+
describe: 'Version number (e.g., v0.8.36)',
|
|
47
|
+
})
|
|
48
|
+
.option('release-id', {
|
|
49
|
+
type: 'string',
|
|
50
|
+
default: getenv('RELEASE_ID', ''),
|
|
51
|
+
describe: 'GitHub release ID',
|
|
52
|
+
})
|
|
53
|
+
.option('repository', {
|
|
54
|
+
type: 'string',
|
|
55
|
+
default: getenv('REPOSITORY', ''),
|
|
56
|
+
describe: 'GitHub repository (e.g., owner/repo)',
|
|
57
|
+
})
|
|
58
|
+
.option('commit-sha', {
|
|
59
|
+
type: 'string',
|
|
60
|
+
default: getenv('COMMIT_SHA', ''),
|
|
61
|
+
describe: 'Commit SHA for PR detection',
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const releaseId = config.releaseId;
|
|
66
|
+
const version = config.releaseVersion;
|
|
67
|
+
const repository = config.repository;
|
|
68
|
+
const passedCommitSha = config.commitSha;
|
|
69
|
+
|
|
70
|
+
if (!releaseId || !version || !repository) {
|
|
71
|
+
console.error(
|
|
72
|
+
'Usage: format-release-notes.mjs --release-id <releaseId> --release-version <version> --repository <repository> [--commit-sha <sha>]'
|
|
73
|
+
);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
// Get current release body
|
|
79
|
+
const result = await $`gh api repos/${repository}/releases/${releaseId}`.run({
|
|
80
|
+
capture: true,
|
|
81
|
+
});
|
|
82
|
+
const releaseData = JSON.parse(result.stdout);
|
|
83
|
+
|
|
84
|
+
const currentBody = releaseData.body || '';
|
|
85
|
+
|
|
86
|
+
// Skip if already formatted (has shields.io badge image)
|
|
87
|
+
if (currentBody.includes('img.shields.io')) {
|
|
88
|
+
console.log('ℹ️ Release notes already formatted');
|
|
89
|
+
process.exit(0);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Extract changes section (Major, Minor, or Patch)
|
|
93
|
+
// This regex handles multiple formats:
|
|
94
|
+
// 1. With commit hash: "### [Major|Minor|Patch] Changes\n- abc1234: Description"
|
|
95
|
+
// 2. Without commit hash: "### [Major|Minor|Patch] Changes\n- Description"
|
|
96
|
+
const changesPattern =
|
|
97
|
+
/### (Major|Minor|Patch) Changes\s*\n\s*-\s+(?:([a-f0-9]+):\s+)?(.+?)$/s;
|
|
98
|
+
const changesMatch = currentBody.match(changesPattern);
|
|
99
|
+
|
|
100
|
+
let commitHash = null;
|
|
101
|
+
let rawDescription = null;
|
|
102
|
+
let changeType = null;
|
|
103
|
+
|
|
104
|
+
if (changesMatch) {
|
|
105
|
+
// Extract: [full match, changeType, commitHash (optional), description]
|
|
106
|
+
[, changeType, commitHash, rawDescription] = changesMatch;
|
|
107
|
+
console.log(`ℹ️ Found ${changeType} Changes section`);
|
|
108
|
+
|
|
109
|
+
// If commitHash is undefined and description contains it, try to extract
|
|
110
|
+
if (!commitHash && rawDescription) {
|
|
111
|
+
// This handles the case where description itself might be null/undefined
|
|
112
|
+
// and we need to safely check for commit hash at the start
|
|
113
|
+
const descWithHashMatch = rawDescription.match(/^([a-f0-9]+):\s+(.+)$/s);
|
|
114
|
+
if (descWithHashMatch) {
|
|
115
|
+
[, commitHash, rawDescription] = descWithHashMatch;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
console.log('⚠️ Could not parse changes from release notes');
|
|
120
|
+
console.log(' Looking for pattern: ### [Major|Minor|Patch] Changes');
|
|
121
|
+
process.exit(0);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Clean up the description:
|
|
125
|
+
// 1. Convert literal \n sequences (escaped newlines from GitHub API) to actual newlines
|
|
126
|
+
// 2. Remove leading/trailing quotes (including escaped quotes from command-stream shell escaping)
|
|
127
|
+
// 3. Remove any trailing npm package links or markdown that might be there
|
|
128
|
+
// 4. Normalize whitespace while preserving line breaks
|
|
129
|
+
const cleanDescription = rawDescription
|
|
130
|
+
.replace(/\\n/g, '\n') // Convert escaped \n to actual newlines
|
|
131
|
+
.replace(/^(\\['"])+/g, '') // Remove leading escaped quotes (e.g., \', \", \'', \'')
|
|
132
|
+
.replace(/(['"])+$/g, '') // Remove trailing unescaped quotes (e.g., ', ", '', '')
|
|
133
|
+
.replace(/^(['"])+/g, '') // Remove leading unescaped quotes
|
|
134
|
+
.replace(/📦.*$/s, '') // Remove any existing npm package info
|
|
135
|
+
.replace(/---.*$/s, '') // Remove any existing separators and everything after
|
|
136
|
+
.trim()
|
|
137
|
+
.split('\n') // Split by lines
|
|
138
|
+
.map((line) => line.trim()) // Trim whitespace from each line
|
|
139
|
+
.join('\n') // Rejoin with newlines
|
|
140
|
+
.replace(/\n{3,}/g, '\n\n'); // Normalize excessive blank lines (3+ becomes 2)
|
|
141
|
+
|
|
142
|
+
// Find the PR that contains the release commit
|
|
143
|
+
// Uses commit hash from changelog or passed commit SHA from workflow
|
|
144
|
+
let prNumber = null;
|
|
145
|
+
|
|
146
|
+
// Determine which commit SHA to use for PR lookup
|
|
147
|
+
const commitShaToLookup = commitHash || passedCommitSha;
|
|
148
|
+
|
|
149
|
+
if (commitShaToLookup) {
|
|
150
|
+
const source = commitHash ? 'changelog' : 'workflow';
|
|
151
|
+
console.log(
|
|
152
|
+
`ℹ️ Looking up PR for commit ${commitShaToLookup} (from ${source})`
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
const prResult =
|
|
157
|
+
await $`gh api "repos/${repository}/commits/${commitShaToLookup}/pulls"`.run(
|
|
158
|
+
{ capture: true }
|
|
159
|
+
);
|
|
160
|
+
const prsData = JSON.parse(prResult.stdout);
|
|
161
|
+
|
|
162
|
+
// Find the PR that's not the version bump PR (not "chore: version packages")
|
|
163
|
+
const relevantPr = prsData.find(
|
|
164
|
+
(pr) => !pr.title.includes('version packages')
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
if (relevantPr) {
|
|
168
|
+
prNumber = relevantPr.number;
|
|
169
|
+
console.log(`✅ Found PR #${prNumber} containing commit`);
|
|
170
|
+
} else if (prsData.length > 0) {
|
|
171
|
+
console.log(
|
|
172
|
+
'⚠️ Found PRs but all are version bump PRs, not linking any'
|
|
173
|
+
);
|
|
174
|
+
} else {
|
|
175
|
+
console.log(
|
|
176
|
+
'ℹ️ No PR found containing this commit - not adding PR link'
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
} catch (error) {
|
|
180
|
+
console.log('⚠️ Could not find PR for commit', commitShaToLookup);
|
|
181
|
+
console.log(' Error:', error.message);
|
|
182
|
+
if (process.env.DEBUG) {
|
|
183
|
+
console.error(error);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
// No commit hash available from any source
|
|
188
|
+
console.log('ℹ️ No commit SHA available - not adding PR link');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Build formatted release notes
|
|
192
|
+
const versionWithoutV = version.replace(/^v/, '');
|
|
193
|
+
const npmBadge = `[](https://www.npmjs.com/package/${PACKAGE_NAME}/v/${versionWithoutV})`;
|
|
194
|
+
|
|
195
|
+
let formattedBody = `${cleanDescription}`;
|
|
196
|
+
|
|
197
|
+
// Add PR link if available
|
|
198
|
+
if (prNumber) {
|
|
199
|
+
formattedBody += `\n\n**Related Pull Request:** #${prNumber}`;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
formattedBody += `\n\n---\n\n${npmBadge}`;
|
|
203
|
+
|
|
204
|
+
// Update the release using JSON input to properly handle special characters
|
|
205
|
+
const updatePayload = JSON.stringify({ body: formattedBody });
|
|
206
|
+
await $`gh api repos/${repository}/releases/${releaseId} -X PATCH --input -`.run(
|
|
207
|
+
{ stdin: updatePayload }
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
console.log(`✅ Formatted release notes for v${versionWithoutV}`);
|
|
211
|
+
if (prNumber) {
|
|
212
|
+
console.log(` - Added link to PR #${prNumber}`);
|
|
213
|
+
}
|
|
214
|
+
console.log(' - Added shields.io npm badge');
|
|
215
|
+
console.log(' - Cleaned up formatting');
|
|
216
|
+
} catch (error) {
|
|
217
|
+
console.error('❌ Error formatting release notes:', error.message);
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Instant version bump script for manual releases
|
|
5
|
+
* Bypasses the changeset workflow and directly updates version and changelog
|
|
6
|
+
*
|
|
7
|
+
* Usage: node scripts/instant-version-bump.mjs --bump-type <major|minor|patch> [--description <description>]
|
|
8
|
+
*
|
|
9
|
+
* Uses link-foundation libraries:
|
|
10
|
+
* - use-m: Dynamic package loading without package.json dependencies
|
|
11
|
+
* - command-stream: Modern shell command execution with streaming support
|
|
12
|
+
* - lino-arguments: Unified configuration from CLI args, env vars, and .lenv files
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
16
|
+
|
|
17
|
+
// Load use-m dynamically
|
|
18
|
+
const { use } = eval(
|
|
19
|
+
await (await fetch('https://unpkg.com/use-m/use.js')).text()
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// Import link-foundation libraries
|
|
23
|
+
const { $ } = await use('command-stream');
|
|
24
|
+
const { makeConfig } = await use('lino-arguments');
|
|
25
|
+
|
|
26
|
+
// Parse CLI arguments using lino-arguments
|
|
27
|
+
const config = makeConfig({
|
|
28
|
+
yargs: ({ yargs, getenv }) =>
|
|
29
|
+
yargs
|
|
30
|
+
.option('bump-type', {
|
|
31
|
+
type: 'string',
|
|
32
|
+
default: getenv('BUMP_TYPE', ''),
|
|
33
|
+
describe: 'Version bump type: major, minor, or patch',
|
|
34
|
+
choices: ['major', 'minor', 'patch'],
|
|
35
|
+
})
|
|
36
|
+
.option('description', {
|
|
37
|
+
type: 'string',
|
|
38
|
+
default: getenv('DESCRIPTION', ''),
|
|
39
|
+
describe: 'Description for the version bump',
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const { bumpType, description } = config;
|
|
45
|
+
const finalDescription = description || `Manual ${bumpType} release`;
|
|
46
|
+
|
|
47
|
+
if (!bumpType || !['major', 'minor', 'patch'].includes(bumpType)) {
|
|
48
|
+
console.error(
|
|
49
|
+
'Usage: node scripts/instant-version-bump.mjs --bump-type <major|minor|patch> [--description <description>]'
|
|
50
|
+
);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
console.log(`\nBumping version (${bumpType})...`);
|
|
55
|
+
|
|
56
|
+
// Get current version
|
|
57
|
+
const packageJson = JSON.parse(readFileSync('package.json', 'utf-8'));
|
|
58
|
+
const oldVersion = packageJson.version;
|
|
59
|
+
console.log(`Current version: ${oldVersion}`);
|
|
60
|
+
|
|
61
|
+
// Bump version using npm version (doesn't create git tag)
|
|
62
|
+
await $`npm version ${bumpType} --no-git-tag-version`;
|
|
63
|
+
|
|
64
|
+
// Get new version
|
|
65
|
+
const updatedPackageJson = JSON.parse(readFileSync('package.json', 'utf-8'));
|
|
66
|
+
const newVersion = updatedPackageJson.version;
|
|
67
|
+
console.log(`New version: ${newVersion}`);
|
|
68
|
+
|
|
69
|
+
// Update CHANGELOG.md
|
|
70
|
+
console.log('\nUpdating CHANGELOG.md...');
|
|
71
|
+
const changelogPath = 'CHANGELOG.md';
|
|
72
|
+
let changelog = readFileSync(changelogPath, 'utf-8');
|
|
73
|
+
|
|
74
|
+
// Create new changelog entry
|
|
75
|
+
const newEntry = `## ${newVersion}
|
|
76
|
+
|
|
77
|
+
### ${bumpType.charAt(0).toUpperCase() + bumpType.slice(1)} Changes
|
|
78
|
+
|
|
79
|
+
- ${finalDescription}
|
|
80
|
+
|
|
81
|
+
`;
|
|
82
|
+
|
|
83
|
+
// Insert new entry after the first heading (# Changelog or similar)
|
|
84
|
+
// Look for the first ## heading and insert before it
|
|
85
|
+
const firstVersionMatch = changelog.match(/^## /m);
|
|
86
|
+
|
|
87
|
+
if (firstVersionMatch) {
|
|
88
|
+
const insertPosition = firstVersionMatch.index;
|
|
89
|
+
changelog =
|
|
90
|
+
changelog.slice(0, insertPosition) +
|
|
91
|
+
newEntry +
|
|
92
|
+
changelog.slice(insertPosition);
|
|
93
|
+
} else {
|
|
94
|
+
// If no version headings exist, append after the main heading
|
|
95
|
+
const mainHeadingMatch = changelog.match(/^# .+$/m);
|
|
96
|
+
if (mainHeadingMatch) {
|
|
97
|
+
const insertPosition =
|
|
98
|
+
mainHeadingMatch.index + mainHeadingMatch[0].length;
|
|
99
|
+
changelog = `${changelog.slice(0, insertPosition)}\n\n${newEntry}${changelog.slice(insertPosition)}`;
|
|
100
|
+
} else {
|
|
101
|
+
// If no headings at all, prepend
|
|
102
|
+
changelog = `${newEntry}\n${changelog}`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
writeFileSync(changelogPath, changelog, 'utf-8');
|
|
107
|
+
console.log('✅ CHANGELOG.md updated');
|
|
108
|
+
|
|
109
|
+
// Synchronize package-lock.json
|
|
110
|
+
console.log('\nSynchronizing package-lock.json...');
|
|
111
|
+
await $`npm install --package-lock-only`;
|
|
112
|
+
|
|
113
|
+
console.log('\n✅ Instant version bump complete');
|
|
114
|
+
console.log(`Version: ${oldVersion} → ${newVersion}`);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.error('Error during instant version bump:', error.message);
|
|
117
|
+
if (process.env.DEBUG) {
|
|
118
|
+
console.error('Stack trace:', error.stack);
|
|
119
|
+
}
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|