cicy-code 0.1.1 → 0.1.3
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 +21 -4
- package/package.json +1 -1
- package/scripts/install.js +3 -2
package/bin/cicy-code.js
CHANGED
|
@@ -7,14 +7,24 @@ const https = require('https');
|
|
|
7
7
|
const pkg = require('../package.json');
|
|
8
8
|
const binPath = path.join(__dirname, 'cicy-code');
|
|
9
9
|
|
|
10
|
+
const cn = process.argv.includes('--cn') || process.env.CN_MIRROR === '1';
|
|
11
|
+
|
|
10
12
|
if (process.argv.includes('--cn')) {
|
|
11
13
|
process.env.CN_MIRROR = '1';
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
if (cn) {
|
|
17
|
+
console.log(' [mirror] Using Chinese mirrors (npm + GitHub proxy)');
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
// Check for updates
|
|
15
21
|
function checkUpdate() {
|
|
22
|
+
const registry = cn
|
|
23
|
+
? 'https://registry.npmmirror.com/cicy-code/latest'
|
|
24
|
+
: 'https://registry.npmjs.org/cicy-code/latest';
|
|
25
|
+
if (cn) console.log(` [mirror] Registry: registry.npmmirror.com`);
|
|
16
26
|
return new Promise((resolve) => {
|
|
17
|
-
https.get(
|
|
27
|
+
https.get(registry, (res) => {
|
|
18
28
|
let data = '';
|
|
19
29
|
res.on('data', (c) => data += c);
|
|
20
30
|
res.on('end', () => {
|
|
@@ -42,7 +52,10 @@ async function main() {
|
|
|
42
52
|
console.log(`\n Update available: ${pkg.version} → ${latest}`);
|
|
43
53
|
console.log(` Updating...\n`);
|
|
44
54
|
try {
|
|
45
|
-
|
|
55
|
+
const npmCmd = cn
|
|
56
|
+
? `npm install -g cicy-code@${latest} --registry=https://registry.npmmirror.com`
|
|
57
|
+
: `npm install -g cicy-code@${latest}`;
|
|
58
|
+
execSync(npmCmd, { stdio: 'inherit' });
|
|
46
59
|
console.log(`\n Updated to ${latest}! Restarting...\n`);
|
|
47
60
|
// Re-exec with new version
|
|
48
61
|
const child = spawn('cicy-code', process.argv.slice(2), { stdio: 'inherit', env: process.env });
|
|
@@ -55,11 +68,15 @@ async function main() {
|
|
|
55
68
|
|
|
56
69
|
// Install globally if not already
|
|
57
70
|
try {
|
|
58
|
-
execSync('
|
|
71
|
+
const globalBin = execSync('npm prefix -g', { encoding: 'utf8' }).trim() + '/bin/cicy-code';
|
|
72
|
+
if (!fs.existsSync(globalBin)) throw new Error('not installed');
|
|
59
73
|
} catch {
|
|
60
74
|
console.log(' Installing cicy-code globally...');
|
|
61
75
|
try {
|
|
62
|
-
|
|
76
|
+
const npmCmd = cn
|
|
77
|
+
? 'npm install -g cicy-code --registry=https://registry.npmmirror.com'
|
|
78
|
+
: 'npm install -g cicy-code';
|
|
79
|
+
execSync(npmCmd, { stdio: 'inherit' });
|
|
63
80
|
console.log(' Installed! You can now run: cicy-code\n');
|
|
64
81
|
} catch {}
|
|
65
82
|
}
|
package/package.json
CHANGED
package/scripts/install.js
CHANGED
|
@@ -2,7 +2,7 @@ const https = require('https');
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
|
|
5
|
-
const VERSION = '0.1.
|
|
5
|
+
const VERSION = '0.1.3';
|
|
6
6
|
const GH_URL = `https://github.com/cicy-ai/cicy-code/releases/download/v${VERSION}`;
|
|
7
7
|
const CN_URL = `https://gh-proxy.com/https://github.com/cicy-ai/cicy-code/releases/download/v${VERSION}`;
|
|
8
8
|
|
|
@@ -28,7 +28,8 @@ const binDir = path.join(__dirname, '..', 'bin');
|
|
|
28
28
|
const binPath = path.join(binDir, 'cicy-code');
|
|
29
29
|
const url = `${BASE_URL}/${binName}`;
|
|
30
30
|
|
|
31
|
-
console.log(`Downloading ${binName}${cn ? ' (CN mirror)' : ''}...`);
|
|
31
|
+
console.log(`Downloading ${binName}${cn ? ' (CN mirror: gh-proxy.com)' : ''}...`);
|
|
32
|
+
console.log(` URL: ${url}`);
|
|
32
33
|
|
|
33
34
|
function download(url, dest, redirects = 5) {
|
|
34
35
|
return new Promise((resolve, reject) => {
|