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
|
'use strict';
const { execFileSync, spawnSync } = require('node:child_process');
const path = require('node:path');
const pluginDir = path.resolve(__dirname, '..');
try {
const revision = execFileSync('git', ['log', '-1', '--format=%ct:%h', '--', '.'], {
cwd: pluginDir,
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'pipe']
}).trim();
const match = /^(\d+):([0-9a-f]+)$/.exec(revision);
if (!match) throw new Error('Cannot read the last plugin commit for the package version.');
const timestamp = new Date(Number(match[1]) * 1000).toISOString();
const date = timestamp.slice(0, 10).replace(/-/g, '');
const time = timestamp.slice(11, 19).replace(/:/g, '');
const commit = match[2];
const version = `${date}.${Number(time)}.0+${commit}`;
const filename = `cpsc-plugin-${date}-${time}-${commit}.vsix`;
const result = spawnSync(process.execPath, [
require.resolve('@vscode/vsce/vsce'), 'package', version,
'--no-update-package-json', '--no-dependencies', '--out', filename
], { cwd: pluginDir, stdio: 'inherit' });
if (result.error) throw result.error;
process.exitCode = result.status ?? 1;
} catch (error) {
console.error(`Cannot package plugin: ${error.message}`);
process.exitCode = 1;
}
|