|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2026 Arm Limited |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +// generated with AI |
| 20 | + |
| 21 | +/** |
| 22 | + * CLI usage: |
| 23 | + * - Preferred: npm run package |
| 24 | + * - With extra vsce flags: npm run package -- <vsce-args> |
| 25 | + * - Direct invocation: node ./scripts/vsce-release.js [package] [vsce-args] |
| 26 | + * |
| 27 | + * Notes: |
| 28 | + * - This helper only supports the `package` command. |
| 29 | + * - `--pre-release` is appended automatically for odd minor versions. |
| 30 | + */ |
| 31 | + |
| 32 | +import fs from 'node:fs'; |
| 33 | +import path from 'node:path'; |
| 34 | +import { spawnSync } from 'node:child_process'; |
| 35 | +import { fileURLToPath } from 'node:url'; |
| 36 | + |
| 37 | +const __filename = fileURLToPath(import.meta.url); |
| 38 | +const __dirname = path.dirname(__filename); |
| 39 | +const rootPath = path.resolve(__dirname, '..'); |
| 40 | +const packageJsonPath = path.join(rootPath, 'package.json'); |
| 41 | + |
| 42 | +const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); |
| 43 | +const version = packageJson.version; |
| 44 | + |
| 45 | +const match = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/.exec(version); |
| 46 | +if (!match) { |
| 47 | + console.error(`Unsupported package.json version format: ${version}`); |
| 48 | + process.exit(1); |
| 49 | +} |
| 50 | + |
| 51 | +const minor = Number(match[2]); |
| 52 | +const isPreReleaseChannel = minor % 2 === 1; |
| 53 | + |
| 54 | +const allowedCommands = new Set(['package']); |
| 55 | +const firstArg = process.argv[2]; |
| 56 | +const command = firstArg && !firstArg.startsWith('-') ? firstArg : 'package'; |
| 57 | + |
| 58 | +if (!allowedCommands.has(command)) { |
| 59 | + console.error(`Unsupported vsce command: ${command}`); |
| 60 | + console.error('Supported commands: package'); |
| 61 | + process.exit(1); |
| 62 | +} |
| 63 | + |
| 64 | +const passthroughArgs = command === firstArg ? process.argv.slice(3) : process.argv.slice(2); |
| 65 | +const args = [command, ...passthroughArgs]; |
| 66 | + |
| 67 | +if (isPreReleaseChannel) { |
| 68 | + args.push('--pre-release'); |
| 69 | +} |
| 70 | + |
| 71 | +console.log(`Running: vsce ${args.join(' ')}`); |
| 72 | + |
| 73 | +const result = spawnSync('vsce', args, { |
| 74 | + cwd: rootPath, |
| 75 | + stdio: 'inherit', |
| 76 | + shell: process.platform === 'win32' |
| 77 | +}); |
| 78 | + |
| 79 | +if (result.error) { |
| 80 | + console.error(result.error.message); |
| 81 | + process.exit(1); |
| 82 | +} |
| 83 | + |
| 84 | +process.exit(result.status ?? 1); |
0 commit comments