@rs-x/cli 2.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@rs-x/cli",
3
+ "version": "2.0.0-next.0",
4
+ "description": "CLI for installing RS-X compiler tooling and VS Code integration",
5
+ "bin": {
6
+ "rsx": "./bin/rsx.cjs"
7
+ },
8
+ "files": [
9
+ "bin",
10
+ "scripts",
11
+ "*.vsix",
12
+ "README.md"
13
+ ],
14
+ "engines": {
15
+ "node": ">=20"
16
+ },
17
+ "keywords": [
18
+ "rs-x",
19
+ "cli",
20
+ "compiler",
21
+ "vscode",
22
+ "typescript"
23
+ ],
24
+ "scripts": {
25
+ "build": "node -e \"console.log('No build step required for @rs-x/cli')\"",
26
+ "postinstall": "node ./scripts/postinstall.cjs"
27
+ }
28
+ }
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawnSync } = require('node:child_process');
4
+ const fs = require('node:fs');
5
+ const path = require('node:path');
6
+
7
+ function runCapture(command, args) {
8
+ return spawnSync(command, args, {
9
+ stdio: ['ignore', 'pipe', 'pipe'],
10
+ encoding: 'utf8',
11
+ });
12
+ }
13
+
14
+ function hasCommand(command) {
15
+ const result = runCapture(command, ['--version']);
16
+ return !result.error && result.status === 0;
17
+ }
18
+
19
+ function shouldSkipInstall() {
20
+ if (process.env.CI === 'true') {
21
+ return true;
22
+ }
23
+ if (process.env.RSX_SKIP_VSCODE_EXTENSION_INSTALL === 'true') {
24
+ return true;
25
+ }
26
+ return false;
27
+ }
28
+
29
+ function installVsCodeExtension() {
30
+ if (shouldSkipInstall()) {
31
+ console.log(
32
+ '[rs-x] Skipping VS Code extension auto-install (CI or RSX_SKIP_VSCODE_EXTENSION_INSTALL=true).',
33
+ );
34
+ return;
35
+ }
36
+
37
+ if (!hasCommand('code')) {
38
+ console.log(
39
+ '[rs-x] VS Code CLI (`code`) not found on PATH. Skipping VS Code extension install.',
40
+ );
41
+ return;
42
+ }
43
+
44
+ const localVsix = resolveBundledVsix();
45
+ if (!localVsix) {
46
+ console.log(
47
+ '[rs-x] No bundled VSIX found in @rs-x/cli package. Skipping VS Code extension install.',
48
+ );
49
+ return;
50
+ }
51
+
52
+ const args = ['--install-extension', localVsix];
53
+
54
+ const result = spawnSync('code', args, {
55
+ stdio: 'inherit',
56
+ });
57
+
58
+ if (result.error || result.status !== 0) {
59
+ console.log(
60
+ '[rs-x] Could not auto-install bundled VSIX. You can install manually:',
61
+ );
62
+ console.log(` code --install-extension "${localVsix}"`);
63
+ return;
64
+ }
65
+
66
+ console.log(`[rs-x] Installed bundled VSIX: ${path.basename(localVsix)}`);
67
+ }
68
+
69
+ function resolveBundledVsix() {
70
+ const packageRoot = path.resolve(__dirname, '..');
71
+ const candidates = fs
72
+ .readdirSync(packageRoot)
73
+ .filter((name) => /^rs-x-vscode-extension-.*\.vsix$/u.test(name))
74
+ .map((name) => path.join(packageRoot, name));
75
+
76
+ if (candidates.length === 0) {
77
+ return null;
78
+ }
79
+
80
+ const latest = candidates
81
+ .map((fullPath) => ({
82
+ fullPath,
83
+ mtimeMs: fs.statSync(fullPath).mtimeMs,
84
+ }))
85
+ .sort((a, b) => b.mtimeMs - a.mtimeMs)[0];
86
+
87
+ return latest?.fullPath ?? null;
88
+ }
89
+
90
+ installVsCodeExtension();
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+
6
+ const cliRoot = path.resolve(__dirname, '..');
7
+ const extensionDistDir = path.resolve(
8
+ cliRoot,
9
+ '..',
10
+ 'rs-x-vscode-extension',
11
+ 'dist',
12
+ );
13
+
14
+ function findLatestVsix(distDir) {
15
+ if (!fs.existsSync(distDir)) {
16
+ return null;
17
+ }
18
+
19
+ const files = fs
20
+ .readdirSync(distDir)
21
+ .filter((name) => /^rs-x-vscode-extension-.*\.vsix$/u.test(name))
22
+ .map((name) => {
23
+ const fullPath = path.join(distDir, name);
24
+ const stat = fs.statSync(fullPath);
25
+ return { name, fullPath, mtimeMs: stat.mtimeMs };
26
+ })
27
+ .sort((a, b) => b.mtimeMs - a.mtimeMs);
28
+
29
+ return files[0] ?? null;
30
+ }
31
+
32
+ function cleanupExistingVsixInCli() {
33
+ const entries = fs
34
+ .readdirSync(cliRoot)
35
+ .filter((name) => /^rs-x-vscode-extension-.*\.vsix$/u.test(name));
36
+
37
+ for (const fileName of entries) {
38
+ fs.rmSync(path.join(cliRoot, fileName), { force: true });
39
+ }
40
+ }
41
+
42
+ function main() {
43
+ const latestVsix = findLatestVsix(extensionDistDir);
44
+
45
+ cleanupExistingVsixInCli();
46
+
47
+ if (!latestVsix) {
48
+ console.warn(
49
+ `[rs-x-cli] No VSIX found in ${extensionDistDir}. Continuing without bundling a local extension package.`,
50
+ );
51
+ return;
52
+ }
53
+
54
+ const targetPath = path.join(cliRoot, latestVsix.name);
55
+ fs.copyFileSync(latestVsix.fullPath, targetPath);
56
+ console.log(`[rs-x-cli] Bundled VSIX: ${latestVsix.name}`);
57
+ }
58
+
59
+ main();