@coze-arch/cli 0.0.36-alpha.fd6b86 → 0.0.36
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/README.md +0 -11
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +18 -73
- package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
- package/lib/__templates__/expo/server/package.json +1 -1
- package/lib/__templates__/nextjs/package.json +2 -2
- package/lib/__templates__/nextjs/pnpm-lock.yaml +258 -197
- package/lib/__templates__/nextjs/scripts/dev.sh +1 -82
- package/lib/__templates__/nextjs/template.config.js +1 -3
- package/lib/__templates__/nuxt-vue/scripts/dev.sh +1 -82
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +26 -63
- package/lib/__templates__/taro/pnpm-lock.yaml +5 -5
- package/lib/__templates__/taro/server/package.json +1 -1
- package/lib/__templates__/templates.json +0 -25
- package/lib/__templates__/vite/scripts/dev.sh +1 -82
- package/lib/__templates__/vite/template.config.js +1 -3
- package/lib/cli.js +199 -3446
- package/package.json +3 -5
- package/docs/deploy.md +0 -171
- package/lib/__templates__/phaser/.coze +0 -13
- package/lib/__templates__/phaser/README.md +0 -37
- package/lib/__templates__/phaser/_gitignore +0 -23
- package/lib/__templates__/phaser/_npmrc +0 -14
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/manifest.json +0 -11
- package/lib/__templates__/phaser/debug-runtime/flow-graph.json +0 -20
- package/lib/__templates__/phaser/index.html +0 -12
- package/lib/__templates__/phaser/package.json +0 -31
- package/lib/__templates__/phaser/pnpm-lock.yaml +0 -661
- package/lib/__templates__/phaser/scripts/build.sh +0 -8
- package/lib/__templates__/phaser/scripts/dev.sh +0 -82
- package/lib/__templates__/phaser/scripts/prepare.sh +0 -7
- package/lib/__templates__/phaser/scripts/spawn-detached.cjs +0 -29
- package/lib/__templates__/phaser/scripts/start.sh +0 -82
- package/lib/__templates__/phaser/scripts/validate.sh +0 -7
- package/lib/__templates__/phaser/src/assets.ts +0 -15
- package/lib/__templates__/phaser/src/global.d.ts +0 -36
- package/lib/__templates__/phaser/src/main.ts +0 -28
- package/lib/__templates__/phaser/src/scene/BootScene.ts +0 -209
- package/lib/__templates__/phaser/src/scene/DevLoadingScene.ts +0 -66
- package/lib/__templates__/phaser/src/style.css +0 -28
- package/lib/__templates__/phaser/src/types.ts +0 -32
- package/lib/__templates__/phaser/src/utils/asset-loader.ts +0 -319
- package/lib/__templates__/phaser/src/utils/index.ts +0 -2
- package/lib/__templates__/phaser/src/utils/mark-editable.ts +0 -6
- package/lib/__templates__/phaser/template.config.js +0 -43
- package/lib/__templates__/phaser/tsconfig.json +0 -23
- package/lib/__templates__/phaser/vite.config.ts +0 -96
- package/lib/deploy/package-project.js +0 -226
- package/lib/deploy/package-project.py +0 -168
package/lib/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ var perf_hooks = require('perf_hooks');
|
|
|
14
14
|
var fs$1 = require('fs/promises');
|
|
15
15
|
var os = require('os');
|
|
16
16
|
var jsYaml = require('js-yaml');
|
|
17
|
-
var
|
|
17
|
+
var toml = require('@iarna/toml');
|
|
18
18
|
var crypto = require('crypto');
|
|
19
19
|
var fastGlob = require('fast-glob');
|
|
20
20
|
var child_process = require('child_process');
|
|
@@ -23,13 +23,6 @@ var Ajv = require('ajv');
|
|
|
23
23
|
var minimist = require('minimist');
|
|
24
24
|
var changeCase = require('change-case');
|
|
25
25
|
var ejs = require('ejs');
|
|
26
|
-
var node_crypto = require('node:crypto');
|
|
27
|
-
var node_os = require('node:os');
|
|
28
|
-
var promises = require('node:fs/promises');
|
|
29
|
-
var node_child_process = require('node:child_process');
|
|
30
|
-
var node_util = require('node:util');
|
|
31
|
-
var tar = require('tar');
|
|
32
|
-
var node_stream = require('node:stream');
|
|
33
26
|
|
|
34
27
|
/**
|
|
35
28
|
* 读取 templates.json 配置
|
|
@@ -1635,7 +1628,7 @@ function createNodeTransport() {
|
|
|
1635
1628
|
};
|
|
1636
1629
|
}
|
|
1637
1630
|
|
|
1638
|
-
function _nullishCoalesce$
|
|
1631
|
+
function _nullishCoalesce$a(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$t(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/**
|
|
1639
1632
|
* Slardar CLI Reporter 主类
|
|
1640
1633
|
* 封装 @slardar/base 的初始化和上报逻辑
|
|
1641
1634
|
*/
|
|
@@ -1692,7 +1685,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1692
1685
|
release: config.release,
|
|
1693
1686
|
env: config.env,
|
|
1694
1687
|
name: config.name,
|
|
1695
|
-
useLocalConfig: _nullishCoalesce$
|
|
1688
|
+
useLocalConfig: _nullishCoalesce$a(config.useLocalConfig, () => ( false)), // 默认使用服务端配置
|
|
1696
1689
|
domain: config.domain,
|
|
1697
1690
|
// 设置本地采样率为 100%,确保事件不被过滤
|
|
1698
1691
|
sample: {
|
|
@@ -1707,7 +1700,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1707
1700
|
this.client.on('send', (ev) => {
|
|
1708
1701
|
log$6(
|
|
1709
1702
|
'send hook called for event: %s',
|
|
1710
|
-
(_optionalChain$
|
|
1703
|
+
(_optionalChain$t([ev, 'optionalAccess', _ => _.ev_type]) ) || 'unknown',
|
|
1711
1704
|
);
|
|
1712
1705
|
});
|
|
1713
1706
|
|
|
@@ -1765,7 +1758,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1765
1758
|
)
|
|
1766
1759
|
: undefined;
|
|
1767
1760
|
|
|
1768
|
-
_optionalChain$
|
|
1761
|
+
_optionalChain$t([this, 'access', _2 => _2.client, 'access', _3 => _3.sendEvent, 'optionalCall', _4 => _4({
|
|
1769
1762
|
name,
|
|
1770
1763
|
metrics: cleanMetrics ,
|
|
1771
1764
|
categories: cleanCategories ,
|
|
@@ -1836,7 +1829,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1836
1829
|
log$6('Reporting JS error:', {
|
|
1837
1830
|
name: error.name,
|
|
1838
1831
|
message: error.message.slice(0, 100),
|
|
1839
|
-
stack: _optionalChain$
|
|
1832
|
+
stack: _optionalChain$t([error, 'access', _5 => _5.stack, 'optionalAccess', _6 => _6.slice, 'call', _7 => _7(0, 200)]),
|
|
1840
1833
|
extra,
|
|
1841
1834
|
source,
|
|
1842
1835
|
});
|
|
@@ -1856,7 +1849,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1856
1849
|
if (!this.ensureInitialized()) {
|
|
1857
1850
|
return;
|
|
1858
1851
|
}
|
|
1859
|
-
_optionalChain$
|
|
1852
|
+
_optionalChain$t([this, 'access', _8 => _8.client, 'access', _9 => _9.context, 'optionalAccess', _10 => _10.set, 'call', _11 => _11(key, value)]);
|
|
1860
1853
|
}
|
|
1861
1854
|
|
|
1862
1855
|
/**
|
|
@@ -1867,7 +1860,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1867
1860
|
return;
|
|
1868
1861
|
}
|
|
1869
1862
|
log$6('Merging context:', context);
|
|
1870
|
-
_optionalChain$
|
|
1863
|
+
_optionalChain$t([this, 'access', _12 => _12.client, 'access', _13 => _13.context, 'optionalAccess', _14 => _14.merge, 'call', _15 => _15(context)]);
|
|
1871
1864
|
}
|
|
1872
1865
|
|
|
1873
1866
|
/**
|
|
@@ -1877,7 +1870,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1877
1870
|
if (!this.ensureInitialized()) {
|
|
1878
1871
|
return;
|
|
1879
1872
|
}
|
|
1880
|
-
_optionalChain$
|
|
1873
|
+
_optionalChain$t([this, 'access', _16 => _16.client, 'access', _17 => _17.context, 'optionalAccess', _18 => _18.delete, 'call', _19 => _19(key)]);
|
|
1881
1874
|
}
|
|
1882
1875
|
|
|
1883
1876
|
/**
|
|
@@ -1887,7 +1880,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1887
1880
|
if (!this.ensureInitialized()) {
|
|
1888
1881
|
return;
|
|
1889
1882
|
}
|
|
1890
|
-
_optionalChain$
|
|
1883
|
+
_optionalChain$t([this, 'access', _20 => _20.client, 'access', _21 => _21.context, 'optionalAccess', _22 => _22.clear, 'call', _23 => _23()]);
|
|
1891
1884
|
}
|
|
1892
1885
|
|
|
1893
1886
|
/**
|
|
@@ -1924,7 +1917,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1924
1917
|
return;
|
|
1925
1918
|
}
|
|
1926
1919
|
log$6('Flushing Slardar data...');
|
|
1927
|
-
_optionalChain$
|
|
1920
|
+
_optionalChain$t([this, 'access', _24 => _24.client, 'access', _25 => _25.getSender, 'optionalCall', _26 => _26(), 'optionalAccess', _27 => _27.flush, 'call', _28 => _28()]);
|
|
1928
1921
|
log$6('Waiting %dms for events to be sent...', waitMs);
|
|
1929
1922
|
await new Promise(resolve => setTimeout(resolve, waitMs));
|
|
1930
1923
|
log$6('Slardar data flushed');
|
|
@@ -1943,7 +1936,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1943
1936
|
*/
|
|
1944
1937
|
const reporter = new SlardarCLIReporter();
|
|
1945
1938
|
|
|
1946
|
-
function _optionalChain$
|
|
1939
|
+
function _optionalChain$s(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1947
1940
|
|
|
1948
1941
|
|
|
1949
1942
|
|
|
@@ -2003,11 +1996,11 @@ const EventBuilder = {
|
|
|
2003
1996
|
name: CLI_EVENTS.CLI_COMMAND,
|
|
2004
1997
|
categories: {
|
|
2005
1998
|
command,
|
|
2006
|
-
args: _optionalChain$
|
|
1999
|
+
args: _optionalChain$s([options, 'optionalAccess', _ => _.args]),
|
|
2007
2000
|
status: 'running' ,
|
|
2008
|
-
..._optionalChain$
|
|
2001
|
+
..._optionalChain$s([options, 'optionalAccess', _2 => _2.categories]),
|
|
2009
2002
|
},
|
|
2010
|
-
metrics: _optionalChain$
|
|
2003
|
+
metrics: _optionalChain$s([options, 'optionalAccess', _3 => _3.metrics]),
|
|
2011
2004
|
};
|
|
2012
2005
|
},
|
|
2013
2006
|
|
|
@@ -2028,13 +2021,13 @@ const EventBuilder = {
|
|
|
2028
2021
|
name: CLI_EVENTS.CLI_COMMAND_COMPLETE,
|
|
2029
2022
|
categories: {
|
|
2030
2023
|
command,
|
|
2031
|
-
args: _optionalChain$
|
|
2024
|
+
args: _optionalChain$s([options, 'optionalAccess', _4 => _4.args]),
|
|
2032
2025
|
status: success ? ('success' ) : ('fail' ),
|
|
2033
|
-
..._optionalChain$
|
|
2026
|
+
..._optionalChain$s([options, 'optionalAccess', _5 => _5.categories]),
|
|
2034
2027
|
},
|
|
2035
2028
|
metrics: {
|
|
2036
2029
|
duration,
|
|
2037
|
-
...(_optionalChain$
|
|
2030
|
+
...(_optionalChain$s([options, 'optionalAccess', _6 => _6.errorCode]) && { errorCode: options.errorCode }),
|
|
2038
2031
|
},
|
|
2039
2032
|
};
|
|
2040
2033
|
},
|
|
@@ -2055,12 +2048,12 @@ const EventBuilder = {
|
|
|
2055
2048
|
name: CLI_EVENTS.NETWORK_REQUEST,
|
|
2056
2049
|
categories: {
|
|
2057
2050
|
url,
|
|
2058
|
-
method: _optionalChain$
|
|
2059
|
-
statusCode: _optionalChain$
|
|
2060
|
-
status: _optionalChain$
|
|
2051
|
+
method: _optionalChain$s([options, 'optionalAccess', _7 => _7.method]) || 'GET',
|
|
2052
|
+
statusCode: _optionalChain$s([options, 'optionalAccess', _8 => _8.statusCode, 'optionalAccess', _9 => _9.toString, 'call', _10 => _10()]),
|
|
2053
|
+
status: _optionalChain$s([options, 'optionalAccess', _11 => _11.success]) ? ('success' ) : ('fail' ),
|
|
2061
2054
|
},
|
|
2062
2055
|
metrics: {
|
|
2063
|
-
duration: _optionalChain$
|
|
2056
|
+
duration: _optionalChain$s([options, 'optionalAccess', _12 => _12.duration]),
|
|
2064
2057
|
},
|
|
2065
2058
|
};
|
|
2066
2059
|
},
|
|
@@ -2082,11 +2075,11 @@ const EventBuilder = {
|
|
|
2082
2075
|
categories: {
|
|
2083
2076
|
operation,
|
|
2084
2077
|
filePath,
|
|
2085
|
-
status: _optionalChain$
|
|
2078
|
+
status: _optionalChain$s([options, 'optionalAccess', _13 => _13.success]) ? ('success' ) : ('fail' ),
|
|
2086
2079
|
},
|
|
2087
2080
|
metrics: {
|
|
2088
|
-
duration: _optionalChain$
|
|
2089
|
-
fileSize: _optionalChain$
|
|
2081
|
+
duration: _optionalChain$s([options, 'optionalAccess', _14 => _14.duration]),
|
|
2082
|
+
fileSize: _optionalChain$s([options, 'optionalAccess', _15 => _15.fileSize]),
|
|
2090
2083
|
},
|
|
2091
2084
|
};
|
|
2092
2085
|
},
|
|
@@ -2114,7 +2107,7 @@ const EventBuilder = {
|
|
|
2114
2107
|
};
|
|
2115
2108
|
|
|
2116
2109
|
var name = "@coze-arch/cli";
|
|
2117
|
-
var version = "0.0.36
|
|
2110
|
+
var version = "0.0.36";
|
|
2118
2111
|
var description = "coze coding devtools cli";
|
|
2119
2112
|
var license = "MIT";
|
|
2120
2113
|
var author = "fanwenjie.fe@bytedance.com";
|
|
@@ -2126,7 +2119,6 @@ var bin = {
|
|
|
2126
2119
|
var files = [
|
|
2127
2120
|
"lib",
|
|
2128
2121
|
"bin",
|
|
2129
|
-
"docs/deploy.md",
|
|
2130
2122
|
"lib/**/.npmrc",
|
|
2131
2123
|
"!**/*.tsbuildinfo",
|
|
2132
2124
|
"!**/*.map",
|
|
@@ -2163,9 +2155,7 @@ var dependencies = {
|
|
|
2163
2155
|
"fast-glob": "^3.3.3",
|
|
2164
2156
|
"js-yaml": "^4.2.0",
|
|
2165
2157
|
minimist: "^1.2.8",
|
|
2166
|
-
|
|
2167
|
-
shelljs: "^0.10.0",
|
|
2168
|
-
tar: "^7.5.22"
|
|
2158
|
+
shelljs: "^0.10.0"
|
|
2169
2159
|
};
|
|
2170
2160
|
var devDependencies = {
|
|
2171
2161
|
"@coze-arch/cli-logger": "workspace:*",
|
|
@@ -2196,6 +2186,7 @@ var devDependencies = {
|
|
|
2196
2186
|
rollup: "^4.60.1",
|
|
2197
2187
|
sucrase: "^3.35.1",
|
|
2198
2188
|
tsx: "^4.23.11",
|
|
2189
|
+
"tree-kill": "^1.2.2",
|
|
2199
2190
|
vitest: "~4.1.10"
|
|
2200
2191
|
};
|
|
2201
2192
|
var publishConfig = {
|
|
@@ -2224,7 +2215,7 @@ var packageJson = {
|
|
|
2224
2215
|
cozePublishConfig: cozePublishConfig
|
|
2225
2216
|
};
|
|
2226
2217
|
|
|
2227
|
-
function _optionalChain$
|
|
2218
|
+
function _optionalChain$r(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/**
|
|
2228
2219
|
* Slardar 监控初始化和上报
|
|
2229
2220
|
*/
|
|
2230
2221
|
|
|
@@ -2327,11 +2318,11 @@ const reportCommandComplete = safeRun(
|
|
|
2327
2318
|
,
|
|
2328
2319
|
) => {
|
|
2329
2320
|
const event = EventBuilder.cliCommandComplete(command, success, duration, {
|
|
2330
|
-
args: _optionalChain$
|
|
2331
|
-
errorCode: _optionalChain$
|
|
2321
|
+
args: _optionalChain$r([options, 'optionalAccess', _ => _.args]),
|
|
2322
|
+
errorCode: _optionalChain$r([options, 'optionalAccess', _2 => _2.errorCode]),
|
|
2332
2323
|
categories: {
|
|
2333
|
-
...(_optionalChain$
|
|
2334
|
-
..._optionalChain$
|
|
2324
|
+
...(_optionalChain$r([options, 'optionalAccess', _3 => _3.errorMessage]) && { errorMessage: options.errorMessage }),
|
|
2325
|
+
..._optionalChain$r([options, 'optionalAccess', _4 => _4.categories]),
|
|
2335
2326
|
},
|
|
2336
2327
|
});
|
|
2337
2328
|
reporter.sendEvent(event.name, event.metrics, event.categories);
|
|
@@ -2390,7 +2381,7 @@ const flushSlardar = safeRun('flushSlardar', async () => {
|
|
|
2390
2381
|
await reporter.flush();
|
|
2391
2382
|
});
|
|
2392
2383
|
|
|
2393
|
-
function _nullishCoalesce$
|
|
2384
|
+
function _nullishCoalesce$9(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$q(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var LogLevel; (function (LogLevel) {
|
|
2394
2385
|
const ERROR = 0; LogLevel[LogLevel["ERROR"] = ERROR] = "ERROR";
|
|
2395
2386
|
const WARN = 1; LogLevel[LogLevel["WARN"] = WARN] = "WARN";
|
|
2396
2387
|
const SUCCESS = 2; LogLevel[LogLevel["SUCCESS"] = SUCCESS] = "SUCCESS";
|
|
@@ -2428,7 +2419,7 @@ class Logger {
|
|
|
2428
2419
|
|
|
2429
2420
|
constructor(options = {}) {
|
|
2430
2421
|
this.level = this.parseLogLevel(options.level);
|
|
2431
|
-
this.useColor = _nullishCoalesce$
|
|
2422
|
+
this.useColor = _nullishCoalesce$9(options.useColor, () => ( this.isColorSupported()));
|
|
2432
2423
|
this.prefix = options.prefix;
|
|
2433
2424
|
}
|
|
2434
2425
|
|
|
@@ -2437,7 +2428,7 @@ class Logger {
|
|
|
2437
2428
|
return level;
|
|
2438
2429
|
}
|
|
2439
2430
|
|
|
2440
|
-
const envLevel = _optionalChain$
|
|
2431
|
+
const envLevel = _optionalChain$q([process, 'access', _ => _.env, 'access', _2 => _2.LOG_LEVEL, 'optionalAccess', _3 => _3.toLowerCase, 'call', _4 => _4()]);
|
|
2441
2432
|
if (envLevel && envLevel in LOG_LEVEL_MAP) {
|
|
2442
2433
|
// envLevel 已通过 `in` 检查确认为 LOG_LEVEL_MAP 的键;
|
|
2443
2434
|
// 显式判空以满足 noUncheckedIndexedAccess,运行时行为不变
|
|
@@ -2454,7 +2445,7 @@ class Logger {
|
|
|
2454
2445
|
// 简单检测:Node.js 环境且支持 TTY
|
|
2455
2446
|
return (
|
|
2456
2447
|
typeof process !== 'undefined' &&
|
|
2457
|
-
_optionalChain$
|
|
2448
|
+
_optionalChain$q([process, 'access', _5 => _5.stdout, 'optionalAccess', _6 => _6.isTTY]) === true &&
|
|
2458
2449
|
process.env.NO_COLOR === undefined
|
|
2459
2450
|
);
|
|
2460
2451
|
}
|
|
@@ -2479,7 +2470,7 @@ class Logger {
|
|
|
2479
2470
|
|
|
2480
2471
|
const icon = this.colorize(options.icon, options.color);
|
|
2481
2472
|
const prefix = this.prefix ? `${icon} ${this.prefix}` : icon;
|
|
2482
|
-
console.log(prefix, options.message, ...(_nullishCoalesce$
|
|
2473
|
+
console.log(prefix, options.message, ...(_nullishCoalesce$9(options.args, () => ( []))));
|
|
2483
2474
|
}
|
|
2484
2475
|
|
|
2485
2476
|
error(message, ...args) {
|
|
@@ -2824,7 +2815,7 @@ const executeWarmup = async (options) => {
|
|
|
2824
2815
|
/**
|
|
2825
2816
|
* 注册 warmup 命令到 program
|
|
2826
2817
|
*/
|
|
2827
|
-
const registerCommand$
|
|
2818
|
+
const registerCommand$6 = program => {
|
|
2828
2819
|
program
|
|
2829
2820
|
.command('warmup')
|
|
2830
2821
|
.description('Pre-install dependencies for templates to speed up init')
|
|
@@ -2847,9 +2838,9 @@ const COZE_HOME_DIR = '.coze';
|
|
|
2847
2838
|
|
|
2848
2839
|
/**
|
|
2849
2840
|
* Logs directory name
|
|
2850
|
-
* Default:
|
|
2841
|
+
* Default: .coze-logs
|
|
2851
2842
|
*/
|
|
2852
|
-
const LOGS_DIR = 'logs';
|
|
2843
|
+
const LOGS_DIR = '.coze-logs';
|
|
2853
2844
|
|
|
2854
2845
|
/**
|
|
2855
2846
|
* Get the Coze home directory path
|
|
@@ -2864,10 +2855,10 @@ const getCozeHome = () =>
|
|
|
2864
2855
|
* Get the logs directory path
|
|
2865
2856
|
* Can be customized via COZE_LOG_DIR environment variable
|
|
2866
2857
|
*
|
|
2867
|
-
* @returns Absolute path to logs directory (default: ~/.coze
|
|
2858
|
+
* @returns Absolute path to logs directory (default: ~/.coze-logs)
|
|
2868
2859
|
*/
|
|
2869
2860
|
const getCozeLogsDir = () =>
|
|
2870
|
-
process.env.COZE_LOG_DIR || path.join(
|
|
2861
|
+
process.env.COZE_LOG_DIR || path.join(os.homedir(), LOGS_DIR);
|
|
2871
2862
|
|
|
2872
2863
|
/**
|
|
2873
2864
|
* Get path for a specific file/directory within Coze home
|
|
@@ -2898,7 +2889,7 @@ const getCozeFilePath = (relativePath) =>
|
|
|
2898
2889
|
* @example
|
|
2899
2890
|
* ```ts
|
|
2900
2891
|
* const devLog = getCozeLogPath('dev.log');
|
|
2901
|
-
* // Returns: ~/.coze
|
|
2892
|
+
* // Returns: ~/.coze-logs/dev.log
|
|
2902
2893
|
* ```
|
|
2903
2894
|
*/
|
|
2904
2895
|
const getCozeLogPath = (filename) =>
|
|
@@ -3236,7 +3227,7 @@ const executeUpdate = (
|
|
|
3236
3227
|
/**
|
|
3237
3228
|
* 注册 update 命令到 program
|
|
3238
3229
|
*/
|
|
3239
|
-
const registerCommand$
|
|
3230
|
+
const registerCommand$5 = program => {
|
|
3240
3231
|
program
|
|
3241
3232
|
.command('update <package>')
|
|
3242
3233
|
.description('Update a package dependency')
|
|
@@ -3262,7 +3253,7 @@ const registerCommand$6 = program => {
|
|
|
3262
3253
|
});
|
|
3263
3254
|
};
|
|
3264
3255
|
|
|
3265
|
-
function _optionalChain$
|
|
3256
|
+
function _optionalChain$p(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// Safe JSON parsing utilities with type safety and error handling
|
|
3266
3257
|
// Provides fallback values, validation, and error monitoring capabilities
|
|
3267
3258
|
|
|
3268
3259
|
/**
|
|
@@ -3362,12 +3353,12 @@ function safeJsonParse(
|
|
|
3362
3353
|
const parsed = JSON.parse(String(input));
|
|
3363
3354
|
|
|
3364
3355
|
// Optional validation
|
|
3365
|
-
if (_optionalChain$
|
|
3356
|
+
if (_optionalChain$p([options, 'optionalAccess', _ => _.validate])) {
|
|
3366
3357
|
if (options.validate(parsed)) {
|
|
3367
3358
|
return parsed;
|
|
3368
3359
|
} else {
|
|
3369
3360
|
const validationError = new Error('JSON validation failed');
|
|
3370
|
-
_optionalChain$
|
|
3361
|
+
_optionalChain$p([options, 'access', _2 => _2.onError, 'optionalCall', _3 => _3(validationError, input)]);
|
|
3371
3362
|
|
|
3372
3363
|
if (options.throwOnValidationError) {
|
|
3373
3364
|
throw validationError;
|
|
@@ -3379,10 +3370,10 @@ function safeJsonParse(
|
|
|
3379
3370
|
return parsed;
|
|
3380
3371
|
} catch (error) {
|
|
3381
3372
|
// Re-throw validation errors when throwOnValidationError is true
|
|
3382
|
-
if (error instanceof Error && error.message === 'JSON validation failed' && _optionalChain$
|
|
3373
|
+
if (error instanceof Error && error.message === 'JSON validation failed' && _optionalChain$p([options, 'optionalAccess', _4 => _4.throwOnValidationError])) {
|
|
3383
3374
|
throw error;
|
|
3384
3375
|
}
|
|
3385
|
-
_optionalChain$
|
|
3376
|
+
_optionalChain$p([options, 'optionalAccess', _5 => _5.onError, 'optionalCall', _6 => _6(error , input)]);
|
|
3386
3377
|
return defaultValue;
|
|
3387
3378
|
}
|
|
3388
3379
|
}
|
|
@@ -3422,7 +3413,7 @@ function isNode(node) {
|
|
|
3422
3413
|
}
|
|
3423
3414
|
const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
|
|
3424
3415
|
|
|
3425
|
-
function _optionalChain$
|
|
3416
|
+
function _optionalChain$o(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
3426
3417
|
const BREAK = Symbol('break visit');
|
|
3427
3418
|
const SKIP = Symbol('skip children');
|
|
3428
3419
|
const REMOVE = Symbol('remove node');
|
|
@@ -3535,15 +3526,15 @@ function callVisitor(key, node, visitor, path) {
|
|
|
3535
3526
|
if (typeof visitor === 'function')
|
|
3536
3527
|
return visitor(key, node, path);
|
|
3537
3528
|
if (isMap(node))
|
|
3538
|
-
return _optionalChain$
|
|
3529
|
+
return _optionalChain$o([visitor, 'access', _ => _.Map, 'optionalCall', _2 => _2(key, node, path)]);
|
|
3539
3530
|
if (isSeq(node))
|
|
3540
|
-
return _optionalChain$
|
|
3531
|
+
return _optionalChain$o([visitor, 'access', _3 => _3.Seq, 'optionalCall', _4 => _4(key, node, path)]);
|
|
3541
3532
|
if (isPair(node))
|
|
3542
|
-
return _optionalChain$
|
|
3533
|
+
return _optionalChain$o([visitor, 'access', _5 => _5.Pair, 'optionalCall', _6 => _6(key, node, path)]);
|
|
3543
3534
|
if (isScalar(node))
|
|
3544
|
-
return _optionalChain$
|
|
3535
|
+
return _optionalChain$o([visitor, 'access', _7 => _7.Scalar, 'optionalCall', _8 => _8(key, node, path)]);
|
|
3545
3536
|
if (isAlias(node))
|
|
3546
|
-
return _optionalChain$
|
|
3537
|
+
return _optionalChain$o([visitor, 'access', _9 => _9.Alias, 'optionalCall', _10 => _10(key, node, path)]);
|
|
3547
3538
|
return undefined;
|
|
3548
3539
|
}
|
|
3549
3540
|
function replaceNode(key, path, node) {
|
|
@@ -3634,7 +3625,7 @@ function applyReviver(reviver, obj, key, val) {
|
|
|
3634
3625
|
return reviver.call(obj, key, val);
|
|
3635
3626
|
}
|
|
3636
3627
|
|
|
3637
|
-
function _optionalChain$
|
|
3628
|
+
function _optionalChain$n(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
3638
3629
|
/**
|
|
3639
3630
|
* Recursively convert any node or its contents to native JavaScript
|
|
3640
3631
|
*
|
|
@@ -3664,7 +3655,7 @@ function toJS(value, arg, ctx) {
|
|
|
3664
3655
|
ctx.onCreate(res);
|
|
3665
3656
|
return res;
|
|
3666
3657
|
}
|
|
3667
|
-
if (typeof value === 'bigint' && !_optionalChain$
|
|
3658
|
+
if (typeof value === 'bigint' && !_optionalChain$n([ctx, 'optionalAccess', _ => _.keep]))
|
|
3668
3659
|
return Number(value);
|
|
3669
3660
|
return value;
|
|
3670
3661
|
}
|
|
@@ -3702,7 +3693,7 @@ class NodeBase {
|
|
|
3702
3693
|
}
|
|
3703
3694
|
}
|
|
3704
3695
|
|
|
3705
|
-
function _optionalChain$
|
|
3696
|
+
function _optionalChain$m(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
3706
3697
|
class Alias extends NodeBase {
|
|
3707
3698
|
constructor(source) {
|
|
3708
3699
|
super(ALIAS);
|
|
@@ -3718,10 +3709,10 @@ class Alias extends NodeBase {
|
|
|
3718
3709
|
* instance of the `source` anchor before this node.
|
|
3719
3710
|
*/
|
|
3720
3711
|
resolve(doc, ctx) {
|
|
3721
|
-
if (_optionalChain$
|
|
3712
|
+
if (_optionalChain$m([ctx, 'optionalAccess', _ => _.maxAliasCount]) === 0)
|
|
3722
3713
|
throw new ReferenceError('Alias resolution is disabled');
|
|
3723
3714
|
let nodes;
|
|
3724
|
-
if (_optionalChain$
|
|
3715
|
+
if (_optionalChain$m([ctx, 'optionalAccess', _2 => _2.aliasResolveCache])) {
|
|
3725
3716
|
nodes = ctx.aliasResolveCache;
|
|
3726
3717
|
}
|
|
3727
3718
|
else {
|
|
@@ -3760,7 +3751,7 @@ class Alias extends NodeBase {
|
|
|
3760
3751
|
data = anchors.get(source);
|
|
3761
3752
|
}
|
|
3762
3753
|
/* istanbul ignore if */
|
|
3763
|
-
if (_optionalChain$
|
|
3754
|
+
if (_optionalChain$m([data, 'optionalAccess', _3 => _3.res]) === undefined) {
|
|
3764
3755
|
const msg = 'This should not happen: Alias anchor was not resolved?';
|
|
3765
3756
|
throw new ReferenceError(msg);
|
|
3766
3757
|
}
|
|
@@ -3812,7 +3803,7 @@ function getAliasCount(doc, node, anchors) {
|
|
|
3812
3803
|
return 1;
|
|
3813
3804
|
}
|
|
3814
3805
|
|
|
3815
|
-
function _optionalChain$
|
|
3806
|
+
function _optionalChain$l(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
3816
3807
|
const isScalarValue = (value) => !value || (typeof value !== 'function' && typeof value !== 'object');
|
|
3817
3808
|
class Scalar extends NodeBase {
|
|
3818
3809
|
constructor(value) {
|
|
@@ -3820,7 +3811,7 @@ class Scalar extends NodeBase {
|
|
|
3820
3811
|
this.value = value;
|
|
3821
3812
|
}
|
|
3822
3813
|
toJSON(arg, ctx) {
|
|
3823
|
-
return _optionalChain$
|
|
3814
|
+
return _optionalChain$l([ctx, 'optionalAccess', _ => _.keep]) ? this.value : toJS(this.value, arg, ctx);
|
|
3824
3815
|
}
|
|
3825
3816
|
toString() {
|
|
3826
3817
|
return String(this.value);
|
|
@@ -3832,17 +3823,17 @@ Scalar.PLAIN = 'PLAIN';
|
|
|
3832
3823
|
Scalar.QUOTE_DOUBLE = 'QUOTE_DOUBLE';
|
|
3833
3824
|
Scalar.QUOTE_SINGLE = 'QUOTE_SINGLE';
|
|
3834
3825
|
|
|
3835
|
-
function _nullishCoalesce$
|
|
3826
|
+
function _nullishCoalesce$8(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$k(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
3836
3827
|
const defaultTagPrefix = 'tag:yaml.org,2002:';
|
|
3837
3828
|
function findTagObject(value, tagName, tags) {
|
|
3838
3829
|
if (tagName) {
|
|
3839
3830
|
const match = tags.filter(t => t.tag === tagName);
|
|
3840
|
-
const tagObj = _nullishCoalesce$
|
|
3831
|
+
const tagObj = _nullishCoalesce$8(match.find(t => !t.format), () => ( match[0]));
|
|
3841
3832
|
if (!tagObj)
|
|
3842
3833
|
throw new Error(`Tag ${tagName} not found`);
|
|
3843
3834
|
return tagObj;
|
|
3844
3835
|
}
|
|
3845
|
-
return tags.find(t => _optionalChain$
|
|
3836
|
+
return tags.find(t => _optionalChain$k([t, 'access', _ => _.identify, 'optionalCall', _2 => _2(value)]) && !t.format);
|
|
3846
3837
|
}
|
|
3847
3838
|
function createNode(value, tagName, ctx) {
|
|
3848
3839
|
if (isDocument(value))
|
|
@@ -3850,7 +3841,7 @@ function createNode(value, tagName, ctx) {
|
|
|
3850
3841
|
if (isNode(value))
|
|
3851
3842
|
return value;
|
|
3852
3843
|
if (isPair(value)) {
|
|
3853
|
-
const map = _optionalChain$
|
|
3844
|
+
const map = _optionalChain$k([ctx, 'access', _3 => _3.schema, 'access', _4 => _4[MAP], 'access', _5 => _5.createNode, 'optionalCall', _6 => _6(ctx.schema, null, ctx)]);
|
|
3854
3845
|
map.items.push(value);
|
|
3855
3846
|
return map;
|
|
3856
3847
|
}
|
|
@@ -3869,7 +3860,7 @@ function createNode(value, tagName, ctx) {
|
|
|
3869
3860
|
if (aliasDuplicateObjects && value && typeof value === 'object') {
|
|
3870
3861
|
ref = sourceObjects.get(value);
|
|
3871
3862
|
if (ref) {
|
|
3872
|
-
_nullishCoalesce$
|
|
3863
|
+
_nullishCoalesce$8(ref.anchor, () => ( (ref.anchor = onAnchor(value))));
|
|
3873
3864
|
return new Alias(ref.anchor);
|
|
3874
3865
|
}
|
|
3875
3866
|
else {
|
|
@@ -3877,7 +3868,7 @@ function createNode(value, tagName, ctx) {
|
|
|
3877
3868
|
sourceObjects.set(value, ref);
|
|
3878
3869
|
}
|
|
3879
3870
|
}
|
|
3880
|
-
if (_optionalChain$
|
|
3871
|
+
if (_optionalChain$k([tagName, 'optionalAccess', _7 => _7.startsWith, 'call', _8 => _8('!!')]))
|
|
3881
3872
|
tagName = defaultTagPrefix + tagName.slice(2);
|
|
3882
3873
|
let tagObj = findTagObject(value, tagName, schema.tags);
|
|
3883
3874
|
if (!tagObj) {
|
|
@@ -3902,9 +3893,9 @@ function createNode(value, tagName, ctx) {
|
|
|
3902
3893
|
onTagObj(tagObj);
|
|
3903
3894
|
delete ctx.onTagObj;
|
|
3904
3895
|
}
|
|
3905
|
-
const node = _optionalChain$
|
|
3896
|
+
const node = _optionalChain$k([tagObj, 'optionalAccess', _9 => _9.createNode])
|
|
3906
3897
|
? tagObj.createNode(ctx.schema, value, ctx)
|
|
3907
|
-
: typeof _optionalChain$
|
|
3898
|
+
: typeof _optionalChain$k([tagObj, 'optionalAccess', _10 => _10.nodeClass, 'optionalAccess', _11 => _11.from]) === 'function'
|
|
3908
3899
|
? tagObj.nodeClass.from(ctx.schema, value, ctx)
|
|
3909
3900
|
: new Scalar(value);
|
|
3910
3901
|
if (tagName)
|
|
@@ -4222,7 +4213,7 @@ function consumeMoreIndentedLines(text, i, indent) {
|
|
|
4222
4213
|
return end;
|
|
4223
4214
|
}
|
|
4224
4215
|
|
|
4225
|
-
function _optionalChain$
|
|
4216
|
+
function _optionalChain$j(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
4226
4217
|
const getFoldOptions = (ctx, isBlock) => ({
|
|
4227
4218
|
indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
|
|
4228
4219
|
lineWidth: ctx.options.lineWidth,
|
|
@@ -4507,9 +4498,9 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
4507
4498
|
// booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
|
|
4508
4499
|
// and others in v1.1.
|
|
4509
4500
|
if (actualString) {
|
|
4510
|
-
const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && _optionalChain$
|
|
4501
|
+
const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && _optionalChain$j([tag, 'access', _ => _.test, 'optionalAccess', _2 => _2.test, 'call', _3 => _3(str)]);
|
|
4511
4502
|
const { compat, tags } = ctx.doc.schema;
|
|
4512
|
-
if (tags.some(test) || _optionalChain$
|
|
4503
|
+
if (tags.some(test) || _optionalChain$j([compat, 'optionalAccess', _4 => _4.some, 'call', _5 => _5(test)]))
|
|
4513
4504
|
return quotedString(value, ctx);
|
|
4514
4505
|
}
|
|
4515
4506
|
return implicitKey
|
|
@@ -4555,7 +4546,7 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
|
4555
4546
|
return res;
|
|
4556
4547
|
}
|
|
4557
4548
|
|
|
4558
|
-
function _nullishCoalesce$
|
|
4549
|
+
function _nullishCoalesce$7(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$i(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
4559
4550
|
function createStringifyContext(doc, options) {
|
|
4560
4551
|
const opt = Object.assign({
|
|
4561
4552
|
blockQuote: true,
|
|
@@ -4602,27 +4593,27 @@ function getTagObject(tags, item) {
|
|
|
4602
4593
|
if (item.tag) {
|
|
4603
4594
|
const match = tags.filter(t => t.tag === item.tag);
|
|
4604
4595
|
if (match.length > 0)
|
|
4605
|
-
return _nullishCoalesce$
|
|
4596
|
+
return _nullishCoalesce$7(match.find(t => t.format === item.format), () => ( match[0]));
|
|
4606
4597
|
}
|
|
4607
4598
|
let tagObj = undefined;
|
|
4608
4599
|
let obj;
|
|
4609
4600
|
if (isScalar(item)) {
|
|
4610
4601
|
obj = item.value;
|
|
4611
|
-
let match = tags.filter(t => _optionalChain$
|
|
4602
|
+
let match = tags.filter(t => _optionalChain$i([t, 'access', _ => _.identify, 'optionalCall', _2 => _2(obj)]));
|
|
4612
4603
|
if (match.length > 1) {
|
|
4613
4604
|
const testMatch = match.filter(t => t.test);
|
|
4614
4605
|
if (testMatch.length > 0)
|
|
4615
4606
|
match = testMatch;
|
|
4616
4607
|
}
|
|
4617
4608
|
tagObj =
|
|
4618
|
-
_nullishCoalesce$
|
|
4609
|
+
_nullishCoalesce$7(match.find(t => t.format === item.format), () => ( match.find(t => !t.format)));
|
|
4619
4610
|
}
|
|
4620
4611
|
else {
|
|
4621
4612
|
obj = item;
|
|
4622
4613
|
tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
|
|
4623
4614
|
}
|
|
4624
4615
|
if (!tagObj) {
|
|
4625
|
-
const name = _nullishCoalesce$
|
|
4616
|
+
const name = _nullishCoalesce$7(_optionalChain$i([obj, 'optionalAccess', _3 => _3.constructor, 'optionalAccess', _4 => _4.name]), () => ( (obj === null ? 'null' : typeof obj)));
|
|
4626
4617
|
throw new Error(`Tag not resolved for ${name} value`);
|
|
4627
4618
|
}
|
|
4628
4619
|
return tagObj;
|
|
@@ -4637,7 +4628,7 @@ function stringifyProps(node, tagObj, { anchors, doc }) {
|
|
|
4637
4628
|
anchors.add(anchor);
|
|
4638
4629
|
props.push(`&${anchor}`);
|
|
4639
4630
|
}
|
|
4640
|
-
const tag = _nullishCoalesce$
|
|
4631
|
+
const tag = _nullishCoalesce$7(node.tag, () => ( (tagObj.default ? null : tagObj.tag)));
|
|
4641
4632
|
if (tag)
|
|
4642
4633
|
props.push(doc.directives.tagString(tag));
|
|
4643
4634
|
return props.join(' ');
|
|
@@ -4648,7 +4639,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
4648
4639
|
if (isAlias(item)) {
|
|
4649
4640
|
if (ctx.doc.directives)
|
|
4650
4641
|
return item.toString(ctx);
|
|
4651
|
-
if (_optionalChain$
|
|
4642
|
+
if (_optionalChain$i([ctx, 'access', _5 => _5.resolvedAliases, 'optionalAccess', _6 => _6.has, 'call', _7 => _7(item)])) {
|
|
4652
4643
|
throw new TypeError(`Cannot stringify circular structure without alias nodes`);
|
|
4653
4644
|
}
|
|
4654
4645
|
else {
|
|
@@ -4663,10 +4654,10 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
4663
4654
|
const node = isNode(item)
|
|
4664
4655
|
? item
|
|
4665
4656
|
: ctx.doc.createNode(item, { onTagObj: o => (tagObj = o) });
|
|
4666
|
-
_nullishCoalesce$
|
|
4657
|
+
_nullishCoalesce$7(tagObj, () => ( (tagObj = getTagObject(ctx.doc.schema.tags, node))));
|
|
4667
4658
|
const props = stringifyProps(node, tagObj, ctx);
|
|
4668
4659
|
if (props.length > 0)
|
|
4669
|
-
ctx.indentAtStart = (_nullishCoalesce$
|
|
4660
|
+
ctx.indentAtStart = (_nullishCoalesce$7(ctx.indentAtStart, () => ( 0))) + props.length + 1;
|
|
4670
4661
|
const str = typeof tagObj.stringify === 'function'
|
|
4671
4662
|
? tagObj.stringify(node, ctx, onComment, onChompKeep)
|
|
4672
4663
|
: isScalar(node)
|
|
@@ -4679,7 +4670,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
4679
4670
|
: `${props}\n${ctx.indent}${str}`;
|
|
4680
4671
|
}
|
|
4681
4672
|
|
|
4682
|
-
function _nullishCoalesce$
|
|
4673
|
+
function _nullishCoalesce$6(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
4683
4674
|
function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
|
|
4684
4675
|
const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx;
|
|
4685
4676
|
let keyComment = (isNode(key) && key.comment) || null;
|
|
@@ -4789,7 +4780,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
|
|
|
4789
4780
|
const vs0 = valueStr[0];
|
|
4790
4781
|
const nl0 = valueStr.indexOf('\n');
|
|
4791
4782
|
const hasNewline = nl0 !== -1;
|
|
4792
|
-
const flow = _nullishCoalesce$
|
|
4783
|
+
const flow = _nullishCoalesce$6(_nullishCoalesce$6(ctx.inFlow, () => ( value.flow)), () => ( value.items.length === 0));
|
|
4793
4784
|
if (hasNewline || !flow) {
|
|
4794
4785
|
let hasPropsLine = false;
|
|
4795
4786
|
if (hasNewline && (vs0 === '&' || vs0 === '!')) {
|
|
@@ -4830,7 +4821,7 @@ function warn(logLevel, warning) {
|
|
|
4830
4821
|
}
|
|
4831
4822
|
}
|
|
4832
4823
|
|
|
4833
|
-
function _optionalChain$
|
|
4824
|
+
function _optionalChain$h(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
4834
4825
|
// If the value associated with a merge key is a single mapping node, each of
|
|
4835
4826
|
// its key/value pairs is inserted into the current mapping, unless the key
|
|
4836
4827
|
// already exists in it. If the value associated with the merge key is a
|
|
@@ -4854,7 +4845,7 @@ const isMergeKey = (ctx, key) => (merge.identify(key) ||
|
|
|
4854
4845
|
(isScalar(key) &&
|
|
4855
4846
|
(!key.type || key.type === Scalar.PLAIN) &&
|
|
4856
4847
|
merge.identify(key.value))) &&
|
|
4857
|
-
_optionalChain$
|
|
4848
|
+
_optionalChain$h([ctx, 'optionalAccess', _ => _.doc, 'access', _2 => _2.schema, 'access', _3 => _3.tags, 'access', _4 => _4.some, 'call', _5 => _5(tag => tag.tag === merge.tag && tag.default)]);
|
|
4858
4849
|
function addMergeToJSMap(ctx, map, value) {
|
|
4859
4850
|
const source = resolveAliasValue(ctx, value);
|
|
4860
4851
|
if (isSeq(source))
|
|
@@ -4894,7 +4885,7 @@ function resolveAliasValue(ctx, value) {
|
|
|
4894
4885
|
return ctx && isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
|
|
4895
4886
|
}
|
|
4896
4887
|
|
|
4897
|
-
function _optionalChain$
|
|
4888
|
+
function _optionalChain$g(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
4898
4889
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
4899
4890
|
if (isNode(key) && key.addToJSMap)
|
|
4900
4891
|
key.addToJSMap(ctx, map, value);
|
|
@@ -4931,7 +4922,7 @@ function stringifyKey(key, jsKey, ctx) {
|
|
|
4931
4922
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
4932
4923
|
if (typeof jsKey !== 'object')
|
|
4933
4924
|
return String(jsKey);
|
|
4934
|
-
if (isNode(key) && _optionalChain$
|
|
4925
|
+
if (isNode(key) && _optionalChain$g([ctx, 'optionalAccess', _ => _.doc])) {
|
|
4935
4926
|
const strCtx = createStringifyContext(ctx.doc, {});
|
|
4936
4927
|
strCtx.anchors = new Set();
|
|
4937
4928
|
for (const node of ctx.anchors.keys())
|
|
@@ -4951,7 +4942,7 @@ function stringifyKey(key, jsKey, ctx) {
|
|
|
4951
4942
|
return JSON.stringify(jsKey);
|
|
4952
4943
|
}
|
|
4953
4944
|
|
|
4954
|
-
function _optionalChain$
|
|
4945
|
+
function _optionalChain$f(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
4955
4946
|
function createPair(key, value, ctx) {
|
|
4956
4947
|
const k = createNode(key, undefined, ctx);
|
|
4957
4948
|
const v = createNode(value, undefined, ctx);
|
|
@@ -4972,19 +4963,19 @@ class Pair {
|
|
|
4972
4963
|
return new Pair(key, value);
|
|
4973
4964
|
}
|
|
4974
4965
|
toJSON(_, ctx) {
|
|
4975
|
-
const pair = _optionalChain$
|
|
4966
|
+
const pair = _optionalChain$f([ctx, 'optionalAccess', _2 => _2.mapAsMap]) ? new Map() : {};
|
|
4976
4967
|
return addPairToJSMap(ctx, pair, this);
|
|
4977
4968
|
}
|
|
4978
4969
|
toString(ctx, onComment, onChompKeep) {
|
|
4979
|
-
return _optionalChain$
|
|
4970
|
+
return _optionalChain$f([ctx, 'optionalAccess', _3 => _3.doc])
|
|
4980
4971
|
? stringifyPair(this, ctx, onComment, onChompKeep)
|
|
4981
4972
|
: JSON.stringify(this);
|
|
4982
4973
|
}
|
|
4983
4974
|
}
|
|
4984
4975
|
|
|
4985
|
-
function _nullishCoalesce$
|
|
4976
|
+
function _nullishCoalesce$5(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$e(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
4986
4977
|
function stringifyCollection(collection, ctx, options) {
|
|
4987
|
-
const flow = _nullishCoalesce$
|
|
4978
|
+
const flow = _nullishCoalesce$5(ctx.inFlow, () => ( collection.flow));
|
|
4988
4979
|
const stringify = flow ? stringifyFlowCollection : stringifyBlockCollection;
|
|
4989
4980
|
return stringify(collection, ctx, options);
|
|
4990
4981
|
}
|
|
@@ -5076,7 +5067,7 @@ function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
|
|
|
5076
5067
|
if (iv.commentBefore)
|
|
5077
5068
|
reqNewline = true;
|
|
5078
5069
|
}
|
|
5079
|
-
else if (item.value == null && _optionalChain$
|
|
5070
|
+
else if (item.value == null && _optionalChain$e([ik, 'optionalAccess', _ => _.comment])) {
|
|
5080
5071
|
comment = ik.comment;
|
|
5081
5072
|
}
|
|
5082
5073
|
}
|
|
@@ -5131,7 +5122,7 @@ function addCommentBefore({ indent, options: { commentString } }, lines, comment
|
|
|
5131
5122
|
}
|
|
5132
5123
|
}
|
|
5133
5124
|
|
|
5134
|
-
function _nullishCoalesce$
|
|
5125
|
+
function _nullishCoalesce$4(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$d(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
5135
5126
|
function findPair(items, key) {
|
|
5136
5127
|
const k = isScalar(key) ? key.value : key;
|
|
5137
5128
|
for (const it of items) {
|
|
@@ -5192,12 +5183,12 @@ class YAMLMap extends Collection {
|
|
|
5192
5183
|
_pair = pair;
|
|
5193
5184
|
else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
|
|
5194
5185
|
// In TypeScript, this never happens.
|
|
5195
|
-
_pair = new Pair(pair, _optionalChain$
|
|
5186
|
+
_pair = new Pair(pair, _optionalChain$d([pair, 'optionalAccess', _2 => _2.value]));
|
|
5196
5187
|
}
|
|
5197
5188
|
else
|
|
5198
5189
|
_pair = new Pair(pair.key, pair.value);
|
|
5199
5190
|
const prev = findPair(this.items, _pair.key);
|
|
5200
|
-
const sortEntries = _optionalChain$
|
|
5191
|
+
const sortEntries = _optionalChain$d([this, 'access', _3 => _3.schema, 'optionalAccess', _4 => _4.sortMapEntries]);
|
|
5201
5192
|
if (prev) {
|
|
5202
5193
|
if (!overwrite)
|
|
5203
5194
|
throw new Error(`Key ${_pair.key} already set`);
|
|
@@ -5227,8 +5218,8 @@ class YAMLMap extends Collection {
|
|
|
5227
5218
|
}
|
|
5228
5219
|
get(key, keepScalar) {
|
|
5229
5220
|
const it = findPair(this.items, key);
|
|
5230
|
-
const node = _optionalChain$
|
|
5231
|
-
return _nullishCoalesce$
|
|
5221
|
+
const node = _optionalChain$d([it, 'optionalAccess', _5 => _5.value]);
|
|
5222
|
+
return _nullishCoalesce$4((!keepScalar && isScalar(node) ? node.value : node), () => ( undefined));
|
|
5232
5223
|
}
|
|
5233
5224
|
has(key) {
|
|
5234
5225
|
return !!findPair(this.items, key);
|
|
@@ -5242,8 +5233,8 @@ class YAMLMap extends Collection {
|
|
|
5242
5233
|
* @returns Instance of Type, Map, or Object
|
|
5243
5234
|
*/
|
|
5244
5235
|
toJSON(_, ctx, Type) {
|
|
5245
|
-
const map = Type ? new Type() : _optionalChain$
|
|
5246
|
-
if (_optionalChain$
|
|
5236
|
+
const map = Type ? new Type() : _optionalChain$d([ctx, 'optionalAccess', _6 => _6.mapAsMap]) ? new Map() : {};
|
|
5237
|
+
if (_optionalChain$d([ctx, 'optionalAccess', _7 => _7.onCreate]))
|
|
5247
5238
|
ctx.onCreate(map);
|
|
5248
5239
|
for (const item of this.items)
|
|
5249
5240
|
addPairToJSMap(ctx, map, item);
|
|
@@ -5268,7 +5259,7 @@ class YAMLMap extends Collection {
|
|
|
5268
5259
|
}
|
|
5269
5260
|
}
|
|
5270
5261
|
|
|
5271
|
-
function _optionalChain$
|
|
5262
|
+
function _optionalChain$c(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
5272
5263
|
class YAMLSeq extends Collection {
|
|
5273
5264
|
static get tagName() {
|
|
5274
5265
|
return 'tag:yaml.org,2002:seq';
|
|
@@ -5331,7 +5322,7 @@ class YAMLSeq extends Collection {
|
|
|
5331
5322
|
}
|
|
5332
5323
|
toJSON(_, ctx) {
|
|
5333
5324
|
const seq = [];
|
|
5334
|
-
if (_optionalChain$
|
|
5325
|
+
if (_optionalChain$c([ctx, 'optionalAccess', _2 => _2.onCreate]))
|
|
5335
5326
|
ctx.onCreate(seq);
|
|
5336
5327
|
let i = 0;
|
|
5337
5328
|
for (const item of this.items)
|
|
@@ -5410,7 +5401,7 @@ function createPairs(schema, iterable, ctx) {
|
|
|
5410
5401
|
return pairs;
|
|
5411
5402
|
}
|
|
5412
5403
|
|
|
5413
|
-
function _optionalChain$
|
|
5404
|
+
function _optionalChain$b(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
5414
5405
|
class YAMLOMap extends YAMLSeq {
|
|
5415
5406
|
constructor() {
|
|
5416
5407
|
super();
|
|
@@ -5429,7 +5420,7 @@ class YAMLOMap extends YAMLSeq {
|
|
|
5429
5420
|
if (!ctx)
|
|
5430
5421
|
return super.toJSON(_);
|
|
5431
5422
|
const map = new Map();
|
|
5432
|
-
if (_optionalChain$
|
|
5423
|
+
if (_optionalChain$b([ctx, 'optionalAccess', _2 => _2.onCreate]))
|
|
5433
5424
|
ctx.onCreate(map);
|
|
5434
5425
|
for (const pair of this.items) {
|
|
5435
5426
|
let key, value;
|
|
@@ -5547,7 +5538,7 @@ const isDirExists = async (file) => {
|
|
|
5547
5538
|
}
|
|
5548
5539
|
};
|
|
5549
5540
|
|
|
5550
|
-
function _optionalChain$
|
|
5541
|
+
function _optionalChain$a(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// ABOUTME: Project type detection utility
|
|
5551
5542
|
|
|
5552
5543
|
/**
|
|
5553
5544
|
* 支持的项目类型枚举
|
|
@@ -5649,7 +5640,7 @@ const collectProjectInfo = async (
|
|
|
5649
5640
|
}
|
|
5650
5641
|
|
|
5651
5642
|
const scripts = Object.entries(
|
|
5652
|
-
(_optionalChain$
|
|
5643
|
+
(_optionalChain$a([packageJson, 'optionalAccess', _ => _.scripts]) ) || {},
|
|
5653
5644
|
).reduce((acc, [name, script]) => {
|
|
5654
5645
|
if (typeof script === 'string') {
|
|
5655
5646
|
acc[name] = script;
|
|
@@ -5803,7 +5794,7 @@ const detectProjectType = async (
|
|
|
5803
5794
|
};
|
|
5804
5795
|
};
|
|
5805
5796
|
|
|
5806
|
-
function _optionalChain$
|
|
5797
|
+
function _optionalChain$9(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
5807
5798
|
|
|
5808
5799
|
|
|
5809
5800
|
/**
|
|
@@ -5815,7 +5806,7 @@ function _optionalChain$l(ops) { let lastAccessLHS = undefined; let value = ops[
|
|
|
5815
5806
|
const parseConfigContent = (content) => {
|
|
5816
5807
|
// 1. 尝试 TOML 格式 (默认)
|
|
5817
5808
|
try {
|
|
5818
|
-
const config =
|
|
5809
|
+
const config = toml.parse(content);
|
|
5819
5810
|
return config ;
|
|
5820
5811
|
} catch (error) {
|
|
5821
5812
|
// TOML 解析失败,继续尝试其他格式
|
|
@@ -5849,7 +5840,7 @@ const parseConfigContent = (content) => {
|
|
|
5849
5840
|
*/
|
|
5850
5841
|
const parseTomlConfigContent = (content) => {
|
|
5851
5842
|
try {
|
|
5852
|
-
return
|
|
5843
|
+
return toml.parse(content) ;
|
|
5853
5844
|
} catch (e) {
|
|
5854
5845
|
return null;
|
|
5855
5846
|
}
|
|
@@ -5930,7 +5921,7 @@ const saveTomlCozeConfig = async (
|
|
|
5930
5921
|
projectPath,
|
|
5931
5922
|
`.coze.tmp-${process.pid}-${Date.now()}`,
|
|
5932
5923
|
);
|
|
5933
|
-
const content =
|
|
5924
|
+
const content = toml.stringify(config );
|
|
5934
5925
|
|
|
5935
5926
|
try {
|
|
5936
5927
|
await fs$1.writeFile(tempCozeConfigPath, content, 'utf-8');
|
|
@@ -5977,16 +5968,16 @@ const getCommandConfig = (
|
|
|
5977
5968
|
|
|
5978
5969
|
switch (commandName) {
|
|
5979
5970
|
case 'dev':
|
|
5980
|
-
commandConfig = _optionalChain$
|
|
5971
|
+
commandConfig = _optionalChain$9([config, 'access', _ => _.dev, 'optionalAccess', _2 => _2.run]);
|
|
5981
5972
|
break;
|
|
5982
5973
|
case 'build':
|
|
5983
|
-
commandConfig = _optionalChain$
|
|
5974
|
+
commandConfig = _optionalChain$9([config, 'access', _3 => _3.deploy, 'optionalAccess', _4 => _4.build]);
|
|
5984
5975
|
break;
|
|
5985
5976
|
case 'start':
|
|
5986
|
-
commandConfig = _optionalChain$
|
|
5977
|
+
commandConfig = _optionalChain$9([config, 'access', _5 => _5.deploy, 'optionalAccess', _6 => _6.run]);
|
|
5987
5978
|
break;
|
|
5988
5979
|
case 'validate':
|
|
5989
|
-
commandConfig = _optionalChain$
|
|
5980
|
+
commandConfig = _optionalChain$9([config, 'access', _7 => _7.dev, 'optionalAccess', _8 => _8.validate]);
|
|
5990
5981
|
break;
|
|
5991
5982
|
default:
|
|
5992
5983
|
throw new Error(`Unknown command: ${commandName}`);
|
|
@@ -6137,7 +6128,7 @@ const byFlag = (flag) => {
|
|
|
6137
6128
|
return predicate;
|
|
6138
6129
|
};
|
|
6139
6130
|
|
|
6140
|
-
function _optionalChain$
|
|
6131
|
+
function _optionalChain$8(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
6141
6132
|
|
|
6142
6133
|
|
|
6143
6134
|
|
|
@@ -6168,7 +6159,7 @@ echo "Validate passed!"
|
|
|
6168
6159
|
* @returns
|
|
6169
6160
|
*/
|
|
6170
6161
|
const isCozeValid$3 = (cozeConfig) => {
|
|
6171
|
-
if (_optionalChain$
|
|
6162
|
+
if (_optionalChain$8([cozeConfig, 'access', _ => _.dev, 'optionalAccess', _2 => _2.validate])) {
|
|
6172
6163
|
logger.info('[patch-expo-validate] NOT APPLY: dev.validate exists');
|
|
6173
6164
|
return false;
|
|
6174
6165
|
}
|
|
@@ -6313,7 +6304,7 @@ const patchExpoValidate = {
|
|
|
6313
6304
|
},
|
|
6314
6305
|
};
|
|
6315
6306
|
|
|
6316
|
-
function _optionalChain$
|
|
6307
|
+
function _optionalChain$7(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
6317
6308
|
|
|
6318
6309
|
|
|
6319
6310
|
|
|
@@ -6346,7 +6337,7 @@ echo "Validate passed!"
|
|
|
6346
6337
|
* @returns
|
|
6347
6338
|
*/
|
|
6348
6339
|
const isCozeValid$2 = (cozeConfig) => {
|
|
6349
|
-
if (_optionalChain$
|
|
6340
|
+
if (_optionalChain$7([cozeConfig, 'access', _ => _.dev, 'optionalAccess', _2 => _2.validate])) {
|
|
6350
6341
|
logger.info('[patch-nextjs-validate] NOT APPLY: dev.validate exists');
|
|
6351
6342
|
return false;
|
|
6352
6343
|
}
|
|
@@ -6494,7 +6485,7 @@ const patchNextjsValidate = {
|
|
|
6494
6485
|
},
|
|
6495
6486
|
};
|
|
6496
6487
|
|
|
6497
|
-
function _optionalChain$
|
|
6488
|
+
function _optionalChain$6(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
6498
6489
|
|
|
6499
6490
|
const PATCH_ID$5 = 'nextjs/validate-concurrently@0.0.30';
|
|
6500
6491
|
const PACKAGE_JSON_FILE$3 = 'package.json';
|
|
@@ -6527,7 +6518,7 @@ const readPackageJson = async (projectFolder) => {
|
|
|
6527
6518
|
};
|
|
6528
6519
|
|
|
6529
6520
|
const getTargetValidateScript = (packageJson) => {
|
|
6530
|
-
const validateScript = _optionalChain$
|
|
6521
|
+
const validateScript = _optionalChain$6([packageJson, 'access', _ => _.scripts, 'optionalAccess', _2 => _2.validate]);
|
|
6531
6522
|
if (typeof validateScript !== 'string') {
|
|
6532
6523
|
return null;
|
|
6533
6524
|
}
|
|
@@ -6544,7 +6535,7 @@ const getTargetValidateScript = (packageJson) => {
|
|
|
6544
6535
|
|
|
6545
6536
|
const canStackAfterNextjsValidatePatch = async (context, packageJson) => {
|
|
6546
6537
|
const scripts = packageJson.scripts || {};
|
|
6547
|
-
if (typeof scripts.validate !== 'undefined' || typeof scripts['ts-check'] !== 'string' || _optionalChain$
|
|
6538
|
+
if (typeof scripts.validate !== 'undefined' || typeof scripts['ts-check'] !== 'string' || _optionalChain$6([context, 'access', _3 => _3.cozeConfig, 'access', _4 => _4.dev, 'optionalAccess', _5 => _5.validate])) {
|
|
6548
6539
|
return false;
|
|
6549
6540
|
}
|
|
6550
6541
|
|
|
@@ -6613,7 +6604,7 @@ const patchNextjsValidateConcurrently = {
|
|
|
6613
6604
|
apply: patchPackageJson$2,
|
|
6614
6605
|
};
|
|
6615
6606
|
|
|
6616
|
-
function _optionalChain$
|
|
6607
|
+
function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
6617
6608
|
|
|
6618
6609
|
|
|
6619
6610
|
|
|
@@ -6646,7 +6637,7 @@ echo "Validate passed!"
|
|
|
6646
6637
|
* @returns
|
|
6647
6638
|
*/
|
|
6648
6639
|
const isCozeValid$1 = (cozeConfig) => {
|
|
6649
|
-
if (_optionalChain$
|
|
6640
|
+
if (_optionalChain$5([cozeConfig, 'access', _ => _.dev, 'optionalAccess', _2 => _2.validate])) {
|
|
6650
6641
|
logger.info('[patch-vite-validate] NOT APPLY: dev.validate exists');
|
|
6651
6642
|
return false;
|
|
6652
6643
|
}
|
|
@@ -6791,7 +6782,7 @@ const patchViteValidate = {
|
|
|
6791
6782
|
},
|
|
6792
6783
|
};
|
|
6793
6784
|
|
|
6794
|
-
function _optionalChain$
|
|
6785
|
+
function _optionalChain$4(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
6795
6786
|
|
|
6796
6787
|
|
|
6797
6788
|
|
|
@@ -6828,7 +6819,7 @@ echo "Validate passed!"
|
|
|
6828
6819
|
* @returns
|
|
6829
6820
|
*/
|
|
6830
6821
|
const isCozeValid = (cozeConfig) => {
|
|
6831
|
-
if (_optionalChain$
|
|
6822
|
+
if (_optionalChain$4([cozeConfig, 'access', _ => _.dev, 'optionalAccess', _2 => _2.validate])) {
|
|
6832
6823
|
logger.info('[patch-taro-validate] NOT APPLY: dev.validate exists');
|
|
6833
6824
|
return false;
|
|
6834
6825
|
}
|
|
@@ -6977,7 +6968,7 @@ const patchTaroValidate = {
|
|
|
6977
6968
|
},
|
|
6978
6969
|
};
|
|
6979
6970
|
|
|
6980
|
-
function _optionalChain$
|
|
6971
|
+
function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
6981
6972
|
const PATCH_ID$2 = 'taro/update-pack-script-for-tt-build@0.0.13';
|
|
6982
6973
|
const PACKAGE_JSON_FILE = 'package.json';
|
|
6983
6974
|
const PACK_SCRIPT_FILE = '.cozeproj/scripts/pack.sh';
|
|
@@ -7056,12 +7047,12 @@ const readPackageScripts = async (
|
|
|
7056
7047
|
const packageJsonContent = await fs$1.readFile(packageJsonPath, 'utf-8');
|
|
7057
7048
|
const packageJson = safeJsonParse(packageJsonContent, null);
|
|
7058
7049
|
|
|
7059
|
-
return _optionalChain$
|
|
7050
|
+
return _optionalChain$3([packageJson, 'optionalAccess', _ => _.scripts]) || null;
|
|
7060
7051
|
};
|
|
7061
7052
|
|
|
7062
7053
|
const hasBuildTtScript = async (projectFolder) => {
|
|
7063
7054
|
const scripts = await readPackageScripts(projectFolder);
|
|
7064
|
-
return typeof _optionalChain$
|
|
7055
|
+
return typeof _optionalChain$3([scripts, 'optionalAccess', _2 => _2['build:tt']]) === 'string';
|
|
7065
7056
|
};
|
|
7066
7057
|
|
|
7067
7058
|
const hasLegacyPackScript = async (projectFolder) => {
|
|
@@ -7415,7 +7406,7 @@ const getTemplatePatches = (
|
|
|
7415
7406
|
) =>
|
|
7416
7407
|
patches.filter(patch => patch.template === template);
|
|
7417
7408
|
|
|
7418
|
-
function _nullishCoalesce$
|
|
7409
|
+
function _nullishCoalesce$3(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
7419
7410
|
const DEFAULT_LEGACY_VERSION = 'legacy';
|
|
7420
7411
|
|
|
7421
7412
|
const loadFlagsWithFallback = async () => {
|
|
@@ -7521,7 +7512,7 @@ const getNextPatchState = (
|
|
|
7521
7512
|
|
|
7522
7513
|
) => ({
|
|
7523
7514
|
template,
|
|
7524
|
-
version: _optionalChain$
|
|
7515
|
+
version: _optionalChain$2([config, 'access', _ => _.project, 'optionalAccess', _2 => _2.version]) || DEFAULT_LEGACY_VERSION,
|
|
7525
7516
|
appliedPatches: [...appliedPatches, patchId],
|
|
7526
7517
|
});
|
|
7527
7518
|
|
|
@@ -7545,15 +7536,15 @@ const executePatch = async (
|
|
|
7545
7536
|
}
|
|
7546
7537
|
|
|
7547
7538
|
const template =
|
|
7548
|
-
_optionalChain$
|
|
7539
|
+
_optionalChain$2([config, 'access', _3 => _3.project, 'optionalAccess', _4 => _4.template]) || (await detectTemplateKey(projectFolder));
|
|
7549
7540
|
|
|
7550
7541
|
if (!template) {
|
|
7551
7542
|
logger.info('Patch skipped: template not detected');
|
|
7552
7543
|
return;
|
|
7553
7544
|
}
|
|
7554
7545
|
|
|
7555
|
-
const appliedPatches = [...(_optionalChain$
|
|
7556
|
-
const projectVersion = _optionalChain$
|
|
7546
|
+
const appliedPatches = [...(_optionalChain$2([config, 'access', _5 => _5.project, 'optionalAccess', _6 => _6.appliedPatches]) || [])];
|
|
7547
|
+
const projectVersion = _optionalChain$2([config, 'access', _7 => _7.project, 'optionalAccess', _8 => _8.version]);
|
|
7557
7548
|
const flags = await loadFlagsWithFallback();
|
|
7558
7549
|
|
|
7559
7550
|
const context = {
|
|
@@ -7598,7 +7589,7 @@ const executePatch = async (
|
|
|
7598
7589
|
|
|
7599
7590
|
if (options.dryRun) {
|
|
7600
7591
|
logger.info(`Detected template: ${template}`);
|
|
7601
|
-
logger.info(`Current version: ${_nullishCoalesce$
|
|
7592
|
+
logger.info(`Current version: ${_nullishCoalesce$3(projectVersion, () => ( DEFAULT_LEGACY_VERSION))}`);
|
|
7602
7593
|
logger.info(`Applied patches: ${appliedPatches.join(', ') || '(none)'}`);
|
|
7603
7594
|
logger.info('Matched patches:');
|
|
7604
7595
|
matchedPatches.forEach(patch => {
|
|
@@ -7639,7 +7630,7 @@ const executePatch = async (
|
|
|
7639
7630
|
}
|
|
7640
7631
|
};
|
|
7641
7632
|
|
|
7642
|
-
const registerCommand$
|
|
7633
|
+
const registerCommand$4 = program => {
|
|
7643
7634
|
program
|
|
7644
7635
|
.command('patch')
|
|
7645
7636
|
.description('Apply template patches for existing projects')
|
|
@@ -7656,14 +7647,14 @@ const registerCommand$5 = program => {
|
|
|
7656
7647
|
) => {
|
|
7657
7648
|
await executePatch({
|
|
7658
7649
|
directory,
|
|
7659
|
-
dryRun: _optionalChain$
|
|
7660
|
-
showFlags: _optionalChain$
|
|
7650
|
+
dryRun: _optionalChain$2([command, 'optionalAccess', _9 => _9.dryRun]),
|
|
7651
|
+
showFlags: _optionalChain$2([command, 'optionalAccess', _10 => _10.showFlags]),
|
|
7661
7652
|
});
|
|
7662
7653
|
},
|
|
7663
7654
|
);
|
|
7664
7655
|
};
|
|
7665
7656
|
|
|
7666
|
-
function _nullishCoalesce$
|
|
7657
|
+
function _nullishCoalesce$2(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
7667
7658
|
const d$1 = debug('coze-init-cli:run');
|
|
7668
7659
|
|
|
7669
7660
|
/**
|
|
@@ -7794,12 +7785,12 @@ const executeRun = async (commandName, options = {}) => {
|
|
|
7794
7785
|
}
|
|
7795
7786
|
|
|
7796
7787
|
// 将输出同时写入控制台和日志文件
|
|
7797
|
-
_optionalChain$
|
|
7788
|
+
_optionalChain$1([childProcess, 'access', _ => _.stdout, 'optionalAccess', _2 => _2.on, 'call', _3 => _3('data', (data) => {
|
|
7798
7789
|
process.stdout.write(data);
|
|
7799
7790
|
logStream.write(data);
|
|
7800
7791
|
})]);
|
|
7801
7792
|
|
|
7802
|
-
_optionalChain$
|
|
7793
|
+
_optionalChain$1([childProcess, 'access', _4 => _4.stderr, 'optionalAccess', _5 => _5.on, 'call', _6 => _6('data', (data) => {
|
|
7803
7794
|
process.stderr.write(data);
|
|
7804
7795
|
logStream.write(data);
|
|
7805
7796
|
})]);
|
|
@@ -7812,7 +7803,7 @@ const executeRun = async (commandName, options = {}) => {
|
|
|
7812
7803
|
const buildDuration = Date.now() - buildStartTime;
|
|
7813
7804
|
|
|
7814
7805
|
if (code !== 0) {
|
|
7815
|
-
const errorMessage = `Command exited with code ${_nullishCoalesce$
|
|
7806
|
+
const errorMessage = `Command exited with code ${_nullishCoalesce$2(code, () => ( 'unknown'))}${signal ? ` and signal ${signal}` : ''}`;
|
|
7816
7807
|
logger.error(errorMessage);
|
|
7817
7808
|
logger.error(`Check log file for details: ${logFilePath}`);
|
|
7818
7809
|
|
|
@@ -7824,12 +7815,12 @@ const executeRun = async (commandName, options = {}) => {
|
|
|
7824
7815
|
categories: {
|
|
7825
7816
|
fixDuration: String(fixDuration),
|
|
7826
7817
|
buildDuration: String(buildDuration),
|
|
7827
|
-
exitCode: String(_nullishCoalesce$
|
|
7818
|
+
exitCode: String(_nullishCoalesce$2(code, () => ( 'unknown'))),
|
|
7828
7819
|
projectType,
|
|
7829
7820
|
},
|
|
7830
7821
|
errorContext: {
|
|
7831
|
-
exitCode: String(_nullishCoalesce$
|
|
7832
|
-
signal: _nullishCoalesce$
|
|
7822
|
+
exitCode: String(_nullishCoalesce$2(code, () => ( 'unknown'))),
|
|
7823
|
+
signal: _nullishCoalesce$2(signal, () => ( 'none')),
|
|
7833
7824
|
logFile: logFilePath,
|
|
7834
7825
|
projectType,
|
|
7835
7826
|
},
|
|
@@ -7905,7 +7896,7 @@ const executeRun = async (commandName, options = {}) => {
|
|
|
7905
7896
|
/**
|
|
7906
7897
|
* 注册 dev/build/start 命令到 program
|
|
7907
7898
|
*/
|
|
7908
|
-
const registerCommand$
|
|
7899
|
+
const registerCommand$3 = program => {
|
|
7909
7900
|
// dev 命令
|
|
7910
7901
|
program
|
|
7911
7902
|
.command('dev')
|
|
@@ -8743,7 +8734,7 @@ const scanRoutesOnce = async (
|
|
|
8743
8734
|
}
|
|
8744
8735
|
};
|
|
8745
8736
|
|
|
8746
|
-
function _optionalChain
|
|
8737
|
+
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// Route manifest generation command
|
|
8747
8738
|
|
|
8748
8739
|
|
|
8749
8740
|
const log = debug('coze:routes');
|
|
@@ -8831,7 +8822,7 @@ const executeRoutes = async (
|
|
|
8831
8822
|
/**
|
|
8832
8823
|
* Register routes command to program
|
|
8833
8824
|
*/
|
|
8834
|
-
const registerCommand$
|
|
8825
|
+
const registerCommand$2 = program => {
|
|
8835
8826
|
program
|
|
8836
8827
|
.command('routes')
|
|
8837
8828
|
.description('Generate routes manifest for the current project')
|
|
@@ -8844,11 +8835,11 @@ const registerCommand$3 = program => {
|
|
|
8844
8835
|
'Output file path (defaults to ~/.coze/routes.json)',
|
|
8845
8836
|
)
|
|
8846
8837
|
.action(async (directory, options) => {
|
|
8847
|
-
await executeRoutes({ directory, output: _optionalChain
|
|
8838
|
+
await executeRoutes({ directory, output: _optionalChain([options, 'optionalAccess', _ => _.output]) });
|
|
8848
8839
|
});
|
|
8849
8840
|
};
|
|
8850
8841
|
|
|
8851
|
-
function _nullishCoalesce$
|
|
8842
|
+
function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
8852
8843
|
|
|
8853
8844
|
|
|
8854
8845
|
const d = debug('coze-init-cli:check-bins');
|
|
@@ -8905,7 +8896,7 @@ const checkBins = async (cwd, fix) => {
|
|
|
8905
8896
|
|
|
8906
8897
|
const bins =
|
|
8907
8898
|
typeof depPkg.bin === 'string'
|
|
8908
|
-
? { [_nullishCoalesce$
|
|
8899
|
+
? { [_nullishCoalesce$1(depName.split('/').pop(), () => ( depName))]: depPkg.bin }
|
|
8909
8900
|
: depPkg.bin;
|
|
8910
8901
|
|
|
8911
8902
|
d('%s declares bins: %o', depName, Object.keys(bins));
|
|
@@ -8955,7 +8946,7 @@ const checkBins = async (cwd, fix) => {
|
|
|
8955
8946
|
d('pnpm i --force completed');
|
|
8956
8947
|
};
|
|
8957
8948
|
|
|
8958
|
-
const registerCommand$
|
|
8949
|
+
const registerCommand$1 = program => {
|
|
8959
8950
|
program
|
|
8960
8951
|
.command('check-bins')
|
|
8961
8952
|
.description(
|
|
@@ -9849,7 +9840,7 @@ const execute = async (
|
|
|
9849
9840
|
};
|
|
9850
9841
|
};
|
|
9851
9842
|
|
|
9852
|
-
function _nullishCoalesce
|
|
9843
|
+
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
9853
9844
|
/**
|
|
9854
9845
|
* 运行 pnpm install
|
|
9855
9846
|
*/
|
|
@@ -9970,8 +9961,8 @@ const runDev = (projectPath) => {
|
|
|
9970
9961
|
// 获取当前 CLI 的可执行文件路径
|
|
9971
9962
|
// process.argv[0] 是 node,process.argv[1] 是 CLI 入口文件
|
|
9972
9963
|
// 二者在 CLI 运行时必然存在,兜底空串仅为满足类型收窄,运行时不会命中
|
|
9973
|
-
const nodeBin = _nullishCoalesce
|
|
9974
|
-
const cliPath = _nullishCoalesce
|
|
9964
|
+
const nodeBin = _nullishCoalesce(process.argv[0], () => ( ''));
|
|
9965
|
+
const cliPath = _nullishCoalesce(process.argv[1], () => ( ''));
|
|
9975
9966
|
|
|
9976
9967
|
try {
|
|
9977
9968
|
// 使用通用的后台执行函数启动开发服务器
|
|
@@ -10041,7 +10032,7 @@ const executeTemplateEngineStep = async ctx => {
|
|
|
10041
10032
|
templateName: ctx.templateName,
|
|
10042
10033
|
outputPath: ctx.outputPath,
|
|
10043
10034
|
command: ctx.command,
|
|
10044
|
-
force: _nullishCoalesce
|
|
10035
|
+
force: _nullishCoalesce(ctx.options.force, () => ( false)),
|
|
10045
10036
|
});
|
|
10046
10037
|
|
|
10047
10038
|
// 保存结果到上下文
|
|
@@ -10300,7 +10291,7 @@ const executeInit = async (
|
|
|
10300
10291
|
/**
|
|
10301
10292
|
* 注册 init 命令到 program
|
|
10302
10293
|
*/
|
|
10303
|
-
const registerCommand
|
|
10294
|
+
const registerCommand = program => {
|
|
10304
10295
|
program
|
|
10305
10296
|
.command('init')
|
|
10306
10297
|
.description('Initialize a new project from a template')
|
|
@@ -10318,3302 +10309,64 @@ const registerCommand$1 = program => {
|
|
|
10318
10309
|
.allowUnknownOption() // 允许透传参数
|
|
10319
10310
|
.action(async (directory, options, command) => {
|
|
10320
10311
|
// 位置参数优先级高于 --output 选项
|
|
10321
|
-
const outputPath = _nullishCoalesce
|
|
10312
|
+
const outputPath = _nullishCoalesce(directory, () => ( options.output));
|
|
10322
10313
|
// Always use force mode - overwrite existing files without conflict check
|
|
10323
10314
|
const force = true;
|
|
10324
10315
|
await executeInit({ ...options, output: outputPath, force }, command);
|
|
10325
10316
|
});
|
|
10326
10317
|
};
|
|
10327
10318
|
|
|
10328
|
-
const
|
|
10329
|
-
|
|
10330
|
-
|
|
10331
|
-
|
|
10332
|
-
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10336
|
-
|
|
10337
|
-
while (current) {
|
|
10338
|
-
if (deployCommands.has(current)) {
|
|
10339
|
-
return current;
|
|
10340
|
-
}
|
|
10341
|
-
current = current.parent;
|
|
10342
|
-
}
|
|
10343
|
-
throw new Error('Unable to resolve the coze-dev deploy command context.');
|
|
10344
|
-
};
|
|
10345
|
-
|
|
10346
|
-
class CliError extends Error {
|
|
10347
|
-
constructor(
|
|
10348
|
-
message,
|
|
10349
|
-
code = 'DEPLOY_CLI_ERROR',
|
|
10350
|
-
details,
|
|
10351
|
-
) {
|
|
10352
|
-
super(message);this.code = code;this.details = details; this.name = 'CliError';
|
|
10353
|
-
}
|
|
10354
|
-
}
|
|
10355
|
-
|
|
10356
|
-
const toErrorPayload = (error) => {
|
|
10357
|
-
if (error instanceof CliError) {
|
|
10358
|
-
return { code: error.code, message: error.message, details: error.details };
|
|
10359
|
-
}
|
|
10360
|
-
return {
|
|
10361
|
-
code: 'INTERNAL_ERROR',
|
|
10362
|
-
message: error instanceof Error ? error.message : String(error),
|
|
10363
|
-
};
|
|
10364
|
-
};
|
|
10365
|
-
|
|
10366
|
-
const APPLICATION_TYPES = new Set([
|
|
10367
|
-
'service',
|
|
10368
|
-
'pages',
|
|
10369
|
-
'mini_program',
|
|
10370
|
-
]);
|
|
10371
|
-
|
|
10372
|
-
const PAGES_SERVICE_TYPE = 3;
|
|
10373
|
-
|
|
10374
|
-
const inferApplicationTypeFromProjectType = (
|
|
10375
|
-
projectType,
|
|
10376
|
-
) => {
|
|
10377
|
-
switch (projectType) {
|
|
10378
|
-
case 'miniapp':
|
|
10379
|
-
case 'miniprogram':
|
|
10380
|
-
return 'mini_program';
|
|
10381
|
-
case undefined:
|
|
10382
|
-
case '':
|
|
10383
|
-
return undefined;
|
|
10384
|
-
default:
|
|
10385
|
-
return 'service';
|
|
10386
|
-
}
|
|
10387
|
-
};
|
|
10388
|
-
|
|
10389
|
-
const parseApplicationType = (
|
|
10390
|
-
value,
|
|
10391
|
-
) => {
|
|
10392
|
-
if (!value) {
|
|
10393
|
-
return undefined;
|
|
10394
|
-
}
|
|
10395
|
-
if (!APPLICATION_TYPES.has(value )) {
|
|
10396
|
-
throw new CliError(
|
|
10397
|
-
`Unsupported application type ${value}; expected service, pages, or mini_program.`,
|
|
10398
|
-
'INVALID_APPLICATION_TYPE',
|
|
10399
|
-
);
|
|
10400
|
-
}
|
|
10401
|
-
return value ;
|
|
10402
|
-
};
|
|
10403
|
-
|
|
10404
|
-
const withRequestedApplicationType = (
|
|
10405
|
-
config,
|
|
10406
|
-
requestedType,
|
|
10407
|
-
hasApplication = false,
|
|
10408
|
-
) => {
|
|
10409
|
-
if (!requestedType) {
|
|
10410
|
-
return config;
|
|
10411
|
-
}
|
|
10412
|
-
if (hasApplication && config.application_type !== requestedType) {
|
|
10413
|
-
throw new CliError(
|
|
10414
|
-
`Application type mismatch: the application is ${config.application_type}, but ${requestedType} was requested.`,
|
|
10415
|
-
'APPLICATION_TYPE_MISMATCH',
|
|
10416
|
-
);
|
|
10417
|
-
}
|
|
10418
|
-
if (requestedType !== 'pages') {
|
|
10419
|
-
if (config.application_type !== requestedType) {
|
|
10420
|
-
throw new CliError(
|
|
10421
|
-
`Application type mismatch: server resolved ${config.application_type}, but ${requestedType} was requested.`,
|
|
10422
|
-
'APPLICATION_TYPE_MISMATCH',
|
|
10423
|
-
);
|
|
10424
|
-
}
|
|
10425
|
-
return config;
|
|
10426
|
-
}
|
|
10427
|
-
return {
|
|
10428
|
-
...config,
|
|
10429
|
-
application_type: 'pages',
|
|
10430
|
-
deploy_config: {
|
|
10431
|
-
...config.deploy_config,
|
|
10432
|
-
service_type: PAGES_SERVICE_TYPE,
|
|
10433
|
-
computer_id: undefined,
|
|
10434
|
-
},
|
|
10435
|
-
};
|
|
10436
|
-
};
|
|
10437
|
-
|
|
10438
|
-
function _optionalChain$b(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
10439
|
-
|
|
10440
|
-
const DEFAULT_CONFIG = {
|
|
10441
|
-
apiBaseUrl: 'https://code.coze.cn/',
|
|
10442
|
-
openApiBaseUrl: 'https://api.coze.cn',
|
|
10443
|
-
clientId: '95438868623436343239609434490626.app.coze',
|
|
10444
|
-
};
|
|
10445
|
-
|
|
10446
|
-
const getSharedConfigPath = () =>
|
|
10447
|
-
node_path.join(node_os.homedir(), '.coze', 'cli', 'config.json');
|
|
10448
|
-
|
|
10449
|
-
const getLegacyConfigPath = () => node_path.join(node_os.homedir(), '.coze', 'config.json');
|
|
10450
|
-
|
|
10451
|
-
const isRecord$3 = (value) =>
|
|
10452
|
-
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
10319
|
+
const commands = [
|
|
10320
|
+
registerCommand,
|
|
10321
|
+
registerCommand$3,
|
|
10322
|
+
registerCommand$6,
|
|
10323
|
+
registerCommand$4,
|
|
10324
|
+
registerCommand$5,
|
|
10325
|
+
registerCommand$2,
|
|
10326
|
+
registerCommand$1,
|
|
10327
|
+
];
|
|
10453
10328
|
|
|
10454
|
-
const
|
|
10455
|
-
|
|
10456
|
-
|
|
10457
|
-
return isRecord$3(parsed) ? parsed : undefined;
|
|
10458
|
-
} catch (error) {
|
|
10459
|
-
if ((error ).code === 'ENOENT') {
|
|
10460
|
-
return undefined;
|
|
10461
|
-
}
|
|
10462
|
-
throw new CliError(`Unable to read config ${path}: ${String(error)}`, 'CONFIG_INVALID');
|
|
10463
|
-
}
|
|
10464
|
-
};
|
|
10465
|
-
|
|
10466
|
-
const configuredPath = (options) =>
|
|
10467
|
-
_optionalChain$b([options, 'optionalAccess', _ => _.config]) || process.env.COZE_CONFIG_FILE;
|
|
10468
|
-
|
|
10469
|
-
const loadConfig = async (options = {}) => {
|
|
10470
|
-
const customPath = configuredPath(options);
|
|
10471
|
-
const globalConfig = customPath
|
|
10472
|
-
? await readJson(node_path.resolve(customPath))
|
|
10473
|
-
: (await readJson(getSharedConfigPath())) || (await readJson(getLegacyConfigPath()));
|
|
10474
|
-
const environmentAccessToken = process.env.COZE_API_TOKEN;
|
|
10475
|
-
const config = {
|
|
10476
|
-
...DEFAULT_CONFIG,
|
|
10477
|
-
...globalConfig,
|
|
10478
|
-
...(environmentAccessToken
|
|
10479
|
-
? {
|
|
10480
|
-
accessToken: environmentAccessToken,
|
|
10481
|
-
// COZE_API_TOKEN is a fixed runtime credential. Never combine it with
|
|
10482
|
-
// refresh metadata left by an earlier OAuth login in config.json.
|
|
10483
|
-
refreshToken: undefined,
|
|
10484
|
-
tokenExpiresAt: undefined,
|
|
10485
|
-
}
|
|
10486
|
-
: {}),
|
|
10487
|
-
...(process.env.COZE_ORG_ID ? { organizationId: process.env.COZE_ORG_ID } : {}),
|
|
10488
|
-
...(process.env.COZE_SPACE_ID ? { spaceId: process.env.COZE_SPACE_ID } : {}),
|
|
10489
|
-
...(process.env.COZE_PROJECT_ID ? { projectId: process.env.COZE_PROJECT_ID } : {}),
|
|
10490
|
-
...(options.orgId ? { organizationId: options.orgId } : {}),
|
|
10491
|
-
...(options.spaceId ? { spaceId: options.spaceId } : {}),
|
|
10492
|
-
...(options.apiBaseUrl ? { apiBaseUrl: options.apiBaseUrl } : {}),
|
|
10493
|
-
};
|
|
10494
|
-
return config;
|
|
10495
|
-
};
|
|
10329
|
+
const main = async () => {
|
|
10330
|
+
// 初始化 Slardar 监控
|
|
10331
|
+
initSlardar();
|
|
10496
10332
|
|
|
10497
|
-
|
|
10498
|
-
|
|
10499
|
-
|
|
10500
|
-
|
|
10501
|
-
|
|
10502
|
-
const existing = (await readJson(target)) || {};
|
|
10503
|
-
const temp = node_path.join(node_path.dirname(target), `.config-${node_crypto.randomUUID()}.tmp`);
|
|
10504
|
-
await promises.mkdir(node_path.dirname(target), { recursive: true });
|
|
10505
|
-
try {
|
|
10506
|
-
await promises.writeFile(temp, `${JSON.stringify({ ...existing, ...patch }, null, 2)}\n`, {
|
|
10507
|
-
encoding: 'utf8',
|
|
10508
|
-
mode: 0o600,
|
|
10333
|
+
// 监听未捕获的异常
|
|
10334
|
+
process.on('uncaughtException', async (error) => {
|
|
10335
|
+
reportError(error, {
|
|
10336
|
+
type: 'uncaughtException',
|
|
10337
|
+
context: 'global',
|
|
10509
10338
|
});
|
|
10510
|
-
await
|
|
10511
|
-
|
|
10512
|
-
await promises.rm(temp, { force: true });
|
|
10513
|
-
}
|
|
10514
|
-
};
|
|
10515
|
-
|
|
10516
|
-
const FIVE_MINUTES = 5 * 60 * 1000;
|
|
10517
|
-
|
|
10518
|
-
|
|
10519
|
-
|
|
10520
|
-
|
|
10521
|
-
|
|
10522
|
-
|
|
10523
|
-
|
|
10524
|
-
const resolveExpiry = (expiresIn) =>
|
|
10525
|
-
expiresIn > 946684800 ? expiresIn * 1000 : Date.now() + expiresIn * 1000;
|
|
10526
|
-
|
|
10527
|
-
const parseJson = async (response) => {
|
|
10528
|
-
const text = await response.text();
|
|
10529
|
-
if (!text) {
|
|
10530
|
-
return {};
|
|
10531
|
-
}
|
|
10532
|
-
const parsed = safeJsonParse(text, {});
|
|
10533
|
-
return typeof parsed === 'object' && parsed !== null
|
|
10534
|
-
? (parsed )
|
|
10535
|
-
: {};
|
|
10536
|
-
};
|
|
10537
|
-
|
|
10538
|
-
const isRecord$2 = (value) =>
|
|
10539
|
-
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
10540
|
-
|
|
10541
|
-
const getCurrentUser = async (
|
|
10542
|
-
config,
|
|
10543
|
-
options,
|
|
10544
|
-
) => {
|
|
10545
|
-
const token = await getAccessToken(config, options);
|
|
10546
|
-
const response = await fetch(new URL('/v1/users/me', config.openApiBaseUrl), {
|
|
10547
|
-
headers: { authorization: `Bearer ${token}` },
|
|
10339
|
+
await flushSlardar();
|
|
10340
|
+
process.exit(1);
|
|
10548
10341
|
});
|
|
10549
|
-
const payload = await parseJson(response);
|
|
10550
|
-
if (!response.ok) {
|
|
10551
|
-
throw new CliError(
|
|
10552
|
-
typeof payload.msg === 'string'
|
|
10553
|
-
? payload.msg
|
|
10554
|
-
: 'Unable to validate the current login. Run `coze-dev deploy auth login` again.',
|
|
10555
|
-
response.status === 401 ? 'AUTH_REQUIRED' : 'AUTH_STATUS_FAILED',
|
|
10556
|
-
{ status: response.status },
|
|
10557
|
-
);
|
|
10558
|
-
}
|
|
10559
|
-
return isRecord$2(payload.data) ? payload.data : payload;
|
|
10560
|
-
};
|
|
10561
|
-
|
|
10562
|
-
const clearAuthPatch = {
|
|
10563
|
-
accessToken: undefined,
|
|
10564
|
-
refreshToken: undefined,
|
|
10565
|
-
tokenExpiresAt: undefined,
|
|
10566
|
-
organizationId: undefined,
|
|
10567
|
-
enterpriseId: undefined,
|
|
10568
|
-
spaceId: undefined,
|
|
10569
|
-
projectId: undefined,
|
|
10570
|
-
};
|
|
10571
|
-
|
|
10572
|
-
const getAccessToken = async (
|
|
10573
|
-
config,
|
|
10574
|
-
options,
|
|
10575
|
-
) => {
|
|
10576
|
-
if (!config.accessToken) {
|
|
10577
|
-
throw new CliError(
|
|
10578
|
-
'No shared login found. Run `coze-dev deploy auth login` first.',
|
|
10579
|
-
'AUTH_REQUIRED',
|
|
10580
|
-
);
|
|
10581
|
-
}
|
|
10582
|
-
if (!config.refreshToken || !config.tokenExpiresAt) {
|
|
10583
|
-
return config.accessToken;
|
|
10584
|
-
}
|
|
10585
|
-
if (Date.now() < config.tokenExpiresAt - FIVE_MINUTES) {
|
|
10586
|
-
return config.accessToken;
|
|
10587
|
-
}
|
|
10588
|
-
|
|
10589
|
-
const response = await fetch(
|
|
10590
|
-
new URL('/api/permission/oauth2/token', config.openApiBaseUrl),
|
|
10591
|
-
{
|
|
10592
|
-
method: 'POST',
|
|
10593
|
-
headers: { 'content-type': 'application/json' },
|
|
10594
|
-
body: JSON.stringify({
|
|
10595
|
-
grant_type: 'refresh_token',
|
|
10596
|
-
client_id: config.clientId,
|
|
10597
|
-
refresh_token: config.refreshToken,
|
|
10598
|
-
}),
|
|
10599
|
-
},
|
|
10600
|
-
);
|
|
10601
|
-
const payload = await parseJson(response);
|
|
10602
|
-
if (!response.ok || typeof payload.access_token !== 'string') {
|
|
10603
|
-
throw new CliError(
|
|
10604
|
-
typeof payload.error_description === 'string'
|
|
10605
|
-
? payload.error_description
|
|
10606
|
-
: 'Shared login has expired. Run `coze-dev deploy auth login` again.',
|
|
10607
|
-
'AUTH_REFRESH_FAILED',
|
|
10608
|
-
);
|
|
10609
|
-
}
|
|
10610
|
-
const token = payload ;
|
|
10611
|
-
const patch = {
|
|
10612
|
-
accessToken: token.access_token,
|
|
10613
|
-
refreshToken: token.refresh_token || config.refreshToken,
|
|
10614
|
-
tokenExpiresAt: resolveExpiry(token.expires_in),
|
|
10615
|
-
};
|
|
10616
|
-
Object.assign(config, patch);
|
|
10617
|
-
await saveSharedConfig(patch, options);
|
|
10618
|
-
return token.access_token;
|
|
10619
|
-
};
|
|
10620
|
-
|
|
10621
|
-
const saveOAuthToken = async (
|
|
10622
|
-
config,
|
|
10623
|
-
options,
|
|
10624
|
-
token,
|
|
10625
|
-
) => {
|
|
10626
|
-
const patch = {
|
|
10627
|
-
accessToken: token.access_token,
|
|
10628
|
-
refreshToken: token.refresh_token,
|
|
10629
|
-
tokenExpiresAt: resolveExpiry(token.expires_in),
|
|
10630
|
-
organizationId: undefined,
|
|
10631
|
-
enterpriseId: undefined,
|
|
10632
|
-
spaceId: undefined,
|
|
10633
|
-
projectId: undefined,
|
|
10634
|
-
};
|
|
10635
|
-
Object.assign(config, patch);
|
|
10636
|
-
await saveSharedConfig(patch, options);
|
|
10637
|
-
};
|
|
10638
|
-
|
|
10639
|
-
const logout = async (
|
|
10640
|
-
config,
|
|
10641
|
-
options,
|
|
10642
|
-
) => {
|
|
10643
|
-
Object.assign(config, clearAuthPatch);
|
|
10644
|
-
await saveSharedConfig(clearAuthPatch, options);
|
|
10645
|
-
};
|
|
10646
|
-
|
|
10647
|
-
const getAuthStatus = async (
|
|
10648
|
-
config,
|
|
10649
|
-
options,
|
|
10650
|
-
) => {
|
|
10651
|
-
if (!config.accessToken) {
|
|
10652
|
-
return { logged_in: false };
|
|
10653
|
-
}
|
|
10654
|
-
const user = await getCurrentUser(config, options);
|
|
10655
|
-
return {
|
|
10656
|
-
logged_in: true,
|
|
10657
|
-
user,
|
|
10658
|
-
token_expires_at: config.tokenExpiresAt
|
|
10659
|
-
? new Date(config.tokenExpiresAt).toISOString()
|
|
10660
|
-
: 'Never (PAT)',
|
|
10661
|
-
};
|
|
10662
|
-
};
|
|
10663
|
-
|
|
10664
|
-
const DEFAULT_POLL_INTERVAL_MS = 5000;
|
|
10665
|
-
const SLOW_DOWN_INCREMENT_MS = 5000;
|
|
10666
10342
|
|
|
10667
|
-
|
|
10668
|
-
|
|
10669
|
-
|
|
10670
|
-
|
|
10671
|
-
|
|
10672
|
-
|
|
10673
|
-
|
|
10674
|
-
|
|
10675
|
-
|
|
10676
|
-
const post = async (
|
|
10677
|
-
baseUrl,
|
|
10678
|
-
path,
|
|
10679
|
-
body,
|
|
10680
|
-
) => {
|
|
10681
|
-
const response = await fetch(new URL(path, baseUrl), {
|
|
10682
|
-
method: 'POST',
|
|
10683
|
-
headers: { 'content-type': 'application/json' },
|
|
10684
|
-
body: JSON.stringify(body),
|
|
10343
|
+
// 监听未处理的 Promise rejection
|
|
10344
|
+
process.on('unhandledRejection', async (reason) => {
|
|
10345
|
+
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
10346
|
+
reportError(error, {
|
|
10347
|
+
type: 'unhandledRejection',
|
|
10348
|
+
context: 'global',
|
|
10349
|
+
});
|
|
10350
|
+
await flushSlardar();
|
|
10351
|
+
process.exit(1);
|
|
10685
10352
|
});
|
|
10686
|
-
return { payload: await readPayload(response), response };
|
|
10687
|
-
};
|
|
10688
|
-
|
|
10689
|
-
const requireString = (
|
|
10690
|
-
payload,
|
|
10691
|
-
key,
|
|
10692
|
-
) => {
|
|
10693
|
-
const value = payload[key];
|
|
10694
|
-
if (typeof value !== 'string' || !value) {
|
|
10695
|
-
throw new CliError(`OAuth response returned no ${key}.`, 'INVALID_AUTH_RESPONSE');
|
|
10696
|
-
}
|
|
10697
|
-
return value;
|
|
10698
|
-
};
|
|
10699
|
-
|
|
10700
|
-
const requireNumber = (
|
|
10701
|
-
payload,
|
|
10702
|
-
key,
|
|
10703
|
-
) => {
|
|
10704
|
-
const value = Number(payload[key]);
|
|
10705
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
10706
|
-
throw new CliError(`OAuth response returned no ${key}.`, 'INVALID_AUTH_RESPONSE');
|
|
10707
|
-
}
|
|
10708
|
-
return value;
|
|
10709
|
-
};
|
|
10710
|
-
|
|
10711
|
-
const requestDeviceCode = async (config) => {
|
|
10712
|
-
const { payload, response } = await post(
|
|
10713
|
-
config.openApiBaseUrl,
|
|
10714
|
-
'/api/permission/oauth2/device/code',
|
|
10715
|
-
{ client_id: config.clientId },
|
|
10716
|
-
);
|
|
10717
|
-
if (!response.ok) {
|
|
10718
|
-
throw new CliError(
|
|
10719
|
-
typeof payload.error_description === 'string'
|
|
10720
|
-
? payload.error_description
|
|
10721
|
-
: 'Unable to start OAuth login.',
|
|
10722
|
-
'AUTH_LOGIN_FAILED',
|
|
10723
|
-
{ status: response.status },
|
|
10724
|
-
);
|
|
10725
|
-
}
|
|
10726
|
-
return {
|
|
10727
|
-
device_code: requireString(payload, 'device_code'),
|
|
10728
|
-
user_code: requireString(payload, 'user_code'),
|
|
10729
|
-
verification_uri: requireString(payload, 'verification_uri'),
|
|
10730
|
-
expires_in: requireNumber(payload, 'expires_in'),
|
|
10731
|
-
interval:
|
|
10732
|
-
typeof payload.interval === 'number' && payload.interval > 0
|
|
10733
|
-
? payload.interval
|
|
10734
|
-
: undefined,
|
|
10735
|
-
};
|
|
10736
|
-
};
|
|
10737
|
-
|
|
10738
|
-
const buildVerificationUrl = (deviceCode) => {
|
|
10739
|
-
const url = new URL(deviceCode.verification_uri);
|
|
10740
|
-
url.searchParams.set('user_code', deviceCode.user_code);
|
|
10741
|
-
return url.toString();
|
|
10742
|
-
};
|
|
10743
|
-
|
|
10744
|
-
const openBrowser = (url) => {
|
|
10745
|
-
const command =
|
|
10746
|
-
process.platform === 'darwin'
|
|
10747
|
-
? 'open'
|
|
10748
|
-
: process.platform === 'win32'
|
|
10749
|
-
? 'cmd'
|
|
10750
|
-
: 'xdg-open';
|
|
10751
|
-
const args = process.platform === 'win32' ? ['/c', 'start', '""', url] : [url];
|
|
10752
|
-
try {
|
|
10753
|
-
const child = node_child_process.spawn(command, args, { detached: true, stdio: 'ignore' });
|
|
10754
|
-
child.on('error', () => undefined);
|
|
10755
|
-
child.unref();
|
|
10756
|
-
} catch (error) {
|
|
10757
|
-
}
|
|
10758
|
-
};
|
|
10759
|
-
|
|
10760
|
-
const sleep = async (milliseconds) =>
|
|
10761
|
-
new Promise(resolve => setTimeout(resolve, milliseconds));
|
|
10762
|
-
|
|
10763
|
-
const pollToken = async (
|
|
10764
|
-
config,
|
|
10765
|
-
deviceCode,
|
|
10766
|
-
) => {
|
|
10767
|
-
const expiresAt = Date.now() + deviceCode.expires_in * 1000;
|
|
10768
|
-
let interval = (deviceCode.interval || DEFAULT_POLL_INTERVAL_MS / 1000) * 1000;
|
|
10769
|
-
while (Date.now() < expiresAt) {
|
|
10770
|
-
const { payload, response } = await post(
|
|
10771
|
-
config.openApiBaseUrl,
|
|
10772
|
-
'/api/permission/oauth2/token',
|
|
10773
|
-
{
|
|
10774
|
-
grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
|
|
10775
|
-
client_id: config.clientId,
|
|
10776
|
-
device_code: deviceCode.device_code,
|
|
10777
|
-
},
|
|
10778
|
-
);
|
|
10779
|
-
if (response.ok) {
|
|
10780
|
-
return {
|
|
10781
|
-
access_token: requireString(payload, 'access_token'),
|
|
10782
|
-
refresh_token: requireString(payload, 'refresh_token'),
|
|
10783
|
-
expires_in: requireNumber(payload, 'expires_in'),
|
|
10784
|
-
};
|
|
10785
|
-
}
|
|
10786
|
-
if (payload.error === 'authorization_pending') {
|
|
10787
|
-
await sleep(interval);
|
|
10788
|
-
continue;
|
|
10789
|
-
}
|
|
10790
|
-
if (payload.error === 'slow_down') {
|
|
10791
|
-
interval += SLOW_DOWN_INCREMENT_MS;
|
|
10792
|
-
await sleep(interval);
|
|
10793
|
-
continue;
|
|
10794
|
-
}
|
|
10795
|
-
throw new CliError(
|
|
10796
|
-
typeof payload.error_description === 'string'
|
|
10797
|
-
? payload.error_description
|
|
10798
|
-
: 'OAuth authorization failed.',
|
|
10799
|
-
'AUTH_LOGIN_FAILED',
|
|
10800
|
-
{ oauth_error: payload.error, status: response.status },
|
|
10801
|
-
);
|
|
10802
|
-
}
|
|
10803
|
-
throw new CliError('OAuth authorization expired. Please try again.', 'AUTH_LOGIN_EXPIRED');
|
|
10804
|
-
};
|
|
10805
|
-
|
|
10806
|
-
const loginWithOAuth = async (
|
|
10807
|
-
config,
|
|
10808
|
-
options,
|
|
10809
|
-
callbacks,
|
|
10810
|
-
) => {
|
|
10811
|
-
const deviceCode = await requestDeviceCode(config);
|
|
10812
|
-
const verificationUrl = buildVerificationUrl(deviceCode);
|
|
10813
|
-
callbacks.onVerification(verificationUrl);
|
|
10814
|
-
openBrowser(verificationUrl);
|
|
10815
|
-
await saveOAuthToken(config, options, await pollToken(config, deviceCode));
|
|
10816
|
-
};
|
|
10817
|
-
|
|
10818
|
-
function _optionalChain$a(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
10353
|
|
|
10354
|
+
const program = new commander.Command();
|
|
10822
10355
|
|
|
10356
|
+
program
|
|
10357
|
+
.name('coze-dev')
|
|
10358
|
+
.description(
|
|
10359
|
+
'Coze Coding CLI - Project template engine for frontend stacks',
|
|
10360
|
+
)
|
|
10361
|
+
.version(packageJson.version);
|
|
10823
10362
|
|
|
10363
|
+
commands.forEach(initCmd => initCmd(program));
|
|
10824
10364
|
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
|
|
10834
|
-
|
|
10835
|
-
|
|
10836
|
-
|
|
10837
|
-
const API_PREFIX = '/api/coding/deployment/v2';
|
|
10838
|
-
const CREATE_PROJECT_PATH = '/api/ideserver_api/project/create_vibe_project';
|
|
10839
|
-
const LIST_SPACES_PATH = '/api/playground_api/space/list';
|
|
10840
|
-
const ENCRYPT_PROJECT_SECRET_PATH =
|
|
10841
|
-
'/api/permission_api/project_secret/encrypt_project_secret';
|
|
10842
|
-
const MAX_MESSAGE_LENGTH = 512;
|
|
10843
|
-
|
|
10844
|
-
const isRecord = (value) =>
|
|
10845
|
-
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
10846
|
-
|
|
10847
|
-
|
|
10848
|
-
|
|
10849
|
-
|
|
10850
|
-
|
|
10851
|
-
|
|
10852
|
-
|
|
10853
|
-
const parseResponse = async (response) => {
|
|
10854
|
-
const text = await response.text();
|
|
10855
|
-
if (!text) {
|
|
10856
|
-
return { payload: {}, text, validJson: true };
|
|
10857
|
-
}
|
|
10858
|
-
const invalid = Symbol('invalid-json');
|
|
10859
|
-
const parsed = safeJsonParse(text, invalid);
|
|
10860
|
-
return parsed === invalid
|
|
10861
|
-
? { payload: undefined, text, validJson: false }
|
|
10862
|
-
: { payload: parsed, text, validJson: true };
|
|
10863
|
-
};
|
|
10864
|
-
|
|
10865
|
-
|
|
10866
|
-
|
|
10867
|
-
|
|
10868
|
-
|
|
10869
|
-
|
|
10870
|
-
|
|
10871
|
-
|
|
10872
|
-
|
|
10873
|
-
const responseExcerpt = (text) => {
|
|
10874
|
-
const compact = text.replace(/\s+/gu, ' ').trim();
|
|
10875
|
-
return compact ? compact.slice(0, MAX_MESSAGE_LENGTH) : undefined;
|
|
10876
|
-
};
|
|
10877
|
-
|
|
10878
|
-
const unwrap = (
|
|
10879
|
-
payload,
|
|
10880
|
-
expectedKey,
|
|
10881
|
-
responseMetadata,
|
|
10882
|
-
) => {
|
|
10883
|
-
const root = isRecord(payload) ? payload : undefined;
|
|
10884
|
-
const first = isRecord(_optionalChain$a([root, 'optionalAccess', _ => _.data])) ? root.data : undefined;
|
|
10885
|
-
const second = isRecord(_optionalChain$a([first, 'optionalAccess', _2 => _2.data])) ? first.data : undefined;
|
|
10886
|
-
const envelope = [root, first].find(candidate => candidate && 'code' in candidate);
|
|
10887
|
-
if (_optionalChain$a([envelope, 'optionalAccess', _3 => _3.code]) !== undefined && Number(envelope.code) !== 0) {
|
|
10888
|
-
throw new CliError(
|
|
10889
|
-
typeof envelope.msg === 'string'
|
|
10890
|
-
? envelope.msg.slice(0, MAX_MESSAGE_LENGTH)
|
|
10891
|
-
: 'The deployment request was rejected.',
|
|
10892
|
-
'API_REJECTED',
|
|
10893
|
-
{ business_code: envelope.code, ...responseMetadata },
|
|
10894
|
-
);
|
|
10895
|
-
}
|
|
10896
|
-
if (!expectedKey) {
|
|
10897
|
-
return (second || first || root || {}) ;
|
|
10898
|
-
}
|
|
10899
|
-
const matched = [second, first, root].find(
|
|
10900
|
-
candidate => candidate && expectedKey in candidate,
|
|
10901
|
-
);
|
|
10902
|
-
if (!matched) {
|
|
10903
|
-
throw new CliError(
|
|
10904
|
-
`Deployment API returned no ${expectedKey}.`,
|
|
10905
|
-
'INVALID_RESPONSE',
|
|
10906
|
-
);
|
|
10907
|
-
}
|
|
10908
|
-
return matched ;
|
|
10909
|
-
};
|
|
10910
|
-
|
|
10911
|
-
class DeployApiClient {
|
|
10912
|
-
constructor(
|
|
10913
|
-
config,
|
|
10914
|
-
globalOptions,
|
|
10915
|
-
) {this.config = config;this.globalOptions = globalOptions;}
|
|
10916
|
-
|
|
10917
|
-
debug(message) {
|
|
10918
|
-
if (this.globalOptions.debug) {
|
|
10919
|
-
process.stderr.write(`[debug] [api] ${message}\n`);
|
|
10920
|
-
}
|
|
10921
|
-
}
|
|
10922
|
-
|
|
10923
|
-
async post(
|
|
10924
|
-
path,
|
|
10925
|
-
body,
|
|
10926
|
-
expectedKey,
|
|
10927
|
-
useApiPrefix = true,
|
|
10928
|
-
) {
|
|
10929
|
-
const token = await getAccessToken(this.config, this.globalOptions);
|
|
10930
|
-
const headers = {
|
|
10931
|
-
authorization: `Bearer ${token}`,
|
|
10932
|
-
'content-type': 'application/json',
|
|
10933
|
-
'agw-js-conv': 'str',
|
|
10934
|
-
'x-request-from-coze-cli': '1',
|
|
10935
|
-
};
|
|
10936
|
-
if (this.config.organizationId) {
|
|
10937
|
-
headers['x-coze-account'] = this.config.organizationId;
|
|
10938
|
-
}
|
|
10939
|
-
const lane = _optionalChain$a([this, 'access', _4 => _4.globalOptions, 'access', _5 => _5.lane, 'optionalAccess', _6 => _6.trim, 'call', _7 => _7()]) || _optionalChain$a([this, 'access', _8 => _8.config, 'access', _9 => _9.xTTEnv, 'optionalAccess', _10 => _10.trim, 'call', _11 => _11()]);
|
|
10940
|
-
if (lane) {
|
|
10941
|
-
headers['x-use-ppe'] = '1';
|
|
10942
|
-
headers['x-tt-env'] = lane;
|
|
10943
|
-
}
|
|
10944
|
-
const requestUrl = new URL(
|
|
10945
|
-
`${useApiPrefix ? API_PREFIX : ''}${path}`,
|
|
10946
|
-
this.config.apiBaseUrl,
|
|
10947
|
-
);
|
|
10948
|
-
this.debug(
|
|
10949
|
-
`POST ${requestUrl.toString()}${lane ? ` lane=${lane}` : ''}`,
|
|
10950
|
-
);
|
|
10951
|
-
const response = await fetch(
|
|
10952
|
-
requestUrl,
|
|
10953
|
-
{ method: 'POST', headers, body: JSON.stringify(body) },
|
|
10954
|
-
);
|
|
10955
|
-
const responseMetadata = {
|
|
10956
|
-
status: response.status,
|
|
10957
|
-
status_text: response.statusText,
|
|
10958
|
-
log_id: response.headers.get('x-tt-logid') || undefined,
|
|
10959
|
-
request_path: requestUrl.pathname,
|
|
10960
|
-
content_type: response.headers.get('content-type') || undefined,
|
|
10961
|
-
};
|
|
10962
|
-
this.debug(
|
|
10963
|
-
`${response.status} ${response.statusText} ${requestUrl.pathname}` +
|
|
10964
|
-
`${responseMetadata.log_id ? ` log_id=${responseMetadata.log_id}` : ' log_id=unavailable'}`,
|
|
10965
|
-
);
|
|
10966
|
-
const { payload, text, validJson } = await parseResponse(response);
|
|
10967
|
-
if (!response.ok) {
|
|
10968
|
-
const root = isRecord(payload) ? payload : undefined;
|
|
10969
|
-
throw new CliError(
|
|
10970
|
-
typeof _optionalChain$a([root, 'optionalAccess', _12 => _12.msg]) === 'string'
|
|
10971
|
-
? root.msg.slice(0, MAX_MESSAGE_LENGTH)
|
|
10972
|
-
: `Deployment API failed: ${response.status} ${response.statusText}` +
|
|
10973
|
-
`${validJson ? '' : '; response was not JSON'}`,
|
|
10974
|
-
response.status === 401 ? 'AUTH_REQUIRED' : 'HTTP_ERROR',
|
|
10975
|
-
{
|
|
10976
|
-
...responseMetadata,
|
|
10977
|
-
response_excerpt: responseExcerpt(text),
|
|
10978
|
-
},
|
|
10979
|
-
);
|
|
10980
|
-
}
|
|
10981
|
-
if (!validJson) {
|
|
10982
|
-
throw new CliError(
|
|
10983
|
-
`Deployment API returned invalid JSON (${response.status}).`,
|
|
10984
|
-
'INVALID_RESPONSE',
|
|
10985
|
-
{
|
|
10986
|
-
...responseMetadata,
|
|
10987
|
-
response_excerpt: responseExcerpt(text),
|
|
10988
|
-
},
|
|
10989
|
-
);
|
|
10990
|
-
}
|
|
10991
|
-
return unwrap(payload, expectedKey, responseMetadata);
|
|
10992
|
-
}
|
|
10993
|
-
|
|
10994
|
-
createDeploymentProject(body) {
|
|
10995
|
-
return this.post(
|
|
10996
|
-
CREATE_PROJECT_PATH,
|
|
10997
|
-
body,
|
|
10998
|
-
'project_id',
|
|
10999
|
-
false,
|
|
11000
|
-
);
|
|
11001
|
-
}
|
|
11002
|
-
|
|
11003
|
-
listSpaces(body
|
|
11004
|
-
|
|
11005
|
-
|
|
11006
|
-
|
|
11007
|
-
|
|
11008
|
-
) {
|
|
11009
|
-
return this.post(
|
|
11010
|
-
LIST_SPACES_PATH,
|
|
11011
|
-
body,
|
|
11012
|
-
'bot_space_list',
|
|
11013
|
-
false,
|
|
11014
|
-
);
|
|
11015
|
-
}
|
|
11016
|
-
|
|
11017
|
-
encryptProjectSecret(projectId, secrets) {
|
|
11018
|
-
return this.post(
|
|
11019
|
-
ENCRYPT_PROJECT_SECRET_PATH,
|
|
11020
|
-
{
|
|
11021
|
-
project_id: projectId,
|
|
11022
|
-
encrypt_secrets: {
|
|
11023
|
-
secrets,
|
|
11024
|
-
cred_providers: [],
|
|
11025
|
-
},
|
|
11026
|
-
},
|
|
11027
|
-
'sealed_secrets',
|
|
11028
|
-
false,
|
|
11029
|
-
);
|
|
11030
|
-
}
|
|
11031
|
-
|
|
11032
|
-
// 列当前登录用户名下的 Application,跨 Project。服务端从登录态取 user_id,
|
|
11033
|
-
// 请求体里只有分页参数(deploy_app/list 已去掉 project_id / user_id 两个寻址入参)。
|
|
11034
|
-
listApplications(body) {
|
|
11035
|
-
return this.post(
|
|
11036
|
-
'/deploy_app/list', body, 'items',
|
|
11037
|
-
);
|
|
11038
|
-
}
|
|
11039
|
-
|
|
11040
|
-
getApplication(appId) {
|
|
11041
|
-
return this.post('/deploy_app/get', { app_id: appId }, 'app_id');
|
|
11042
|
-
}
|
|
11043
|
-
|
|
11044
|
-
updateApplication(body) {
|
|
11045
|
-
return this.post('/deploy_app/update', body, 'app_id');
|
|
11046
|
-
}
|
|
11047
|
-
|
|
11048
|
-
// 删除 Application:服务端只接受 **Stopped** 状态,其余状态会带上当前状态报错(先 stop 再 delete)。
|
|
11049
|
-
// 已删除的再删一次是幂等成功。
|
|
11050
|
-
deleteApplication(appId) {
|
|
11051
|
-
return this.post('/deploy_app/delete', { app_id: appId });
|
|
11052
|
-
}
|
|
11053
|
-
|
|
11054
|
-
getDeployConfig(body
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
|
|
11058
|
-
|
|
11059
|
-
|
|
11060
|
-
) {
|
|
11061
|
-
return this.post('/deploy_config/get', body, 'deploy_config');
|
|
11062
|
-
}
|
|
11063
|
-
|
|
11064
|
-
createDeployHistory(body) {
|
|
11065
|
-
return this.post('/deploy_history/create', body, 'app_id');
|
|
11066
|
-
}
|
|
11067
|
-
|
|
11068
|
-
preDeployUpload(body
|
|
11069
|
-
|
|
11070
|
-
|
|
11071
|
-
) {
|
|
11072
|
-
return this.post('/deploy_history/pre_upload', body, 'upload_url');
|
|
11073
|
-
}
|
|
11074
|
-
|
|
11075
|
-
getDeployHistory(body) {
|
|
11076
|
-
return this.post('/deploy_history/get', body, 'deploy_history_id');
|
|
11077
|
-
}
|
|
11078
|
-
|
|
11079
|
-
listDeployHistory(body) {
|
|
11080
|
-
return this.post
|
|
11081
|
-
|
|
11082
|
-
|
|
11083
|
-
|
|
11084
|
-
('/deploy_history/list', body, 'deploy_history_list');
|
|
11085
|
-
}
|
|
11086
|
-
|
|
11087
|
-
getOnlineDeployHistory(appId) {
|
|
11088
|
-
return this.post(
|
|
11089
|
-
'/deploy_history/get_online', { app_id: appId }, 'deploy_history_list',
|
|
11090
|
-
);
|
|
11091
|
-
}
|
|
11092
|
-
|
|
11093
|
-
getOnlineEnvironment(appId) {
|
|
11094
|
-
return this.post(
|
|
11095
|
-
'/environment/get_online', { app_id: appId }, 'app_id',
|
|
11096
|
-
);
|
|
11097
|
-
}
|
|
11098
|
-
|
|
11099
|
-
checkRollbackDatabase(body) {
|
|
11100
|
-
return this.post(
|
|
11101
|
-
'/deploy_history/check_rollback_database', body, 'is_rollback_possible',
|
|
11102
|
-
);
|
|
11103
|
-
}
|
|
11104
|
-
|
|
11105
|
-
cancelDeployHistory(body) {
|
|
11106
|
-
return this.post('/deploy_history/cancel', body);
|
|
11107
|
-
}
|
|
11108
|
-
|
|
11109
|
-
rollbackDeployHistory(body
|
|
11110
|
-
|
|
11111
|
-
|
|
11112
|
-
|
|
11113
|
-
) {
|
|
11114
|
-
return this.post(
|
|
11115
|
-
'/deploy_history/rollback', body, 'new_deploy_history_id',
|
|
11116
|
-
);
|
|
11117
|
-
}
|
|
11118
|
-
|
|
11119
|
-
stopApplication(appId) {
|
|
11120
|
-
return this.post('/application/stop', { app_id: appId });
|
|
11121
|
-
}
|
|
11122
|
-
|
|
11123
|
-
resumeApplication(appId) {
|
|
11124
|
-
return this.post('/application/resume', { app_id: appId });
|
|
11125
|
-
}
|
|
11126
|
-
|
|
11127
|
-
// 暂停是可逆的:只把线上 Unit 从 Ready 改成 Paused,函数留着,可被 resume 推回 Ready。
|
|
11128
|
-
// stop 会连函数一起删、落到 Stopped,只能靠重新部署恢复 —— resume 配对的是 pause,不是 stop。
|
|
11129
|
-
pauseApplication(appId) {
|
|
11130
|
-
return this.post('/application/pause', { app_id: appId });
|
|
11131
|
-
}
|
|
11132
|
-
|
|
11133
|
-
// PV / UV。入参是 app_id,但服务端反查 project_id 后按 **Project** 聚合 —— 埋点链路只有
|
|
11134
|
-
// project 维度,同一 Project 下多个 Application 拿到的是同一份数据。
|
|
11135
|
-
getUserAnalyticsMetrics(body) {
|
|
11136
|
-
return this.post(
|
|
11137
|
-
'/metrics/user_analytics/get', body, 'charts',
|
|
11138
|
-
);
|
|
11139
|
-
}
|
|
11140
|
-
|
|
11141
|
-
getBuildLog(body) {
|
|
11142
|
-
return this.post('/deploy_history/log', body, 'log');
|
|
11143
|
-
}
|
|
11144
|
-
|
|
11145
|
-
searchRuntimeLog(body) {
|
|
11146
|
-
return this.post(
|
|
11147
|
-
'/runtime_log/search', body, 'logs',
|
|
11148
|
-
);
|
|
11149
|
-
}
|
|
11150
|
-
|
|
11151
|
-
getRuntimeLogCount(appId) {
|
|
11152
|
-
return this.post(
|
|
11153
|
-
'/runtime_log/count', { app_id: appId }, 'limit',
|
|
11154
|
-
);
|
|
11155
|
-
}
|
|
11156
|
-
|
|
11157
|
-
getDeployCount(appId) {
|
|
11158
|
-
return this.post(
|
|
11159
|
-
'/deploy_history/get_count', { app_id: appId }, 'success_count',
|
|
11160
|
-
);
|
|
11161
|
-
}
|
|
11162
|
-
|
|
11163
|
-
getApplicationMetrics(body) {
|
|
11164
|
-
return this.post(
|
|
11165
|
-
'/metrics/get', body, 'charts',
|
|
11166
|
-
);
|
|
11167
|
-
}
|
|
11168
|
-
|
|
11169
|
-
getHostedUsageMonthly(body) {
|
|
11170
|
-
return this.post(
|
|
11171
|
-
'/hosted_usage/monthly', body, 'summary',
|
|
11172
|
-
);
|
|
11173
|
-
}
|
|
11174
|
-
|
|
11175
|
-
authorizeMiniProgram(body
|
|
11176
|
-
|
|
11177
|
-
|
|
11178
|
-
|
|
11179
|
-
|
|
11180
|
-
|
|
11181
|
-
|
|
11182
|
-
) {
|
|
11183
|
-
return this.post
|
|
11184
|
-
|
|
11185
|
-
|
|
11186
|
-
|
|
11187
|
-
('/mini_program/auth', body);
|
|
11188
|
-
}
|
|
11189
|
-
|
|
11190
|
-
createMiniProgramPreview(body
|
|
11191
|
-
|
|
11192
|
-
|
|
11193
|
-
|
|
11194
|
-
|
|
11195
|
-
) {
|
|
11196
|
-
return this.post
|
|
11197
|
-
|
|
11198
|
-
|
|
11199
|
-
|
|
11200
|
-
|
|
11201
|
-
('/mini_program/preview', body);
|
|
11202
|
-
}
|
|
11203
|
-
|
|
11204
|
-
listDomains(appId, unitType) {
|
|
11205
|
-
return this.post(
|
|
11206
|
-
'/domain/list', {
|
|
11207
|
-
app_id: appId,
|
|
11208
|
-
...(unitType === undefined ? {} : { unit_type: unitType }),
|
|
11209
|
-
}, 'items',
|
|
11210
|
-
);
|
|
11211
|
-
}
|
|
11212
|
-
|
|
11213
|
-
createDomain(body) {
|
|
11214
|
-
return this.post('/domain/create', body, 'domain');
|
|
11215
|
-
}
|
|
11216
|
-
|
|
11217
|
-
// 改的是系统分配的 <prefix>.coze.site 里的 prefix,不是 createDomain 加进来的自定义域名 ——
|
|
11218
|
-
// 那类域名服务端只提供 create/delete,域名串本身不可改。
|
|
11219
|
-
updateDefaultDomainPrefix(body) {
|
|
11220
|
-
return this.post
|
|
11221
|
-
|
|
11222
|
-
|
|
11223
|
-
|
|
11224
|
-
|
|
11225
|
-
('/domain/update_default_prefix', body, 'new_domain_host_canonical');
|
|
11226
|
-
}
|
|
11227
|
-
|
|
11228
|
-
getMiniProgramAuthStatus(body) {
|
|
11229
|
-
return this.post
|
|
11230
|
-
|
|
11231
|
-
|
|
11232
|
-
|
|
11233
|
-
|
|
11234
|
-
('/api/coding/deployment/auth/status', body, 'is_authorized', false);
|
|
11235
|
-
}
|
|
11236
|
-
|
|
11237
|
-
bindMiniProgramAuth(body
|
|
11238
|
-
|
|
11239
|
-
|
|
11240
|
-
|
|
11241
|
-
|
|
11242
|
-
|
|
11243
|
-
) {
|
|
11244
|
-
return this.post
|
|
11245
|
-
|
|
11246
|
-
|
|
11247
|
-
|
|
11248
|
-
|
|
11249
|
-
|
|
11250
|
-
|
|
11251
|
-
('/api/coding/deployment/auth/bind', body, 'bind_status', false);
|
|
11252
|
-
}
|
|
11253
|
-
|
|
11254
|
-
submitMiniProgramAuthCode(body
|
|
11255
|
-
|
|
11256
|
-
|
|
11257
|
-
|
|
11258
|
-
|
|
11259
|
-
|
|
11260
|
-
) {
|
|
11261
|
-
return this.post(
|
|
11262
|
-
'/api/coding/deployment/auth/submit_code', body, undefined, false,
|
|
11263
|
-
);
|
|
11264
|
-
}
|
|
11265
|
-
|
|
11266
|
-
unbindMiniProgramAuth(body) {
|
|
11267
|
-
return this.post(
|
|
11268
|
-
'/api/coding/deployment/auth/unbind', body, undefined, false,
|
|
11269
|
-
);
|
|
11270
|
-
}
|
|
11271
|
-
}
|
|
11272
|
-
|
|
11273
|
-
const textValue = (value) => {
|
|
11274
|
-
if (typeof value === 'string') {
|
|
11275
|
-
return value;
|
|
11276
|
-
}
|
|
11277
|
-
return JSON.stringify(value, null, 2);
|
|
11278
|
-
};
|
|
11279
|
-
|
|
11280
|
-
class Output {
|
|
11281
|
-
constructor(
|
|
11282
|
-
format,
|
|
11283
|
-
debugEnabled = false,
|
|
11284
|
-
) {this.format = format;this.debugEnabled = debugEnabled;}
|
|
11285
|
-
|
|
11286
|
-
print(value) {
|
|
11287
|
-
process.stdout.write(
|
|
11288
|
-
this.format === 'json'
|
|
11289
|
-
? `${JSON.stringify(value, null, 2)}\n`
|
|
11290
|
-
: `${textValue(value)}\n`,
|
|
11291
|
-
);
|
|
11292
|
-
}
|
|
11293
|
-
|
|
11294
|
-
info(message) {
|
|
11295
|
-
if (this.format === 'text') {
|
|
11296
|
-
process.stderr.write(`${message}\n`);
|
|
11297
|
-
}
|
|
11298
|
-
}
|
|
11299
|
-
|
|
11300
|
-
notice(message) {
|
|
11301
|
-
process.stderr.write(`${message}\n`);
|
|
11302
|
-
}
|
|
11303
|
-
|
|
11304
|
-
warn(message) {
|
|
11305
|
-
process.stderr.write(`Warning: ${message}\n`);
|
|
11306
|
-
}
|
|
11307
|
-
|
|
11308
|
-
debug(message) {
|
|
11309
|
-
if (this.debugEnabled) {
|
|
11310
|
-
process.stderr.write(`[debug] ${message}\n`);
|
|
11311
|
-
}
|
|
11312
|
-
}
|
|
11313
|
-
}
|
|
11314
|
-
|
|
11315
|
-
const runtimes = new WeakMap();
|
|
11316
|
-
|
|
11317
|
-
const getRuntime = async (command) => {
|
|
11318
|
-
const deploy = findDeployCommand(command);
|
|
11319
|
-
let runtime = runtimes.get(deploy);
|
|
11320
|
-
if (!runtime) {
|
|
11321
|
-
runtime = (async () => {
|
|
11322
|
-
const options = deploy.opts();
|
|
11323
|
-
const config = await loadConfig(options);
|
|
11324
|
-
return {
|
|
11325
|
-
client: new DeployApiClient(config, options),
|
|
11326
|
-
config,
|
|
11327
|
-
cwd: process.cwd(),
|
|
11328
|
-
globalOptions: options,
|
|
11329
|
-
output: new Output(options.format || 'json', options.debug),
|
|
11330
|
-
};
|
|
11331
|
-
})();
|
|
11332
|
-
runtimes.set(deploy, runtime);
|
|
11333
|
-
}
|
|
11334
|
-
return runtime;
|
|
11335
|
-
};
|
|
11336
|
-
|
|
11337
|
-
const PRIVACY_POLICY_URL = 'https://docs.coze.cn/guides/privacy';
|
|
11338
|
-
const TERMS_OF_SERVICE_URL = 'https://docs.coze.cn/guides/terms-of-service';
|
|
11339
|
-
|
|
11340
|
-
const registerAuth = (program) => {
|
|
11341
|
-
const auth = program.command('auth').description('Manage deployment CLI authentication');
|
|
11342
|
-
|
|
11343
|
-
auth
|
|
11344
|
-
.command('login')
|
|
11345
|
-
.description('Login with Coze OAuth and save shared credentials')
|
|
11346
|
-
.action(async (_options, command) => {
|
|
11347
|
-
const runtime = await getRuntime(command);
|
|
11348
|
-
await loginWithOAuth(runtime.config, runtime.globalOptions, {
|
|
11349
|
-
onVerification: url => {
|
|
11350
|
-
runtime.output.notice(
|
|
11351
|
-
[
|
|
11352
|
-
'Open this URL to authorize coze-dev deploy:',
|
|
11353
|
-
url,
|
|
11354
|
-
`Privacy Policy: ${PRIVACY_POLICY_URL}`,
|
|
11355
|
-
`Terms of Service: ${TERMS_OF_SERVICE_URL}`,
|
|
11356
|
-
].join('\n'),
|
|
11357
|
-
);
|
|
11358
|
-
},
|
|
11359
|
-
});
|
|
11360
|
-
runtime.output.print({ success: true, logged_in: true, method: 'OAuth' });
|
|
11361
|
-
});
|
|
11362
|
-
|
|
11363
|
-
auth
|
|
11364
|
-
.command('status')
|
|
11365
|
-
.description('Check and refresh the current shared login')
|
|
11366
|
-
.action(async (_options, command) => {
|
|
11367
|
-
const runtime = await getRuntime(command);
|
|
11368
|
-
runtime.output.print(await getAuthStatus(runtime.config, runtime.globalOptions));
|
|
11369
|
-
});
|
|
11370
|
-
|
|
11371
|
-
auth
|
|
11372
|
-
.command('logout')
|
|
11373
|
-
.description('Clear shared credentials and account context')
|
|
11374
|
-
.action(async (_options, command) => {
|
|
11375
|
-
const runtime = await getRuntime(command);
|
|
11376
|
-
await logout(runtime.config, runtime.globalOptions);
|
|
11377
|
-
runtime.output.print({ success: true, logged_out: true });
|
|
11378
|
-
});
|
|
11379
|
-
};
|
|
11380
|
-
|
|
11381
|
-
const execFileAsync = node_util.promisify(node_child_process.execFile);
|
|
11382
|
-
|
|
11383
|
-
const registerContext = (program) => {
|
|
11384
|
-
const context = program.command('context').description('Show or update deployment context');
|
|
11385
|
-
context.command('show').action(async (_options, command) => {
|
|
11386
|
-
const runtime = await getRuntime(command);
|
|
11387
|
-
runtime.output.print({
|
|
11388
|
-
organization_id: runtime.config.organizationId,
|
|
11389
|
-
space_id: runtime.config.spaceId,
|
|
11390
|
-
project_id: runtime.config.projectId,
|
|
11391
|
-
lane: runtime.globalOptions.lane || runtime.config.xTTEnv,
|
|
11392
|
-
config_path: runtime.globalOptions.config || getSharedConfigPath(),
|
|
11393
|
-
});
|
|
11394
|
-
});
|
|
11395
|
-
context
|
|
11396
|
-
.command('use')
|
|
11397
|
-
.option('--space-id <spaceId>', 'Default Space ID')
|
|
11398
|
-
.option('--project-id <projectId>', 'Default Project ID')
|
|
11399
|
-
.action(async (options, command) => {
|
|
11400
|
-
const runtime = await getRuntime(command);
|
|
11401
|
-
await saveSharedConfig(
|
|
11402
|
-
{
|
|
11403
|
-
...(options.spaceId ? { spaceId: options.spaceId } : {}),
|
|
11404
|
-
...(options.projectId ? { projectId: options.projectId } : {}),
|
|
11405
|
-
},
|
|
11406
|
-
runtime.globalOptions,
|
|
11407
|
-
);
|
|
11408
|
-
runtime.output.print({
|
|
11409
|
-
space_id: options.spaceId || runtime.config.spaceId,
|
|
11410
|
-
project_id: options.projectId || runtime.config.projectId,
|
|
11411
|
-
});
|
|
11412
|
-
});
|
|
11413
|
-
};
|
|
11414
|
-
|
|
11415
|
-
const registerDoctor = (program) => {
|
|
11416
|
-
program
|
|
11417
|
-
.command('doctor')
|
|
11418
|
-
.description('Check deployment CLI prerequisites and shared login')
|
|
11419
|
-
.action(async (_options, command) => {
|
|
11420
|
-
const runtime = await getRuntime(command);
|
|
11421
|
-
let gitAvailable = true;
|
|
11422
|
-
try {
|
|
11423
|
-
await execFileAsync('git', ['--version']);
|
|
11424
|
-
} catch (e) {
|
|
11425
|
-
gitAvailable = false;
|
|
11426
|
-
}
|
|
11427
|
-
runtime.output.print({
|
|
11428
|
-
ok: gitAvailable && Boolean(runtime.config.accessToken),
|
|
11429
|
-
git: gitAvailable ? 'ok' : 'missing',
|
|
11430
|
-
login: runtime.config.accessToken ? 'reused' : 'missing',
|
|
11431
|
-
login_config: runtime.globalOptions.config || getSharedConfigPath(),
|
|
11432
|
-
project_id: runtime.config.projectId || 'not configured',
|
|
11433
|
-
});
|
|
11434
|
-
});
|
|
11435
|
-
};
|
|
11436
|
-
|
|
11437
|
-
function _optionalChain$9(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
11438
|
-
|
|
11439
|
-
|
|
11440
|
-
|
|
11441
|
-
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
|
|
11445
|
-
|
|
11446
|
-
|
|
11447
|
-
|
|
11448
|
-
|
|
11449
|
-
|
|
11450
|
-
|
|
11451
|
-
|
|
11452
|
-
|
|
11453
|
-
|
|
11454
|
-
|
|
11455
|
-
|
|
11456
|
-
|
|
11457
|
-
|
|
11458
|
-
|
|
11459
|
-
|
|
11460
|
-
|
|
11461
|
-
|
|
11462
|
-
|
|
11463
|
-
|
|
11464
|
-
|
|
11465
|
-
|
|
11466
|
-
|
|
11467
|
-
const getDeployParentOptions = (command) =>
|
|
11468
|
-
_optionalChain$9([command, 'access', _ => _.parent, 'optionalAccess', _2 => _2.opts, 'call', _3 => _3()]) || {};
|
|
11469
|
-
|
|
11470
|
-
const getDeployAppIdOption = (
|
|
11471
|
-
options,
|
|
11472
|
-
command,
|
|
11473
|
-
) => options.appId || getDeployParentOptions(command).appId;
|
|
11474
|
-
|
|
11475
|
-
const getCreateDeployConfig = (config) => ({
|
|
11476
|
-
deploy_config: {
|
|
11477
|
-
cpu: config.deploy_config.cpu,
|
|
11478
|
-
memory_mb: config.deploy_config.memory_mb,
|
|
11479
|
-
max_instance: config.deploy_config.max_instance,
|
|
11480
|
-
max_concurrency: config.deploy_config.max_concurrency,
|
|
11481
|
-
},
|
|
11482
|
-
service_type: config.deploy_config.service_type,
|
|
11483
|
-
...(config.deploy_config.computer_id
|
|
11484
|
-
? { computer_id: config.deploy_config.computer_id }
|
|
11485
|
-
: {}),
|
|
11486
|
-
});
|
|
11487
|
-
|
|
11488
|
-
const DEPLOY_STATUS = {
|
|
11489
|
-
pending: 1,
|
|
11490
|
-
running: 2,
|
|
11491
|
-
succeeded: 3,
|
|
11492
|
-
failed: 4,
|
|
11493
|
-
canceled: 5,
|
|
11494
|
-
interrupted: 6,
|
|
11495
|
-
preDeploy: 7,
|
|
11496
|
-
} ;
|
|
11497
|
-
|
|
11498
|
-
const STATUS_NAMES = {
|
|
11499
|
-
[DEPLOY_STATUS.pending]: 'Pending',
|
|
11500
|
-
[DEPLOY_STATUS.running]: 'Running',
|
|
11501
|
-
[DEPLOY_STATUS.succeeded]: 'Succeeded',
|
|
11502
|
-
[DEPLOY_STATUS.failed]: 'Failed',
|
|
11503
|
-
[DEPLOY_STATUS.canceled]: 'Canceled',
|
|
11504
|
-
[DEPLOY_STATUS.interrupted]: 'Interrupted',
|
|
11505
|
-
[DEPLOY_STATUS.preDeploy]: 'WaitingForUpload',
|
|
11506
|
-
};
|
|
11507
|
-
|
|
11508
|
-
const TERMINAL_STATUSES = new Set([
|
|
11509
|
-
DEPLOY_STATUS.succeeded,
|
|
11510
|
-
DEPLOY_STATUS.failed,
|
|
11511
|
-
DEPLOY_STATUS.canceled,
|
|
11512
|
-
DEPLOY_STATUS.interrupted,
|
|
11513
|
-
]);
|
|
11514
|
-
|
|
11515
|
-
const getDeployStatusText = (status) =>
|
|
11516
|
-
status ? STATUS_NAMES[status] || 'Unknown' : 'Unknown';
|
|
11517
|
-
|
|
11518
|
-
function _optionalChain$8(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
11519
|
-
|
|
11520
|
-
const formatDeployDetails = (history) =>
|
|
11521
|
-
(_optionalChain$8([history, 'optionalAccess', _ => _.deploy_detail]) || []).map(detail => ({
|
|
11522
|
-
target: detail.target,
|
|
11523
|
-
status: getDeployStatusText(detail.status),
|
|
11524
|
-
deploy_log_key: detail.deploy_log_key,
|
|
11525
|
-
deploy_log_url: detail.deploy_log_url,
|
|
11526
|
-
}));
|
|
11527
|
-
|
|
11528
|
-
const getDeployLogKeys = (history) =>
|
|
11529
|
-
[...new Set(
|
|
11530
|
-
(history.deploy_detail || [])
|
|
11531
|
-
.map(detail => _optionalChain$8([detail, 'access', _2 => _2.deploy_log_key, 'optionalAccess', _3 => _3.trim, 'call', _4 => _4()]))
|
|
11532
|
-
.filter((key) => Boolean(key)),
|
|
11533
|
-
)];
|
|
11534
|
-
|
|
11535
|
-
const normalizePositiveId = (value) => {
|
|
11536
|
-
const normalized = value === undefined ? '' : String(value).trim();
|
|
11537
|
-
return /^[1-9]\d*$/.test(normalized) ? normalized : undefined;
|
|
11538
|
-
};
|
|
11539
|
-
|
|
11540
|
-
const resolveDeployHistoryId = (
|
|
11541
|
-
deployHistoryId,
|
|
11542
|
-
previousDeployHistoryId,
|
|
11543
|
-
) =>
|
|
11544
|
-
normalizePositiveId(deployHistoryId) || normalizePositiveId(previousDeployHistoryId);
|
|
11545
|
-
|
|
11546
|
-
function _optionalChain$7(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
11547
|
-
|
|
11548
|
-
const SOURCE_SNAPSHOT_BYTES = 20;
|
|
11549
|
-
const PROJECT_METADATA_FILE_MODE = 0o644;
|
|
11550
|
-
|
|
11551
|
-
const isId = (value) =>
|
|
11552
|
-
typeof value === 'string' && /^\d+$/u.test(value);
|
|
11553
|
-
|
|
11554
|
-
|
|
11555
|
-
const resolveAppId = async (cwd, appId) => {
|
|
11556
|
-
const explicit = _optionalChain$7([appId, 'optionalAccess', _ => _.trim, 'call', _2 => _2()]);
|
|
11557
|
-
if (explicit) {
|
|
11558
|
-
return explicit;
|
|
11559
|
-
}
|
|
11560
|
-
try {
|
|
11561
|
-
return (await readProjectMetadata(node_path.resolve(cwd))).appId;
|
|
11562
|
-
} catch (error) {
|
|
11563
|
-
if ((error ).code === 'COZE_FILE_NOT_FOUND') {
|
|
11564
|
-
return undefined;
|
|
11565
|
-
}
|
|
11566
|
-
throw error;
|
|
11567
|
-
}
|
|
11568
|
-
};
|
|
11569
|
-
|
|
11570
|
-
const requireAppId = async (cwd, appId) => {
|
|
11571
|
-
const resolved = await resolveAppId(cwd, appId);
|
|
11572
|
-
if (!resolved) {
|
|
11573
|
-
throw new CliError(
|
|
11574
|
-
'Application ID is required. Pass --app-id or use a directory whose .coze [project] contains app_id.',
|
|
11575
|
-
'APP_ID_REQUIRED',
|
|
11576
|
-
);
|
|
11577
|
-
}
|
|
11578
|
-
return resolved;
|
|
11579
|
-
};
|
|
11580
|
-
|
|
11581
|
-
const resolveSourceSnapshot = (sourceRootInput) => {
|
|
11582
|
-
const sourceRoot = node_path.resolve(sourceRootInput);
|
|
11583
|
-
const commitHash = node_crypto.randomBytes(SOURCE_SNAPSHOT_BYTES).toString('hex');
|
|
11584
|
-
return { commitHash, sourceRoot };
|
|
11585
|
-
};
|
|
11586
|
-
|
|
11587
|
-
const readProjectMetadata = async (
|
|
11588
|
-
sourceRoot,
|
|
11589
|
-
) => {
|
|
11590
|
-
let cozeFileContent = '';
|
|
11591
|
-
try {
|
|
11592
|
-
cozeFileContent = await promises.readFile(node_path.join(sourceRoot, '.coze'), 'utf8');
|
|
11593
|
-
} catch (error) {
|
|
11594
|
-
if ((error ).code === 'ENOENT') {
|
|
11595
|
-
throw new CliError(
|
|
11596
|
-
`No .coze file found in ${sourceRoot}.`,
|
|
11597
|
-
'COZE_FILE_NOT_FOUND',
|
|
11598
|
-
);
|
|
11599
|
-
}
|
|
11600
|
-
throw error;
|
|
11601
|
-
}
|
|
11602
|
-
const projectSection = _optionalChain$7([cozeFileContent, 'access', _3 => _3.match, 'call', _4 => _4(
|
|
11603
|
-
/^\s*\[project\]\s*(?:#.*)?$([\s\S]*?)(?=^\s*\[[^\]]+\]\s*(?:#.*)?$|(?![\s\S]))/mu,
|
|
11604
|
-
), 'optionalAccess', _5 => _5[1]]);
|
|
11605
|
-
const readProjectString = (key) =>
|
|
11606
|
-
_optionalChain$7([projectSection
|
|
11607
|
-
, 'optionalAccess', _6 => _6.match, 'call', _7 => _7(new RegExp(`^\\s*${key}\\s*=\\s*["']([^"']+)["']`, 'mu')), 'optionalAccess', _8 => _8[1]
|
|
11608
|
-
, 'optionalAccess', _9 => _9.trim, 'call', _10 => _10()]);
|
|
11609
|
-
const name = readProjectString('name');
|
|
11610
|
-
const projectType = readProjectString('project_type');
|
|
11611
|
-
const projectId = readProjectString('project_id');
|
|
11612
|
-
const appId = readProjectString('app_id');
|
|
11613
|
-
const hasUnquotedId = (key) =>
|
|
11614
|
-
Boolean(_optionalChain$7([projectSection, 'optionalAccess', _11 => _11.match, 'call', _12 => _12(new RegExp(`^\\s*${key}\\s*=\\s*(?!["'])\\S+`, 'mu'))]));
|
|
11615
|
-
if (hasUnquotedId('project_id') || hasUnquotedId('app_id')) {
|
|
11616
|
-
throw new CliError(
|
|
11617
|
-
'.coze [project].project_id and app_id must be quoted decimal strings.',
|
|
11618
|
-
'INVALID_COZE_FILE',
|
|
11619
|
-
);
|
|
11620
|
-
}
|
|
11621
|
-
if (projectId && !isId(projectId)) {
|
|
11622
|
-
throw new CliError('.coze [project].project_id must be a quoted decimal string.', 'INVALID_COZE_FILE');
|
|
11623
|
-
}
|
|
11624
|
-
if (appId && !isId(appId)) {
|
|
11625
|
-
throw new CliError('.coze [project].app_id must be a quoted decimal string.', 'INVALID_COZE_FILE');
|
|
11626
|
-
}
|
|
11627
|
-
return { name, projectType, projectId, appId, cozeFileContent };
|
|
11628
|
-
};
|
|
11629
|
-
|
|
11630
|
-
const updateProjectValue = (content, key, value) => {
|
|
11631
|
-
const sectionMatch = /^\s*\[project\]\s*(?:#.*)?$/mu.exec(content);
|
|
11632
|
-
if (!sectionMatch || sectionMatch.index === undefined) {
|
|
11633
|
-
const prefix = `[project]\n${key} = ${JSON.stringify(value)}\n\n`;
|
|
11634
|
-
return `${prefix}${content}`;
|
|
11635
|
-
}
|
|
11636
|
-
const sectionStart = sectionMatch.index + sectionMatch[0].length;
|
|
11637
|
-
const following = content.slice(sectionStart);
|
|
11638
|
-
const nextSection = /^\s*\[[^\]]+\]\s*(?:#.*)?$/mu.exec(following);
|
|
11639
|
-
const sectionEnd = _optionalChain$7([nextSection, 'optionalAccess', _13 => _13.index]) === undefined
|
|
11640
|
-
? content.length
|
|
11641
|
-
: sectionStart + nextSection.index;
|
|
11642
|
-
const before = content.slice(0, sectionStart);
|
|
11643
|
-
let body = content.slice(sectionStart, sectionEnd);
|
|
11644
|
-
const keyPattern = new RegExp(`^(\\s*)${key}\\s*=.*$`, 'mu');
|
|
11645
|
-
if (keyPattern.test(body)) {
|
|
11646
|
-
body = body.replace(keyPattern, `$1${key} = ${JSON.stringify(value)}`);
|
|
11647
|
-
} else {
|
|
11648
|
-
const separator = body.startsWith('\n') || body.startsWith('\r\n') ? '' : '\n';
|
|
11649
|
-
body = `${separator}${body}`;
|
|
11650
|
-
const trailingNewline = body.endsWith('\n') ? '' : '\n';
|
|
11651
|
-
body = `${body}${trailingNewline}${key} = ${JSON.stringify(value)}\n`;
|
|
11652
|
-
}
|
|
11653
|
-
return `${before}${body}${content.slice(sectionEnd)}`;
|
|
11654
|
-
};
|
|
11655
|
-
|
|
11656
|
-
const writeProjectBinding = async (
|
|
11657
|
-
sourceRoot,
|
|
11658
|
-
binding,
|
|
11659
|
-
) => {
|
|
11660
|
-
const path = node_path.join(sourceRoot, '.coze');
|
|
11661
|
-
let content = await promises.readFile(path, 'utf8');
|
|
11662
|
-
if (binding.projectId) {
|
|
11663
|
-
content = updateProjectValue(content, 'project_id', binding.projectId);
|
|
11664
|
-
}
|
|
11665
|
-
if (binding.appId) {
|
|
11666
|
-
content = updateProjectValue(content, 'app_id', binding.appId);
|
|
11667
|
-
}
|
|
11668
|
-
const tempPath = node_path.join(node_path.dirname(path), `.coze-${node_crypto.randomUUID()}.tmp`);
|
|
11669
|
-
try {
|
|
11670
|
-
await promises.writeFile(tempPath, content, {
|
|
11671
|
-
encoding: 'utf8',
|
|
11672
|
-
mode: PROJECT_METADATA_FILE_MODE,
|
|
11673
|
-
});
|
|
11674
|
-
await promises.chmod(tempPath, PROJECT_METADATA_FILE_MODE);
|
|
11675
|
-
await promises.rename(tempPath, path);
|
|
11676
|
-
} finally {
|
|
11677
|
-
await promises.rm(tempPath, { force: true });
|
|
11678
|
-
}
|
|
11679
|
-
return readProjectMetadata(sourceRoot);
|
|
11680
|
-
};
|
|
11681
|
-
|
|
11682
|
-
const ensureProjectMetadata = async (
|
|
11683
|
-
sourceRoot,
|
|
11684
|
-
options,
|
|
11685
|
-
) => {
|
|
11686
|
-
try {
|
|
11687
|
-
return await readProjectMetadata(sourceRoot);
|
|
11688
|
-
} catch (error) {
|
|
11689
|
-
if ((error ).code !== 'COZE_FILE_NOT_FOUND' || !options.allowCreate) {
|
|
11690
|
-
throw error;
|
|
11691
|
-
}
|
|
11692
|
-
}
|
|
11693
|
-
const name = _optionalChain$7([options, 'access', _14 => _14.name, 'optionalAccess', _15 => _15.trim, 'call', _16 => _16()]) || 'Pages application';
|
|
11694
|
-
const projectType = _optionalChain$7([options, 'access', _17 => _17.projectType, 'optionalAccess', _18 => _18.trim, 'call', _19 => _19()]) || 'web';
|
|
11695
|
-
await promises.writeFile(
|
|
11696
|
-
node_path.join(sourceRoot, '.coze'),
|
|
11697
|
-
`[project]\nname = ${JSON.stringify(name)}\nproject_type = ${JSON.stringify(projectType)}\n`,
|
|
11698
|
-
{ encoding: 'utf8', mode: PROJECT_METADATA_FILE_MODE },
|
|
11699
|
-
);
|
|
11700
|
-
await promises.chmod(node_path.join(sourceRoot, '.coze'), PROJECT_METADATA_FILE_MODE);
|
|
11701
|
-
return readProjectMetadata(sourceRoot);
|
|
11702
|
-
};
|
|
11703
|
-
|
|
11704
|
-
function _optionalChain$6(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
11705
|
-
const isFile = async (path) => {
|
|
11706
|
-
try {
|
|
11707
|
-
return (await promises.stat(path)).isFile();
|
|
11708
|
-
} catch (error) {
|
|
11709
|
-
if ((error ).code === 'ENOENT') {
|
|
11710
|
-
return false;
|
|
11711
|
-
}
|
|
11712
|
-
throw error;
|
|
11713
|
-
}
|
|
11714
|
-
};
|
|
11715
|
-
|
|
11716
|
-
const validatePagesSource = async (
|
|
11717
|
-
sourceRoot,
|
|
11718
|
-
cozeFileContent,
|
|
11719
|
-
) => {
|
|
11720
|
-
if (await isFile(node_path.join(sourceRoot, 'index.html'))) {
|
|
11721
|
-
return;
|
|
11722
|
-
}
|
|
11723
|
-
|
|
11724
|
-
let config;
|
|
11725
|
-
try {
|
|
11726
|
-
config = TOML.parse(cozeFileContent);
|
|
11727
|
-
} catch (error) {
|
|
11728
|
-
throw new CliError(
|
|
11729
|
-
`Unable to parse .coze: ${error instanceof Error ? error.message : String(error)}`,
|
|
11730
|
-
'INVALID_COZE_FILE',
|
|
11731
|
-
);
|
|
11732
|
-
}
|
|
11733
|
-
const project = config.project ;
|
|
11734
|
-
if (typeof _optionalChain$6([project, 'optionalAccess', _ => _.template]) !== 'string' || project.template.trim().toLowerCase() !== 'nextjs') {
|
|
11735
|
-
throw new CliError(
|
|
11736
|
-
'Pages source contains no index.html; .coze project.template must be "nextjs".',
|
|
11737
|
-
'PAGES_BUILD_CONFIG_REQUIRED',
|
|
11738
|
-
);
|
|
11739
|
-
}
|
|
11740
|
-
const deploy = config.deploy ;
|
|
11741
|
-
const build = _optionalChain$6([deploy, 'optionalAccess', _2 => _2.build]);
|
|
11742
|
-
if (!Array.isArray(build) || build.length === 0 || !build.every(part => typeof part === 'string' && part.length > 0)) {
|
|
11743
|
-
throw new CliError(
|
|
11744
|
-
'Pages source contains no index.html; .coze deploy.build must be a non-empty string array.',
|
|
11745
|
-
'PAGES_BUILD_CONFIG_REQUIRED',
|
|
11746
|
-
);
|
|
11747
|
-
}
|
|
11748
|
-
};
|
|
11749
|
-
|
|
11750
|
-
const readDeployLocalContext = async (
|
|
11751
|
-
sourceRoot,
|
|
11752
|
-
requestedApplicationType,
|
|
11753
|
-
appId,
|
|
11754
|
-
client,
|
|
11755
|
-
) => {
|
|
11756
|
-
const sourceSnapshot = resolveSourceSnapshot(sourceRoot);
|
|
11757
|
-
let applicationTypeHint = requestedApplicationType;
|
|
11758
|
-
let effectiveAppId = appId;
|
|
11759
|
-
if (!effectiveAppId) {
|
|
11760
|
-
try {
|
|
11761
|
-
effectiveAppId = (await ensureProjectMetadata(sourceRoot, { allowCreate: false })).appId;
|
|
11762
|
-
} catch (error) {
|
|
11763
|
-
if ((error ).code !== 'COZE_FILE_NOT_FOUND') {
|
|
11764
|
-
throw error;
|
|
11765
|
-
}
|
|
11766
|
-
}
|
|
11767
|
-
}
|
|
11768
|
-
if (!applicationTypeHint && effectiveAppId) {
|
|
11769
|
-
applicationTypeHint = (await client.getApplication(effectiveAppId)).application_type;
|
|
11770
|
-
}
|
|
11771
|
-
const isPagesDeployment = applicationTypeHint === 'pages';
|
|
11772
|
-
const metadata = await ensureProjectMetadata(sourceRoot, {
|
|
11773
|
-
allowCreate: isPagesDeployment,
|
|
11774
|
-
projectType: isPagesDeployment ? 'web' : undefined,
|
|
11775
|
-
});
|
|
11776
|
-
if (isPagesDeployment) {
|
|
11777
|
-
await validatePagesSource(sourceRoot, metadata.cozeFileContent);
|
|
11778
|
-
}
|
|
11779
|
-
return { ...sourceSnapshot, metadata, isPagesDeployment };
|
|
11780
|
-
};
|
|
11781
|
-
|
|
11782
|
-
// 服务端 deploy_app/list 的 page_size 上限,超了会被判参数错误。
|
|
11783
|
-
// 客户端先拦一道,是为了把错误说在本地(带上上限值),而不是回一句服务端的通用参数错误。
|
|
11784
|
-
const APP_LIST_MAX_PAGE_SIZE = 100;
|
|
11785
|
-
|
|
11786
|
-
// page_token 是**页码的十进制字符串**(服务端口径,与 deploy_history/list 一致),不是不透明游标。
|
|
11787
|
-
// 所以这里能、也应该在本地校验:`--page-token abc` 早报错,比发出去再被拒强。
|
|
11788
|
-
const parsePositiveInt = (
|
|
11789
|
-
raw,
|
|
11790
|
-
option,
|
|
11791
|
-
code,
|
|
11792
|
-
max,
|
|
11793
|
-
) => {
|
|
11794
|
-
const value = Number(raw);
|
|
11795
|
-
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
11796
|
-
throw new CliError(`${option} must be a positive integer.`, code, { [option]: raw });
|
|
11797
|
-
}
|
|
11798
|
-
if (max !== undefined && value > max) {
|
|
11799
|
-
throw new CliError(`${option} must not exceed ${String(max)}.`, code, { [option]: raw });
|
|
11800
|
-
}
|
|
11801
|
-
return value;
|
|
11802
|
-
};
|
|
11803
|
-
|
|
11804
|
-
// ⛔ 别再用 `Number(options.pageSize || 20)`:`--page-size abc` 会算出 NaN,
|
|
11805
|
-
// JSON.stringify 把它写成 null 发给服务端,最后表现为「参数没生效」而不是「参数写错了」。
|
|
11806
|
-
const parsePageSize = (
|
|
11807
|
-
raw,
|
|
11808
|
-
fallback,
|
|
11809
|
-
max,
|
|
11810
|
-
) => {
|
|
11811
|
-
if (raw === undefined || raw === '') {
|
|
11812
|
-
return fallback;
|
|
11813
|
-
}
|
|
11814
|
-
return parsePositiveInt(raw, '--page-size', 'INVALID_PAGE_SIZE', max);
|
|
11815
|
-
};
|
|
11816
|
-
|
|
11817
|
-
const parsePageToken = (raw) => {
|
|
11818
|
-
if (raw === undefined || raw === '') {
|
|
11819
|
-
return undefined;
|
|
11820
|
-
}
|
|
11821
|
-
parsePositiveInt(raw, '--page-token', 'INVALID_PAGE_TOKEN');
|
|
11822
|
-
return raw;
|
|
11823
|
-
};
|
|
11824
|
-
|
|
11825
|
-
|
|
11826
|
-
|
|
11827
|
-
|
|
11828
|
-
|
|
11829
|
-
|
|
11830
|
-
|
|
11831
|
-
// collectAllPages 顺着 next_page_token 把所有页取回来。
|
|
11832
|
-
//
|
|
11833
|
-
// 服务端从「全量单页」改成真分页之后,`app list` 一次只回一页;想要「我的全部应用」就得翻页。
|
|
11834
|
-
// 与其让每个调用方各写一遍循环,不如给一个 --all。
|
|
11835
|
-
//
|
|
11836
|
-
// ⚠️ 不设页数上限截断:静默截断正是这次要修掉的毛病。只防死循环——服务端如果一直回同一个
|
|
11837
|
-
// token(或说 has_more 却不给 token),直接报错,而不是无限翻。
|
|
11838
|
-
const collectAllPages = async (
|
|
11839
|
-
fetchPage,
|
|
11840
|
-
) => {
|
|
11841
|
-
const items = [];
|
|
11842
|
-
const seen = new Set();
|
|
11843
|
-
let pageToken;
|
|
11844
|
-
let pages = 0;
|
|
11845
|
-
for (;;) {
|
|
11846
|
-
const page = await fetchPage(pageToken);
|
|
11847
|
-
items.push(...(page.items || []));
|
|
11848
|
-
pages += 1;
|
|
11849
|
-
if (!page.has_more) {
|
|
11850
|
-
return { items, pages };
|
|
11851
|
-
}
|
|
11852
|
-
const next = page.next_page_token;
|
|
11853
|
-
if (!next || seen.has(next)) {
|
|
11854
|
-
throw new CliError(
|
|
11855
|
-
'The server reported more pages but returned no usable next_page_token.',
|
|
11856
|
-
'INVALID_PAGE_TOKEN',
|
|
11857
|
-
{ next_page_token: next, pages },
|
|
11858
|
-
);
|
|
11859
|
-
}
|
|
11860
|
-
seen.add(next);
|
|
11861
|
-
pageToken = next;
|
|
11862
|
-
}
|
|
11863
|
-
};
|
|
11864
|
-
|
|
11865
|
-
async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
11866
|
-
|
|
11867
|
-
const registerDeployReadCommands = (deploy) => {
|
|
11868
|
-
deploy
|
|
11869
|
-
.command('status')
|
|
11870
|
-
.option('--app-id <appId>', 'Application ID')
|
|
11871
|
-
.option('--deploy-id <deployId>', 'Deployment history ID')
|
|
11872
|
-
.action(async (options, command) => {
|
|
11873
|
-
const runtime = await getRuntime(command);
|
|
11874
|
-
const appId = await requireAppId(runtime.cwd, getDeployAppIdOption(options, command));
|
|
11875
|
-
let deployHistoryId = options.deployId;
|
|
11876
|
-
if (!deployHistoryId) {
|
|
11877
|
-
deployHistoryId = await _asyncOptionalChain([(
|
|
11878
|
-
await runtime.client.listDeployHistory({ app_id: appId, page_size: 1 })
|
|
11879
|
-
), 'access', async _ => _.deploy_history_list, 'optionalAccess', async _2 => _2[0], 'optionalAccess', async _3 => _3.deploy_history_id]);
|
|
11880
|
-
}
|
|
11881
|
-
if (!deployHistoryId) {
|
|
11882
|
-
throw new CliError('No deployment history found.', 'DEPLOYMENT_NOT_FOUND');
|
|
11883
|
-
}
|
|
11884
|
-
const history = await runtime.client.getDeployHistory({
|
|
11885
|
-
app_id: appId,
|
|
11886
|
-
deploy_history_id: deployHistoryId,
|
|
11887
|
-
});
|
|
11888
|
-
runtime.output.print({
|
|
11889
|
-
app_id: appId,
|
|
11890
|
-
deploy_history_id: deployHistoryId,
|
|
11891
|
-
status: getDeployStatusText(history.status),
|
|
11892
|
-
commit_hash: history.commit_hash,
|
|
11893
|
-
domains: history.domain_list || [],
|
|
11894
|
-
error_analysis: history.error_analysis,
|
|
11895
|
-
deploy_detail: formatDeployDetails(history),
|
|
11896
|
-
connector_data_list: history.connector_data_list || [],
|
|
11897
|
-
mobile_artifact_list: history.mobile_artifact_list || [],
|
|
11898
|
-
});
|
|
11899
|
-
});
|
|
11900
|
-
|
|
11901
|
-
deploy
|
|
11902
|
-
.command('list')
|
|
11903
|
-
.option('--app-id <appId>', 'Application ID')
|
|
11904
|
-
.option('--page-size <pageSize>', 'Page size', '10')
|
|
11905
|
-
.option('--page-token <pageToken>', 'Page token (page number)')
|
|
11906
|
-
.action(async (options, command) => {
|
|
11907
|
-
// 先在本地校验:`--page-size abc` 以前算出 NaN 发出去,表现成「参数没生效」。
|
|
11908
|
-
const pageSize = parsePageSize(options.pageSize, 10);
|
|
11909
|
-
const pageToken = parsePageToken(options.pageToken);
|
|
11910
|
-
const runtime = await getRuntime(command);
|
|
11911
|
-
const appId = await requireAppId(runtime.cwd, getDeployAppIdOption(options, command));
|
|
11912
|
-
const data = await runtime.client.listDeployHistory({
|
|
11913
|
-
app_id: appId,
|
|
11914
|
-
page_size: pageSize,
|
|
11915
|
-
page_token: pageToken,
|
|
11916
|
-
});
|
|
11917
|
-
runtime.output.print({
|
|
11918
|
-
items: (data.deploy_history_list || []).map(item => ({
|
|
11919
|
-
deploy_history_id: item.deploy_history_id,
|
|
11920
|
-
status: getDeployStatusText(item.status),
|
|
11921
|
-
commit_hash: item.commit_hash_short || item.commit_hash,
|
|
11922
|
-
created_at: item.created_at,
|
|
11923
|
-
can_rollback: item.can_rollback,
|
|
11924
|
-
deploy_detail: formatDeployDetails(item),
|
|
11925
|
-
connector_data_list: item.connector_data_list || [],
|
|
11926
|
-
mobile_artifact_list: item.mobile_artifact_list || [],
|
|
11927
|
-
})),
|
|
11928
|
-
next_page_token: data.next_page_token,
|
|
11929
|
-
has_more: data.has_more,
|
|
11930
|
-
});
|
|
11931
|
-
});
|
|
11932
|
-
|
|
11933
|
-
deploy
|
|
11934
|
-
.command('online')
|
|
11935
|
-
.description('Show the current online deployment')
|
|
11936
|
-
.option('--app-id <appId>', 'Application ID')
|
|
11937
|
-
.action(async (options, command) => {
|
|
11938
|
-
const runtime = await getRuntime(command);
|
|
11939
|
-
const appId = await requireAppId(runtime.cwd, getDeployAppIdOption(options, command));
|
|
11940
|
-
const data = await runtime.client.getOnlineDeployHistory(appId);
|
|
11941
|
-
runtime.output.print({
|
|
11942
|
-
app_id: appId,
|
|
11943
|
-
items: (data.deploy_history_list || []).map(item => ({
|
|
11944
|
-
deploy_history_id: item.deploy_history_id,
|
|
11945
|
-
status: getDeployStatusText(item.status),
|
|
11946
|
-
commit_hash: item.commit_hash_short || item.commit_hash,
|
|
11947
|
-
created_at: item.created_at,
|
|
11948
|
-
deploy_detail: formatDeployDetails(item),
|
|
11949
|
-
domains: item.domain_list || [],
|
|
11950
|
-
mobile_artifact_list: item.mobile_artifact_list || [],
|
|
11951
|
-
})),
|
|
11952
|
-
});
|
|
11953
|
-
});
|
|
11954
|
-
|
|
11955
|
-
deploy
|
|
11956
|
-
.command('rollback-check')
|
|
11957
|
-
.description('Check whether a deployment supports database rollback')
|
|
11958
|
-
.requiredOption('--deploy-id <deployId>', 'Target deployment history ID')
|
|
11959
|
-
.option('--app-id <appId>', 'Application ID')
|
|
11960
|
-
.action(async (options, command) => {
|
|
11961
|
-
const runtime = await getRuntime(command);
|
|
11962
|
-
const appId = await requireAppId(runtime.cwd, getDeployAppIdOption(options, command));
|
|
11963
|
-
const data = await runtime.client.checkRollbackDatabase({
|
|
11964
|
-
app_id: appId,
|
|
11965
|
-
deploy_history_id: options.deployId || '',
|
|
11966
|
-
});
|
|
11967
|
-
runtime.output.print({ app_id: appId, deploy_history_id: options.deployId, ...data });
|
|
11968
|
-
});
|
|
11969
|
-
|
|
11970
|
-
deploy
|
|
11971
|
-
.command('log-count')
|
|
11972
|
-
.description('Show runtime log count and limit')
|
|
11973
|
-
.option('--app-id <appId>', 'Application ID')
|
|
11974
|
-
.action(async (options, command) => {
|
|
11975
|
-
const runtime = await getRuntime(command);
|
|
11976
|
-
const appId = await requireAppId(runtime.cwd, getDeployAppIdOption(options, command));
|
|
11977
|
-
const data = await runtime.client.getRuntimeLogCount(appId);
|
|
11978
|
-
runtime.output.print({ app_id: appId, ...data });
|
|
11979
|
-
});
|
|
11980
|
-
|
|
11981
|
-
deploy
|
|
11982
|
-
.command('count')
|
|
11983
|
-
.description('Show successful deployment count')
|
|
11984
|
-
.option('--app-id <appId>', 'Application ID')
|
|
11985
|
-
.action(async (options, command) => {
|
|
11986
|
-
const runtime = await getRuntime(command);
|
|
11987
|
-
const appId = await requireAppId(runtime.cwd, getDeployAppIdOption(options, command));
|
|
11988
|
-
const data = await runtime.client.getDeployCount(appId);
|
|
11989
|
-
runtime.output.print({ app_id: appId, ...data });
|
|
11990
|
-
});
|
|
11991
|
-
};
|
|
11992
|
-
|
|
11993
|
-
const registerEnv = (code) => {
|
|
11994
|
-
const env = code
|
|
11995
|
-
.command('env')
|
|
11996
|
-
.description('Inspect the current online environment snapshot');
|
|
11997
|
-
|
|
11998
|
-
env
|
|
11999
|
-
.command('list')
|
|
12000
|
-
.description('List environment variables of the current online deployment')
|
|
12001
|
-
.option('--app-id <appId>', 'Application ID')
|
|
12002
|
-
.action(async (options, command) => {
|
|
12003
|
-
const runtime = await getRuntime(command);
|
|
12004
|
-
const appId = await requireAppId(
|
|
12005
|
-
runtime.cwd,
|
|
12006
|
-
getDeployAppIdOption(options, command),
|
|
12007
|
-
);
|
|
12008
|
-
runtime.output.print(await runtime.client.getOnlineEnvironment(appId));
|
|
12009
|
-
});
|
|
12010
|
-
};
|
|
12011
|
-
|
|
12012
|
-
function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/* eslint-disable security/detect-non-literal-fs-filename -- validated project-local build output paths */
|
|
12013
|
-
|
|
12014
|
-
const BUILD_OUTPUT_DIRS = new Set(['dist', 'dist-tt']);
|
|
12015
|
-
const EXCLUDED_PARTS = new Set([
|
|
12016
|
-
'.git',
|
|
12017
|
-
'.env',
|
|
12018
|
-
'node_modules',
|
|
12019
|
-
]);
|
|
12020
|
-
const REPRODUCIBLE_ARCHIVE_MTIME = new Date(0);
|
|
12021
|
-
|
|
12022
|
-
const validateBuildOutput = async (
|
|
12023
|
-
sourceRoot,
|
|
12024
|
-
buildOutputDir,
|
|
12025
|
-
) => {
|
|
12026
|
-
if (!BUILD_OUTPUT_DIRS.has(buildOutputDir)) {
|
|
12027
|
-
throw new CliError(
|
|
12028
|
-
`Unsupported Mini-program build output directory: ${buildOutputDir}.`,
|
|
12029
|
-
'SOURCE_PACKAGE_FAILED',
|
|
12030
|
-
);
|
|
12031
|
-
}
|
|
12032
|
-
const buildOutputRoot = node_path.resolve(sourceRoot, buildOutputDir);
|
|
12033
|
-
try {
|
|
12034
|
-
const info = await promises.lstat(buildOutputRoot);
|
|
12035
|
-
if (info.isSymbolicLink() || !info.isDirectory()) {
|
|
12036
|
-
throw new Error('build output must be a regular directory');
|
|
12037
|
-
}
|
|
12038
|
-
const realSourceRoot = await promises.realpath(sourceRoot);
|
|
12039
|
-
const realBuildOutputRoot = await promises.realpath(buildOutputRoot);
|
|
12040
|
-
const relativeOutput = node_path.relative(realSourceRoot, realBuildOutputRoot);
|
|
12041
|
-
if (!relativeOutput || relativeOutput.startsWith('..')) {
|
|
12042
|
-
throw new Error('build output must be inside the source root');
|
|
12043
|
-
}
|
|
12044
|
-
} catch (error) {
|
|
12045
|
-
throw new CliError(
|
|
12046
|
-
`Invalid Mini-program build output ${buildOutputRoot}: ${error instanceof Error ? error.message : String(error)}`,
|
|
12047
|
-
'SOURCE_PACKAGE_FAILED',
|
|
12048
|
-
);
|
|
12049
|
-
}
|
|
12050
|
-
};
|
|
12051
|
-
|
|
12052
|
-
const shouldInclude = (
|
|
12053
|
-
archivePath,
|
|
12054
|
-
entry,
|
|
12055
|
-
) => {
|
|
12056
|
-
if (_optionalChain$5([entry, 'access', _ => _.isSymbolicLink, 'optionalCall', _2 => _2()])) {
|
|
12057
|
-
return false;
|
|
12058
|
-
}
|
|
12059
|
-
return !archivePath.split(/[\\/]/u).some(part =>
|
|
12060
|
-
EXCLUDED_PARTS.has(part) || part.startsWith('.git'),
|
|
12061
|
-
);
|
|
12062
|
-
};
|
|
12063
|
-
|
|
12064
|
-
const createMiniProgramPackage = async (
|
|
12065
|
-
sourceRoot,
|
|
12066
|
-
buildOutputDir,
|
|
12067
|
-
) => {
|
|
12068
|
-
const resolvedSourceRoot = node_path.resolve(sourceRoot);
|
|
12069
|
-
await validateBuildOutput(resolvedSourceRoot, buildOutputDir);
|
|
12070
|
-
const tempDirectory = await promises.mkdtemp(node_path.join(node_os.tmpdir(), 'coze-mini-program-source-'));
|
|
12071
|
-
const outputPath = node_path.join(tempDirectory, 'source.tar.gz');
|
|
12072
|
-
try {
|
|
12073
|
-
await tar.create(
|
|
12074
|
-
{
|
|
12075
|
-
cwd: resolvedSourceRoot,
|
|
12076
|
-
file: outputPath,
|
|
12077
|
-
filter: shouldInclude,
|
|
12078
|
-
gzip: true,
|
|
12079
|
-
mtime: REPRODUCIBLE_ARCHIVE_MTIME,
|
|
12080
|
-
portable: true,
|
|
12081
|
-
},
|
|
12082
|
-
[buildOutputDir],
|
|
12083
|
-
);
|
|
12084
|
-
const info = await promises.stat(outputPath);
|
|
12085
|
-
if (info.size === 0) {
|
|
12086
|
-
throw new Error('source archive is empty');
|
|
12087
|
-
}
|
|
12088
|
-
return {
|
|
12089
|
-
path: outputPath,
|
|
12090
|
-
sizeBytes: info.size,
|
|
12091
|
-
cleanup: () => promises.rm(tempDirectory, { recursive: true, force: true }),
|
|
12092
|
-
};
|
|
12093
|
-
} catch (error) {
|
|
12094
|
-
await promises.rm(tempDirectory, { recursive: true, force: true });
|
|
12095
|
-
throw new CliError(
|
|
12096
|
-
`Unable to package Mini-program build output: ${error instanceof Error ? error.message : String(error)}`,
|
|
12097
|
-
'SOURCE_PACKAGE_FAILED',
|
|
12098
|
-
);
|
|
12099
|
-
}
|
|
12100
|
-
};
|
|
12101
|
-
|
|
12102
|
-
function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$4(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
12103
|
-
const CONNECTOR_IDS = {
|
|
12104
|
-
wechat: '10000127',
|
|
12105
|
-
douyin: '10000126',
|
|
12106
|
-
} ;
|
|
12107
|
-
|
|
12108
|
-
const MINI_PROGRAM_BUILD_OUTPUT_DIRS = {
|
|
12109
|
-
wechat: 'dist',
|
|
12110
|
-
douyin: 'dist-tt',
|
|
12111
|
-
} ;
|
|
12112
|
-
|
|
12113
|
-
|
|
12114
|
-
|
|
12115
|
-
|
|
12116
|
-
|
|
12117
|
-
|
|
12118
|
-
|
|
12119
|
-
|
|
12120
|
-
|
|
12121
|
-
|
|
12122
|
-
|
|
12123
|
-
|
|
12124
|
-
|
|
12125
|
-
|
|
12126
|
-
const resolveConnectorId = (platform) => {
|
|
12127
|
-
const connectorId = CONNECTOR_IDS[platform ];
|
|
12128
|
-
if (!connectorId) {
|
|
12129
|
-
throw new CliError(
|
|
12130
|
-
`Unsupported Mini-program platform ${String(platform)}; expected wechat or douyin.`,
|
|
12131
|
-
'INVALID_MINIPROGRAM_PLATFORM',
|
|
12132
|
-
);
|
|
12133
|
-
}
|
|
12134
|
-
return connectorId;
|
|
12135
|
-
};
|
|
12136
|
-
|
|
12137
|
-
const resolveBuildOutputDir = (platform) => {
|
|
12138
|
-
const outputDir =
|
|
12139
|
-
MINI_PROGRAM_BUILD_OUTPUT_DIRS[platform ];
|
|
12140
|
-
if (!outputDir) {
|
|
12141
|
-
throw new CliError(
|
|
12142
|
-
`Unsupported Mini-program platform ${String(platform)}; expected wechat or douyin.`,
|
|
12143
|
-
'INVALID_MINIPROGRAM_PLATFORM',
|
|
12144
|
-
);
|
|
12145
|
-
}
|
|
12146
|
-
return outputDir;
|
|
12147
|
-
};
|
|
12148
|
-
|
|
12149
|
-
const resolveProjectId = async (
|
|
12150
|
-
command,
|
|
12151
|
-
options,
|
|
12152
|
-
) => {
|
|
12153
|
-
if (_optionalChain$4([options, 'access', _ => _.projectId, 'optionalAccess', _2 => _2.trim, 'call', _3 => _3()])) {
|
|
12154
|
-
return options.projectId.trim();
|
|
12155
|
-
}
|
|
12156
|
-
const runtime = await getRuntime(command);
|
|
12157
|
-
const sourceRoot = node_path.resolve(runtime.cwd, options.sourceRoot || '.');
|
|
12158
|
-
const metadata = await readProjectMetadata(sourceRoot);
|
|
12159
|
-
if (!metadata.projectId) {
|
|
12160
|
-
throw new CliError(
|
|
12161
|
-
'Project ID is required. Pass --project-id or use a source directory whose .coze [project] contains project_id.',
|
|
12162
|
-
'PROJECT_ID_REQUIRED',
|
|
12163
|
-
);
|
|
12164
|
-
}
|
|
12165
|
-
return metadata.projectId;
|
|
12166
|
-
};
|
|
12167
|
-
|
|
12168
|
-
const MINI_PROGRAM_AUTH_STATUS = {
|
|
12169
|
-
authorized: 1,
|
|
12170
|
-
needAuthorize: 2,
|
|
12171
|
-
boundToOtherUser: 3,
|
|
12172
|
-
} ;
|
|
12173
|
-
|
|
12174
|
-
const getBoundToOtherUserMessage = (platform) => {
|
|
12175
|
-
const platformName = platform === 'wechat' ? 'WeChat' : 'Douyin';
|
|
12176
|
-
const platformConsole =
|
|
12177
|
-
platform === 'wechat' ? 'WeChat Public Platform' : 'Douyin Open Platform';
|
|
12178
|
-
return [
|
|
12179
|
-
`This ${platformName} Mini-program AppID is authorized by another Coze user.`,
|
|
12180
|
-
`If this is an AppID you manage, revoke Coze's previous third-party platform authorization in the ${platformConsole}, then rerun this auth command. The CLI will recheck the AppID and authorize it for your current Coze account.`,
|
|
12181
|
-
'If this is not your AppID, change --mini-app-id to an AppID for which you have administrator permission, then rerun this auth command.',
|
|
12182
|
-
].join(' ');
|
|
12183
|
-
};
|
|
12184
|
-
|
|
12185
|
-
const getAuthRequiredMessage = () =>
|
|
12186
|
-
'This Mini-program AppID is not authorized for the current Coze user. Run `coze-dev deploy code mini-program auth` first.';
|
|
12187
|
-
|
|
12188
|
-
const getPreviewFailureMessage = (data
|
|
12189
|
-
|
|
12190
|
-
|
|
12191
|
-
) =>
|
|
12192
|
-
_optionalChain$4([data, 'access', _4 => _4.stderr, 'optionalAccess', _5 => _5.trim, 'call', _6 => _6()]) || _optionalChain$4([data, 'access', _7 => _7.stdout, 'optionalAccess', _8 => _8.trim, 'call', _9 => _9()]) || 'Mini-program preview failed.';
|
|
12193
|
-
|
|
12194
|
-
const registerAuthorizationCommand = (miniProgram) => {
|
|
12195
|
-
miniProgram
|
|
12196
|
-
.command('auth')
|
|
12197
|
-
.description('Authorize a Mini-program AppID for the current Coze user')
|
|
12198
|
-
.requiredOption('--platform <platform>', 'wechat or douyin')
|
|
12199
|
-
.requiredOption('--mini-app-id <miniAppId>', 'Mini-program AppID')
|
|
12200
|
-
.option('--project-id <projectId>', 'Deployment Project ID')
|
|
12201
|
-
.option('--source-root <sourceRoot>', 'Directory containing .coze', '.')
|
|
12202
|
-
.action(async (options, command) => {
|
|
12203
|
-
const runtime = await getRuntime(command);
|
|
12204
|
-
const projectId = await resolveProjectId(command, options);
|
|
12205
|
-
const authorization = await runtime.client.authorizeMiniProgram({
|
|
12206
|
-
project_id: projectId,
|
|
12207
|
-
app_id: options.miniAppId || '',
|
|
12208
|
-
connector_id: resolveConnectorId(options.platform),
|
|
12209
|
-
redirect_url: 'https://code.coze.cn/coding/auth/callback/miniprogram',
|
|
12210
|
-
});
|
|
12211
|
-
if (authorization.status === MINI_PROGRAM_AUTH_STATUS.needAuthorize) {
|
|
12212
|
-
runtime.output.print({
|
|
12213
|
-
project_id: projectId,
|
|
12214
|
-
mini_app_id: options.miniAppId,
|
|
12215
|
-
platform: options.platform,
|
|
12216
|
-
authorization_required: true,
|
|
12217
|
-
auth_url: authorization.auth_url,
|
|
12218
|
-
});
|
|
12219
|
-
return;
|
|
12220
|
-
}
|
|
12221
|
-
if (authorization.status === MINI_PROGRAM_AUTH_STATUS.boundToOtherUser) {
|
|
12222
|
-
throw new CliError(
|
|
12223
|
-
getBoundToOtherUserMessage(options.platform),
|
|
12224
|
-
'MINIPROGRAM_AUTHORIZED_BY_OTHER_USER',
|
|
12225
|
-
);
|
|
12226
|
-
}
|
|
12227
|
-
if (authorization.status !== MINI_PROGRAM_AUTH_STATUS.authorized) {
|
|
12228
|
-
throw new CliError(
|
|
12229
|
-
`Unexpected Mini-program authorization status: ${String(authorization.status)}.`,
|
|
12230
|
-
'INVALID_RESPONSE',
|
|
12231
|
-
);
|
|
12232
|
-
}
|
|
12233
|
-
runtime.output.print({
|
|
12234
|
-
project_id: projectId,
|
|
12235
|
-
mini_app_id: options.miniAppId,
|
|
12236
|
-
platform: options.platform,
|
|
12237
|
-
authorized: true,
|
|
12238
|
-
});
|
|
12239
|
-
});
|
|
12240
|
-
};
|
|
12241
|
-
|
|
12242
|
-
const registerPreviewCommand = (miniProgram) => {
|
|
12243
|
-
miniProgram
|
|
12244
|
-
.command('preview')
|
|
12245
|
-
.description('Create a Mini-program preview QR code from the local build artifact')
|
|
12246
|
-
.requiredOption('--platform <platform>', 'wechat or douyin')
|
|
12247
|
-
.requiredOption('--mini-app-id <miniAppId>', 'Mini-program AppID')
|
|
12248
|
-
.option('--project-id <projectId>', 'Deployment Project ID')
|
|
12249
|
-
.option('--source-root <sourceRoot>', 'Directory containing dist or dist-tt', '.')
|
|
12250
|
-
.action(async (options, command) => {
|
|
12251
|
-
const runtime = await getRuntime(command);
|
|
12252
|
-
const projectId = await resolveProjectId(command, options);
|
|
12253
|
-
const authorization = await runtime.client.getMiniProgramAuthStatus({
|
|
12254
|
-
project_id: projectId,
|
|
12255
|
-
connector_id: resolveConnectorId(options.platform),
|
|
12256
|
-
});
|
|
12257
|
-
if (
|
|
12258
|
-
!authorization.is_authorized ||
|
|
12259
|
-
authorization.bound_related_id !== options.miniAppId
|
|
12260
|
-
) {
|
|
12261
|
-
throw new CliError(
|
|
12262
|
-
getAuthRequiredMessage(),
|
|
12263
|
-
'MINIPROGRAM_AUTH_REQUIRED',
|
|
12264
|
-
);
|
|
12265
|
-
}
|
|
12266
|
-
const sourceRoot = node_path.resolve(runtime.cwd, options.sourceRoot || '.');
|
|
12267
|
-
const buildOutputDir = resolveBuildOutputDir(options.platform);
|
|
12268
|
-
const sourcePackage = await createMiniProgramPackage(
|
|
12269
|
-
sourceRoot,
|
|
12270
|
-
buildOutputDir,
|
|
12271
|
-
);
|
|
12272
|
-
try {
|
|
12273
|
-
const content = await promises.readFile(sourcePackage.path);
|
|
12274
|
-
const data = await runtime.client.createMiniProgramPreview({
|
|
12275
|
-
project_id: projectId,
|
|
12276
|
-
app_id: options.miniAppId || '',
|
|
12277
|
-
connector_id: resolveConnectorId(options.platform),
|
|
12278
|
-
source_package_base64: content.toString('base64'),
|
|
12279
|
-
});
|
|
12280
|
-
if (data.failed) {
|
|
12281
|
-
throw new CliError(
|
|
12282
|
-
getPreviewFailureMessage(data),
|
|
12283
|
-
'MINIPROGRAM_PREVIEW_FAILED',
|
|
12284
|
-
);
|
|
12285
|
-
}
|
|
12286
|
-
runtime.output.print({
|
|
12287
|
-
project_id: projectId,
|
|
12288
|
-
mini_app_id: options.miniAppId,
|
|
12289
|
-
platform: options.platform,
|
|
12290
|
-
source_package_size_bytes: sourcePackage.sizeBytes,
|
|
12291
|
-
...data,
|
|
12292
|
-
});
|
|
12293
|
-
} finally {
|
|
12294
|
-
await sourcePackage.cleanup();
|
|
12295
|
-
}
|
|
12296
|
-
});
|
|
12297
|
-
};
|
|
12298
|
-
|
|
12299
|
-
const registerMiniProgram = (code) => {
|
|
12300
|
-
const miniProgram = code
|
|
12301
|
-
.command('mini-program')
|
|
12302
|
-
.alias('miniprogram')
|
|
12303
|
-
.description('Manage WeChat or Douyin Mini-program authorization');
|
|
12304
|
-
|
|
12305
|
-
miniProgram
|
|
12306
|
-
.command('status')
|
|
12307
|
-
.requiredOption('--platform <platform>', 'wechat or douyin')
|
|
12308
|
-
.option('--project-id <projectId>', 'Deployment Project ID')
|
|
12309
|
-
.option('--source-root <sourceRoot>', 'Directory containing .coze', '.')
|
|
12310
|
-
.action(async (options, command) => {
|
|
12311
|
-
const runtime = await getRuntime(command);
|
|
12312
|
-
const projectId = await resolveProjectId(command, options);
|
|
12313
|
-
const connectorId = resolveConnectorId(options.platform);
|
|
12314
|
-
const data = await runtime.client.getMiniProgramAuthStatus({
|
|
12315
|
-
project_id: projectId,
|
|
12316
|
-
connector_id: connectorId,
|
|
12317
|
-
});
|
|
12318
|
-
runtime.output.print({ project_id: projectId, platform: options.platform, ...data });
|
|
12319
|
-
});
|
|
12320
|
-
|
|
12321
|
-
miniProgram
|
|
12322
|
-
.command('bind')
|
|
12323
|
-
.requiredOption('--platform <platform>', 'wechat or douyin')
|
|
12324
|
-
.requiredOption('--mini-app-id <miniAppId>', 'Mini-program AppID')
|
|
12325
|
-
.requiredOption('--redirect-url <redirectUrl>', 'OAuth callback URL')
|
|
12326
|
-
.option('--project-id <projectId>', 'Deployment Project ID')
|
|
12327
|
-
.option('--source-root <sourceRoot>', 'Directory containing .coze', '.')
|
|
12328
|
-
.option('--override', 'Move an AppID already bound to another project owned by you')
|
|
12329
|
-
.action(async (options, command) => {
|
|
12330
|
-
const runtime = await getRuntime(command);
|
|
12331
|
-
const projectId = await resolveProjectId(command, options);
|
|
12332
|
-
const connectorId = resolveConnectorId(options.platform);
|
|
12333
|
-
const data = await runtime.client.bindMiniProgramAuth({
|
|
12334
|
-
project_id: projectId,
|
|
12335
|
-
connector_id: connectorId,
|
|
12336
|
-
redirect_url: options.redirectUrl || '',
|
|
12337
|
-
auth_params: { app_id: options.miniAppId || '' },
|
|
12338
|
-
override: _nullishCoalesce$1(options.override, () => ( false)),
|
|
12339
|
-
});
|
|
12340
|
-
runtime.output.print({
|
|
12341
|
-
project_id: projectId,
|
|
12342
|
-
platform: options.platform,
|
|
12343
|
-
mini_app_id: options.miniAppId,
|
|
12344
|
-
...data,
|
|
12345
|
-
});
|
|
12346
|
-
});
|
|
12347
|
-
|
|
12348
|
-
miniProgram
|
|
12349
|
-
.command('submit-code')
|
|
12350
|
-
.requiredOption('--platform <platform>', 'wechat or douyin')
|
|
12351
|
-
.requiredOption('--mini-app-id <miniAppId>', 'Mini-program AppID')
|
|
12352
|
-
.requiredOption('--code <code>', 'OAuth authorization code')
|
|
12353
|
-
.requiredOption('--verify-state <verifyState>', 'State returned by bind')
|
|
12354
|
-
.option('--project-id <projectId>', 'Deployment Project ID')
|
|
12355
|
-
.option('--source-root <sourceRoot>', 'Directory containing .coze', '.')
|
|
12356
|
-
.action(async (options, command) => {
|
|
12357
|
-
const runtime = await getRuntime(command);
|
|
12358
|
-
const projectId = await resolveProjectId(command, options);
|
|
12359
|
-
await runtime.client.submitMiniProgramAuthCode({
|
|
12360
|
-
project_id: projectId,
|
|
12361
|
-
connector_id: resolveConnectorId(options.platform),
|
|
12362
|
-
code: options.code || '',
|
|
12363
|
-
verify_state: options.verifyState || '',
|
|
12364
|
-
auth_params: { app_id: options.miniAppId || '' },
|
|
12365
|
-
});
|
|
12366
|
-
runtime.output.print({ project_id: projectId, platform: options.platform, bound: true });
|
|
12367
|
-
});
|
|
12368
|
-
|
|
12369
|
-
miniProgram
|
|
12370
|
-
.command('unbind')
|
|
12371
|
-
.requiredOption('--platform <platform>', 'wechat or douyin')
|
|
12372
|
-
.option('--project-id <projectId>', 'Deployment Project ID')
|
|
12373
|
-
.option('--source-root <sourceRoot>', 'Directory containing .coze', '.')
|
|
12374
|
-
.action(async (options, command) => {
|
|
12375
|
-
const runtime = await getRuntime(command);
|
|
12376
|
-
const projectId = await resolveProjectId(command, options);
|
|
12377
|
-
await runtime.client.unbindMiniProgramAuth({
|
|
12378
|
-
project_id: projectId,
|
|
12379
|
-
connector_id: resolveConnectorId(options.platform),
|
|
12380
|
-
});
|
|
12381
|
-
runtime.output.print({ project_id: projectId, platform: options.platform, unbound: true });
|
|
12382
|
-
});
|
|
12383
|
-
|
|
12384
|
-
registerAuthorizationCommand(miniProgram);
|
|
12385
|
-
registerPreviewCommand(miniProgram);
|
|
12386
|
-
};
|
|
12387
|
-
|
|
12388
|
-
function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
12389
|
-
|
|
12390
|
-
const POLL_INTERVAL_MS = 3000;
|
|
12391
|
-
const MAX_CONSECUTIVE_RETRIES = 5;
|
|
12392
|
-
const TRANSIENT_RPC_ERROR_CODE = 230000001;
|
|
12393
|
-
|
|
12394
|
-
const wait = async () =>
|
|
12395
|
-
new Promise(resolve => setTimeout(resolve, POLL_INTERVAL_MS));
|
|
12396
|
-
|
|
12397
|
-
const isRetryablePollError = (error) =>
|
|
12398
|
-
error instanceof CliError &&
|
|
12399
|
-
error.code === 'API_REJECTED' &&
|
|
12400
|
-
Number(_optionalChain$3([error, 'access', _ => _.details, 'optionalAccess', _2 => _2.business_code])) === TRANSIENT_RPC_ERROR_CODE;
|
|
12401
|
-
|
|
12402
|
-
const pollHistory = async (
|
|
12403
|
-
command,
|
|
12404
|
-
appId,
|
|
12405
|
-
deployHistoryId,
|
|
12406
|
-
) => {
|
|
12407
|
-
const runtime = await getRuntime(command);
|
|
12408
|
-
const startedAt = Date.now();
|
|
12409
|
-
let consecutiveFailures = 0;
|
|
12410
|
-
while (true) {
|
|
12411
|
-
try {
|
|
12412
|
-
const history = await runtime.client.getDeployHistory({
|
|
12413
|
-
app_id: appId,
|
|
12414
|
-
deploy_history_id: deployHistoryId,
|
|
12415
|
-
});
|
|
12416
|
-
consecutiveFailures = 0;
|
|
12417
|
-
const status = getDeployStatusText(history.status);
|
|
12418
|
-
runtime.output.debug(
|
|
12419
|
-
`[deploy] History ${deployHistoryId}: ${status} (${String(Math.floor((Date.now() - startedAt) / 1000))}s elapsed)`,
|
|
12420
|
-
);
|
|
12421
|
-
if (history.status && TERMINAL_STATUSES.has(history.status)) {
|
|
12422
|
-
return history;
|
|
12423
|
-
}
|
|
12424
|
-
} catch (error) {
|
|
12425
|
-
if (!isRetryablePollError(error) || consecutiveFailures >= MAX_CONSECUTIVE_RETRIES) {
|
|
12426
|
-
throw error;
|
|
12427
|
-
}
|
|
12428
|
-
consecutiveFailures += 1;
|
|
12429
|
-
runtime.output.debug(
|
|
12430
|
-
`[deploy] Status check failed transiently; retrying (${String(consecutiveFailures)}/${String(MAX_CONSECUTIVE_RETRIES)}).`,
|
|
12431
|
-
);
|
|
12432
|
-
}
|
|
12433
|
-
await wait();
|
|
12434
|
-
}
|
|
12435
|
-
};
|
|
12436
|
-
|
|
12437
|
-
const GENERAL_PROJECT_TYPE = 9;
|
|
12438
|
-
|
|
12439
|
-
/**
|
|
12440
|
-
* Map `.coze` `[project].project_type` to the VibeProjectType used when creating the
|
|
12441
|
-
* deployment project.
|
|
12442
|
-
*
|
|
12443
|
-
* The values on the left are the ones the deploy server understands (see `cozefileutil`
|
|
12444
|
-
* `ResolveDeployKindByProjectType` / `GeneralProjectTypeByCozeProjectType` in coze-coding);
|
|
12445
|
-
* the numbers on the right are `VibeProjectType` (idl/coze.coding.ide/project.thrift).
|
|
12446
|
-
*
|
|
12447
|
-
* Keeping the two in sync matters beyond project metadata: the created project type decides
|
|
12448
|
-
* the project-scoped `COZE_PROJECT_TYPE` secret injected into the runtime, whether a Postgres
|
|
12449
|
-
* database is provisioned for the project, and whether the traffic gateway enforces inbound
|
|
12450
|
-
* auth. Creating an `agent` project as General(9) therefore deploys successfully but leaves a
|
|
12451
|
-
* dead service: the agent template reads `COZE_PROJECT_TYPE` to pick its graph and needs
|
|
12452
|
-
* `PGDATABASE_URL` on startup.
|
|
12453
|
-
*
|
|
12454
|
-
* VibeProjectType WebApp(3) and AssistantAgent(8) are intentionally absent: no `.coze`
|
|
12455
|
-
* project_type maps to them.
|
|
12456
|
-
*/
|
|
12457
|
-
const resolveCreationProjectType = (
|
|
12458
|
-
projectType,
|
|
12459
|
-
) => {
|
|
12460
|
-
switch (projectType) {
|
|
12461
|
-
case 'agent':
|
|
12462
|
-
return 1;
|
|
12463
|
-
case 'workflow':
|
|
12464
|
-
case 'automation':
|
|
12465
|
-
return 2;
|
|
12466
|
-
case 'app':
|
|
12467
|
-
return 4;
|
|
12468
|
-
case 'skill':
|
|
12469
|
-
return 5;
|
|
12470
|
-
case 'web':
|
|
12471
|
-
case 'backend':
|
|
12472
|
-
return 6;
|
|
12473
|
-
case 'miniapp':
|
|
12474
|
-
case 'miniprogram':
|
|
12475
|
-
return 7;
|
|
12476
|
-
default:
|
|
12477
|
-
return GENERAL_PROJECT_TYPE;
|
|
12478
|
-
}
|
|
12479
|
-
};
|
|
12480
|
-
|
|
12481
|
-
const formatDeployment = (deployment) =>
|
|
12482
|
-
typeof deployment === 'object' && deployment
|
|
12483
|
-
? {
|
|
12484
|
-
...(deployment ),
|
|
12485
|
-
status: getDeployStatusText(
|
|
12486
|
-
Number((deployment ).status),
|
|
12487
|
-
),
|
|
12488
|
-
}
|
|
12489
|
-
: undefined;
|
|
12490
|
-
|
|
12491
|
-
const formatApplication = (application) => ({
|
|
12492
|
-
...application,
|
|
12493
|
-
online_deployment: formatDeployment(application.online_deployment),
|
|
12494
|
-
latest_deployment: formatDeployment(application.latest_deployment),
|
|
12495
|
-
});
|
|
12496
|
-
|
|
12497
|
-
// 对应 IDL 的 MetricTimeRange,数值与 V1 保持一致。
|
|
12498
|
-
const TIME_RANGES = {
|
|
12499
|
-
day: 1,
|
|
12500
|
-
week: 2,
|
|
12501
|
-
month: 3,
|
|
12502
|
-
yesterday: 4,
|
|
12503
|
-
'three-days': 5,
|
|
12504
|
-
};
|
|
12505
|
-
|
|
12506
|
-
const resolveTimeRange = (value) => {
|
|
12507
|
-
const timeRange = TIME_RANGES[value || 'day'];
|
|
12508
|
-
if (!timeRange) {
|
|
12509
|
-
throw new CliError(
|
|
12510
|
-
`Invalid time range; expected one of ${Object.keys(TIME_RANGES).join(', ')}.`,
|
|
12511
|
-
'INVALID_TIME_RANGE',
|
|
12512
|
-
{ time_range: value },
|
|
12513
|
-
);
|
|
12514
|
-
}
|
|
12515
|
-
return timeRange;
|
|
12516
|
-
};
|
|
12517
|
-
|
|
12518
|
-
const UNIT_TYPES = { dev: 1, prod: 2 };
|
|
12519
|
-
|
|
12520
|
-
// 改 Application 本身的两条写操作,都要显式 --yes 才生效。
|
|
12521
|
-
// 单独拎出来是因为它们和 registerApp 里其余只读命令性质不同(会改线上资产),
|
|
12522
|
-
// 顺带让 registerApp 保持在 max-line-per-function 之内。
|
|
12523
|
-
const registerAppMutations = (app) => {
|
|
12524
|
-
app
|
|
12525
|
-
.command('rename <name>')
|
|
12526
|
-
.description('Rename an application')
|
|
12527
|
-
.option('--app-id <appId>', 'Application ID')
|
|
12528
|
-
.option('--yes', 'Confirm rename')
|
|
12529
|
-
.action(async (name, options, command) => {
|
|
12530
|
-
if (!options.yes) {
|
|
12531
|
-
throw new CliError('Pass --yes to rename the application.', 'CONFIRMATION_REQUIRED');
|
|
12532
|
-
}
|
|
12533
|
-
const normalizedName = name.trim();
|
|
12534
|
-
if (!normalizedName || normalizedName.length > 255) {
|
|
12535
|
-
throw new CliError(
|
|
12536
|
-
'Application name must contain 1 to 255 characters.',
|
|
12537
|
-
'INVALID_APPLICATION_NAME',
|
|
12538
|
-
);
|
|
12539
|
-
}
|
|
12540
|
-
const runtime = await getRuntime(command);
|
|
12541
|
-
const appId = await requireAppId(runtime.cwd, options.appId);
|
|
12542
|
-
const application = await runtime.client.updateApplication({
|
|
12543
|
-
app_id: appId,
|
|
12544
|
-
name: normalizedName,
|
|
12545
|
-
});
|
|
12546
|
-
runtime.output.print(
|
|
12547
|
-
formatApplication(application ),
|
|
12548
|
-
);
|
|
12549
|
-
});
|
|
12550
|
-
app
|
|
12551
|
-
// 删除是终态、不可撤销,所以和 rename 一样必须显式 --yes。
|
|
12552
|
-
//
|
|
12553
|
-
// 服务端只接受 **Stopped** 的应用:还在服务的先 `code deploy stop --yes`,否则会拿到一条
|
|
12554
|
-
// 带当前状态的报错。这里刻意不替用户先停 —— 停服会真的把线上服务摘掉,那得是用户自己按的。
|
|
12555
|
-
.command('delete')
|
|
12556
|
-
.description('Delete a stopped application (irreversible)')
|
|
12557
|
-
.option('--app-id <appId>', 'Application ID')
|
|
12558
|
-
.option('--yes', 'Confirm delete')
|
|
12559
|
-
.action(async (options, command) => {
|
|
12560
|
-
if (!options.yes) {
|
|
12561
|
-
throw new CliError('Pass --yes to delete the application.', 'CONFIRMATION_REQUIRED');
|
|
12562
|
-
}
|
|
12563
|
-
const runtime = await getRuntime(command);
|
|
12564
|
-
const appId = await requireAppId(runtime.cwd, options.appId);
|
|
12565
|
-
await runtime.client.deleteApplication(appId);
|
|
12566
|
-
// 本地 .coze 里的 app_id 不动(这条命令可能是在别的目录带 --app-id 跑的),但要说清楚:
|
|
12567
|
-
// 不清掉它,同目录下一次 deploy 会打到一个已删除的应用上、被服务端拒。
|
|
12568
|
-
runtime.output.print({
|
|
12569
|
-
app_id: appId,
|
|
12570
|
-
deleted: true,
|
|
12571
|
-
note: 'Remove app_id from .coze [project] before deploying this directory again.',
|
|
12572
|
-
});
|
|
12573
|
-
});
|
|
12574
|
-
};
|
|
12575
|
-
|
|
12576
|
-
const registerApp = (code) => {
|
|
12577
|
-
const app = code.command('app').description('Manage deployment applications');
|
|
12578
|
-
registerAppMutations(app);
|
|
12579
|
-
app
|
|
12580
|
-
.command('list')
|
|
12581
|
-
// 列的是当前登录用户名下**跨 Project** 的全部 Application。没有 --project-id:
|
|
12582
|
-
// V2 的资产归属是 Owner 而不是 Project,同一个 Project 下的应用可以分属不同用户。
|
|
12583
|
-
// 也不传 user_id:服务端直接从登录态取,客户端传了也只能传自己。
|
|
12584
|
-
//
|
|
12585
|
-
// ⚠️ 服务端是真分页(一页最多 100 条),一次调用只回一页。要「我的全部应用」用 --all,
|
|
12586
|
-
// 它顺着 next_page_token 翻到底 —— 别再默认第一页就是全部。
|
|
12587
|
-
.option('--page-token <pageToken>', 'Pagination token (page number)')
|
|
12588
|
-
.option('--page-size <pageSize>', 'Page size', '20')
|
|
12589
|
-
.option('--all', 'Fetch every page by following next_page_token')
|
|
12590
|
-
.action(async (options, command) => {
|
|
12591
|
-
const pageSize = parsePageSize(options.pageSize, 20, APP_LIST_MAX_PAGE_SIZE);
|
|
12592
|
-
const pageToken = parsePageToken(options.pageToken);
|
|
12593
|
-
if (options.all && pageToken) {
|
|
12594
|
-
throw new CliError(
|
|
12595
|
-
'--all fetches every page and cannot be combined with --page-token.',
|
|
12596
|
-
'INVALID_PAGE_TOKEN',
|
|
12597
|
-
{ page_token: options.pageToken },
|
|
12598
|
-
);
|
|
12599
|
-
}
|
|
12600
|
-
const runtime = await getRuntime(command);
|
|
12601
|
-
const format = (items) =>
|
|
12602
|
-
items.map(item => formatApplication(item ));
|
|
12603
|
-
if (options.all) {
|
|
12604
|
-
const { items, pages } = await collectAllPages(next =>
|
|
12605
|
-
runtime.client.listApplications({ page_token: next, page_size: pageSize }),
|
|
12606
|
-
);
|
|
12607
|
-
runtime.output.print({ items: format(items), pages, has_more: false });
|
|
12608
|
-
return;
|
|
12609
|
-
}
|
|
12610
|
-
const data = await runtime.client.listApplications({
|
|
12611
|
-
page_token: pageToken,
|
|
12612
|
-
page_size: pageSize,
|
|
12613
|
-
});
|
|
12614
|
-
runtime.output.print({
|
|
12615
|
-
items: format(data.items),
|
|
12616
|
-
next_page_token: data.next_page_token,
|
|
12617
|
-
has_more: data.has_more,
|
|
12618
|
-
});
|
|
12619
|
-
});
|
|
12620
|
-
app
|
|
12621
|
-
.command('show')
|
|
12622
|
-
.requiredOption('--app-id <appId>', 'Application ID')
|
|
12623
|
-
.action(async (options, command) => {
|
|
12624
|
-
const runtime = await getRuntime(command);
|
|
12625
|
-
runtime.output.print(
|
|
12626
|
-
formatApplication(
|
|
12627
|
-
(await runtime.client.getApplication(options.appId))
|
|
12628
|
-
|
|
12629
|
-
|
|
12630
|
-
,
|
|
12631
|
-
),
|
|
12632
|
-
);
|
|
12633
|
-
});
|
|
12634
|
-
app
|
|
12635
|
-
.command('analytics')
|
|
12636
|
-
.description('Show PV / UV charts')
|
|
12637
|
-
.option('--app-id <appId>', 'Application ID')
|
|
12638
|
-
.option(
|
|
12639
|
-
'--time-range <timeRange>',
|
|
12640
|
-
`Time range: ${Object.keys(TIME_RANGES).join(', ')}`,
|
|
12641
|
-
'day',
|
|
12642
|
-
)
|
|
12643
|
-
.action(async (options, command) => {
|
|
12644
|
-
const timeRange = resolveTimeRange(options.timeRange);
|
|
12645
|
-
const runtime = await getRuntime(command);
|
|
12646
|
-
const appId = await requireAppId(runtime.cwd, options.appId);
|
|
12647
|
-
const data = await runtime.client.getUserAnalyticsMetrics({
|
|
12648
|
-
app_id: appId,
|
|
12649
|
-
time_range: timeRange,
|
|
12650
|
-
});
|
|
12651
|
-
runtime.output.print({ app_id: appId, charts: data.charts || [] });
|
|
12652
|
-
});
|
|
12653
|
-
app
|
|
12654
|
-
.command('metrics')
|
|
12655
|
-
.description('Show application runtime metrics')
|
|
12656
|
-
.option('--app-id <appId>', 'Application ID')
|
|
12657
|
-
.option(
|
|
12658
|
-
'--time-range <timeRange>',
|
|
12659
|
-
`Time range: ${Object.keys(TIME_RANGES).join(', ')}`,
|
|
12660
|
-
'day',
|
|
12661
|
-
)
|
|
12662
|
-
.action(async (options, command) => {
|
|
12663
|
-
const timeRange = resolveTimeRange(options.timeRange);
|
|
12664
|
-
const runtime = await getRuntime(command);
|
|
12665
|
-
const appId = await requireAppId(runtime.cwd, options.appId);
|
|
12666
|
-
const data = await runtime.client.getApplicationMetrics({
|
|
12667
|
-
app_id: appId,
|
|
12668
|
-
time_range: timeRange,
|
|
12669
|
-
});
|
|
12670
|
-
runtime.output.print({
|
|
12671
|
-
app_id: appId,
|
|
12672
|
-
charts: data.charts || [],
|
|
12673
|
-
stats: data.stats || [],
|
|
12674
|
-
});
|
|
12675
|
-
});
|
|
12676
|
-
app
|
|
12677
|
-
.command('usage')
|
|
12678
|
-
.description('Show monthly hosted usage')
|
|
12679
|
-
.option('--app-id <appId>', 'Application ID')
|
|
12680
|
-
.requiredOption('--bill-month <billMonth>', 'Billing month in YYYY-MM format')
|
|
12681
|
-
.action(async (options, command) => {
|
|
12682
|
-
const billMonth = options.billMonth || '';
|
|
12683
|
-
if (!/^\d{4}-(?:0[1-9]|1[0-2])$/u.test(billMonth)) {
|
|
12684
|
-
throw new CliError(
|
|
12685
|
-
'Invalid billing month; expected YYYY-MM.',
|
|
12686
|
-
'INVALID_BILL_MONTH',
|
|
12687
|
-
{ bill_month: billMonth },
|
|
12688
|
-
);
|
|
12689
|
-
}
|
|
12690
|
-
const runtime = await getRuntime(command);
|
|
12691
|
-
const appId = await requireAppId(runtime.cwd, options.appId);
|
|
12692
|
-
const data = await runtime.client.getHostedUsageMonthly({
|
|
12693
|
-
app_id: appId,
|
|
12694
|
-
bill_month: billMonth,
|
|
12695
|
-
});
|
|
12696
|
-
runtime.output.print({ app_id: appId, summary: data.summary });
|
|
12697
|
-
});
|
|
12698
|
-
};
|
|
12699
|
-
|
|
12700
|
-
const registerDomain = (code) => {
|
|
12701
|
-
const domain = code.command('domain').description('Manage application domains');
|
|
12702
|
-
domain
|
|
12703
|
-
.command('list')
|
|
12704
|
-
.option('--app-id <appId>', 'Application ID')
|
|
12705
|
-
.option('--unit-type <unitType>', 'Unit type: dev or prod', 'prod')
|
|
12706
|
-
.action(async (options, command) => {
|
|
12707
|
-
const unitType = UNIT_TYPES[options.unitType || 'prod'];
|
|
12708
|
-
if (!unitType) {
|
|
12709
|
-
throw new CliError(
|
|
12710
|
-
'Invalid unit type; expected dev or prod.',
|
|
12711
|
-
'INVALID_UNIT_TYPE',
|
|
12712
|
-
{ unit_type: options.unitType },
|
|
12713
|
-
);
|
|
12714
|
-
}
|
|
12715
|
-
const runtime = await getRuntime(command);
|
|
12716
|
-
const appId = await requireAppId(runtime.cwd, options.appId);
|
|
12717
|
-
const data = await runtime.client.listDomains(appId, unitType);
|
|
12718
|
-
runtime.output.print({
|
|
12719
|
-
app_id: appId,
|
|
12720
|
-
unit_type: options.unitType || 'prod',
|
|
12721
|
-
items: (data.items || []).map(item => ({
|
|
12722
|
-
id: item.id,
|
|
12723
|
-
domain_host: item.domain_host,
|
|
12724
|
-
})),
|
|
12725
|
-
});
|
|
12726
|
-
});
|
|
12727
|
-
domain
|
|
12728
|
-
// 改的是系统分配的 <prefix>.coze.site 的 prefix,不是 `domain add` 加进来的自定义域名 ——
|
|
12729
|
-
// 那类域名服务端只有 create/delete,域名串本身改不了。
|
|
12730
|
-
//
|
|
12731
|
-
// 和 rename 一样要 --yes:旧默认域名会立刻停止指向本应用,已经发出去的链接会失效。
|
|
12732
|
-
.command('set-prefix <prefix>')
|
|
12733
|
-
.description('Change the default domain prefix (<prefix>.coze.site)')
|
|
12734
|
-
.option('--app-id <appId>', 'Application ID')
|
|
12735
|
-
.option('--yes', 'Confirm prefix change')
|
|
12736
|
-
.action(async (prefix, options, command) => {
|
|
12737
|
-
if (!options.yes) {
|
|
12738
|
-
throw new CliError(
|
|
12739
|
-
'Pass --yes to change the default domain prefix.',
|
|
12740
|
-
'CONFIRMATION_REQUIRED',
|
|
12741
|
-
);
|
|
12742
|
-
}
|
|
12743
|
-
const normalizedPrefix = prefix.trim();
|
|
12744
|
-
// 只做形态校验:长度、保留词、占用与权益都由服务端判,客户端不复制第二套规则。
|
|
12745
|
-
if (!/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/u.test(normalizedPrefix)) {
|
|
12746
|
-
throw new CliError(
|
|
12747
|
-
'Invalid prefix; use lowercase letters, digits and hyphens, not starting or ending with a hyphen.',
|
|
12748
|
-
'INVALID_DOMAIN_PREFIX',
|
|
12749
|
-
{ prefix },
|
|
12750
|
-
);
|
|
12751
|
-
}
|
|
12752
|
-
const runtime = await getRuntime(command);
|
|
12753
|
-
const appId = await requireAppId(runtime.cwd, options.appId);
|
|
12754
|
-
const data = await runtime.client.updateDefaultDomainPrefix({
|
|
12755
|
-
app_id: appId,
|
|
12756
|
-
prefix: normalizedPrefix,
|
|
12757
|
-
});
|
|
12758
|
-
runtime.output.print({
|
|
12759
|
-
app_id: appId,
|
|
12760
|
-
prefix: normalizedPrefix,
|
|
12761
|
-
old_domain_host: data.old_domain_host_canonical,
|
|
12762
|
-
new_domain_host: data.new_domain_host_canonical,
|
|
12763
|
-
});
|
|
12764
|
-
});
|
|
12765
|
-
domain
|
|
12766
|
-
.command('add <domain>')
|
|
12767
|
-
.option('--app-id <appId>', 'Application ID')
|
|
12768
|
-
.action(async (domainHost, options, command) => {
|
|
12769
|
-
if (!/^[a-zA-Z0-9](?:[a-zA-Z0-9-]*\.)+[a-zA-Z0-9-]+$/u.test(domainHost)) {
|
|
12770
|
-
throw new CliError('Invalid domain.', 'INVALID_DOMAIN', { domain: domainHost });
|
|
12771
|
-
}
|
|
12772
|
-
const runtime = await getRuntime(command);
|
|
12773
|
-
const appId = await requireAppId(runtime.cwd, options.appId);
|
|
12774
|
-
await runtime.client.createDomain({ app_id: appId, domain: domainHost });
|
|
12775
|
-
runtime.output.print({ app_id: appId, domain: domainHost });
|
|
12776
|
-
});
|
|
12777
|
-
};
|
|
12778
|
-
|
|
12779
|
-
function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
12780
|
-
|
|
12781
|
-
const firstPage = { page: 1, size: 1 };
|
|
12782
|
-
|
|
12783
|
-
const listSpaceRequest = (runtime) => ({
|
|
12784
|
-
...(runtime.config.organizationId
|
|
12785
|
-
? { organization_id: runtime.config.organizationId }
|
|
12786
|
-
: {}),
|
|
12787
|
-
...(runtime.config.enterpriseId
|
|
12788
|
-
? { enterprise_id: runtime.config.enterpriseId }
|
|
12789
|
-
: {}),
|
|
12790
|
-
});
|
|
12791
|
-
|
|
12792
|
-
const resolveDeploymentSpaceId = async (runtime) => {
|
|
12793
|
-
const configuredSpaceId = _optionalChain$2([runtime, 'access', _ => _.config, 'access', _2 => _2.spaceId, 'optionalAccess', _3 => _3.trim, 'call', _4 => _4()]);
|
|
12794
|
-
const request = listSpaceRequest(runtime);
|
|
12795
|
-
if (configuredSpaceId) {
|
|
12796
|
-
const data = await runtime.client.listSpaces(request);
|
|
12797
|
-
if (!data.bot_space_list.some(space => space.id === configuredSpaceId)) {
|
|
12798
|
-
throw new CliError(
|
|
12799
|
-
`Space ID ${configuredSpaceId} is invalid or is not available to the current account.`,
|
|
12800
|
-
'INVALID_SPACE_ID',
|
|
12801
|
-
);
|
|
12802
|
-
}
|
|
12803
|
-
return configuredSpaceId;
|
|
12804
|
-
}
|
|
12805
|
-
|
|
12806
|
-
const data = await runtime.client.listSpaces({ ...request, ...firstPage });
|
|
12807
|
-
const space = data.bot_space_list.find(item => item.id);
|
|
12808
|
-
if (!space) {
|
|
12809
|
-
throw new CliError(
|
|
12810
|
-
'No available Space was found for the current account. Create or join a Space before deploying.',
|
|
12811
|
-
'SPACE_NOT_FOUND',
|
|
12812
|
-
);
|
|
12813
|
-
}
|
|
12814
|
-
|
|
12815
|
-
runtime.config.spaceId = space.id;
|
|
12816
|
-
try {
|
|
12817
|
-
await saveSharedConfig({ spaceId: space.id }, runtime.globalOptions);
|
|
12818
|
-
} catch (error) {
|
|
12819
|
-
runtime.output.warn(`Unable to save the auto-selected Space: ${String(error)}`);
|
|
12820
|
-
}
|
|
12821
|
-
runtime.output.debug(`Auto-selected Space: ${space.name || space.id} (${space.id})`);
|
|
12822
|
-
return space.id;
|
|
12823
|
-
};
|
|
12824
|
-
|
|
12825
|
-
const PACKAGE_SCRIPT_CANDIDATES = [
|
|
12826
|
-
node_path.resolve(__dirname, 'deploy/package-project.js'),
|
|
12827
|
-
node_path.resolve(__dirname, '../../../scripts/deploy/package-project.js'),
|
|
12828
|
-
];
|
|
12829
|
-
|
|
12830
|
-
const packageCommand = (args) => {
|
|
12831
|
-
const packageScript = PACKAGE_SCRIPT_CANDIDATES.find(candidate =>
|
|
12832
|
-
node_fs.existsSync(candidate),
|
|
12833
|
-
);
|
|
12834
|
-
if (!packageScript) {
|
|
12835
|
-
throw new CliError(
|
|
12836
|
-
'The deployment packaging script is missing from this coze-dev installation.',
|
|
12837
|
-
'SOURCE_PACKAGE_FAILED',
|
|
12838
|
-
);
|
|
12839
|
-
}
|
|
12840
|
-
return [packageScript, ...args];
|
|
12841
|
-
};
|
|
12842
|
-
|
|
12843
|
-
const runPackageScript = async (args, debug = false) =>
|
|
12844
|
-
new Promise((resolvePromise, reject) => {
|
|
12845
|
-
const child = node_child_process.spawn(process.execPath, packageCommand(args), {
|
|
12846
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
12847
|
-
});
|
|
12848
|
-
let errorOutput = '';
|
|
12849
|
-
const forward = (chunk) => {
|
|
12850
|
-
const text = chunk.toString();
|
|
12851
|
-
if (debug) {
|
|
12852
|
-
process.stderr.write(text);
|
|
12853
|
-
}
|
|
12854
|
-
errorOutput = `${errorOutput}${text}`.slice(-65536);
|
|
12855
|
-
};
|
|
12856
|
-
child.stdout.on('data', forward);
|
|
12857
|
-
child.stderr.on('data', forward);
|
|
12858
|
-
child.once('error', reject);
|
|
12859
|
-
child.once('close', code => {
|
|
12860
|
-
if (code === 0) {
|
|
12861
|
-
resolvePromise();
|
|
12862
|
-
return;
|
|
12863
|
-
}
|
|
12864
|
-
reject(new Error(
|
|
12865
|
-
`Packaging process exited with code ${String(code)}${errorOutput ? `\n${errorOutput.trim()}` : ''}`,
|
|
12866
|
-
));
|
|
12867
|
-
});
|
|
12868
|
-
});
|
|
12869
|
-
|
|
12870
|
-
|
|
12871
|
-
|
|
12872
|
-
|
|
12873
|
-
|
|
12874
|
-
|
|
12875
|
-
|
|
12876
|
-
|
|
12877
|
-
|
|
12878
|
-
|
|
12879
|
-
|
|
12880
|
-
|
|
12881
|
-
const createSourcePackageArchive = async (
|
|
12882
|
-
sourceRoot,
|
|
12883
|
-
applicationType = 'service',
|
|
12884
|
-
debug = false,
|
|
12885
|
-
) => {
|
|
12886
|
-
const tempDirectory = await promises.mkdtemp(node_path.join(node_os.tmpdir(), 'coze-deploy-source-'));
|
|
12887
|
-
const outputPath = node_path.join(tempDirectory, 'source.tar.gz');
|
|
12888
|
-
try {
|
|
12889
|
-
await runPackageScript(
|
|
12890
|
-
[sourceRoot, outputPath, ...(applicationType === 'pages' ? ['--pages'] : [])],
|
|
12891
|
-
debug,
|
|
12892
|
-
);
|
|
12893
|
-
const info = await promises.stat(outputPath);
|
|
12894
|
-
if (info.size === 0) {
|
|
12895
|
-
throw new CliError('Source package is empty.', 'SOURCE_PACKAGE_FAILED');
|
|
12896
|
-
}
|
|
12897
|
-
return {
|
|
12898
|
-
path: outputPath,
|
|
12899
|
-
sizeBytes: info.size,
|
|
12900
|
-
cleanup: () => promises.rm(tempDirectory, { recursive: true, force: true }),
|
|
12901
|
-
};
|
|
12902
|
-
} catch (error) {
|
|
12903
|
-
await promises.rm(tempDirectory, { recursive: true, force: true });
|
|
12904
|
-
if (error instanceof CliError) {
|
|
12905
|
-
throw error;
|
|
12906
|
-
}
|
|
12907
|
-
throw new CliError(
|
|
12908
|
-
`Unable to package local source: ${error instanceof Error ? error.message : String(error)}`,
|
|
12909
|
-
'SOURCE_PACKAGE_FAILED',
|
|
12910
|
-
);
|
|
12911
|
-
}
|
|
12912
|
-
};
|
|
12913
|
-
|
|
12914
|
-
const UPLOAD_SESSION_FILENAME = '.coze-deploy-upload.json';
|
|
12915
|
-
|
|
12916
|
-
|
|
12917
|
-
|
|
12918
|
-
|
|
12919
|
-
|
|
12920
|
-
|
|
12921
|
-
|
|
12922
|
-
|
|
12923
|
-
|
|
12924
|
-
|
|
12925
|
-
|
|
12926
|
-
const isUploadSession = (value) => {
|
|
12927
|
-
if (!value || typeof value !== 'object') {
|
|
12928
|
-
return false;
|
|
12929
|
-
}
|
|
12930
|
-
const session = value ;
|
|
12931
|
-
return typeof session.idempotencyKey === 'string' &&
|
|
12932
|
-
typeof session.createdAt === 'number' &&
|
|
12933
|
-
typeof session.sourcePackageSizeBytes === 'number' &&
|
|
12934
|
-
Boolean(session.request && typeof session.request === 'object');
|
|
12935
|
-
};
|
|
12936
|
-
|
|
12937
|
-
const readUploadSession = async (sourceRoot) => {
|
|
12938
|
-
try {
|
|
12939
|
-
const parsed = safeJsonParse(
|
|
12940
|
-
await promises.readFile(node_path.join(sourceRoot, UPLOAD_SESSION_FILENAME), 'utf8'),
|
|
12941
|
-
undefined,
|
|
12942
|
-
);
|
|
12943
|
-
return isUploadSession(parsed) ? parsed : undefined;
|
|
12944
|
-
} catch (error) {
|
|
12945
|
-
if ((error ).code === 'ENOENT') {
|
|
12946
|
-
return undefined;
|
|
12947
|
-
}
|
|
12948
|
-
throw error;
|
|
12949
|
-
}
|
|
12950
|
-
};
|
|
12951
|
-
|
|
12952
|
-
const writeUploadSession = async (sourceRoot, session) => {
|
|
12953
|
-
const path = node_path.join(sourceRoot, UPLOAD_SESSION_FILENAME);
|
|
12954
|
-
const tempPath = node_path.join(node_path.dirname(path), `.coze-deploy-upload-${node_crypto.randomUUID()}.tmp`);
|
|
12955
|
-
await promises.mkdir(node_path.dirname(path), { recursive: true });
|
|
12956
|
-
try {
|
|
12957
|
-
await promises.writeFile(tempPath, `${JSON.stringify(session, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
12958
|
-
await promises.rename(tempPath, path);
|
|
12959
|
-
} finally {
|
|
12960
|
-
await promises.rm(tempPath, { force: true });
|
|
12961
|
-
}
|
|
12962
|
-
};
|
|
12963
|
-
|
|
12964
|
-
const removeUploadSession = async (sourceRoot) => {
|
|
12965
|
-
await promises.rm(node_path.join(sourceRoot, UPLOAD_SESSION_FILENAME), { force: true });
|
|
12966
|
-
};
|
|
12967
|
-
|
|
12968
|
-
function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
12969
|
-
const INLINE_SOURCE_PACKAGE_MAX_BYTES = 1024 * 1024;
|
|
12970
|
-
const PRE_DEPLOY_SESSION_TTL_MS = 2 * 60 * 60 * 1000;
|
|
12971
|
-
|
|
12972
|
-
const uploadFile = async (
|
|
12973
|
-
uploadUrl,
|
|
12974
|
-
requiredHeaders,
|
|
12975
|
-
archive,
|
|
12976
|
-
) => {
|
|
12977
|
-
const uploadRequest = {
|
|
12978
|
-
method: 'PUT',
|
|
12979
|
-
headers: requiredHeaders,
|
|
12980
|
-
body: node_stream.Readable.toWeb(node_fs.createReadStream(archive.path)) ,
|
|
12981
|
-
duplex: 'half',
|
|
12982
|
-
};
|
|
12983
|
-
const response = await fetch(uploadUrl, uploadRequest);
|
|
12984
|
-
if (!response.ok) {
|
|
12985
|
-
throw new CliError(`Direct artifact upload failed: ${response.status} ${response.statusText}`, 'ARTIFACT_UPLOAD_FAILED');
|
|
12986
|
-
}
|
|
12987
|
-
};
|
|
12988
|
-
|
|
12989
|
-
const createDeploymentWithSourcePackage = async (
|
|
12990
|
-
client,
|
|
12991
|
-
request,
|
|
12992
|
-
archive,
|
|
12993
|
-
sourceRoot,
|
|
12994
|
-
) => {
|
|
12995
|
-
if (archive.sizeBytes <= INLINE_SOURCE_PACKAGE_MAX_BYTES) {
|
|
12996
|
-
const content = await promises.readFile(archive.path);
|
|
12997
|
-
return {
|
|
12998
|
-
uploadMode: 'inline' ,
|
|
12999
|
-
result: await client.createDeployHistory({ ...request, source_package_base64: content.toString('base64') }),
|
|
13000
|
-
};
|
|
13001
|
-
}
|
|
13002
|
-
|
|
13003
|
-
const savedSession = await readUploadSession(sourceRoot);
|
|
13004
|
-
let retryRequest = request;
|
|
13005
|
-
let reconciledSession = savedSession;
|
|
13006
|
-
if (_optionalChain$1([savedSession, 'optionalAccess', _ => _.appId]) && savedSession.deployHistoryId) {
|
|
13007
|
-
const history = await client.getDeployHistory({
|
|
13008
|
-
app_id: savedSession.appId,
|
|
13009
|
-
deploy_history_id: savedSession.deployHistoryId,
|
|
13010
|
-
});
|
|
13011
|
-
switch (history.status) {
|
|
13012
|
-
case DEPLOY_STATUS.preDeploy:
|
|
13013
|
-
// The server is authoritative for the session lifetime. Reuse the
|
|
13014
|
-
// original key even if the local two-hour clock is close to expiry;
|
|
13015
|
-
// pre_upload will either refresh the URL or release an expired slot.
|
|
13016
|
-
break;
|
|
13017
|
-
case DEPLOY_STATUS.pending:
|
|
13018
|
-
case DEPLOY_STATUS.running:
|
|
13019
|
-
case DEPLOY_STATUS.interrupted:
|
|
13020
|
-
case DEPLOY_STATUS.succeeded:
|
|
13021
|
-
// The previous create request was accepted but its response may have
|
|
13022
|
-
// been lost. Do not upload or create another deployment.
|
|
13023
|
-
await removeUploadSession(sourceRoot);
|
|
13024
|
-
return {
|
|
13025
|
-
uploadMode: 'direct' ,
|
|
13026
|
-
result: {
|
|
13027
|
-
app_id: savedSession.appId,
|
|
13028
|
-
deploy_history_id: savedSession.deployHistoryId,
|
|
13029
|
-
status: history.status,
|
|
13030
|
-
version: typeof history.version === 'number' ? history.version : undefined,
|
|
13031
|
-
},
|
|
13032
|
-
};
|
|
13033
|
-
case DEPLOY_STATUS.failed:
|
|
13034
|
-
case DEPLOY_STATUS.canceled:
|
|
13035
|
-
// The reserved history can no longer be claimed. Start a new upload
|
|
13036
|
-
// against the Application that pre_upload already created.
|
|
13037
|
-
await removeUploadSession(sourceRoot);
|
|
13038
|
-
reconciledSession = undefined;
|
|
13039
|
-
retryRequest = {
|
|
13040
|
-
...request,
|
|
13041
|
-
project_id: undefined,
|
|
13042
|
-
app_id: savedSession.appId,
|
|
13043
|
-
};
|
|
13044
|
-
break;
|
|
13045
|
-
default:
|
|
13046
|
-
throw new CliError(
|
|
13047
|
-
`Unable to reconcile pre-deploy history ${savedSession.deployHistoryId}: unknown status ${String(history.status)}.`,
|
|
13048
|
-
'INVALID_RESPONSE',
|
|
13049
|
-
);
|
|
13050
|
-
}
|
|
13051
|
-
}
|
|
13052
|
-
const liveSavedSession = reconciledSession && (
|
|
13053
|
-
reconciledSession.appId && reconciledSession.deployHistoryId ||
|
|
13054
|
-
Date.now() - reconciledSession.createdAt < PRE_DEPLOY_SESSION_TTL_MS
|
|
13055
|
-
)
|
|
13056
|
-
? reconciledSession
|
|
13057
|
-
: undefined;
|
|
13058
|
-
if (liveSavedSession && liveSavedSession.sourcePackageSizeBytes !== archive.sizeBytes) {
|
|
13059
|
-
throw new CliError(
|
|
13060
|
-
'A different source package is waiting for upload. Cancel that deployment or wait for its two-hour session to expire.',
|
|
13061
|
-
'PRE_DEPLOY_SOURCE_CHANGED',
|
|
13062
|
-
);
|
|
13063
|
-
}
|
|
13064
|
-
if (reconciledSession && !liveSavedSession) {
|
|
13065
|
-
await removeUploadSession(sourceRoot);
|
|
13066
|
-
}
|
|
13067
|
-
const resumableSession = liveSavedSession;
|
|
13068
|
-
const session = resumableSession || {
|
|
13069
|
-
idempotencyKey: node_crypto.randomUUID(),
|
|
13070
|
-
createdAt: Date.now(),
|
|
13071
|
-
sourcePackageSizeBytes: archive.sizeBytes,
|
|
13072
|
-
request: retryRequest,
|
|
13073
|
-
};
|
|
13074
|
-
// Persist before preDeployUpload: if the server creates PreDeploy but the response is lost,
|
|
13075
|
-
// the next CLI run must reuse the same idempotency key.
|
|
13076
|
-
await writeUploadSession(sourceRoot, session);
|
|
13077
|
-
const preDeploy = await client.preDeployUpload({
|
|
13078
|
-
...session.request,
|
|
13079
|
-
source_package_size_bytes: String(archive.sizeBytes),
|
|
13080
|
-
idempotency_key: session.idempotencyKey,
|
|
13081
|
-
});
|
|
13082
|
-
await writeUploadSession(sourceRoot, {
|
|
13083
|
-
...session,
|
|
13084
|
-
appId: preDeploy.app_id,
|
|
13085
|
-
deployHistoryId: preDeploy.deploy_history_id,
|
|
13086
|
-
uploadReceipt: preDeploy.upload_receipt,
|
|
13087
|
-
});
|
|
13088
|
-
await uploadFile(preDeploy.upload_url, preDeploy.required_headers || {}, archive);
|
|
13089
|
-
const result = await client.createDeployHistory({
|
|
13090
|
-
...session.request,
|
|
13091
|
-
project_id: undefined,
|
|
13092
|
-
app_id: preDeploy.app_id,
|
|
13093
|
-
pre_deploy_history_id: preDeploy.deploy_history_id,
|
|
13094
|
-
upload_receipt: preDeploy.upload_receipt,
|
|
13095
|
-
source_package_size_bytes: String(archive.sizeBytes),
|
|
13096
|
-
});
|
|
13097
|
-
await removeUploadSession(sourceRoot);
|
|
13098
|
-
return { uploadMode: 'direct' , result };
|
|
13099
|
-
};
|
|
13100
|
-
|
|
13101
|
-
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
13102
|
-
const SUPPORTED_MINIPROGRAM_CONNECTOR_IDS = new Set(['10000127', '10000126']);
|
|
13103
|
-
const collectConnectorId = (value, previous) => [
|
|
13104
|
-
...previous,
|
|
13105
|
-
value,
|
|
13106
|
-
];
|
|
13107
|
-
|
|
13108
|
-
const getConnectorConfigs = (connectorIds) =>
|
|
13109
|
-
(connectorIds || []).map(connectorId => {
|
|
13110
|
-
if (!SUPPORTED_MINIPROGRAM_CONNECTOR_IDS.has(connectorId)) {
|
|
13111
|
-
throw new CliError(
|
|
13112
|
-
`Unsupported connector ID ${connectorId}; expected 10000127 (WeChat) or 10000126 (Douyin).`,
|
|
13113
|
-
'INVALID_CONNECTOR_ID',
|
|
13114
|
-
);
|
|
13115
|
-
}
|
|
13116
|
-
return { connector_id: connectorId };
|
|
13117
|
-
});
|
|
13118
|
-
|
|
13119
|
-
// Keep deployment option and output contracts together for auditing against the V2 IDL.
|
|
13120
|
-
// eslint-disable-next-line @coze-arch/max-line-per-function -- keep V2 deployment contracts together
|
|
13121
|
-
const registerDeploy = (code) => {
|
|
13122
|
-
const deploy = code
|
|
13123
|
-
.command('deploy')
|
|
13124
|
-
.description('Deploy an application using deployment V2')
|
|
13125
|
-
.option('--source-root <sourceRoot>', 'Local source root', '.')
|
|
13126
|
-
.option('--project-id <projectId>', 'Project ID for the first deployment')
|
|
13127
|
-
.option('--app-id <appId>', 'Application ID')
|
|
13128
|
-
.option(
|
|
13129
|
-
'--application-type <type>',
|
|
13130
|
-
'Deployment application type: service, pages, or mini_program',
|
|
13131
|
-
)
|
|
13132
|
-
.option('-n, --name <name>', 'Application name for the first deployment')
|
|
13133
|
-
.option('--message <message>', 'Deployment message')
|
|
13134
|
-
.option(
|
|
13135
|
-
'--connector-id <connectorId>',
|
|
13136
|
-
'Mini-program channel: 10000127 (WeChat) or 10000126 (Douyin); repeatable',
|
|
13137
|
-
collectConnectorId,
|
|
13138
|
-
[],
|
|
13139
|
-
)
|
|
13140
|
-
.option('--wait', 'Wait for deployment completion')
|
|
13141
|
-
.option('--yes', 'Confirm deployment')
|
|
13142
|
-
// eslint-disable-next-line @coze-arch/max-line-per-function -- deployment orchestration is one auditable flow
|
|
13143
|
-
.action(async (options, command) => {
|
|
13144
|
-
const runtime = await getRuntime(command);
|
|
13145
|
-
const sourceRoot = node_path.resolve(runtime.cwd, options.sourceRoot || '.');
|
|
13146
|
-
const requestedApplicationType = parseApplicationType(options.applicationType);
|
|
13147
|
-
runtime.output.debug(`[deploy] Reading local project: ${sourceRoot}`);
|
|
13148
|
-
const localContext =
|
|
13149
|
-
await readDeployLocalContext(
|
|
13150
|
-
sourceRoot,
|
|
13151
|
-
requestedApplicationType,
|
|
13152
|
-
options.appId,
|
|
13153
|
-
runtime.client,
|
|
13154
|
-
);
|
|
13155
|
-
const { commitHash, isPagesDeployment } = localContext;
|
|
13156
|
-
let { metadata } = localContext;
|
|
13157
|
-
const deploymentName = _nullishCoalesce(options.name, () => ( metadata.name));
|
|
13158
|
-
let projectId = options.projectId || metadata.projectId;
|
|
13159
|
-
let appId = options.appId || metadata.appId;
|
|
13160
|
-
const appIdFromCoze = Boolean(metadata.appId && !options.appId);
|
|
13161
|
-
let projectCreated = false;
|
|
13162
|
-
let linkedApplicationType;
|
|
13163
|
-
if (appId) {
|
|
13164
|
-
const linkedApplication = await runtime.client.getApplication(appId);
|
|
13165
|
-
linkedApplicationType = linkedApplication.application_type;
|
|
13166
|
-
const linkedProjectId = linkedApplication.project_id;
|
|
13167
|
-
if (!options.appId && projectId && linkedProjectId && projectId !== linkedProjectId) {
|
|
13168
|
-
throw new CliError(
|
|
13169
|
-
`Project ${projectId} does not own application ${appId}; it belongs to project ${linkedProjectId}.`,
|
|
13170
|
-
'PROJECT_ID_CONFLICT',
|
|
13171
|
-
);
|
|
13172
|
-
}
|
|
13173
|
-
if (options.appId && linkedProjectId) {
|
|
13174
|
-
projectId = linkedProjectId;
|
|
13175
|
-
} else {
|
|
13176
|
-
projectId ||= linkedProjectId;
|
|
13177
|
-
}
|
|
13178
|
-
if (!projectId) {
|
|
13179
|
-
throw new CliError(
|
|
13180
|
-
`Application ${appId} did not return its associated project_id.`,
|
|
13181
|
-
'INVALID_RESPONSE',
|
|
13182
|
-
);
|
|
13183
|
-
}
|
|
13184
|
-
const inferredApplicationType = linkedApplicationType === 'pages'
|
|
13185
|
-
? 'pages'
|
|
13186
|
-
: inferApplicationTypeFromProjectType(metadata.projectType);
|
|
13187
|
-
const targetApplicationType = requestedApplicationType || inferredApplicationType;
|
|
13188
|
-
if (appIdFromCoze && targetApplicationType && linkedApplicationType !== targetApplicationType) {
|
|
13189
|
-
runtime.output.warn(
|
|
13190
|
-
`The linked application ${appId} is ${linkedApplicationType}, but ${targetApplicationType} is required. A new application will be created and written to .coze.`,
|
|
13191
|
-
);
|
|
13192
|
-
appId = undefined;
|
|
13193
|
-
}
|
|
13194
|
-
}
|
|
13195
|
-
if (!projectId) {
|
|
13196
|
-
runtime.output.debug('[deploy] Creating a dedicated deployment project...');
|
|
13197
|
-
const spaceId = await resolveDeploymentSpaceId(runtime);
|
|
13198
|
-
const project = await runtime.client.createDeploymentProject({
|
|
13199
|
-
space_id: spaceId,
|
|
13200
|
-
user_query: deploymentName || 'CLI deployment project',
|
|
13201
|
-
project_type: resolveCreationProjectType(metadata.projectType),
|
|
13202
|
-
create_source: 'cli',
|
|
13203
|
-
project_settings: { project_symbol: 'v3.5' },
|
|
13204
|
-
});
|
|
13205
|
-
projectId = project.project_id;
|
|
13206
|
-
projectCreated = true;
|
|
13207
|
-
}
|
|
13208
|
-
if (metadata.projectId !== projectId) {
|
|
13209
|
-
metadata = await writeProjectBinding(sourceRoot, { projectId });
|
|
13210
|
-
}
|
|
13211
|
-
runtime.output.debug(`[deploy] Using project ${projectId} from ${projectCreated ? 'new project' : options.projectId ? '--project-id' : appId ? 'application binding' : '.coze'}`);
|
|
13212
|
-
const cozeFileContent = metadata.cozeFileContent;
|
|
13213
|
-
runtime.output.debug('[deploy] Loading deployment configuration...');
|
|
13214
|
-
const serverConfig = await runtime.client.getDeployConfig({
|
|
13215
|
-
...(appId ? { app_id: appId } : { project_id: projectId }),
|
|
13216
|
-
commit_hash: commitHash,
|
|
13217
|
-
...(isPagesDeployment ? { application_type: 'pages' } : {}),
|
|
13218
|
-
...(cozeFileContent ? { coze_file_content: cozeFileContent } : {}),
|
|
13219
|
-
});
|
|
13220
|
-
const config = withRequestedApplicationType(
|
|
13221
|
-
serverConfig,
|
|
13222
|
-
requestedApplicationType,
|
|
13223
|
-
Boolean(appId),
|
|
13224
|
-
);
|
|
13225
|
-
const applicationType = config.application_type;
|
|
13226
|
-
const connectorConfigs = getConnectorConfigs(options.connectorId);
|
|
13227
|
-
if (!options.yes) {
|
|
13228
|
-
runtime.output.debug('[deploy] Preflight complete; confirmation is required.');
|
|
13229
|
-
runtime.output.print({
|
|
13230
|
-
confirmation_required: true,
|
|
13231
|
-
app_id: appId,
|
|
13232
|
-
project_id: projectId,
|
|
13233
|
-
application_type: applicationType,
|
|
13234
|
-
commit_hash: commitHash,
|
|
13235
|
-
source_root: sourceRoot,
|
|
13236
|
-
deploy_config: config.deploy_config,
|
|
13237
|
-
current_version: config.current_version,
|
|
13238
|
-
next_version: config.next_version,
|
|
13239
|
-
risks: config.risk_list || [],
|
|
13240
|
-
...(!appId && deploymentName ? { name: deploymentName } : {}),
|
|
13241
|
-
message: options.message,
|
|
13242
|
-
lane: runtime.globalOptions.lane || runtime.config.xTTEnv,
|
|
13243
|
-
});
|
|
13244
|
-
return;
|
|
13245
|
-
}
|
|
13246
|
-
let encryptEnvVariable;
|
|
13247
|
-
if (applicationType !== 'pages') {
|
|
13248
|
-
runtime.output.debug('[deploy] Loading and encrypting online environment variables...');
|
|
13249
|
-
const onlineEnvironment = appId
|
|
13250
|
-
? await runtime.client.getOnlineEnvironment(appId)
|
|
13251
|
-
: undefined;
|
|
13252
|
-
if (onlineEnvironment && onlineEnvironment.snapshot_status >= 3) {
|
|
13253
|
-
throw new CliError(
|
|
13254
|
-
onlineEnvironment.status_message ||
|
|
13255
|
-
'The current online environment snapshot is unavailable.',
|
|
13256
|
-
'ONLINE_ENVIRONMENT_UNAVAILABLE',
|
|
13257
|
-
);
|
|
13258
|
-
}
|
|
13259
|
-
const envSecrets = (_optionalChain([onlineEnvironment, 'optionalAccess', _ => _.variables]) || [])
|
|
13260
|
-
.filter(variable => variable.source === 'user')
|
|
13261
|
-
.map(variable => ({
|
|
13262
|
-
secret_id: '',
|
|
13263
|
-
secret_key: variable.key,
|
|
13264
|
-
secret_val: variable.value,
|
|
13265
|
-
secret_type: 'user_custom' ,
|
|
13266
|
-
}));
|
|
13267
|
-
const encrypted = await runtime.client.encryptProjectSecret(projectId, envSecrets);
|
|
13268
|
-
encryptEnvVariable = encrypted.sealed_secrets;
|
|
13269
|
-
if (!encryptEnvVariable) {
|
|
13270
|
-
throw new CliError(
|
|
13271
|
-
'The project secret encryption API returned no sealed_secrets.',
|
|
13272
|
-
'INVALID_RESPONSE',
|
|
13273
|
-
);
|
|
13274
|
-
}
|
|
13275
|
-
}
|
|
13276
|
-
runtime.output.debug(
|
|
13277
|
-
`[deploy] Building and packaging ${applicationType} artifact...`,
|
|
13278
|
-
);
|
|
13279
|
-
const sourcePackage = await createSourcePackageArchive(
|
|
13280
|
-
sourceRoot,
|
|
13281
|
-
applicationType,
|
|
13282
|
-
runtime.globalOptions.debug,
|
|
13283
|
-
);
|
|
13284
|
-
runtime.output.debug(
|
|
13285
|
-
`[deploy] Package ready: ${String(sourcePackage.sizeBytes)} bytes`,
|
|
13286
|
-
);
|
|
13287
|
-
runtime.output.debug('[deploy] Uploading package and creating deployment...');
|
|
13288
|
-
const deploymentRequest = {
|
|
13289
|
-
...(appId ? { app_id: appId } : { project_id: projectId }),
|
|
13290
|
-
application_type: applicationType,
|
|
13291
|
-
commit_hash: commitHash,
|
|
13292
|
-
...(!appId
|
|
13293
|
-
? { name: deploymentName, source_root: sourceRoot }
|
|
13294
|
-
: {}),
|
|
13295
|
-
is_sync_db_to_prod: false,
|
|
13296
|
-
table_sync_configs: [],
|
|
13297
|
-
connector_configs: connectorConfigs,
|
|
13298
|
-
...(cozeFileContent ? { coze_file_content: cozeFileContent } : {}),
|
|
13299
|
-
...(encryptEnvVariable
|
|
13300
|
-
? { encrypt_env_variable: encryptEnvVariable }
|
|
13301
|
-
: {}),
|
|
13302
|
-
...getCreateDeployConfig(config),
|
|
13303
|
-
};
|
|
13304
|
-
let deployment;
|
|
13305
|
-
try {
|
|
13306
|
-
deployment = await createDeploymentWithSourcePackage(runtime.client, deploymentRequest, sourcePackage, sourceRoot);
|
|
13307
|
-
} finally {
|
|
13308
|
-
await sourcePackage.cleanup();
|
|
13309
|
-
}
|
|
13310
|
-
const { result } = deployment;
|
|
13311
|
-
const deployHistoryId = resolveDeployHistoryId(
|
|
13312
|
-
result.deploy_history_id,
|
|
13313
|
-
result.prev_deploy_history_id,
|
|
13314
|
-
);
|
|
13315
|
-
if (!deployHistoryId) {
|
|
13316
|
-
throw new CliError('Deployment response returned no deploy_history_id.', 'INVALID_RESPONSE');
|
|
13317
|
-
}
|
|
13318
|
-
if (metadata.appId !== result.app_id || metadata.projectId !== projectId) {
|
|
13319
|
-
await writeProjectBinding(sourceRoot, {
|
|
13320
|
-
projectId,
|
|
13321
|
-
appId: result.app_id,
|
|
13322
|
-
});
|
|
13323
|
-
if (!appId) {
|
|
13324
|
-
runtime.output.warn(`Created application ${result.app_id} and saved it to .coze.`);
|
|
13325
|
-
}
|
|
13326
|
-
}
|
|
13327
|
-
if (options.wait) {
|
|
13328
|
-
runtime.output.debug('[deploy] Deployment accepted; waiting for completion...');
|
|
13329
|
-
} else {
|
|
13330
|
-
runtime.output.debug('[deploy] Deployment accepted.');
|
|
13331
|
-
}
|
|
13332
|
-
const history = options.wait
|
|
13333
|
-
? await pollHistory(command, result.app_id, deployHistoryId)
|
|
13334
|
-
: undefined;
|
|
13335
|
-
runtime.output.print({
|
|
13336
|
-
app_id: result.app_id,
|
|
13337
|
-
deploy_history_id: deployHistoryId,
|
|
13338
|
-
version: result.version,
|
|
13339
|
-
commit_hash: commitHash,
|
|
13340
|
-
status: getDeployStatusText(_nullishCoalesce(_optionalChain([history, 'optionalAccess', _2 => _2.status]), () => ( result.status))),
|
|
13341
|
-
source_package_size_bytes: sourcePackage.sizeBytes,
|
|
13342
|
-
upload_mode: deployment.uploadMode,
|
|
13343
|
-
local_link: appId && !projectCreated ? 'unchanged' : 'written',
|
|
13344
|
-
mobile_artifact_list: _optionalChain([history, 'optionalAccess', _3 => _3.mobile_artifact_list]) || [],
|
|
13345
|
-
});
|
|
13346
|
-
});
|
|
13347
|
-
|
|
13348
|
-
registerDeployReadCommands(deploy);
|
|
13349
|
-
|
|
13350
|
-
deploy
|
|
13351
|
-
.command('cancel')
|
|
13352
|
-
.requiredOption('--deploy-id <deployId>', 'Deployment history ID')
|
|
13353
|
-
.option('--app-id <appId>', 'Application ID')
|
|
13354
|
-
.option('--yes', 'Confirm cancellation')
|
|
13355
|
-
.action(async (options, command) => {
|
|
13356
|
-
const parentOptions = getDeployParentOptions(command);
|
|
13357
|
-
if (!options.yes && !parentOptions.yes) {
|
|
13358
|
-
throw new CliError('Pass --yes to cancel deployment.', 'CONFIRMATION_REQUIRED');
|
|
13359
|
-
}
|
|
13360
|
-
const runtime = await getRuntime(command);
|
|
13361
|
-
const appId = await requireAppId(runtime.cwd, getDeployAppIdOption(options, command));
|
|
13362
|
-
await runtime.client.cancelDeployHistory({
|
|
13363
|
-
app_id: appId,
|
|
13364
|
-
deploy_history_id: options.deployId || '',
|
|
13365
|
-
});
|
|
13366
|
-
runtime.output.print({ app_id: appId, canceled: true });
|
|
13367
|
-
});
|
|
13368
|
-
|
|
13369
|
-
deploy
|
|
13370
|
-
.command('rollback')
|
|
13371
|
-
.requiredOption('--deploy-id <deployId>', 'Target deployment history ID')
|
|
13372
|
-
.option('--app-id <appId>', 'Application ID')
|
|
13373
|
-
.option('--rollback-database', 'Rollback database')
|
|
13374
|
-
.option('--yes', 'Confirm rollback')
|
|
13375
|
-
.action(async (options, command) => {
|
|
13376
|
-
const parentOptions = getDeployParentOptions(command);
|
|
13377
|
-
if (!options.yes && !parentOptions.yes) {
|
|
13378
|
-
throw new CliError('Pass --yes to rollback.', 'CONFIRMATION_REQUIRED');
|
|
13379
|
-
}
|
|
13380
|
-
const runtime = await getRuntime(command);
|
|
13381
|
-
const appId = await requireAppId(runtime.cwd, getDeployAppIdOption(options, command));
|
|
13382
|
-
const data = await runtime.client.rollbackDeployHistory({
|
|
13383
|
-
app_id: appId,
|
|
13384
|
-
target_deploy_history_id: options.deployId || '',
|
|
13385
|
-
rollback_database: _nullishCoalesce(options.rollbackDatabase, () => ( false)),
|
|
13386
|
-
});
|
|
13387
|
-
runtime.output.print({ app_id: appId, ...data });
|
|
13388
|
-
});
|
|
13389
|
-
|
|
13390
|
-
// stop 不可逆(删函数 → Stopped,只能重新部署),pause 可逆(→ Paused,resume 能推回 Ready)。
|
|
13391
|
-
const applicationActions = {
|
|
13392
|
-
stop: (client, appId) => client.stopApplication(appId),
|
|
13393
|
-
resume: (client, appId) => client.resumeApplication(appId),
|
|
13394
|
-
pause: (client, appId) => client.pauseApplication(appId),
|
|
13395
|
-
} ;
|
|
13396
|
-
|
|
13397
|
-
for (const action of Object.keys(applicationActions) ) {
|
|
13398
|
-
deploy
|
|
13399
|
-
.command(action)
|
|
13400
|
-
.option('--app-id <appId>', 'Application ID')
|
|
13401
|
-
.option('--yes', `Confirm ${action}`)
|
|
13402
|
-
.action(async (options, command) => {
|
|
13403
|
-
const parentOptions = getDeployParentOptions(command);
|
|
13404
|
-
if (!options.yes && !parentOptions.yes) {
|
|
13405
|
-
throw new CliError(`Pass --yes to ${action}.`, 'CONFIRMATION_REQUIRED');
|
|
13406
|
-
}
|
|
13407
|
-
const runtime = await getRuntime(command);
|
|
13408
|
-
const appId = await requireAppId(runtime.cwd, getDeployAppIdOption(options, command));
|
|
13409
|
-
await applicationActions[action](runtime.client, appId);
|
|
13410
|
-
runtime.output.print({ app_id: appId, action, success: true });
|
|
13411
|
-
});
|
|
13412
|
-
}
|
|
13413
|
-
|
|
13414
|
-
deploy
|
|
13415
|
-
.command('logs')
|
|
13416
|
-
.option('--app-id <appId>', 'Application ID')
|
|
13417
|
-
.option('--start-time <startTime>', 'Start time in milliseconds')
|
|
13418
|
-
.option('--end-time <endTime>', 'End time in milliseconds')
|
|
13419
|
-
.option('--limit <limit>', 'Page size')
|
|
13420
|
-
.option('--cursor <cursor>', 'Pagination cursor')
|
|
13421
|
-
.option('--query <query>', 'Log keyword')
|
|
13422
|
-
.option('--level <level>', 'all, info, warn, or error')
|
|
13423
|
-
.action(async (options, command) => {
|
|
13424
|
-
const runtime = await getRuntime(command);
|
|
13425
|
-
const appId = await requireAppId(runtime.cwd, getDeployAppIdOption(options, command));
|
|
13426
|
-
runtime.output.print(
|
|
13427
|
-
await runtime.client.searchRuntimeLog({
|
|
13428
|
-
app_id: appId,
|
|
13429
|
-
start_time: options.startTime,
|
|
13430
|
-
end_time: options.endTime,
|
|
13431
|
-
limit: options.limit,
|
|
13432
|
-
cursor: options.cursor,
|
|
13433
|
-
query: options.query,
|
|
13434
|
-
level: options.level,
|
|
13435
|
-
}),
|
|
13436
|
-
);
|
|
13437
|
-
});
|
|
13438
|
-
|
|
13439
|
-
deploy
|
|
13440
|
-
.command('build-log')
|
|
13441
|
-
.requiredOption('--deploy-id <deployId>', 'Deployment history ID')
|
|
13442
|
-
.option('--key <key>', 'Deployment log key; inferred when the deployment has one log')
|
|
13443
|
-
.option('--app-id <appId>', 'Application ID')
|
|
13444
|
-
.action(async (options, command) => {
|
|
13445
|
-
const runtime = await getRuntime(command);
|
|
13446
|
-
const appId = await requireAppId(runtime.cwd, getDeployAppIdOption(options, command));
|
|
13447
|
-
let key = _optionalChain([options, 'access', _4 => _4.key, 'optionalAccess', _5 => _5.trim, 'call', _6 => _6()]);
|
|
13448
|
-
if (!key) {
|
|
13449
|
-
const history = await runtime.client.getDeployHistory({
|
|
13450
|
-
app_id: appId,
|
|
13451
|
-
deploy_history_id: options.deployId || '',
|
|
13452
|
-
});
|
|
13453
|
-
const keys = getDeployLogKeys(history);
|
|
13454
|
-
if (keys.length === 0) {
|
|
13455
|
-
throw new CliError(
|
|
13456
|
-
'The deployment has no build log key yet. Retry after deployment stages start.',
|
|
13457
|
-
'BUILD_LOG_NOT_READY',
|
|
13458
|
-
);
|
|
13459
|
-
}
|
|
13460
|
-
if (keys.length > 1) {
|
|
13461
|
-
throw new CliError(
|
|
13462
|
-
'The deployment has multiple build logs. Pass --key using deploy status output.',
|
|
13463
|
-
'BUILD_LOG_KEY_REQUIRED',
|
|
13464
|
-
{ available_keys: keys },
|
|
13465
|
-
);
|
|
13466
|
-
}
|
|
13467
|
-
key = keys[0];
|
|
13468
|
-
}
|
|
13469
|
-
if (!key) {
|
|
13470
|
-
throw new CliError('Deployment log key is empty.', 'BUILD_LOG_NOT_READY');
|
|
13471
|
-
}
|
|
13472
|
-
runtime.output.print(
|
|
13473
|
-
await runtime.client.getBuildLog({
|
|
13474
|
-
app_id: appId,
|
|
13475
|
-
deploy_history_id: options.deployId || '',
|
|
13476
|
-
key,
|
|
13477
|
-
}),
|
|
13478
|
-
);
|
|
13479
|
-
});
|
|
13480
|
-
|
|
13481
|
-
deploy
|
|
13482
|
-
.command('config')
|
|
13483
|
-
.option('--app-id <appId>', 'Application ID')
|
|
13484
|
-
.option('--commit-id <commitId>', 'Commit hash')
|
|
13485
|
-
.action(async (options, command) => {
|
|
13486
|
-
const runtime = await getRuntime(command);
|
|
13487
|
-
const appId = await requireAppId(runtime.cwd, getDeployAppIdOption(options, command));
|
|
13488
|
-
const application = await runtime.client.getApplication(appId);
|
|
13489
|
-
const commitHash = options.commitId || _optionalChain([application, 'access', _7 => _7.latest_deployment, 'optionalAccess', _8 => _8.commit_hash]);
|
|
13490
|
-
if (!commitHash) {
|
|
13491
|
-
throw new CliError('No deployment commit is available.', 'DEPLOYMENT_NOT_FOUND');
|
|
13492
|
-
}
|
|
13493
|
-
const applicationType = application.application_type;
|
|
13494
|
-
const cozeFileContent = applicationType === 'pages'
|
|
13495
|
-
? undefined
|
|
13496
|
-
: (await readProjectMetadata(node_path.resolve(runtime.cwd))).cozeFileContent;
|
|
13497
|
-
runtime.output.print(
|
|
13498
|
-
await runtime.client.getDeployConfig({
|
|
13499
|
-
app_id: appId,
|
|
13500
|
-
commit_hash: commitHash,
|
|
13501
|
-
...(applicationType === 'pages' ? { application_type: 'pages' } : {}),
|
|
13502
|
-
...(cozeFileContent ? { coze_file_content: cozeFileContent } : {}),
|
|
13503
|
-
}),
|
|
13504
|
-
);
|
|
13505
|
-
});
|
|
13506
|
-
};
|
|
13507
|
-
|
|
13508
|
-
const registerCommands = (program) => {
|
|
13509
|
-
registerAuth(program);
|
|
13510
|
-
registerContext(program);
|
|
13511
|
-
registerDoctor(program);
|
|
13512
|
-
const code = program.command('code').description('Deployment operations');
|
|
13513
|
-
registerApp(code);
|
|
13514
|
-
registerDeploy(code);
|
|
13515
|
-
registerDomain(code);
|
|
13516
|
-
registerEnv(code);
|
|
13517
|
-
registerMiniProgram(code);
|
|
13518
|
-
};
|
|
13519
|
-
|
|
13520
|
-
const configureDeployCommand = (command) => {
|
|
13521
|
-
markDeployCommand(command)
|
|
13522
|
-
.description('Deploy and manage Coze applications')
|
|
13523
|
-
.option('--format <format>', 'Output format: json or text', 'json')
|
|
13524
|
-
.option('--config <path>', 'Shared Coze CLI config path')
|
|
13525
|
-
.option('--org-id <id>', 'Override organization ID')
|
|
13526
|
-
.option('--space-id <id>', 'Override space ID')
|
|
13527
|
-
.option('--lane <name>', 'Route API requests to the specified PPE lane')
|
|
13528
|
-
.option('--api-base-url <url>', 'Override API base URL')
|
|
13529
|
-
.option('--debug', 'Print debug diagnostics')
|
|
13530
|
-
.showHelpAfterError()
|
|
13531
|
-
.exitOverride();
|
|
13532
|
-
registerCommands(command);
|
|
13533
|
-
return command;
|
|
13534
|
-
};
|
|
13535
|
-
|
|
13536
|
-
const registerCommand = (program) => {
|
|
13537
|
-
configureDeployCommand(program.command('deploy'));
|
|
13538
|
-
};
|
|
13539
|
-
|
|
13540
|
-
const readFormat = (argv) => {
|
|
13541
|
-
const index = argv.indexOf('--format');
|
|
13542
|
-
return index >= 0 && argv[index + 1] === 'text' ? 'text' : 'json';
|
|
13543
|
-
};
|
|
13544
|
-
|
|
13545
|
-
const handleDeployError = (error, argv = process.argv) => {
|
|
13546
|
-
if (
|
|
13547
|
-
error instanceof commander.CommanderError &&
|
|
13548
|
-
['commander.helpDisplayed', 'commander.version'].includes(error.code)
|
|
13549
|
-
) {
|
|
13550
|
-
return;
|
|
13551
|
-
}
|
|
13552
|
-
const output = new Output(readFormat(argv), argv.includes('--debug'));
|
|
13553
|
-
output.print({ error: toErrorPayload(error) });
|
|
13554
|
-
process.exitCode = error instanceof commander.CommanderError ? 4 : 1;
|
|
13555
|
-
};
|
|
13556
|
-
|
|
13557
|
-
const commands = [
|
|
13558
|
-
registerCommand$1,
|
|
13559
|
-
registerCommand$4,
|
|
13560
|
-
registerCommand$7,
|
|
13561
|
-
registerCommand$5,
|
|
13562
|
-
registerCommand$6,
|
|
13563
|
-
registerCommand$3,
|
|
13564
|
-
registerCommand$2,
|
|
13565
|
-
registerCommand,
|
|
13566
|
-
];
|
|
13567
|
-
|
|
13568
|
-
const main = async () => {
|
|
13569
|
-
// 初始化 Slardar 监控
|
|
13570
|
-
initSlardar();
|
|
13571
|
-
|
|
13572
|
-
// 监听未捕获的异常
|
|
13573
|
-
process.on('uncaughtException', async (error) => {
|
|
13574
|
-
reportError(error, {
|
|
13575
|
-
type: 'uncaughtException',
|
|
13576
|
-
context: 'global',
|
|
13577
|
-
});
|
|
13578
|
-
await flushSlardar();
|
|
13579
|
-
process.exit(1);
|
|
13580
|
-
});
|
|
13581
|
-
|
|
13582
|
-
// 监听未处理的 Promise rejection
|
|
13583
|
-
process.on('unhandledRejection', async (reason) => {
|
|
13584
|
-
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
13585
|
-
reportError(error, {
|
|
13586
|
-
type: 'unhandledRejection',
|
|
13587
|
-
context: 'global',
|
|
13588
|
-
});
|
|
13589
|
-
await flushSlardar();
|
|
13590
|
-
process.exit(1);
|
|
13591
|
-
});
|
|
13592
|
-
|
|
13593
|
-
const program = new commander.Command();
|
|
13594
|
-
|
|
13595
|
-
program
|
|
13596
|
-
.name('coze-dev')
|
|
13597
|
-
.description(
|
|
13598
|
-
'Coze Coding CLI - Project template engine for frontend stacks',
|
|
13599
|
-
)
|
|
13600
|
-
.version(packageJson.version);
|
|
13601
|
-
|
|
13602
|
-
commands.forEach(initCmd => initCmd(program));
|
|
13603
|
-
|
|
13604
|
-
// 在 help 输出中添加模板信息
|
|
13605
|
-
program.addHelpText('after', generateTemplatesHelpText());
|
|
10365
|
+
// 在 help 输出中添加模板信息
|
|
10366
|
+
program.addHelpText('after', generateTemplatesHelpText());
|
|
13606
10367
|
|
|
13607
10368
|
// 使用 parseAsync 等待命令执行完成
|
|
13608
|
-
|
|
13609
|
-
await program.parseAsync(process.argv);
|
|
13610
|
-
} catch (error) {
|
|
13611
|
-
if (process.argv[2] === 'deploy') {
|
|
13612
|
-
handleDeployError(error);
|
|
13613
|
-
} else {
|
|
13614
|
-
throw error;
|
|
13615
|
-
}
|
|
13616
|
-
}
|
|
10369
|
+
await program.parseAsync(process.argv);
|
|
13617
10370
|
|
|
13618
10371
|
// 统一在命令执行完成后 flush
|
|
13619
10372
|
// 注意:如果命令中调用了 process.exit(),不会执行到这里
|