cicy-code 0.1.0 → 0.1.1

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/bin/cicy-code.js CHANGED
@@ -1,23 +1,79 @@
1
1
  #!/usr/bin/env node
2
- const { spawn } = require('child_process');
2
+ const { spawn, execSync } = require('child_process');
3
3
  const path = require('path');
4
4
  const fs = require('fs');
5
+ const https = require('https');
5
6
 
6
- const binDir = path.join(__dirname);
7
- const platform = process.platform;
7
+ const pkg = require('../package.json');
8
+ const binPath = path.join(__dirname, 'cicy-code');
8
9
 
9
- const binName = platform === 'win32' ? 'cicy-code.exe' : 'cicy-code';
10
- const binPath = path.join(binDir, binName);
10
+ if (process.argv.includes('--cn')) {
11
+ process.env.CN_MIRROR = '1';
12
+ }
11
13
 
12
- if (!fs.existsSync(binPath)) {
13
- console.error(`Binary not found: ${binPath}`);
14
- console.error('Run: npm install cicy-code');
15
- process.exit(1);
14
+ // Check for updates
15
+ function checkUpdate() {
16
+ return new Promise((resolve) => {
17
+ https.get('https://registry.npmjs.org/cicy-code/latest', (res) => {
18
+ let data = '';
19
+ res.on('data', (c) => data += c);
20
+ res.on('end', () => {
21
+ try {
22
+ const latest = JSON.parse(data).version;
23
+ if (latest && latest !== pkg.version) {
24
+ resolve(latest);
25
+ } else {
26
+ resolve(null);
27
+ }
28
+ } catch { resolve(null); }
29
+ });
30
+ }).on('error', () => resolve(null));
31
+ });
16
32
  }
17
33
 
18
- const child = spawn(binPath, process.argv.slice(2), {
19
- stdio: 'inherit',
20
- env: process.env
21
- });
34
+ async function main() {
35
+ // Check update (non-blocking, timeout 3s)
36
+ const latest = await Promise.race([
37
+ checkUpdate(),
38
+ new Promise(r => setTimeout(() => r(null), 3000))
39
+ ]);
40
+
41
+ if (latest) {
42
+ console.log(`\n Update available: ${pkg.version} → ${latest}`);
43
+ console.log(` Updating...\n`);
44
+ try {
45
+ execSync(`npm install -g cicy-code@${latest}`, { stdio: 'inherit' });
46
+ console.log(`\n Updated to ${latest}! Restarting...\n`);
47
+ // Re-exec with new version
48
+ const child = spawn('cicy-code', process.argv.slice(2), { stdio: 'inherit', env: process.env });
49
+ child.on('exit', (code) => process.exit(code || 0));
50
+ return;
51
+ } catch (e) {
52
+ console.log(` Update failed, running current version.\n`);
53
+ }
54
+ }
55
+
56
+ // Install globally if not already
57
+ try {
58
+ execSync('which cicy-code', { stdio: 'ignore' });
59
+ } catch {
60
+ console.log(' Installing cicy-code globally...');
61
+ try {
62
+ execSync('npm install -g cicy-code', { stdio: 'inherit' });
63
+ console.log(' Installed! You can now run: cicy-code\n');
64
+ } catch {}
65
+ }
66
+
67
+ if (!fs.existsSync(binPath)) {
68
+ console.error('Binary not found. Reinstall: npm install -g cicy-code');
69
+ process.exit(1);
70
+ }
71
+
72
+ const child = spawn(binPath, process.argv.slice(2), {
73
+ stdio: 'inherit',
74
+ env: process.env
75
+ });
76
+ child.on('exit', (code) => process.exit(code || 0));
77
+ }
22
78
 
23
- child.on('exit', (code) => process.exit(code || 0));
79
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cicy-code",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "CiCy Code - AI-powered development environment",
5
5
  "bin": {
6
6
  "cicy-code": "bin/cicy-code.js"
@@ -1,10 +1,13 @@
1
1
  const https = require('https');
2
2
  const fs = require('fs');
3
3
  const path = require('path');
4
- const { execSync } = require('child_process');
5
4
 
6
- const VERSION = '0.1.0';
7
- const BASE_URL = `https://github.com/cicy-ai/cicy-code/releases/download/v${VERSION}`;
5
+ const VERSION = '0.1.1';
6
+ const GH_URL = `https://github.com/cicy-ai/cicy-code/releases/download/v${VERSION}`;
7
+ const CN_URL = `https://gh-proxy.com/https://github.com/cicy-ai/cicy-code/releases/download/v${VERSION}`;
8
+
9
+ const cn = process.env.CN_MIRROR === '1' || process.argv.includes('--cn');
10
+ const BASE_URL = cn ? CN_URL : GH_URL;
8
11
 
9
12
  const PLATFORMS = {
10
13
  'darwin-arm64': 'cicy-code-darwin-arm64',
@@ -18,35 +21,27 @@ const binName = PLATFORMS[key];
18
21
 
19
22
  if (!binName) {
20
23
  console.error(`Unsupported platform: ${key}`);
21
- console.error('Supported: darwin-arm64, darwin-x64, linux-x64, linux-arm64');
22
24
  process.exit(1);
23
25
  }
24
26
 
25
27
  const binDir = path.join(__dirname, '..', 'bin');
26
- const binPath = path.join(binDir, process.platform === 'win32' ? 'cicy-code.exe' : 'cicy-code');
28
+ const binPath = path.join(binDir, 'cicy-code');
27
29
  const url = `${BASE_URL}/${binName}`;
28
30
 
29
- console.log(`Downloading ${binName}...`);
31
+ console.log(`Downloading ${binName}${cn ? ' (CN mirror)' : ''}...`);
30
32
 
31
33
  function download(url, dest, redirects = 5) {
32
34
  return new Promise((resolve, reject) => {
33
35
  if (redirects === 0) return reject(new Error('Too many redirects'));
34
-
35
36
  const proto = url.startsWith('https') ? https : require('http');
36
37
  proto.get(url, (res) => {
37
38
  if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
38
39
  return download(res.headers.location, dest, redirects - 1).then(resolve).catch(reject);
39
40
  }
40
- if (res.statusCode !== 200) {
41
- return reject(new Error(`HTTP ${res.statusCode}`));
42
- }
41
+ if (res.statusCode !== 200) return reject(new Error(`HTTP ${res.statusCode}`));
43
42
  const file = fs.createWriteStream(dest);
44
43
  res.pipe(file);
45
- file.on('finish', () => {
46
- file.close();
47
- fs.chmodSync(dest, 0o755);
48
- resolve();
49
- });
44
+ file.on('finish', () => { file.close(); fs.chmodSync(dest, 0o755); resolve(); });
50
45
  }).on('error', reject);
51
46
  });
52
47
  }
@@ -55,6 +50,6 @@ download(url, binPath)
55
50
  .then(() => console.log('Done!'))
56
51
  .catch((err) => {
57
52
  console.error('Download failed:', err.message);
58
- console.error('You can manually download from:', url);
53
+ if (!cn) console.error('Try: CN_MIRROR=1 npx cicy-code');
59
54
  process.exit(1);
60
55
  });