@wwkit/cft 1.0.22 → 1.0.24
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/index.js +30 -29
- package/package.json +2 -2
- package/src/config.js +8 -0
- package/src/index.js +1 -1
package/bin/index.js
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { execSync } from 'node:child_process'
|
|
4
|
-
import { readFileSync } from 'node:fs'
|
|
5
|
-
import {
|
|
4
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
5
|
+
import { parseFlags } from '@wwkit/shared'
|
|
6
|
+
import { install, status, clear, showConfig, showEnv, getProxy, USER_CONFIG_FILE, mergeBuiltinConfig } from '../src/index.js'
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function parseInstallArgs(args) {
|
|
12
|
-
let proxy = ''
|
|
13
|
-
for (let i = 3; i < args.length; i++) {
|
|
14
|
-
const arg = args[i]
|
|
15
|
-
if (arg === '-p' || arg === '--proxy') {
|
|
16
|
-
proxy = args[i + 1] || ''
|
|
17
|
-
i++
|
|
18
|
-
} else if (arg.startsWith('--proxy=')) {
|
|
19
|
-
proxy = arg.slice('--proxy='.length)
|
|
20
|
-
}
|
|
8
|
+
// Lazy-init: if user config doesn't exist (postinstall skipped), create it now
|
|
9
|
+
if (!existsSync(USER_CONFIG_FILE)) {
|
|
10
|
+
if (mergeBuiltinConfig()) {
|
|
11
|
+
console.log(`cft: config initialized at ${USER_CONFIG_FILE}`)
|
|
21
12
|
}
|
|
22
|
-
return proxy
|
|
23
13
|
}
|
|
24
14
|
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const pkgVersion = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version
|
|
16
|
+
|
|
17
|
+
const args = process.argv.slice(2)
|
|
18
|
+
const cmd = args[0] ?? 'help'
|
|
19
|
+
|
|
20
|
+
if (cmd === 'install') {
|
|
21
|
+
const { flags } = parseFlags(args.slice(1))
|
|
22
|
+
let proxy = flags.proxy || flags.p || ''
|
|
23
|
+
if (proxy === 'true') proxy = ''
|
|
27
24
|
install(proxy ? { proxy } : {})
|
|
28
|
-
.then((
|
|
25
|
+
.then(() => {
|
|
29
26
|
console.log()
|
|
30
27
|
console.log(' ✓ CFT 安装完成')
|
|
31
28
|
process.exit(0)
|
|
@@ -34,24 +31,24 @@ if (command === 'install') {
|
|
|
34
31
|
console.error(` ✗ CFT 安装失败: ${err.message}`)
|
|
35
32
|
process.exit(1)
|
|
36
33
|
})
|
|
37
|
-
} else if (
|
|
34
|
+
} else if (cmd === 'status') {
|
|
38
35
|
const info = status()
|
|
39
36
|
process.exit(info ? 0 : 1)
|
|
40
|
-
} else if (
|
|
37
|
+
} else if (cmd === 'clear') {
|
|
41
38
|
clear()
|
|
42
39
|
process.exit(0)
|
|
43
|
-
} else if (
|
|
40
|
+
} else if (cmd === 'config') {
|
|
44
41
|
showConfig()
|
|
45
|
-
} else if (
|
|
42
|
+
} else if (cmd === 'env') {
|
|
46
43
|
showEnv()
|
|
47
|
-
} else if (
|
|
44
|
+
} else if (cmd === 'upgrade') {
|
|
48
45
|
const proxy = getProxy()
|
|
49
46
|
const npmArgs = ['install', '-g', '@wwkit/cft@latest']
|
|
50
47
|
if (proxy) npmArgs.push('--proxy', proxy)
|
|
51
48
|
execSync(`npm ${npmArgs.join(' ')}`, { stdio: 'inherit', shell: true })
|
|
52
|
-
} else if (
|
|
49
|
+
} else if (cmd === 'version') {
|
|
53
50
|
console.log(pkgVersion)
|
|
54
|
-
} else if (
|
|
51
|
+
} else if (cmd === 'help' || cmd === '-h' || cmd === '--help' || cmd === undefined) {
|
|
55
52
|
console.log(`cft - Chrome for Testing 安装器
|
|
56
53
|
|
|
57
54
|
用法:
|
|
@@ -65,9 +62,13 @@ if (command === 'install') {
|
|
|
65
62
|
cft version 显示版本号
|
|
66
63
|
cft help 显示本帮助
|
|
67
64
|
|
|
65
|
+
Options:
|
|
66
|
+
-p, --proxy <url> 代理地址(install 时覆盖配置)
|
|
67
|
+
-h, --help 显示帮助
|
|
68
|
+
|
|
68
69
|
安装目录: ~/.config/cft/`)
|
|
69
70
|
} else {
|
|
70
|
-
console.error(`未知命令: ${
|
|
71
|
+
console.error(`未知命令: ${cmd}`)
|
|
71
72
|
console.error('运行 cft help 查看用法')
|
|
72
73
|
process.exit(1)
|
|
73
|
-
}
|
|
74
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wwkit/cft",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24",
|
|
4
4
|
"author": "bluesliu <langcai163@163.com>",
|
|
5
5
|
"description": "Chrome for Testing (CFT) installer — download, extract, chmod, dep-check",
|
|
6
6
|
"type": "module",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"extract-zip": "^2.0.1",
|
|
39
|
-
"@wwkit/shared": "1.0.
|
|
39
|
+
"@wwkit/shared": "1.0.24"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"jest": "^29.7.0"
|
package/src/config.js
CHANGED
|
@@ -24,6 +24,14 @@ export function copyBuiltinConfig() {
|
|
|
24
24
|
return _loader.copyBuiltinConfig()
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* 合并内置配置到用户配置文件(追加缺失 key,不覆盖已有值)
|
|
29
|
+
* @returns {boolean} 是否写入了文件
|
|
30
|
+
*/
|
|
31
|
+
export function mergeBuiltinConfig() {
|
|
32
|
+
return _loader.mergeBuiltinConfig()
|
|
33
|
+
}
|
|
34
|
+
|
|
27
35
|
export function getVersion() {
|
|
28
36
|
return getConfig().version
|
|
29
37
|
}
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { install, status, clear } from './installer.js'
|
|
2
2
|
export { getOs, isWindows, isMacos, isLinux, VALID_OS_TYPES } from './platform.js'
|
|
3
|
-
export { getConfig, getVersion, getRegistry, getProxy, getLocation, copyBuiltinConfig, INSTALL_LOCATION, USER_CONFIG_FILE, showConfig } from './config.js'
|
|
3
|
+
export { getConfig, getVersion, getRegistry, getProxy, getLocation, copyBuiltinConfig, mergeBuiltinConfig, INSTALL_LOCATION, USER_CONFIG_FILE, showConfig } from './config.js'
|
|
4
4
|
export { showEnv } from './env.js'
|