@hubspot/npm-scripts 0.0.4 → 0.0.5-experimental.0

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 CHANGED
@@ -11,6 +11,7 @@ The linking tool helps manage symlinked HubSpot packages in your development env
11
11
  #### Usage
12
12
 
13
13
  It can be used via npx
14
+
14
15
  ```bash
15
16
  npx @hubspot/npm-scripts hubspot-linking
16
17
  ```
@@ -64,8 +65,8 @@ buildReleaseScript({
64
65
  },
65
66
  postLatestRelease: async () => {
66
67
  // Optional function to run after latest releases
67
- }
68
- }
68
+ },
69
+ },
69
70
  });
70
71
  ```
71
72
 
@@ -113,3 +114,67 @@ yarn release -v=patch -t=latest -d
113
114
  - **GitHub integration**: Opens PR and release pages automatically
114
115
  - **Rollback support**: Cleans up on failure
115
116
 
117
+ ### Repo Sync Script Builder (`buildRepoSyncScript`)
118
+
119
+ A utility function that creates a script to sync changes from an internal repository to a target repository (e.g., syncing internal packages to public GitHub).
120
+
121
+ #### Usage
122
+
123
+ Create a repo sync script file (e.g., `scripts/repo-sync.ts`):
124
+
125
+ ```typescript
126
+ import { buildRepoSyncScript } from '@hubspot/npm-scripts';
127
+
128
+ buildRepoSyncScript({
129
+ buildHandlerOptions: {
130
+ targetRepositoryOrg: 'https://github.com/your-org',
131
+ targetRepositoryName: 'public-repo',
132
+ buildCommitMessage: version =>
133
+ `Sync changes from internal repo for version ${version}`,
134
+ mainBranch: 'main', // optional, defaults to 'master'
135
+ excludePatterns: [
136
+ // optional, custom patterns to exclude from sync
137
+ 'internal-only-file.ts',
138
+ 'tests',
139
+ 'tests/**',
140
+ ],
141
+ },
142
+ });
143
+ ```
144
+
145
+ **NOTE:** The sync script will always ignore the `hs-temp-repo-sync` and `.git` directories
146
+
147
+ Then add to your `package.json`:
148
+
149
+ ```json
150
+ {
151
+ "scripts": {
152
+ "repo-sync": "tsx ./scripts/repo-sync.ts repo-sync"
153
+ }
154
+ }
155
+ ```
156
+
157
+ #### Repo Sync Commands
158
+
159
+ ```bash
160
+ # Sync changes to target repository
161
+ yarn repo-sync -v=1.0.0 --ssh-key=~/.ssh/id_rsa
162
+
163
+ # Dry run (test without pushing)
164
+ yarn repo-sync -v=1.0.0 -d
165
+ ```
166
+
167
+ #### Parameters
168
+
169
+ - `-v, --version`: Version to label the sync branch (required)
170
+ - `-d, --dryRun`: Run without pushing changes
171
+ - `--ssh-key`: Path to SSH key for target repository operations
172
+
173
+ #### Features
174
+
175
+ - **Branch protection**: Ensures sync happens from the correct branch
176
+ - **Automatic branching**: Creates a sync branch in the target repository
177
+ - **GitHub integration**: Opens PR page automatically after push
178
+ - **Cleanup support**: Removes temporary directories after completion
179
+
180
+ This script supports a `PUBLIC_README.md` pattern that allows you to maintain an internal readme file that does not sync to the target repo. The `PUBLIC_README.md` file will sync into the target repo as `README.md`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/npm-scripts",
3
- "version": "0.0.4",
3
+ "version": "0.0.5-experimental.0",
4
4
  "description": "Scripts for working with npm packages in the HubSpot ecosystem",
5
5
  "author": "",
6
6
  "license": "Apache-2.0",
@@ -14,13 +14,16 @@
14
14
  "local-dev": "yarn build && cd dist && yarn link && cd .. && tsc -w",
15
15
  "prettier:write": "prettier --write './**/*.{ts,js,json}'",
16
16
  "release": "yarn tsx ./scripts/release.ts release",
17
- "test": "echo \"Error: no test specified\" && exit 1"
17
+ "repo-sync": "yarn tsx ./scripts/repo-sync.ts repo-sync",
18
+ "test": "vitest run",
19
+ "test-dev": "vitest"
18
20
  },
19
21
  "dependencies": {
20
22
  "@inquirer/prompts": "^7.8.6",
21
23
  "chalk": "^5.6.2",
22
24
  "findup-sync": "^5.0.0",
23
25
  "fs-extra": "^11.3.2",
26
+ "minimatch": "^10.0.1",
24
27
  "open": "^10.2.0",
25
28
  "semver": "^7.7.2",
26
29
  "yargs": "17.7.2"
@@ -29,7 +32,7 @@
29
32
  "@eslint/js": "^9.36.0",
30
33
  "@types/findup-sync": "^4.0.5",
31
34
  "@types/fs-extra": "^11.0.4",
32
- "@types/node": "^24.5.2",
35
+ "@types/node": "^25.0.3",
33
36
  "@types/semver": "^7.7.1",
34
37
  "@types/yargs": "^17.0.33",
35
38
  "@typescript-eslint/eslint-plugin": "^8.44.1",
@@ -38,10 +41,11 @@
38
41
  "eslint-plugin-import": "^2.32.0",
39
42
  "globals": "^16.4.0",
40
43
  "husky": "^4.3.8",
41
- "lint-staged": "^16.2.1",
44
+ "lint-staged": "^15.2.10",
42
45
  "prettier": "^3.6.2",
43
46
  "tsx": "^4.20.5",
44
- "typescript": "^5.6.2"
47
+ "typescript": "^5.6.2",
48
+ "vitest": "^2.1.8"
45
49
  },
46
50
  "lint-staged": {
47
51
  "**/*.{js,ts,tsx,scss,css}": [
@@ -3,6 +3,7 @@ export declare const TAG: {
3
3
  readonly LATEST: "latest";
4
4
  readonly NEXT: "next";
5
5
  readonly EXPERIMENTAL: "experimental";
6
+ readonly PREVIOUS: "previous";
6
7
  };
7
8
  export declare const INCREMENT: {
8
9
  readonly PATCH: "patch";
@@ -11,7 +12,8 @@ export declare const INCREMENT: {
11
12
  readonly PRERELEASE: "prerelease";
12
13
  };
13
14
  export declare const VERSION_INCREMENT_OPTIONS: readonly ["patch", "minor", "major", "prerelease"];
14
- export declare const TAG_OPTIONS: readonly ["latest", "next", "experimental"];
15
+ export declare const TAG_OPTIONS: readonly ["latest", "next", "experimental", "previous"];
16
+ export declare const VSCODE_VERSION_INCREMENT_OPTIONS: readonly ["patch", "minor", "major"];
15
17
  export declare const PRERELEASE_IDENTIFIER: {
16
18
  readonly NEXT: "beta";
17
19
  readonly EXPERIMENTAL: "experimental";
@@ -3,6 +3,7 @@ export const TAG = {
3
3
  LATEST: 'latest',
4
4
  NEXT: 'next',
5
5
  EXPERIMENTAL: 'experimental',
6
+ PREVIOUS: 'previous',
6
7
  };
7
8
  export const INCREMENT = {
8
9
  PATCH: 'patch',
@@ -16,7 +17,17 @@ export const VERSION_INCREMENT_OPTIONS = [
16
17
  INCREMENT.MAJOR,
17
18
  INCREMENT.PRERELEASE,
18
19
  ];
19
- export const TAG_OPTIONS = [TAG.LATEST, TAG.NEXT, TAG.EXPERIMENTAL];
20
+ export const TAG_OPTIONS = [
21
+ TAG.LATEST,
22
+ TAG.NEXT,
23
+ TAG.EXPERIMENTAL,
24
+ TAG.PREVIOUS,
25
+ ];
26
+ export const VSCODE_VERSION_INCREMENT_OPTIONS = [
27
+ INCREMENT.PATCH,
28
+ INCREMENT.MINOR,
29
+ INCREMENT.MAJOR,
30
+ ];
20
31
  export const PRERELEASE_IDENTIFIER = {
21
32
  NEXT: 'beta',
22
33
  EXPERIMENTAL: 'experimental',
@@ -0,0 +1,5 @@
1
+ export declare const DEFAULT_INTERNAL_MAIN_BRANCH = "master";
2
+ export declare const DEFAULT_EXTERNAL_MAIN_BRANCH = "main";
3
+ export declare const SYNC_BRANCH_PREFIX = "hs-repo-sync";
4
+ export declare const TEMP_SYNC_DIR = "hs-temp-repo-sync";
5
+ export declare const PUBLIC_README_PATH = "PUBLIC_README.md";
@@ -0,0 +1,5 @@
1
+ export const DEFAULT_INTERNAL_MAIN_BRANCH = 'master';
2
+ export const DEFAULT_EXTERNAL_MAIN_BRANCH = 'main';
3
+ export const SYNC_BRANCH_PREFIX = 'hs-repo-sync';
4
+ export const TEMP_SYNC_DIR = 'hs-temp-repo-sync';
5
+ export const PUBLIC_README_PATH = 'PUBLIC_README.md';
package/src/release.js CHANGED
@@ -1,4 +1,4 @@
1
- import { exec as _exec } from 'node:child_process';
1
+ import { exec as _exec, execSync } from 'node:child_process';
2
2
  import { promisify } from 'util';
3
3
  import yargs from 'yargs';
4
4
  import semver from 'semver';
@@ -8,30 +8,49 @@ import { logger } from './utils/logging.js';
8
8
  import { EXIT_CODES } from './utils/process.js';
9
9
  import { DEFAULT_MAIN_BRANCH, INCREMENT, PRERELEASE_IDENTIFIER, TAG, TAG_OPTIONS, VERSION_INCREMENT_OPTIONS, } from './constants/release.js';
10
10
  import { gitCleanup, getCurrentGitBranch } from './utils/git.js';
11
- import { getDistTags, publish, updateNextTag } from './utils/npm.js';
11
+ import { getDistTags, publish, updateNextTag, updatePreviousTag, } from './utils/npm.js';
12
12
  import { confirm, input } from './utils/prompting.js';
13
13
  const exec = promisify(_exec);
14
- function buildHandler({ build, postLatestRelease, packageName, localVersion, registry, repositoryUrl, mainBranch, }) {
15
- return async function handler({ versionIncrement, tag, dryRun, }) {
14
+ function buildHandler({ build, postLatestRelease, packageName, localVersion, registry, repositoryUrl, mainBranch, previousBranch, ignoreScripts, }) {
15
+ return async function handler({ versionIncrement, tag, dryRun, skipBranchValidation, skipVersionCheck, }) {
16
16
  const branch = await getCurrentGitBranch();
17
17
  const isExperimental = tag === TAG.EXPERIMENTAL;
18
+ const isPrevious = tag === TAG.PREVIOUS;
18
19
  const isDryRun = Boolean(dryRun);
19
- if (isExperimental && branch === mainBranch) {
20
- logger.error(`Releases to experimental tag cannot be published from the ${mainBranch} branch`);
20
+ if (isPrevious && !previousBranch) {
21
+ logger.error('Cannot release to previous tag: previousBranch is not configured');
21
22
  process.exit(EXIT_CODES.ERROR);
22
23
  }
23
- else if (!isExperimental && branch !== mainBranch) {
24
- logger.error(`Releases to latest and next tags can only be published from the ${mainBranch} branch`);
25
- process.exit(EXIT_CODES.ERROR);
24
+ if (!skipBranchValidation) {
25
+ if (isExperimental &&
26
+ (branch === mainBranch || branch === previousBranch)) {
27
+ logger.error(`Releases to experimental tag cannot be published from the ${branch} branch`);
28
+ process.exit(EXIT_CODES.ERROR);
29
+ }
30
+ else if (isPrevious && branch !== previousBranch) {
31
+ logger.error(`Releases to previous tag can only be published from the ${previousBranch} branch`);
32
+ process.exit(EXIT_CODES.ERROR);
33
+ }
34
+ else if (!isExperimental && !isPrevious && branch !== mainBranch) {
35
+ logger.error(`Releases to latest and next tags can only be published from the ${mainBranch} branch`);
36
+ process.exit(EXIT_CODES.ERROR);
37
+ }
26
38
  }
27
- if (tag === TAG.LATEST && versionIncrement === INCREMENT.PRERELEASE) {
28
- logger.error('Invalid release: cannot increment prerelease number on latest tag.');
39
+ if ((tag === TAG.LATEST || tag === TAG.PREVIOUS) &&
40
+ versionIncrement === INCREMENT.PRERELEASE) {
41
+ logger.error(`Invalid release: cannot increment prerelease number on ${tag} tag.`);
29
42
  process.exit(EXIT_CODES.ERROR);
30
43
  }
31
- const { next: currentNextTag, experimental: currentExperimentalTag } = await getDistTags(packageName);
32
- if (!isExperimental && currentNextTag !== localVersion) {
33
- logger.error(`Local package.json version ${localVersion} is out of sync with published version ${currentNextTag}`);
34
- process.exit(EXIT_CODES.ERROR);
44
+ const { latest: currentLatestTag, next: currentNextTag, experimental: currentExperimentalTag, previous: currentPreviousTag, } = await getDistTags(packageName);
45
+ if (!skipVersionCheck) {
46
+ if (!isExperimental && !isPrevious && currentNextTag !== localVersion) {
47
+ logger.error(`Local package.json version ${localVersion} is out of sync with published version ${currentNextTag}`);
48
+ process.exit(EXIT_CODES.ERROR);
49
+ }
50
+ if (isPrevious && currentPreviousTag !== localVersion) {
51
+ logger.error(`Local package.json version ${localVersion} is out of sync with published version ${currentPreviousTag}`);
52
+ process.exit(EXIT_CODES.ERROR);
53
+ }
35
54
  }
36
55
  const currentVersion = isExperimental
37
56
  ? currentExperimentalTag
@@ -39,7 +58,9 @@ function buildHandler({ build, postLatestRelease, packageName, localVersion, reg
39
58
  const prereleaseIdentifier = isExperimental
40
59
  ? PRERELEASE_IDENTIFIER.EXPERIMENTAL
41
60
  : PRERELEASE_IDENTIFIER.NEXT;
42
- const incrementType = tag === TAG.LATEST || versionIncrement === INCREMENT.PRERELEASE
61
+ const incrementType = tag === TAG.LATEST ||
62
+ tag === TAG.PREVIOUS ||
63
+ versionIncrement === INCREMENT.PRERELEASE
43
64
  ? versionIncrement
44
65
  : `pre${versionIncrement}`;
45
66
  const newVersion = semver.inc(currentVersion, incrementType, prereleaseIdentifier);
@@ -59,7 +80,7 @@ function buildHandler({ build, postLatestRelease, packageName, localVersion, reg
59
80
  if (!shouldRelease) {
60
81
  process.exit(EXIT_CODES.SUCCESS);
61
82
  }
62
- if (branch === mainBranch && !dryRun) {
83
+ if ((branch === mainBranch || branch === previousBranch) && !dryRun) {
63
84
  logger.log(`Creating a temporary branch '${tempBranch}' for the release`);
64
85
  await exec(`git checkout -b ${tempBranch}`);
65
86
  }
@@ -86,10 +107,25 @@ function buildHandler({ build, postLatestRelease, packageName, localVersion, reg
86
107
  await build();
87
108
  }
88
109
  else {
110
+ logger.log('Installing dependencies...');
111
+ await exec('yarn');
112
+ logger.log('Building...');
89
113
  await exec(`yarn build`);
90
114
  }
91
115
  let otp = '';
92
116
  if (!isDryRun) {
117
+ try {
118
+ await exec(`npm whoami --registry ${registry}`);
119
+ }
120
+ catch (err) {
121
+ try {
122
+ execSync(`npm adduser --registry ${registry}`, { stdio: 'inherit' });
123
+ }
124
+ catch (authErr) {
125
+ logger.error('Failed to authenticate with npm');
126
+ process.exit(EXIT_CODES.ERROR);
127
+ }
128
+ }
93
129
  otp = await input({
94
130
  message: 'Enter your NPM one-time password:',
95
131
  });
@@ -98,11 +134,11 @@ function buildHandler({ build, postLatestRelease, packageName, localVersion, reg
98
134
  logger.log('\nDry run: skipping one-time password entry');
99
135
  }
100
136
  try {
101
- await publish(tag, otp, isDryRun, registry);
137
+ await publish(tag, otp, isDryRun, ignoreScripts || false, registry);
102
138
  }
103
139
  catch (e) {
104
140
  logger.error(e);
105
- logger.error('An error occurred while releasing the CLI. Correct the error and re-run `yarn build`.');
141
+ logger.error('An error occurred while releasing this package. Correct the error and re-run `yarn build`.');
106
142
  await gitCleanup(newVersion, !isExperimental);
107
143
  process.exit(EXIT_CODES.ERROR);
108
144
  }
@@ -116,6 +152,15 @@ function buildHandler({ build, postLatestRelease, packageName, localVersion, reg
116
152
  logger.log(`npm dist-tag add ${packageName}@${newVersion} ${TAG.NEXT}`);
117
153
  logger.log(gitCommand);
118
154
  }
155
+ if (versionIncrement === INCREMENT.MAJOR) {
156
+ try {
157
+ await updatePreviousTag(packageName, currentLatestTag, otp, isDryRun, registry);
158
+ }
159
+ catch (e) {
160
+ logger.error(`An error occurred while updating the ${TAG.PREVIOUS} tag. To finish this release, run the following command:`);
161
+ logger.log(`npm dist-tag add ${packageName}@${currentLatestTag} ${TAG.PREVIOUS}`);
162
+ }
163
+ }
119
164
  }
120
165
  if (isDryRun) {
121
166
  await gitCleanup(newVersion, !isExperimental);
@@ -132,15 +177,18 @@ function buildHandler({ build, postLatestRelease, packageName, localVersion, reg
132
177
  logger.log(`\nPushing changes to Github...`);
133
178
  await exec(gitCommand);
134
179
  logger.log(`Changes pushed successfully`);
135
- await open(`${repositoryUrl}/compare/${mainBranch}...${tempBranch}`);
180
+ const baseBranch = isPrevious ? previousBranch : mainBranch;
181
+ await open(`${repositoryUrl}/compare/${baseBranch}...${tempBranch}`);
136
182
  }
137
- logger.success(`HubSpot CLI version ${newVersion} published successfully`);
183
+ logger.success(`${packageName} version ${newVersion} published successfully`);
138
184
  logger.log(`https://www.npmjs.com/package/${packageName}?activeTab=versions`);
139
- if (tag === TAG.LATEST) {
185
+ if (tag === TAG.LATEST || tag === TAG.PREVIOUS) {
140
186
  logger.log(`\nRemember to create a new release on Github!`);
141
187
  await open(`${repositoryUrl}/releases/new`);
142
- if (postLatestRelease && typeof postLatestRelease === 'function') {
143
- await postLatestRelease();
188
+ if (tag === TAG.LATEST &&
189
+ postLatestRelease &&
190
+ typeof postLatestRelease === 'function') {
191
+ await postLatestRelease({ newVersion, dryRun });
144
192
  }
145
193
  }
146
194
  };
@@ -162,6 +210,17 @@ async function builder(yargs) {
162
210
  dryRun: {
163
211
  alias: 'd',
164
212
  describe: 'Run through the publish process without actually publishing',
213
+ default: false,
214
+ type: 'boolean',
215
+ },
216
+ skipBranchValidation: {
217
+ describe: 'Bypass the branch validation check',
218
+ default: false,
219
+ type: 'boolean',
220
+ },
221
+ skipVersionCheck: {
222
+ describe: 'Bypass checking that the local version matches the published version',
223
+ default: false,
165
224
  type: 'boolean',
166
225
  },
167
226
  });
@@ -0,0 +1,5 @@
1
+ import { BuildRepoSyncScriptOptions, RepoSyncArguments } from './types.js';
2
+ export declare function handleRepoSync({ sourceDirectory, targetRepositoryUrl, excludePatterns, buildCommitMessage, internalMainBranch, externalMainBranch, version, dryRun, sshKeyPath, }: BuildRepoSyncScriptOptions & RepoSyncArguments): Promise<void>;
3
+ export declare function buildRepoSyncScript({ buildHandlerOptions, }: {
4
+ buildHandlerOptions: BuildRepoSyncScriptOptions;
5
+ }): void;
@@ -0,0 +1,141 @@
1
+ import yargs from 'yargs';
2
+ import open from 'open';
3
+ import fs from 'fs-extra';
4
+ import path from 'path';
5
+ import { logger } from './utils/logging.js';
6
+ import { EXIT_CODES } from './utils/process.js';
7
+ import { DEFAULT_INTERNAL_MAIN_BRANCH, DEFAULT_EXTERNAL_MAIN_BRANCH, SYNC_BRANCH_PREFIX, TEMP_SYNC_DIR, } from './constants/repo-sync.js';
8
+ import { checkoutBranch, cloneRepo, commitChanges, createBranch, getCurrentGitBranch, getGitEnvWithSshKey, pushBranch, } from './utils/git.js';
9
+ import { copyFiles } from './utils/filesystem.js';
10
+ import { confirm } from './utils/prompting.js';
11
+ export async function handleRepoSync({ sourceDirectory, targetRepositoryUrl, excludePatterns, buildCommitMessage, internalMainBranch, externalMainBranch, version, dryRun, sshKeyPath, }) {
12
+ if (!internalMainBranch) {
13
+ internalMainBranch = DEFAULT_INTERNAL_MAIN_BRANCH;
14
+ }
15
+ if (!externalMainBranch) {
16
+ externalMainBranch = DEFAULT_EXTERNAL_MAIN_BRANCH;
17
+ }
18
+ const originalRepoPath = sourceDirectory
19
+ ? path.resolve(sourceDirectory)
20
+ : process.cwd();
21
+ let tempDir = '';
22
+ try {
23
+ logger.log(`Starting sync to target repository: ${targetRepositoryUrl}...`);
24
+ if (dryRun) {
25
+ logger.log();
26
+ logger.info('(DRY RUN) The script will not push any changes.');
27
+ logger.log();
28
+ }
29
+ // Ensure we are on the master branch of the current repository (or continue with confirmation)
30
+ const currentBranch = await getCurrentGitBranch();
31
+ if (currentBranch !== internalMainBranch) {
32
+ const shouldCheckout = await confirm({
33
+ message: `You are on ${currentBranch}. Sync from ${internalMainBranch} branch instead?`,
34
+ });
35
+ if (shouldCheckout) {
36
+ await checkoutBranch(internalMainBranch, true);
37
+ }
38
+ }
39
+ // Create temporary directory
40
+ tempDir = path.join(originalRepoPath, TEMP_SYNC_DIR);
41
+ await fs.ensureDir(tempDir);
42
+ // Get git environment with ssh key to use for target repository operations
43
+ const gitEnvironment = await getGitEnvWithSshKey(sshKeyPath);
44
+ // Clone target repo
45
+ const targetRepoPath = await cloneRepo(targetRepositoryUrl, tempDir, gitEnvironment);
46
+ // Change to target repo directory
47
+ process.chdir(targetRepoPath);
48
+ // Create sync branch
49
+ const syncBranch = `${SYNC_BRANCH_PREFIX}-${version}`;
50
+ await createBranch(syncBranch);
51
+ // Copy files from current repository to target repository tmep dir
52
+ await copyFiles(originalRepoPath, targetRepoPath, excludePatterns);
53
+ // Commit changes
54
+ await commitChanges(buildCommitMessage(version));
55
+ if (dryRun) {
56
+ logger.log();
57
+ logger.info(`(DRY RUN) Exiting without pushing changes to ${targetRepositoryUrl}. Preview the files in ${tempDir}`);
58
+ process.exit(EXIT_CODES.SUCCESS);
59
+ }
60
+ const pushConfirmation = await confirm({
61
+ message: `Push changes to ${targetRepositoryUrl}?`,
62
+ default: true,
63
+ });
64
+ if (!pushConfirmation) {
65
+ logger.log(`Exiting without pushing changes to ${targetRepositoryUrl}.`);
66
+ process.exit(EXIT_CODES.SUCCESS);
67
+ }
68
+ // Push to target repository
69
+ await pushBranch(syncBranch, gitEnvironment);
70
+ // Create pull request
71
+ const prUrl = `${targetRepositoryUrl}/compare/${externalMainBranch}...${syncBranch}?expand=1`;
72
+ logger.log();
73
+ logger.log('Opening target repository sync branch pull request URL in browser...');
74
+ open(prUrl);
75
+ logger.log();
76
+ logger.log(`Pull Request URL: ${prUrl}`);
77
+ logger.success('Sync to target repository completed successfully');
78
+ }
79
+ catch (error) {
80
+ logger.error('Error syncing to target repository:', error);
81
+ process.exit(EXIT_CODES.ERROR);
82
+ }
83
+ finally {
84
+ // Cleanup
85
+ if (tempDir && !dryRun) {
86
+ await fs.remove(tempDir);
87
+ }
88
+ process.chdir(originalRepoPath);
89
+ }
90
+ }
91
+ function buildHandler({ sourceDirectory, targetRepositoryUrl, excludePatterns, buildCommitMessage, internalMainBranch, externalMainBranch, }) {
92
+ return async function handler({ version, dryRun, sshKeyPath, }) {
93
+ await handleRepoSync({
94
+ sourceDirectory,
95
+ targetRepositoryUrl,
96
+ excludePatterns,
97
+ buildCommitMessage,
98
+ internalMainBranch,
99
+ externalMainBranch,
100
+ version,
101
+ dryRun,
102
+ sshKeyPath,
103
+ });
104
+ };
105
+ }
106
+ async function builder(yargs) {
107
+ return yargs.options({
108
+ version: {
109
+ alias: 'v',
110
+ demandOption: true,
111
+ describe: 'Version label for the sync branch',
112
+ type: 'string',
113
+ },
114
+ dryRun: {
115
+ alias: 'd',
116
+ describe: 'Run through the sync process without pushing changes',
117
+ default: false,
118
+ type: 'boolean',
119
+ },
120
+ sshKeyPath: {
121
+ alias: 'ssh-key',
122
+ describe: 'Path to the SSH key to use for commands targeting the destination repository',
123
+ type: 'string',
124
+ },
125
+ });
126
+ }
127
+ export function buildRepoSyncScript({ buildHandlerOptions, }) {
128
+ try {
129
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
130
+ yargs(process.argv.slice(2))
131
+ .scriptName('yarn')
132
+ .usage('Hubspot repo sync script')
133
+ .command('repo-sync', `Syncs changes from the current repository to a target repository`, builder, buildHandler(buildHandlerOptions))
134
+ .version(false)
135
+ .help().argv;
136
+ }
137
+ catch (e) {
138
+ logger.error(e);
139
+ process.exit(EXIT_CODES.ERROR);
140
+ }
141
+ }
package/src/types.d.ts CHANGED
@@ -1,26 +1,64 @@
1
- import { TAG, TAG_OPTIONS, VERSION_INCREMENT_OPTIONS } from './constants/release.js';
1
+ import { TAG, TAG_OPTIONS, VERSION_INCREMENT_OPTIONS, VSCODE_VERSION_INCREMENT_OPTIONS } from './constants/release.js';
2
2
  export type ReleaseArguments = {
3
3
  versionIncrement: (typeof VERSION_INCREMENT_OPTIONS)[number];
4
4
  tag: (typeof TAG_OPTIONS)[number];
5
- dryRun?: boolean;
5
+ dryRun: boolean;
6
+ skipBranchValidation: boolean;
7
+ skipVersionCheck: boolean;
8
+ };
9
+ export type RepoSyncArguments = {
10
+ version: string;
11
+ dryRun: boolean;
12
+ sshKeyPath?: string;
6
13
  };
7
14
  export type DistTags = {
8
15
  [TAG.LATEST]: string;
9
16
  [TAG.NEXT]: string;
10
17
  [TAG.EXPERIMENTAL]: string;
18
+ [TAG.PREVIOUS]: string;
11
19
  };
12
20
  export type Tag = (typeof TAG_OPTIONS)[number];
13
21
  export interface BuildReleaseScriptBase {
14
22
  build?: () => Promise<void> | void;
15
- postLatestRelease?: () => Promise<void> | void;
23
+ postLatestRelease?: ({ newVersion, dryRun, }: {
24
+ newVersion: string;
25
+ dryRun: boolean;
26
+ }) => Promise<void> | void;
16
27
  repositoryUrl: string;
28
+ ignoreScripts?: boolean;
17
29
  mainBranch?: string;
30
+ previousBranch?: string;
18
31
  }
19
32
  export interface BuildReleaseScriptOptions extends BuildReleaseScriptBase {
20
33
  packageName: string;
21
34
  localVersion: string;
22
35
  registry: string;
23
36
  }
37
+ export type VscodeReleaseArguments = {
38
+ versionIncrement: (typeof VSCODE_VERSION_INCREMENT_OPTIONS)[number];
39
+ dryRun: boolean;
40
+ skipTests: boolean;
41
+ };
42
+ export interface VscodeReleaseScriptBase {
43
+ repositoryUrl: string;
44
+ mainBranch?: string;
45
+ marketplaceUrl: string;
46
+ extensionName: string;
47
+ slackChannel?: string;
48
+ build?: () => Promise<void> | void;
49
+ }
50
+ export interface VscodeReleaseScriptOptions extends VscodeReleaseScriptBase {
51
+ packageName: string;
52
+ localVersion: string;
53
+ }
54
+ export interface BuildRepoSyncScriptOptions {
55
+ sourceDirectory?: string;
56
+ targetRepositoryUrl: string;
57
+ buildCommitMessage: (version: string) => string;
58
+ excludePatterns?: string[];
59
+ internalMainBranch?: string;
60
+ externalMainBranch?: string;
61
+ }
24
62
  export interface PackageJson {
25
63
  name: string;
26
64
  version: string;
@@ -0,0 +1 @@
1
+ export {};