@hubspot/npm-scripts 0.0.5-beta.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.
@@ -0,0 +1,5 @@
1
+ import { VscodeReleaseScriptBase } from './types.js';
2
+ export declare function buildVscodeReleaseScript({ packageJsonLocation, buildHandlerOptions, }: {
3
+ packageJsonLocation: string;
4
+ buildHandlerOptions: VscodeReleaseScriptBase;
5
+ }): void;
@@ -0,0 +1,166 @@
1
+ import { exec as _exec } from 'node:child_process';
2
+ import { promisify } from 'util';
3
+ import yargs from 'yargs';
4
+ import semver from 'semver';
5
+ import open from 'open';
6
+ import fs from 'fs-extra';
7
+ import { logger } from './utils/logging.js';
8
+ import { EXIT_CODES } from './utils/process.js';
9
+ import { DEFAULT_MAIN_BRANCH, VSCODE_VERSION_INCREMENT_OPTIONS, } from './constants/release.js';
10
+ import { getCurrentGitBranch } from './utils/git.js';
11
+ import { confirm } from './utils/prompting.js';
12
+ const exec = promisify(_exec);
13
+ function buildHandler({ build, packageName, localVersion, mainBranch, }) {
14
+ return async function handler({ versionIncrement, dryRun, skipTests, }) {
15
+ try {
16
+ const branch = await getCurrentGitBranch();
17
+ const isDryRun = Boolean(dryRun);
18
+ if (branch !== mainBranch) {
19
+ logger.error(`Releases can only be published from the ${mainBranch} branch. Current branch: ${branch}`);
20
+ process.exit(EXIT_CODES.ERROR);
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
+ }
38
+ if (!skipTests) {
39
+ const userHasTested = await confirm({
40
+ message: 'Have you tested the pre-release package locally?',
41
+ default: false,
42
+ });
43
+ if (!userHasTested) {
44
+ logger.log('\nBuilding and packaging the pre-release for testing...\n');
45
+ if (build && typeof build === 'function') {
46
+ await build();
47
+ }
48
+ else {
49
+ logger.log('Installing dependencies...');
50
+ await exec('yarn install');
51
+ logger.log('Running linting...');
52
+ await exec('yarn lint');
53
+ }
54
+ logger.log('\nPackaging pre-release...');
55
+ await exec('npx vsce package --pre-release -o releases/');
56
+ logger.success('Pre-release package created.');
57
+ logger.log('\nTo test the package locally:');
58
+ logger.log(' 1. Open VS Code');
59
+ logger.log(' 2. Go to the Extensions panel');
60
+ logger.log(' 3. Click "..." menu → "Install from VSIX..."');
61
+ logger.log(' 4. Select the .vsix file created above');
62
+ logger.log(' 5. Test key functionality\n');
63
+ const readyToContinue = await confirm({
64
+ message: 'Continue when you have finished testing the pre-release.',
65
+ default: false,
66
+ });
67
+ if (!readyToContinue) {
68
+ logger.log('Release aborted.');
69
+ process.exit(EXIT_CODES.SUCCESS);
70
+ }
71
+ }
72
+ }
73
+ logger.log(`\nUpdating version to ${newVersion}...`);
74
+ await exec(`yarn version --no-git-tag-version --new-version ${newVersion}`);
75
+ logger.success('Version updated in package.json');
76
+ logger.log('\nPackaging regular release...');
77
+ await exec('npx vsce package -o releases/');
78
+ logger.success('Regular release package created.');
79
+ const confirmRegularRelease = await confirm({
80
+ message: 'Test the regular release .vsix and confirm it works. Ready to proceed?',
81
+ default: false,
82
+ });
83
+ if (!confirmRegularRelease) {
84
+ logger.log('Release aborted after regular release packaging.');
85
+ logger.log('Note: package.json version has been updated locally. Revert if needed.');
86
+ process.exit(EXIT_CODES.SUCCESS);
87
+ }
88
+ const releaseBranch = `release/v${newVersion}`;
89
+ if (isDryRun) {
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`);
97
+ process.exit(EXIT_CODES.SUCCESS);
98
+ }
99
+ logger.log(`\nCreating release branch ${releaseBranch}...`);
100
+ await exec(`git checkout -b ${releaseBranch}`);
101
+ logger.log('Committing changes...');
102
+ await exec('git add package.json');
103
+ await exec(`git commit -m "Bump version to ${newVersion}"`);
104
+ logger.log(`Pushing ${releaseBranch}...`);
105
+ await exec(`git push -u origin ${releaseBranch}`);
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()}`);
112
+ logger.log('\nNext steps:');
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()}`);
116
+ await open('https://marketplace.visualstudio.com/manage/publishers/hubspot');
117
+ logger.success(`\n${packageName} version ${newVersion} release prepared successfully!`);
118
+ }
119
+ catch (e) {
120
+ logger.error(e);
121
+ process.exit(EXIT_CODES.ERROR);
122
+ }
123
+ };
124
+ }
125
+ async function builder(yargs) {
126
+ return yargs.options({
127
+ versionIncrement: {
128
+ alias: 'v',
129
+ demandOption: true,
130
+ describe: 'SemVer increment type for the next release',
131
+ choices: VSCODE_VERSION_INCREMENT_OPTIONS,
132
+ },
133
+ dryRun: {
134
+ alias: 'd',
135
+ describe: 'Run through the release process without pushing or creating releases',
136
+ default: false,
137
+ type: 'boolean',
138
+ },
139
+ skipTests: {
140
+ describe: 'Skip the pre-release testing prompt',
141
+ default: false,
142
+ type: 'boolean',
143
+ },
144
+ });
145
+ }
146
+ export function buildVscodeReleaseScript({ packageJsonLocation, buildHandlerOptions, }) {
147
+ try {
148
+ const packageJsonContents = fs.readJsonSync(packageJsonLocation);
149
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
150
+ yargs(process.argv.slice(2))
151
+ .scriptName('yarn')
152
+ .usage('HubSpot VSCode extension release script')
153
+ .command('release', `Create a new release of the ${packageJsonContents.name} VSCode extension`, builder, buildHandler({
154
+ ...buildHandlerOptions,
155
+ packageName: packageJsonContents.name,
156
+ localVersion: packageJsonContents.version,
157
+ mainBranch: buildHandlerOptions.mainBranch || DEFAULT_MAIN_BRANCH,
158
+ }))
159
+ .version(false)
160
+ .help().argv;
161
+ }
162
+ catch (e) {
163
+ logger.error(e);
164
+ process.exit(EXIT_CODES.ERROR);
165
+ }
166
+ }