@hubspot/npm-scripts 0.0.5-experimental.0 → 0.0.5-experimental.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/npm-scripts",
3
- "version": "0.0.5-experimental.0",
3
+ "version": "0.0.5-experimental.1",
4
4
  "description": "Scripts for working with npm packages in the HubSpot ecosystem",
5
5
  "author": "",
6
6
  "license": "Apache-2.0",
package/src/types.d.ts CHANGED
@@ -40,11 +40,7 @@ export type VscodeReleaseArguments = {
40
40
  skipTests: boolean;
41
41
  };
42
42
  export interface VscodeReleaseScriptBase {
43
- repositoryUrl: string;
44
43
  mainBranch?: string;
45
- marketplaceUrl: string;
46
- extensionName: string;
47
- slackChannel?: string;
48
44
  build?: () => Promise<void> | void;
49
45
  }
50
46
  export interface VscodeReleaseScriptOptions extends VscodeReleaseScriptBase {
@@ -1,4 +1,4 @@
1
- import { exec as _exec, spawn } from 'node:child_process';
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,84 +10,31 @@ 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 runVsceCommand(script) {
14
- return new Promise((resolve, reject) => {
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, }) {
13
+ function buildHandler({ build, packageName, localVersion, mainBranch, }) {
82
14
  return async function handler({ versionIncrement, dryRun, skipTests, }) {
83
15
  try {
84
16
  const branch = await getCurrentGitBranch();
85
17
  const isDryRun = Boolean(dryRun);
86
- const resolvedSlackChannel = slackChannel || '#cli-dev';
87
18
  if (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
  }
22
+ const newVersion = semver.inc(localVersion, versionIncrement);
23
+ if (!newVersion) {
24
+ logger.error('Error incrementing version.');
25
+ process.exit(EXIT_CODES.ERROR);
26
+ }
27
+ if (isDryRun) {
28
+ logger.log('\nDRY RUN');
29
+ }
30
+ logger.log(`\nCurrent version: ${localVersion}`);
31
+ logger.log(`New version to release: ${newVersion}`);
32
+ const shouldRelease = await confirm({
33
+ message: `Release version ${newVersion}?`,
34
+ });
35
+ if (!shouldRelease) {
36
+ process.exit(EXIT_CODES.SUCCESS);
37
+ }
91
38
  if (!skipTests) {
92
39
  const userHasTested = await confirm({
93
40
  message: 'Have you tested the pre-release package locally?',
@@ -105,7 +52,7 @@ function buildHandler({ build, packageName, localVersion, repositoryUrl, mainBra
105
52
  await exec('yarn lint');
106
53
  }
107
54
  logger.log('\nPackaging pre-release...');
108
- await runVsceCommand('vsce:prerelease');
55
+ await exec('npx vsce package --pre-release -o releases/');
109
56
  logger.success('Pre-release package created.');
110
57
  logger.log('\nTo test the package locally:');
111
58
  logger.log(' 1. Open VS Code');
@@ -123,45 +70,11 @@ function buildHandler({ build, packageName, localVersion, repositoryUrl, mainBra
123
70
  }
124
71
  }
125
72
  }
126
- const newVersion = semver.inc(localVersion, versionIncrement);
127
- if (!newVersion) {
128
- logger.error('Error incrementing version.');
129
- process.exit(EXIT_CODES.ERROR);
130
- }
131
- if (isDryRun) {
132
- logger.log('\nDRY RUN');
133
- }
134
- logger.log(`\nCurrent version: ${localVersion}`);
135
- logger.log(`New version to release: ${newVersion}`);
136
- const shouldRelease = await confirm({
137
- message: `Release version ${newVersion}?`,
138
- });
139
- if (!shouldRelease) {
140
- process.exit(EXIT_CODES.SUCCESS);
141
- }
142
73
  logger.log(`\nUpdating version to ${newVersion}...`);
143
74
  await exec(`yarn version --no-git-tag-version --new-version ${newVersion}`);
144
75
  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?',
156
- default: false,
157
- });
158
- if (!changelogUpdated) {
159
- logger.log('Release aborted.');
160
- logger.log('Note: package.json version has been updated locally. Revert if needed.');
161
- process.exit(EXIT_CODES.SUCCESS);
162
- }
163
76
  logger.log('\nPackaging regular release...');
164
- await runVsceCommand('vsce:package');
77
+ await exec('npx vsce package -o releases/');
165
78
  logger.success('Regular release package created.');
166
79
  const confirmRegularRelease = await confirm({
167
80
  message: 'Test the regular release .vsix and confirm it works. Ready to proceed?',
@@ -169,57 +82,37 @@ function buildHandler({ build, packageName, localVersion, repositoryUrl, mainBra
169
82
  });
170
83
  if (!confirmRegularRelease) {
171
84
  logger.log('Release aborted after regular release packaging.');
172
- logger.log('Note: package.json version and CHANGELOG.md have been updated locally. Revert if needed.');
85
+ logger.log('Note: package.json version has been updated locally. Revert if needed.');
173
86
  process.exit(EXIT_CODES.SUCCESS);
174
87
  }
175
88
  const releaseBranch = `release/v${newVersion}`;
176
- const releaseNotes = 'See CHANGELOG.md for details.';
177
89
  if (isDryRun) {
178
- logger.log(`\nDry run: would create branch ${releaseBranch}`);
179
- logger.log('Dry run: would commit package.json + CHANGELOG.md');
180
- logger.log(`Dry run: would push ${releaseBranch}`);
181
- logger.log(`Dry run: would create draft PR against ${mainBranch}`);
182
- logger.log(`Dry run: would create draft GH release v${newVersion}`);
183
- printSlackMessage(generateSlackMessage({
184
- extensionName,
185
- version: newVersion,
186
- marketplaceUrl,
187
- repositoryUrl,
188
- }), resolvedSlackChannel);
189
- logger.log('\nDry run release finished successfully.');
90
+ logger.log('\nDry run complete. Would have:');
91
+ logger.log(` 1. Created branch ${releaseBranch}`);
92
+ logger.log(` 2. Committed package.json version bump`);
93
+ logger.log(` 3. Pushed ${releaseBranch} to origin`);
94
+ logger.log(` 4. Created draft PR against ${mainBranch}`);
95
+ logger.log(` 5. Created draft GH release v${newVersion}`);
96
+ logger.log(` 6. Opened VS Code Marketplace for .vsix upload`);
190
97
  process.exit(EXIT_CODES.SUCCESS);
191
98
  }
192
99
  logger.log(`\nCreating release branch ${releaseBranch}...`);
193
100
  await exec(`git checkout -b ${releaseBranch}`);
194
101
  logger.log('Committing changes...');
195
- await exec('git add package.json CHANGELOG.md');
102
+ await exec('git add package.json');
196
103
  await exec(`git commit -m "Bump version to ${newVersion}"`);
197
104
  logger.log(`Pushing ${releaseBranch}...`);
198
105
  await exec(`git push -u origin ${releaseBranch}`);
199
- const prUrl = await createDraftPR({
200
- baseBranch: mainBranch,
201
- title: `Release v${newVersion}`,
202
- body: `## Release v${newVersion}\n\n${releaseNotes}`,
203
- });
204
- const releaseUrl = await createGithubRelease({
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);
106
+ logger.log('\nCreating draft pull request...');
107
+ const { stdout: prUrl } = await exec(`gh pr create --draft --base ${mainBranch} --title "Release v${newVersion}" --body "## Release v${newVersion}"`);
108
+ logger.success(`Draft PR created: ${prUrl.trim()}`);
109
+ logger.log('\nCreating draft GitHub release...');
110
+ const { stdout: releaseUrl } = await exec(`gh release create v${newVersion} --title "Version ${newVersion}" --notes "" --draft`);
111
+ logger.success(`Draft GitHub release created: ${releaseUrl.trim()}`);
215
112
  logger.log('\nNext steps:');
216
- logger.log(' 1. Upload the .vsix file to the VS Code Marketplace:');
217
- logger.log(` ${marketplaceUrl.replace('/items?itemName=', '/manage/publishers/')}`);
218
- logger.log(' 2. Copy the Slack message above and post it');
219
- logger.log(` 3. Merge the PR: ${prUrl}`);
220
- if (releaseUrl) {
221
- logger.log(` 4. Publish the GH release: ${releaseUrl}`);
222
- }
113
+ logger.log(' 1. Upload the .vsix file to the VS Code Marketplace');
114
+ logger.log(` 2. Merge the PR: ${prUrl.trim()}`);
115
+ logger.log(` 3. Publish the GH release: ${releaseUrl.trim()}`);
223
116
  await open('https://marketplace.visualstudio.com/manage/publishers/hubspot');
224
117
  logger.success(`\n${packageName} version ${newVersion} release prepared successfully!`);
225
118
  }