aboutsummaryrefslogtreecommitdiff
path: root/plugin/scripts/package.js
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-18 07:28:45 +0000
committer_ov4 <ov4@ov4.org>2026-10-18 07:28:45 +0000
commit2141916363d7f33a7a22adf6846f77276d7c4da3 (patch)
treeb4b4b0776053db9b2e8b89a67d8b984343c41af3 /plugin/scripts/package.js
parent2e49a02f27f3ba38a8c73973e91f3afeae1061dd (diff)
feat(plugin): derive package versions from commit metadata
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'plugin/scripts/package.js')
-rw-r--r--plugin/scripts/package.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/plugin/scripts/package.js b/plugin/scripts/package.js
new file mode 100644
index 0000000..67ff99f
--- /dev/null
+++ b/plugin/scripts/package.js
@@ -0,0 +1,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 HEAD 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;
+}