aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/publish_ext_pack.ts
blob: a4e183f5fa9b963e474caa165df2e2ee3e370e71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only

import * as path from 'path';
import { execSync } from 'child_process';
import { program } from 'commander';
import * as fs from 'fs';

import * as common from './common';

function main() {
  common.checkForUncommittedChanges();
  program.option('--pack <string>', 'Name of the extension pack to publish');
  program.option('--dir <string>', 'Path to the extension pack root');
  program.option('--pre-release', 'Publish as pre-release');
  program.option('--git-remote <string>', 'Git remote to push to');
  program.parse(process.argv);
  const options = program.opts();
  const targetExtensionPack = options.pack as string;
  const remote = (options.gitRemote as string)
    ? (options.gitRemote as string)
    : 'origin';
  const extensionRoot = path.resolve(__dirname, '../');
  const targetExtensionPackRoot = path.join(
    extensionRoot,
    options.dir as string
  );
  const preRelease = options.preRelease as boolean;
  const publishCommand = `npx vsce publish ${preRelease ? '--pre-release' : ''}`;
  const version = common.getExtensionVersion(targetExtensionPackRoot);

  execSync(`npm run _prepublish_git`, { stdio: 'inherit' });
  execSync(`npm ci`, { stdio: 'inherit' });
  execSync(`npm run checkChangelog:${targetExtensionPack}`, {
    stdio: 'inherit'
  });
  execSync(publishCommand, {
    cwd: targetExtensionPackRoot,
    stdio: 'inherit'
  });
  // Remove the generated `commit` file
  fs.unlinkSync(path.join(targetExtensionPackRoot, 'commit'));

  common.pushTag(targetExtensionPackRoot, targetExtensionPack, version, remote);

  console.log(
    `Successfully published ${targetExtensionPack} extension pack with version ${version}`
  );
}

main();