Skip to content

Commit aff2a7a

Browse files
committed
build: "npm run package -- --feature foo"
Problem: The version string of feature-branch artifacts is not visually distinct from master artifacts. Solution: If `--feature foo` is passed to `package.ts`, prepend the feature name to the prerelease string. Example: $ npm run package -- --feature foo => 1.77.0-foo-1d4fafb53fec
1 parent ed260da commit aff2a7a

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

scripts/build/package.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,37 @@ function parseArgs() {
3434
// 1: /…/src/scripts/build/package.ts
3535
// 2: foo
3636

37+
const args: { [key: string]: any } = {
38+
/** Produce an unoptimized VSIX. Include git SHA in version string. */
39+
debug: false,
40+
/** Skips `npm run clean` when building the VSIX. This prevents file watching from breaking. */
41+
skipClean: false,
42+
feature: '',
43+
}
44+
3745
const givenArgs = process.argv.slice(2)
38-
const validOptions = ['--debug', '--no-clean']
46+
const validOptions = ['--debug', '--no-clean', '--feature']
47+
const expectValue = ['--feature']
3948

40-
for (const a of givenArgs) {
49+
for (let i = 0; i < givenArgs.length; i++) {
50+
const a = givenArgs[i]
51+
const argName = a.replace(/^-+/, '') // "--foo" => "foo"
4152
if (!validOptions.includes(a)) {
4253
throw Error(`invalid argument: ${a}`)
4354
}
55+
if (expectValue.includes(a)) {
56+
i++
57+
const val = givenArgs[i]
58+
if (val === undefined) {
59+
throw Error(`missing value for arg: ${a}`)
60+
}
61+
args[argName] = val
62+
} else {
63+
args[argName] = true
64+
}
4465
}
4566

46-
return {
47-
/** Produce an unoptimized VSIX. Include git SHA in version string. */
48-
debug: givenArgs.includes('--debug'),
49-
/** Skips `npm run clean` when building the VSIX. This prevents file watching from breaking. */
50-
skipClean: givenArgs.includes('--no-clean'),
51-
}
67+
return args
5268
}
5369

5470
/**
@@ -73,15 +89,15 @@ function isBeta(): boolean {
7389
*
7490
* @returns version-string suffix, for example: "-e6ecd84685a9"
7591
*/
76-
function getVersionSuffix(): string {
92+
function getVersionSuffix(feature: string): string {
7793
if (isRelease()) {
7894
return ''
7995
}
8096
const commitId = child_process.execSync('git rev-parse --short=12 HEAD').toString().trim()
8197
if (!commitId) {
8298
return ''
8399
}
84-
return `-${commitId}`
100+
return `${feature === '' ? '' : `-${feature}`}-${commitId}`
85101
}
86102

87103
function main() {
@@ -101,7 +117,7 @@ function main() {
101117
fs.copyFileSync(webpackConfigJsFile, `${webpackConfigJsFile}.bk`)
102118

103119
const packageJson: typeof manifest = JSON.parse(fs.readFileSync(packageJsonFile, { encoding: 'utf-8' }))
104-
const versionSuffix = getVersionSuffix()
120+
const versionSuffix = getVersionSuffix(args.feature)
105121
const version = packageJson.version
106122
// Setting the version to an arbitrarily high number stops VSC from auto-updating the beta extension
107123
const betaOrDebugVersion = `1.999.0${versionSuffix}`

0 commit comments

Comments
 (0)