|
| 1 | +import { execSync, type ExecSyncOptions } from 'node:child_process'; |
| 2 | +import { readFile, writeFile } from 'node:fs/promises'; |
| 3 | +import { resolve } from 'node:path'; |
| 4 | +import { ROOT, VSCODE_EXTENSION_PATHS } from './publish.constants'; |
| 5 | + |
| 6 | +interface PackageJson { |
| 7 | + private?: boolean; |
| 8 | + [key: string]: unknown; |
| 9 | +} |
| 10 | + |
| 11 | +const markAsPrivate = async ( |
| 12 | + pkgPath: string |
| 13 | +): Promise<{ path: string; original: string }> => { |
| 14 | + const fullPath = resolve(ROOT, pkgPath, 'package.json'); |
| 15 | + const original = await readFile(fullPath, 'utf-8'); |
| 16 | + const pkg: PackageJson = JSON.parse(original); |
| 17 | + pkg.private = true; |
| 18 | + await writeFile(fullPath, JSON.stringify(pkg, null, 2)); |
| 19 | + return { path: fullPath, original }; |
| 20 | +}; |
| 21 | + |
| 22 | +const restoreAll = async ( |
| 23 | + backups: Array<{ path: string; original: string }> |
| 24 | +) => { |
| 25 | + for (const { path, original } of backups) { |
| 26 | + await writeFile(path, original); |
| 27 | + } |
| 28 | +}; |
| 29 | + |
| 30 | +const main = async () => { |
| 31 | + const backups = await Promise.all(VSCODE_EXTENSION_PATHS.map(markAsPrivate)); |
| 32 | + |
| 33 | + const opts: ExecSyncOptions = { stdio: 'inherit', cwd: ROOT }; |
| 34 | + |
| 35 | + try { |
| 36 | + execSync('changeset publish', opts); |
| 37 | + } finally { |
| 38 | + await restoreAll(backups); |
| 39 | + } |
| 40 | +}; |
| 41 | + |
| 42 | +main(); |
0 commit comments