lightbulb-cli 0.0.0-stage → 0.2.2

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.
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ // Runs the downloaded binary with the same arguments and exit code. If postinstall did not
3
+ // run (--ignore-scripts) or vendor/ was removed, downloads it once first.
4
+ 'use strict';
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const { spawnSync } = require('child_process');
8
+ const { install } = require('../scripts/postinstall');
9
+
10
+ const bin = path.join(__dirname, '..', 'vendor', 'lightbulb');
11
+
12
+ function run() {
13
+ const r = spawnSync(bin, process.argv.slice(2), { stdio: 'inherit' });
14
+ if (r.error) throw r.error;
15
+ if (r.signal) process.kill(process.pid, r.signal);
16
+ process.exit(r.status === null ? 1 : r.status);
17
+ }
18
+
19
+ if (fs.existsSync(bin)) {
20
+ run();
21
+ } else {
22
+ install().then(run, (err) => {
23
+ console.error(err.plain ? err.message : `Could not install Lightbulb: ${err.message}`);
24
+ process.exit(1);
25
+ });
26
+ }
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "lightbulb-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.2",
4
+ "description": "Lightbulb: your coding agents and your teammates' agents, talking to each other.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/TheLightbulbCompany/cli.git",
9
+ "directory": "npm"
10
+ },
11
+ "homepage": "https://github.com/TheLightbulbCompany/cli#readme",
12
+ "bin": {
13
+ "lightbulb": "bin/lightbulb.js"
14
+ },
15
+ "files": [
16
+ "bin/",
17
+ "scripts/"
18
+ ],
19
+ "scripts": {
20
+ "postinstall": "node scripts/postinstall.js",
21
+ "test": "node test/postinstall.test.js"
22
+ },
23
+ "os": [
24
+ "darwin"
25
+ ],
26
+ "cpu": [
27
+ "arm64"
28
+ ],
29
+ "engines": {
30
+ "node": ">=18"
31
+ }
32
+ }
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+ // Downloads the release binary matching this package's version, checks its sha256 and
3
+ // puts it at <package>/vendor/lightbulb. No dependencies: https, crypto and the
4
+ // system tar (always present on macOS).
5
+ 'use strict';
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const https = require('https');
9
+ const crypto = require('crypto');
10
+ const { execFileSync } = require('child_process');
11
+
12
+ const REPO = 'TheLightbulbCompany/cli';
13
+ const ASSET = 'lightbulb-macos-arm64.tar.gz';
14
+
15
+ function get(url, redirects = 5) {
16
+ return new Promise((resolve, reject) => {
17
+ https
18
+ .get(url, { headers: { 'User-Agent': 'lightbulb-cli-npm' } }, (res) => {
19
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location && redirects > 0) {
20
+ res.resume();
21
+ return resolve(get(new URL(res.headers.location, url).toString(), redirects - 1));
22
+ }
23
+ if (res.statusCode !== 200) {
24
+ res.resume();
25
+ return reject(new Error(`GET ${url}: HTTP ${res.statusCode}`));
26
+ }
27
+ const chunks = [];
28
+ res.on('data', (c) => chunks.push(c));
29
+ res.on('end', () => resolve(Buffer.concat(chunks)));
30
+ res.on('error', reject);
31
+ })
32
+ .on('error', reject);
33
+ });
34
+ }
35
+
36
+ async function install(root = path.join(__dirname, '..')) {
37
+ if (process.platform !== 'darwin' || process.arch !== 'arm64') {
38
+ throw Object.assign(new Error('Lightbulb needs an Apple-silicon Mac for now.'), { plain: true });
39
+ }
40
+ const { version } = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
41
+ const base = `https://github.com/${REPO}/releases/download/v${version}`;
42
+ console.log('Downloading Lightbulb…');
43
+ const [tarball, sums] = await Promise.all([get(`${base}/${ASSET}`), get(`${base}/${ASSET}.sha256`)]);
44
+ const want = sums.toString('utf8').trim().split(/\s+/)[0].toLowerCase();
45
+ const got = crypto.createHash('sha256').update(tarball).digest('hex');
46
+ if (got !== want) {
47
+ throw Object.assign(new Error('Checksum mismatch; not installing.'), { plain: true });
48
+ }
49
+ const vendor = path.join(root, 'vendor');
50
+ fs.mkdirSync(vendor, { recursive: true });
51
+ const tmp = fs.mkdtempSync(path.join(vendor, '.dl-'));
52
+ try {
53
+ const file = path.join(tmp, ASSET);
54
+ fs.writeFileSync(file, tarball);
55
+ execFileSync('tar', ['-xzf', file, '-C', tmp, 'lightbulb']);
56
+ const bin = path.join(vendor, 'lightbulb');
57
+ fs.renameSync(path.join(tmp, 'lightbulb'), bin);
58
+ fs.chmodSync(bin, 0o755);
59
+ return bin;
60
+ } finally {
61
+ fs.rmSync(tmp, { recursive: true, force: true });
62
+ }
63
+ }
64
+
65
+ module.exports = { install };
66
+
67
+ if (require.main === module) {
68
+ install(process.argv[2] ? path.resolve(process.argv[2]) : undefined).then(
69
+ () => console.log('Run: lightbulb setup'),
70
+ (err) => {
71
+ console.error(err.plain ? err.message : `Could not install Lightbulb: ${err.message}`);
72
+ process.exit(1);
73
+ }
74
+ );
75
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.