@hubspot/npm-scripts 0.0.5-experimental.0 → 0.0.5-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/package.json +1 -1
- package/src/types.d.ts +2 -5
- package/src/vscode-release.js +73 -164
package/package.json
CHANGED
package/src/types.d.ts
CHANGED
|
@@ -37,14 +37,11 @@ export interface BuildReleaseScriptOptions extends BuildReleaseScriptBase {
|
|
|
37
37
|
export type VscodeReleaseArguments = {
|
|
38
38
|
versionIncrement: (typeof VSCODE_VERSION_INCREMENT_OPTIONS)[number];
|
|
39
39
|
dryRun: boolean;
|
|
40
|
-
|
|
40
|
+
skipBranchValidation: boolean;
|
|
41
|
+
skipVersionCheck: boolean;
|
|
41
42
|
};
|
|
42
43
|
export interface VscodeReleaseScriptBase {
|
|
43
|
-
repositoryUrl: string;
|
|
44
44
|
mainBranch?: string;
|
|
45
|
-
marketplaceUrl: string;
|
|
46
|
-
extensionName: string;
|
|
47
|
-
slackChannel?: string;
|
|
48
45
|
build?: () => Promise<void> | void;
|
|
49
46
|
}
|
|
50
47
|
export interface VscodeReleaseScriptOptions extends VscodeReleaseScriptBase {
|
package/src/vscode-release.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { exec as _exec
|
|
1
|
+
import { exec as _exec } from 'node:child_process';
|
|
2
2
|
import { promisify } from 'util';
|
|
3
3
|
import yargs from 'yargs';
|
|
4
4
|
import semver from 'semver';
|
|
@@ -10,118 +10,27 @@ import { DEFAULT_MAIN_BRANCH, VSCODE_VERSION_INCREMENT_OPTIONS, } from './consta
|
|
|
10
10
|
import { getCurrentGitBranch } from './utils/git.js';
|
|
11
11
|
import { confirm } from './utils/prompting.js';
|
|
12
12
|
const exec = promisify(_exec);
|
|
13
|
-
function
|
|
14
|
-
return
|
|
15
|
-
const child = spawn('yarn', [script], {
|
|
16
|
-
stdio: ['pipe', 'inherit', 'inherit'],
|
|
17
|
-
});
|
|
18
|
-
child.stdin?.write('y\n');
|
|
19
|
-
child.stdin?.end();
|
|
20
|
-
child.on('close', code => {
|
|
21
|
-
if (code !== EXIT_CODES.SUCCESS) {
|
|
22
|
-
reject(new Error(`"yarn ${script}" failed with exit code ${code}`));
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
resolve();
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
async function getLastTag() {
|
|
31
|
-
try {
|
|
32
|
-
const { stdout } = await exec('git describe --tags --abbrev=0');
|
|
33
|
-
return stdout.trim();
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
async function createDraftPR({ baseBranch, title, body, }) {
|
|
40
|
-
logger.log('\nCreating draft pull request...');
|
|
41
|
-
try {
|
|
42
|
-
const { stdout } = await exec(`gh pr create --draft --base ${baseBranch} --title "${title}" --body "${body.replace(/"/g, '\\"')}"`);
|
|
43
|
-
const prUrl = stdout.trim();
|
|
44
|
-
logger.success(`Draft PR created: ${prUrl}`);
|
|
45
|
-
return prUrl;
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
logger.error('Failed to create pull request:', error);
|
|
49
|
-
process.exit(EXIT_CODES.ERROR);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
async function createGithubRelease({ tag, title, notes, }) {
|
|
53
|
-
logger.log('\nCreating GitHub release...');
|
|
54
|
-
try {
|
|
55
|
-
const { stdout } = await exec(`gh release create ${tag} --title "${title}" --notes "${notes.replace(/"/g, '\\"')}" --draft`);
|
|
56
|
-
const releaseUrl = stdout.trim();
|
|
57
|
-
logger.success(`Draft GitHub release created: ${releaseUrl}`);
|
|
58
|
-
return releaseUrl;
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
logger.error('Failed to create GitHub release:', error);
|
|
62
|
-
process.exit(EXIT_CODES.ERROR);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function generateSlackMessage({ extensionName, version, marketplaceUrl, repositoryUrl, }) {
|
|
66
|
-
return [
|
|
67
|
-
`\u{1F4E6} ${extensionName} VSCode Extension v${version} Released`,
|
|
68
|
-
'',
|
|
69
|
-
'*Links:*',
|
|
70
|
-
`- Marketplace: ${marketplaceUrl}`,
|
|
71
|
-
`- Changelog: ${repositoryUrl}/blob/master/CHANGELOG.md`,
|
|
72
|
-
].join('\n');
|
|
73
|
-
}
|
|
74
|
-
function printSlackMessage(message, channel) {
|
|
75
|
-
logger.log('\n' + '='.repeat(60));
|
|
76
|
-
logger.log(`Slack message for ${channel}:`);
|
|
77
|
-
logger.log('='.repeat(60));
|
|
78
|
-
logger.log(message);
|
|
79
|
-
logger.log('='.repeat(60));
|
|
80
|
-
}
|
|
81
|
-
function buildHandler({ build, packageName, localVersion, repositoryUrl, mainBranch, marketplaceUrl, extensionName, slackChannel, }) {
|
|
82
|
-
return async function handler({ versionIncrement, dryRun, skipTests, }) {
|
|
13
|
+
function buildHandler({ build, packageName, localVersion, mainBranch, }) {
|
|
14
|
+
return async function handler({ versionIncrement, dryRun, skipBranchValidation, skipVersionCheck, }) {
|
|
83
15
|
try {
|
|
84
16
|
const branch = await getCurrentGitBranch();
|
|
85
17
|
const isDryRun = Boolean(dryRun);
|
|
86
|
-
|
|
87
|
-
if (branch !== mainBranch) {
|
|
18
|
+
if (!skipBranchValidation && branch !== mainBranch) {
|
|
88
19
|
logger.error(`Releases can only be published from the ${mainBranch} branch. Current branch: ${branch}`);
|
|
89
20
|
process.exit(EXIT_CODES.ERROR);
|
|
90
21
|
}
|
|
91
|
-
if (!
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (build && typeof build === 'function') {
|
|
99
|
-
await build();
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
logger.log('Installing dependencies...');
|
|
103
|
-
await exec('yarn install');
|
|
104
|
-
logger.log('Running linting...');
|
|
105
|
-
await exec('yarn lint');
|
|
106
|
-
}
|
|
107
|
-
logger.log('\nPackaging pre-release...');
|
|
108
|
-
await runVsceCommand('vsce:prerelease');
|
|
109
|
-
logger.success('Pre-release package created.');
|
|
110
|
-
logger.log('\nTo test the package locally:');
|
|
111
|
-
logger.log(' 1. Open VS Code');
|
|
112
|
-
logger.log(' 2. Go to the Extensions panel');
|
|
113
|
-
logger.log(' 3. Click "..." menu → "Install from VSIX..."');
|
|
114
|
-
logger.log(' 4. Select the .vsix file created above');
|
|
115
|
-
logger.log(' 5. Test key functionality\n');
|
|
116
|
-
const readyToContinue = await confirm({
|
|
117
|
-
message: 'Continue when you have finished testing the pre-release.',
|
|
118
|
-
default: false,
|
|
119
|
-
});
|
|
120
|
-
if (!readyToContinue) {
|
|
121
|
-
logger.log('Release aborted.');
|
|
122
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
22
|
+
if (!skipVersionCheck) {
|
|
23
|
+
try {
|
|
24
|
+
const { stdout: lastTag } = await exec('git describe --tags --abbrev=0');
|
|
25
|
+
const lastTagVersion = lastTag.trim().replace(/^v/, '');
|
|
26
|
+
if (lastTagVersion !== localVersion) {
|
|
27
|
+
logger.error(`Local package.json version ${localVersion} is out of sync with the latest git tag v${lastTagVersion}`);
|
|
28
|
+
process.exit(EXIT_CODES.ERROR);
|
|
123
29
|
}
|
|
124
30
|
}
|
|
31
|
+
catch {
|
|
32
|
+
logger.warn('No git tags found, skipping version check.');
|
|
33
|
+
}
|
|
125
34
|
}
|
|
126
35
|
const newVersion = semver.inc(localVersion, versionIncrement);
|
|
127
36
|
if (!newVersion) {
|
|
@@ -139,29 +48,44 @@ function buildHandler({ build, packageName, localVersion, repositoryUrl, mainBra
|
|
|
139
48
|
if (!shouldRelease) {
|
|
140
49
|
process.exit(EXIT_CODES.SUCCESS);
|
|
141
50
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
logger.success('Version updated in package.json');
|
|
145
|
-
const lastTag = await getLastTag();
|
|
146
|
-
if (lastTag) {
|
|
147
|
-
logger.log(`\nUpdate CHANGELOG.md with the changes since ${lastTag}:`);
|
|
148
|
-
logger.log(` ${repositoryUrl}/compare/${lastTag}...${mainBranch}`);
|
|
149
|
-
await open(`${repositoryUrl}/compare/${lastTag}...${mainBranch}`);
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
logger.log('\nUpdate CHANGELOG.md with the changes for this release.');
|
|
153
|
-
}
|
|
154
|
-
const changelogUpdated = await confirm({
|
|
155
|
-
message: 'Have you updated CHANGELOG.md?',
|
|
51
|
+
const userHasTested = await confirm({
|
|
52
|
+
message: 'Have you tested the pre-release package locally?',
|
|
156
53
|
default: false,
|
|
157
54
|
});
|
|
158
|
-
if (!
|
|
159
|
-
logger.log('
|
|
160
|
-
|
|
161
|
-
|
|
55
|
+
if (!userHasTested) {
|
|
56
|
+
logger.log('\nBuilding and packaging the pre-release for testing...\n');
|
|
57
|
+
if (build && typeof build === 'function') {
|
|
58
|
+
await build();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
logger.log('Installing dependencies...');
|
|
62
|
+
await exec('yarn install');
|
|
63
|
+
logger.log('Running linting...');
|
|
64
|
+
await exec('yarn lint');
|
|
65
|
+
}
|
|
66
|
+
logger.log('\nPackaging pre-release...');
|
|
67
|
+
await exec('npx vsce package --pre-release -o releases/');
|
|
68
|
+
logger.success('Pre-release package created.');
|
|
69
|
+
logger.log('\nTo test the package locally:');
|
|
70
|
+
logger.log(' 1. Open VS Code');
|
|
71
|
+
logger.log(' 2. Go to the Extensions panel');
|
|
72
|
+
logger.log(' 3. Click "..." menu → "Install from VSIX..."');
|
|
73
|
+
logger.log(' 4. Select the .vsix file created above');
|
|
74
|
+
logger.log(' 5. Test key functionality\n');
|
|
75
|
+
const readyToContinue = await confirm({
|
|
76
|
+
message: 'Continue when you have finished testing the pre-release.',
|
|
77
|
+
default: false,
|
|
78
|
+
});
|
|
79
|
+
if (!readyToContinue) {
|
|
80
|
+
logger.log('Release aborted.');
|
|
81
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
82
|
+
}
|
|
162
83
|
}
|
|
84
|
+
logger.log(`\nUpdating version to ${newVersion}...`);
|
|
85
|
+
await exec(`yarn version --no-git-tag-version --new-version ${newVersion}`);
|
|
86
|
+
logger.success('Version updated in package.json');
|
|
163
87
|
logger.log('\nPackaging regular release...');
|
|
164
|
-
await
|
|
88
|
+
await exec('npx vsce package -o releases/');
|
|
165
89
|
logger.success('Regular release package created.');
|
|
166
90
|
const confirmRegularRelease = await confirm({
|
|
167
91
|
message: 'Test the regular release .vsix and confirm it works. Ready to proceed?',
|
|
@@ -169,57 +93,37 @@ function buildHandler({ build, packageName, localVersion, repositoryUrl, mainBra
|
|
|
169
93
|
});
|
|
170
94
|
if (!confirmRegularRelease) {
|
|
171
95
|
logger.log('Release aborted after regular release packaging.');
|
|
172
|
-
logger.log('Note: package.json version
|
|
96
|
+
logger.log('Note: package.json version has been updated locally. Revert if needed.');
|
|
173
97
|
process.exit(EXIT_CODES.SUCCESS);
|
|
174
98
|
}
|
|
175
99
|
const releaseBranch = `release/v${newVersion}`;
|
|
176
|
-
const releaseNotes = 'See CHANGELOG.md for details.';
|
|
177
100
|
if (isDryRun) {
|
|
178
|
-
logger.log(
|
|
179
|
-
logger.log(
|
|
180
|
-
logger.log(`
|
|
181
|
-
logger.log(`
|
|
182
|
-
logger.log(`
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
version: newVersion,
|
|
186
|
-
marketplaceUrl,
|
|
187
|
-
repositoryUrl,
|
|
188
|
-
}), resolvedSlackChannel);
|
|
189
|
-
logger.log('\nDry run release finished successfully.');
|
|
101
|
+
logger.log('\nDry run complete. Would have:');
|
|
102
|
+
logger.log(` 1. Created branch ${releaseBranch}`);
|
|
103
|
+
logger.log(` 2. Committed package.json version bump`);
|
|
104
|
+
logger.log(` 3. Pushed ${releaseBranch} to origin`);
|
|
105
|
+
logger.log(` 4. Created draft PR against ${mainBranch}`);
|
|
106
|
+
logger.log(` 5. Created draft GH release v${newVersion}`);
|
|
107
|
+
logger.log(` 6. Opened VS Code Marketplace for .vsix upload`);
|
|
190
108
|
process.exit(EXIT_CODES.SUCCESS);
|
|
191
109
|
}
|
|
192
110
|
logger.log(`\nCreating release branch ${releaseBranch}...`);
|
|
193
111
|
await exec(`git checkout -b ${releaseBranch}`);
|
|
194
112
|
logger.log('Committing changes...');
|
|
195
|
-
await exec('git add package.json
|
|
113
|
+
await exec('git add package.json');
|
|
196
114
|
await exec(`git commit -m "Bump version to ${newVersion}"`);
|
|
197
115
|
logger.log(`Pushing ${releaseBranch}...`);
|
|
198
116
|
await exec(`git push -u origin ${releaseBranch}`);
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
tag: `v${newVersion}`,
|
|
206
|
-
title: `Version ${newVersion}`,
|
|
207
|
-
notes: releaseNotes,
|
|
208
|
-
});
|
|
209
|
-
printSlackMessage(generateSlackMessage({
|
|
210
|
-
extensionName,
|
|
211
|
-
version: newVersion,
|
|
212
|
-
marketplaceUrl,
|
|
213
|
-
repositoryUrl,
|
|
214
|
-
}), resolvedSlackChannel);
|
|
117
|
+
logger.log('\nCreating draft pull request...');
|
|
118
|
+
const { stdout: prUrl } = await exec(`gh pr create --draft --base ${mainBranch} --title "Release v${newVersion}" --body "## Release v${newVersion}"`);
|
|
119
|
+
logger.success(`Draft PR created: ${prUrl.trim()}`);
|
|
120
|
+
logger.log('\nCreating draft GitHub release...');
|
|
121
|
+
const { stdout: releaseUrl } = await exec(`gh release create v${newVersion} --title "Version ${newVersion}" --notes "" --draft`);
|
|
122
|
+
logger.success(`Draft GitHub release created: ${releaseUrl.trim()}`);
|
|
215
123
|
logger.log('\nNext steps:');
|
|
216
|
-
logger.log(' 1. Upload the .vsix file to the VS Code Marketplace
|
|
217
|
-
logger.log(`
|
|
218
|
-
logger.log(
|
|
219
|
-
logger.log(` 3. Merge the PR: ${prUrl}`);
|
|
220
|
-
if (releaseUrl) {
|
|
221
|
-
logger.log(` 4. Publish the GH release: ${releaseUrl}`);
|
|
222
|
-
}
|
|
124
|
+
logger.log(' 1. Upload the .vsix file to the VS Code Marketplace');
|
|
125
|
+
logger.log(` 2. Merge the PR: ${prUrl.trim()}`);
|
|
126
|
+
logger.log(` 3. Publish the GH release: ${releaseUrl.trim()}`);
|
|
223
127
|
await open('https://marketplace.visualstudio.com/manage/publishers/hubspot');
|
|
224
128
|
logger.success(`\n${packageName} version ${newVersion} release prepared successfully!`);
|
|
225
129
|
}
|
|
@@ -243,8 +147,13 @@ async function builder(yargs) {
|
|
|
243
147
|
default: false,
|
|
244
148
|
type: 'boolean',
|
|
245
149
|
},
|
|
246
|
-
|
|
247
|
-
describe: '
|
|
150
|
+
skipBranchValidation: {
|
|
151
|
+
describe: 'Bypass the branch validation check',
|
|
152
|
+
default: false,
|
|
153
|
+
type: 'boolean',
|
|
154
|
+
},
|
|
155
|
+
skipVersionCheck: {
|
|
156
|
+
describe: 'Bypass checking that the local version matches the published version',
|
|
248
157
|
default: false,
|
|
249
158
|
type: 'boolean',
|
|
250
159
|
},
|