@hubspot/npm-scripts 0.0.4-experimental.1 → 0.0.4-experimental.2
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/README.md +67 -2
- package/package.json +8 -4
- package/src/constants/release.d.ts +3 -1
- package/src/constants/release.js +12 -1
- package/src/constants/repo-sync.d.ts +5 -0
- package/src/constants/repo-sync.js +5 -0
- package/src/release.js +75 -23
- package/src/repo-sync.d.ts +5 -0
- package/src/repo-sync.js +141 -0
- package/src/types.d.ts +36 -1
- package/src/utils/__tests__/filesystem.test.d.ts +1 -0
- package/src/utils/__tests__/filesystem.test.js +154 -0
- package/src/utils/__tests__/git.test.d.ts +1 -0
- package/src/utils/__tests__/git.test.js +267 -0
- package/src/utils/__tests__/logging.test.d.ts +1 -0
- package/src/utils/__tests__/logging.test.js +64 -0
- package/src/utils/__tests__/npm.test.d.ts +1 -0
- package/src/utils/__tests__/npm.test.js +266 -0
- package/src/utils/__tests__/process.test.d.ts +1 -0
- package/src/utils/__tests__/process.test.js +12 -0
- package/src/utils/__tests__/prompting.test.d.ts +1 -0
- package/src/utils/__tests__/prompting.test.js +100 -0
- package/src/utils/filesystem.d.ts +1 -0
- package/src/utils/filesystem.js +72 -0
- package/src/utils/git.d.ts +6 -0
- package/src/utils/git.js +100 -0
- package/src/utils/logging.js +2 -2
- package/src/utils/npm.d.ts +3 -1
- package/src/utils/npm.js +17 -8
- package/src/vscode-release.d.ts +5 -0
- package/src/vscode-release.js +319 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { exec as _exec, spawn } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import yargs from 'yargs';
|
|
5
|
+
import semver from 'semver';
|
|
6
|
+
import open from 'open';
|
|
7
|
+
import fs from 'fs-extra';
|
|
8
|
+
import { logger } from './utils/logging.js';
|
|
9
|
+
import { EXIT_CODES } from './utils/process.js';
|
|
10
|
+
import { DEFAULT_MAIN_BRANCH, VSCODE_VERSION_INCREMENT_OPTIONS, } from './constants/release.js';
|
|
11
|
+
import { getCurrentGitBranch } from './utils/git.js';
|
|
12
|
+
import { confirm, input } from './utils/prompting.js';
|
|
13
|
+
const exec = promisify(_exec);
|
|
14
|
+
function runVsceCommand(script) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const child = spawn('yarn', [script], {
|
|
17
|
+
stdio: ['pipe', 'inherit', 'inherit'],
|
|
18
|
+
});
|
|
19
|
+
child.stdin?.write('y\n');
|
|
20
|
+
child.stdin?.end();
|
|
21
|
+
child.on('close', code => {
|
|
22
|
+
if (code !== EXIT_CODES.SUCCESS) {
|
|
23
|
+
reject(new Error(`"yarn ${script}" failed with exit code ${code}`));
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
resolve();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async function getCommitsSinceLastTag() {
|
|
32
|
+
try {
|
|
33
|
+
const { stdout: lastTag } = await exec('git describe --tags --abbrev=0 2>/dev/null');
|
|
34
|
+
const { stdout } = await exec(`git log --oneline ${lastTag.trim()}..HEAD`);
|
|
35
|
+
return stdout
|
|
36
|
+
.trim()
|
|
37
|
+
.split('\n')
|
|
38
|
+
.filter(line => line.length > 0);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
const { stdout } = await exec('git log --oneline -20');
|
|
42
|
+
return stdout
|
|
43
|
+
.trim()
|
|
44
|
+
.split('\n')
|
|
45
|
+
.filter(line => line.length > 0);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function promptForChangelogEntries(commits) {
|
|
49
|
+
if (commits.length > 0) {
|
|
50
|
+
logger.log('\nRecent commits since last release:');
|
|
51
|
+
commits.forEach(commit => logger.log(` ${commit}`));
|
|
52
|
+
}
|
|
53
|
+
logger.log('\nEnter changelog entries (one per prompt, empty line to finish):');
|
|
54
|
+
const entries = [];
|
|
55
|
+
let entry = await input({
|
|
56
|
+
message: 'Changelog entry (leave empty to finish):',
|
|
57
|
+
});
|
|
58
|
+
while (entry.trim().length > 0) {
|
|
59
|
+
entries.push(entry.trim());
|
|
60
|
+
entry = await input({
|
|
61
|
+
message: 'Changelog entry (leave empty to finish):',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return entries;
|
|
65
|
+
}
|
|
66
|
+
async function updateChangelog(version, entries, changelogPath) {
|
|
67
|
+
const entriesText = entries.map(e => `- ${e}`).join('\n');
|
|
68
|
+
const newSection = `## [${version}]\n${entriesText}\n`;
|
|
69
|
+
let existing = '';
|
|
70
|
+
try {
|
|
71
|
+
existing = await fs.readFile(changelogPath, 'utf-8');
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
logger.log('No existing CHANGELOG.md found, creating a new one.');
|
|
75
|
+
}
|
|
76
|
+
const headerMatch = existing.match(/^(# .+\n+)/);
|
|
77
|
+
let updated;
|
|
78
|
+
if (headerMatch) {
|
|
79
|
+
const header = headerMatch[1];
|
|
80
|
+
const rest = existing.slice(header.length);
|
|
81
|
+
updated = `${header}${newSection}\n${rest}`;
|
|
82
|
+
}
|
|
83
|
+
else if (existing.length > 0) {
|
|
84
|
+
updated = `${newSection}\n${existing}`;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
updated = `# Changelog\n\n${newSection}\n`;
|
|
88
|
+
}
|
|
89
|
+
await fs.writeFile(changelogPath, updated, 'utf-8');
|
|
90
|
+
logger.success(`Updated ${changelogPath}`);
|
|
91
|
+
}
|
|
92
|
+
async function createDraftPR({ baseBranch, title, body, }) {
|
|
93
|
+
logger.log('\nCreating draft pull request...');
|
|
94
|
+
try {
|
|
95
|
+
const { stdout } = await exec(`gh pr create --draft --base ${baseBranch} --title "${title}" --body "${body.replace(/"/g, '\\"')}"`);
|
|
96
|
+
const prUrl = stdout.trim();
|
|
97
|
+
logger.success(`Draft PR created: ${prUrl}`);
|
|
98
|
+
return prUrl;
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
logger.error('Failed to create pull request:', error);
|
|
102
|
+
process.exit(EXIT_CODES.ERROR);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async function createGithubRelease({ tag, title, notes, }) {
|
|
106
|
+
logger.log('\nCreating GitHub release...');
|
|
107
|
+
try {
|
|
108
|
+
const { stdout } = await exec(`gh release create ${tag} --title "${title}" --notes "${notes.replace(/"/g, '\\"')}" --draft`);
|
|
109
|
+
const releaseUrl = stdout.trim();
|
|
110
|
+
logger.success(`Draft GitHub release created: ${releaseUrl}`);
|
|
111
|
+
return releaseUrl;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
logger.error('Failed to create GitHub release:', error);
|
|
115
|
+
process.exit(EXIT_CODES.ERROR);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function generateSlackMessage({ extensionName, version, changelogEntries, marketplaceUrl, repositoryUrl, }) {
|
|
119
|
+
const changes = changelogEntries.map(e => `- ${e}`).join('\n');
|
|
120
|
+
return [
|
|
121
|
+
`\u{1F4E6} ${extensionName} VSCode Extension v${version} Released`,
|
|
122
|
+
'',
|
|
123
|
+
'*Changes:*',
|
|
124
|
+
changes,
|
|
125
|
+
'',
|
|
126
|
+
'*Links:*',
|
|
127
|
+
`- Marketplace: ${marketplaceUrl}`,
|
|
128
|
+
`- Changelog: ${repositoryUrl}/blob/master/CHANGELOG.md`,
|
|
129
|
+
].join('\n');
|
|
130
|
+
}
|
|
131
|
+
function printSlackMessage(message, channel) {
|
|
132
|
+
logger.log('\n' + '='.repeat(60));
|
|
133
|
+
logger.log(`Slack message for ${channel}:`);
|
|
134
|
+
logger.log('='.repeat(60));
|
|
135
|
+
logger.log(message);
|
|
136
|
+
logger.log('='.repeat(60));
|
|
137
|
+
}
|
|
138
|
+
function buildHandler({ build, packageName, localVersion, repositoryUrl, mainBranch, marketplaceUrl, extensionName, slackChannel, }) {
|
|
139
|
+
return async function handler({ versionIncrement, dryRun, skipTests, }) {
|
|
140
|
+
const branch = await getCurrentGitBranch();
|
|
141
|
+
const isDryRun = Boolean(dryRun);
|
|
142
|
+
const resolvedSlackChannel = slackChannel || '#cli-dev';
|
|
143
|
+
if (branch !== mainBranch) {
|
|
144
|
+
logger.error(`Releases can only be published from the ${mainBranch} branch. Current branch: ${branch}`);
|
|
145
|
+
process.exit(EXIT_CODES.ERROR);
|
|
146
|
+
}
|
|
147
|
+
if (!skipTests) {
|
|
148
|
+
const userHasTested = await confirm({
|
|
149
|
+
message: 'Have you tested the pre-release package locally?',
|
|
150
|
+
default: false,
|
|
151
|
+
});
|
|
152
|
+
if (!userHasTested) {
|
|
153
|
+
logger.log('\nBuilding and packaging the pre-release for testing...\n');
|
|
154
|
+
if (build && typeof build === 'function') {
|
|
155
|
+
await build();
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
logger.log('Installing dependencies...');
|
|
159
|
+
await exec('yarn install');
|
|
160
|
+
logger.log('Running linting...');
|
|
161
|
+
await exec('yarn lint');
|
|
162
|
+
}
|
|
163
|
+
logger.log('\nPackaging pre-release...');
|
|
164
|
+
await runVsceCommand('vsce:prerelease');
|
|
165
|
+
logger.success('Pre-release package created.');
|
|
166
|
+
logger.log('\nTo test the package locally:');
|
|
167
|
+
logger.log(' 1. Open VS Code');
|
|
168
|
+
logger.log(' 2. Go to the Extensions panel');
|
|
169
|
+
logger.log(' 3. Click "..." menu → "Install from VSIX..."');
|
|
170
|
+
logger.log(' 4. Select the .vsix file created above');
|
|
171
|
+
logger.log(' 5. Test key functionality\n');
|
|
172
|
+
const readyToContinue = await confirm({
|
|
173
|
+
message: 'Continue when you have finished testing the pre-release.',
|
|
174
|
+
default: false,
|
|
175
|
+
});
|
|
176
|
+
if (!readyToContinue) {
|
|
177
|
+
logger.log('Release aborted.');
|
|
178
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const newVersion = semver.inc(localVersion, versionIncrement);
|
|
183
|
+
if (!newVersion) {
|
|
184
|
+
logger.error('Error incrementing version.');
|
|
185
|
+
process.exit(EXIT_CODES.ERROR);
|
|
186
|
+
}
|
|
187
|
+
if (isDryRun) {
|
|
188
|
+
logger.log('\nDRY RUN');
|
|
189
|
+
}
|
|
190
|
+
logger.log(`\nCurrent version: ${localVersion}`);
|
|
191
|
+
logger.log(`New version to release: ${newVersion}`);
|
|
192
|
+
const shouldRelease = await confirm({
|
|
193
|
+
message: `Release version ${newVersion}?`,
|
|
194
|
+
});
|
|
195
|
+
if (!shouldRelease) {
|
|
196
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
197
|
+
}
|
|
198
|
+
logger.log(`\nUpdating version to ${newVersion}...`);
|
|
199
|
+
await exec(`yarn version --no-git-tag-version --new-version ${newVersion}`);
|
|
200
|
+
logger.success('Version updated in package.json');
|
|
201
|
+
const changelogPath = path.resolve('CHANGELOG.md');
|
|
202
|
+
const commits = await getCommitsSinceLastTag();
|
|
203
|
+
const changelogEntries = await promptForChangelogEntries(commits);
|
|
204
|
+
if (changelogEntries.length === 0) {
|
|
205
|
+
logger.warn('No changelog entries provided. Skipping CHANGELOG update.');
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
await updateChangelog(newVersion, changelogEntries, changelogPath);
|
|
209
|
+
}
|
|
210
|
+
logger.log('\nPackaging regular release...');
|
|
211
|
+
await runVsceCommand('vsce:package');
|
|
212
|
+
logger.success('Regular release package created.');
|
|
213
|
+
const confirmRegularRelease = await confirm({
|
|
214
|
+
message: 'Test the regular release .vsix and confirm it works. Ready to proceed?',
|
|
215
|
+
default: false,
|
|
216
|
+
});
|
|
217
|
+
if (!confirmRegularRelease) {
|
|
218
|
+
logger.log('Release aborted after regular release packaging.');
|
|
219
|
+
logger.log('Note: package.json version and CHANGELOG.md have been updated locally. Revert if needed.');
|
|
220
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
221
|
+
}
|
|
222
|
+
const releaseBranch = `release/v${newVersion}`;
|
|
223
|
+
const changelogNotes = changelogEntries.length > 0
|
|
224
|
+
? changelogEntries.map(e => `- ${e}`).join('\n')
|
|
225
|
+
: 'See CHANGELOG.md for details.';
|
|
226
|
+
if (isDryRun) {
|
|
227
|
+
logger.log(`\nDry run: would create branch ${releaseBranch}`);
|
|
228
|
+
logger.log('Dry run: would commit package.json + CHANGELOG.md');
|
|
229
|
+
logger.log(`Dry run: would push ${releaseBranch}`);
|
|
230
|
+
logger.log(`Dry run: would create draft PR against ${mainBranch}`);
|
|
231
|
+
logger.log(`Dry run: would create draft GH release v${newVersion}`);
|
|
232
|
+
printSlackMessage(generateSlackMessage({
|
|
233
|
+
extensionName,
|
|
234
|
+
version: newVersion,
|
|
235
|
+
changelogEntries,
|
|
236
|
+
marketplaceUrl,
|
|
237
|
+
repositoryUrl,
|
|
238
|
+
}), resolvedSlackChannel);
|
|
239
|
+
logger.log('\nDry run release finished successfully.');
|
|
240
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
241
|
+
}
|
|
242
|
+
logger.log(`\nCreating release branch ${releaseBranch}...`);
|
|
243
|
+
await exec(`git checkout -b ${releaseBranch}`);
|
|
244
|
+
logger.log('Committing changes...');
|
|
245
|
+
await exec('git add package.json CHANGELOG.md');
|
|
246
|
+
await exec(`git commit -m "Bump version to ${newVersion}"`);
|
|
247
|
+
logger.log(`Pushing ${releaseBranch}...`);
|
|
248
|
+
await exec(`git push -u origin ${releaseBranch}`);
|
|
249
|
+
const prUrl = await createDraftPR({
|
|
250
|
+
baseBranch: mainBranch,
|
|
251
|
+
title: `Release v${newVersion}`,
|
|
252
|
+
body: `## Release v${newVersion}\n\n${changelogNotes}`,
|
|
253
|
+
});
|
|
254
|
+
const releaseUrl = await createGithubRelease({
|
|
255
|
+
tag: `v${newVersion}`,
|
|
256
|
+
title: `Version ${newVersion}`,
|
|
257
|
+
notes: changelogNotes,
|
|
258
|
+
});
|
|
259
|
+
printSlackMessage(generateSlackMessage({
|
|
260
|
+
extensionName,
|
|
261
|
+
version: newVersion,
|
|
262
|
+
changelogEntries,
|
|
263
|
+
marketplaceUrl,
|
|
264
|
+
repositoryUrl,
|
|
265
|
+
}), resolvedSlackChannel);
|
|
266
|
+
logger.log('\nNext steps:');
|
|
267
|
+
logger.log(' 1. Upload the .vsix file to the VS Code Marketplace:');
|
|
268
|
+
logger.log(` ${marketplaceUrl.replace('/items?itemName=', '/manage/publishers/')}`);
|
|
269
|
+
logger.log(' 2. Copy the Slack message above and post it');
|
|
270
|
+
logger.log(` 3. Merge the PR: ${prUrl}`);
|
|
271
|
+
if (releaseUrl) {
|
|
272
|
+
logger.log(` 4. Publish the GH release: ${releaseUrl}`);
|
|
273
|
+
}
|
|
274
|
+
await open('https://marketplace.visualstudio.com/manage/publishers/hubspot');
|
|
275
|
+
logger.success(`\n${packageName} version ${newVersion} release prepared successfully!`);
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
async function builder(yargs) {
|
|
279
|
+
return yargs.options({
|
|
280
|
+
versionIncrement: {
|
|
281
|
+
alias: 'v',
|
|
282
|
+
demandOption: true,
|
|
283
|
+
describe: 'SemVer increment type for the next release',
|
|
284
|
+
choices: VSCODE_VERSION_INCREMENT_OPTIONS,
|
|
285
|
+
},
|
|
286
|
+
dryRun: {
|
|
287
|
+
alias: 'd',
|
|
288
|
+
describe: 'Run through the release process without pushing or creating releases',
|
|
289
|
+
default: false,
|
|
290
|
+
type: 'boolean',
|
|
291
|
+
},
|
|
292
|
+
skipTests: {
|
|
293
|
+
describe: 'Skip the pre-release testing prompt',
|
|
294
|
+
default: false,
|
|
295
|
+
type: 'boolean',
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
export function buildVscodeReleaseScript({ packageJsonLocation, buildHandlerOptions, }) {
|
|
300
|
+
try {
|
|
301
|
+
const packageJsonContents = fs.readJsonSync(packageJsonLocation);
|
|
302
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
303
|
+
yargs(process.argv.slice(2))
|
|
304
|
+
.scriptName('yarn')
|
|
305
|
+
.usage('HubSpot VSCode extension release script')
|
|
306
|
+
.command('release', `Create a new release of the ${packageJsonContents.name} VSCode extension`, builder, buildHandler({
|
|
307
|
+
...buildHandlerOptions,
|
|
308
|
+
packageName: packageJsonContents.name,
|
|
309
|
+
localVersion: packageJsonContents.version,
|
|
310
|
+
mainBranch: buildHandlerOptions.mainBranch || DEFAULT_MAIN_BRANCH,
|
|
311
|
+
}))
|
|
312
|
+
.version(false)
|
|
313
|
+
.help().argv;
|
|
314
|
+
}
|
|
315
|
+
catch (e) {
|
|
316
|
+
logger.error(e);
|
|
317
|
+
process.exit(EXIT_CODES.ERROR);
|
|
318
|
+
}
|
|
319
|
+
}
|