@coze-arch/cli 0.0.36-alpha.0a210b → 0.0.36-alpha.102c95
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 +65 -114
- package/docs/deploy.md +10 -2
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +3 -2
- package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +1 -1
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +1 -1
- package/lib/__templates__/expo/client/metro.config.js +3 -1
- package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
- package/lib/__templates__/expo/server/package.json +2 -2
- package/lib/__templates__/expo/server/src/index.ts +1 -1
- package/lib/__templates__/expo/template.config.js +11 -2
- package/lib/__templates__/native-static/.coze +2 -0
- package/lib/__templates__/native-static/scripts/serve.ps1 +7 -0
- package/lib/__templates__/nextjs/.coze +5 -0
- package/lib/__templates__/nextjs/scripts/build.ps1 +16 -0
- package/lib/__templates__/nextjs/scripts/dev.ps1 +63 -0
- package/lib/__templates__/nextjs/scripts/dev.sh +81 -9
- package/lib/__templates__/nextjs/scripts/prepare.ps1 +18 -0
- package/lib/__templates__/nextjs/scripts/start.ps1 +11 -0
- package/lib/__templates__/nextjs/scripts/validate.ps1 +8 -0
- package/lib/__templates__/nuxt-vue/.coze +5 -0
- package/lib/__templates__/nuxt-vue/scripts/build.ps1 +12 -0
- package/lib/__templates__/nuxt-vue/scripts/dev.ps1 +63 -0
- package/lib/__templates__/nuxt-vue/scripts/dev.sh +82 -1
- package/lib/__templates__/nuxt-vue/scripts/prepare.ps1 +12 -0
- package/lib/__templates__/nuxt-vue/scripts/start.ps1 +11 -0
- package/lib/__templates__/nuxt-vue/scripts/validate.ps1 +8 -0
- package/lib/__templates__/phaser/.coze +5 -0
- package/lib/__templates__/phaser/README.md +8 -0
- package/lib/__templates__/phaser/scripts/build.ps1 +12 -0
- package/lib/__templates__/phaser/scripts/dev.ps1 +49 -0
- package/lib/__templates__/phaser/scripts/prepare.ps1 +8 -0
- package/lib/__templates__/phaser/scripts/start.ps1 +49 -0
- package/lib/__templates__/phaser/scripts/validate.ps1 +7 -0
- package/lib/__templates__/phaser/src/global.d.ts +3 -0
- package/lib/__templates__/phaser/src/scene/BootScene.ts +4 -0
- package/lib/__templates__/phaser/src/scene/DevLoadingScene.ts +3 -0
- package/lib/__templates__/phaser/src/utils/mark-editable.ts +8 -1
- package/lib/__templates__/phaser/vite.config.ts +1 -1
- package/lib/__templates__/phaser-static/.coze +15 -0
- package/lib/__templates__/phaser-static/README.md +40 -0
- package/lib/__templates__/phaser-static/_gitignore +6 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/manifest.json +11 -0
- package/lib/__templates__/phaser-static/debug-runtime/flow-graph.json +20 -0
- package/lib/__templates__/phaser-static/index.html +17 -0
- package/lib/__templates__/phaser-static/scripts/serve.ps1 +7 -0
- package/lib/__templates__/phaser-static/src/assets.js +15 -0
- package/lib/__templates__/phaser-static/src/main.js +26 -0
- package/lib/__templates__/phaser-static/src/phaser.js +7 -0
- package/lib/__templates__/phaser-static/src/scene/BootScene.js +205 -0
- package/lib/__templates__/phaser-static/src/scene/DevLoadingScene.js +67 -0
- package/lib/__templates__/phaser-static/src/style.css +28 -0
- package/lib/__templates__/phaser-static/src/utils/asset-loader.js +267 -0
- package/lib/__templates__/phaser-static/src/utils/index.js +2 -0
- package/lib/__templates__/phaser-static/src/utils/mark-editable.js +3 -0
- package/lib/__templates__/phaser-static/template.config.js +35 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +1 -1
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +144 -68
- package/lib/__templates__/taro/AGENTS.md +11 -7
- package/lib/__templates__/taro/README.md +4 -4
- package/lib/__templates__/taro/config/index.ts +10 -2
- package/lib/__templates__/taro/pnpm-lock.yaml +5 -5
- package/lib/__templates__/taro/server/package.json +1 -1
- package/lib/__templates__/taro/server/src/main.ts +8 -2
- package/lib/__templates__/templates.json +26 -1
- package/lib/__templates__/vite/.coze +5 -0
- package/lib/__templates__/vite/scripts/build.ps1 +16 -0
- package/lib/__templates__/vite/scripts/dev.ps1 +63 -0
- package/lib/__templates__/vite/scripts/dev.sh +82 -1
- package/lib/__templates__/vite/scripts/prepare.ps1 +18 -0
- package/lib/__templates__/vite/scripts/start.ps1 +11 -0
- package/lib/__templates__/vite/scripts/validate.ps1 +8 -0
- package/lib/cli.js +332 -18
- package/lib/deploy/package-project.js +22 -4
- package/lib/deploy/package-project.py +18 -3
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
$ErrorActionPreference = "Stop"
|
|
2
|
+
|
|
3
|
+
$workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
|
|
4
|
+
Set-Location $workspace
|
|
5
|
+
|
|
6
|
+
Write-Host "Installing dependencies..."
|
|
7
|
+
& pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
|
|
8
|
+
if ($LASTEXITCODE -ne 0) {
|
|
9
|
+
exit $LASTEXITCODE
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (Get-Command coze-dev -ErrorAction SilentlyContinue) {
|
|
13
|
+
& coze-dev check-bins --help *> $null
|
|
14
|
+
if ($LASTEXITCODE -eq 0) {
|
|
15
|
+
& coze-dev check-bins --fix
|
|
16
|
+
exit $LASTEXITCODE
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
$ErrorActionPreference = "Stop"
|
|
2
|
+
|
|
3
|
+
$workspace = if ($env:COZE_WORKSPACE_PATH) { $env:COZE_WORKSPACE_PATH } else { (Get-Location).Path }
|
|
4
|
+
$defaultPort = <%= port %>
|
|
5
|
+
$port = if ($env:DEPLOY_RUN_PORT) { $env:DEPLOY_RUN_PORT } elseif ($env:PORT) { $env:PORT } else { $defaultPort }
|
|
6
|
+
Set-Location $workspace
|
|
7
|
+
|
|
8
|
+
Write-Host "Starting express production server on port $port..."
|
|
9
|
+
$env:PORT = "$port"
|
|
10
|
+
& node dist-server/server.js
|
|
11
|
+
exit $LASTEXITCODE
|
package/lib/cli.js
CHANGED
|
@@ -28,6 +28,7 @@ var node_os = require('node:os');
|
|
|
28
28
|
var promises = require('node:fs/promises');
|
|
29
29
|
var node_child_process = require('node:child_process');
|
|
30
30
|
var node_util = require('node:util');
|
|
31
|
+
var tar = require('tar');
|
|
31
32
|
var node_stream = require('node:stream');
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -2113,7 +2114,7 @@ const EventBuilder = {
|
|
|
2113
2114
|
};
|
|
2114
2115
|
|
|
2115
2116
|
var name = "@coze-arch/cli";
|
|
2116
|
-
var version = "0.0.36-alpha.
|
|
2117
|
+
var version = "0.0.36-alpha.102c95";
|
|
2117
2118
|
var description = "coze coding devtools cli";
|
|
2118
2119
|
var license = "MIT";
|
|
2119
2120
|
var author = "fanwenjie.fe@bytedance.com";
|
|
@@ -5961,35 +5962,66 @@ const saveProjectPatchState = async (
|
|
|
5961
5962
|
await saveTomlCozeConfig(config, projectPath);
|
|
5962
5963
|
};
|
|
5963
5964
|
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
* @param config - .coze 配置对象
|
|
5968
|
-
* @param commandName - 命令名称 (dev/build/start)
|
|
5969
|
-
* @returns 命令配置数组
|
|
5970
|
-
*/
|
|
5971
|
-
const getCommandConfig = (
|
|
5965
|
+
|
|
5966
|
+
|
|
5967
|
+
const getDefaultCommandConfig = (
|
|
5972
5968
|
config,
|
|
5973
5969
|
commandName,
|
|
5974
5970
|
) => {
|
|
5975
|
-
|
|
5971
|
+
switch (commandName) {
|
|
5972
|
+
case 'dev':
|
|
5973
|
+
return _optionalChain$k([config, 'access', _ => _.dev, 'optionalAccess', _2 => _2.run]);
|
|
5974
|
+
case 'build':
|
|
5975
|
+
return _optionalChain$k([config, 'access', _3 => _3.deploy, 'optionalAccess', _4 => _4.build]);
|
|
5976
|
+
case 'start':
|
|
5977
|
+
return _optionalChain$k([config, 'access', _5 => _5.deploy, 'optionalAccess', _6 => _6.run]);
|
|
5978
|
+
case 'validate':
|
|
5979
|
+
return _optionalChain$k([config, 'access', _7 => _7.dev, 'optionalAccess', _8 => _8.validate]);
|
|
5980
|
+
default:
|
|
5981
|
+
throw new Error(`Unknown command: ${commandName}`);
|
|
5982
|
+
}
|
|
5983
|
+
};
|
|
5976
5984
|
|
|
5985
|
+
const getWindowsCommandConfig = (
|
|
5986
|
+
config,
|
|
5987
|
+
commandName,
|
|
5988
|
+
) => {
|
|
5977
5989
|
switch (commandName) {
|
|
5978
5990
|
case 'dev':
|
|
5979
|
-
|
|
5980
|
-
break;
|
|
5991
|
+
return _optionalChain$k([config, 'access', _9 => _9.dev, 'optionalAccess', _10 => _10.run_win]);
|
|
5981
5992
|
case 'build':
|
|
5982
|
-
|
|
5983
|
-
break;
|
|
5993
|
+
return _optionalChain$k([config, 'access', _11 => _11.deploy, 'optionalAccess', _12 => _12.build_win]);
|
|
5984
5994
|
case 'start':
|
|
5985
|
-
|
|
5986
|
-
break;
|
|
5995
|
+
return _optionalChain$k([config, 'access', _13 => _13.deploy, 'optionalAccess', _14 => _14.run_win]);
|
|
5987
5996
|
case 'validate':
|
|
5988
|
-
|
|
5989
|
-
break;
|
|
5997
|
+
return _optionalChain$k([config, 'access', _15 => _15.dev, 'optionalAccess', _16 => _16.validate_win]);
|
|
5990
5998
|
default:
|
|
5991
5999
|
throw new Error(`Unknown command: ${commandName}`);
|
|
5992
6000
|
}
|
|
6001
|
+
};
|
|
6002
|
+
|
|
6003
|
+
/**
|
|
6004
|
+
* 获取指定命令的配置
|
|
6005
|
+
*
|
|
6006
|
+
* Windows 优先使用非空的 *_win 配置;其他平台(包括 WSL)始终使用默认配置。
|
|
6007
|
+
*
|
|
6008
|
+
* @param config - .coze 配置对象
|
|
6009
|
+
* @param commandName - 命令名称 (dev/build/start)
|
|
6010
|
+
* @returns 命令配置数组
|
|
6011
|
+
*/
|
|
6012
|
+
const getCommandConfig = (
|
|
6013
|
+
config,
|
|
6014
|
+
commandName,
|
|
6015
|
+
platform = process.platform,
|
|
6016
|
+
) => {
|
|
6017
|
+
const defaultCommandConfig = getDefaultCommandConfig(config, commandName);
|
|
6018
|
+
const windowsCommandConfig =
|
|
6019
|
+
platform === 'win32'
|
|
6020
|
+
? getWindowsCommandConfig(config, commandName)
|
|
6021
|
+
: undefined;
|
|
6022
|
+
const commandConfig = _optionalChain$k([windowsCommandConfig, 'optionalAccess', _17 => _17.length])
|
|
6023
|
+
? windowsCommandConfig
|
|
6024
|
+
: defaultCommandConfig;
|
|
5993
6025
|
|
|
5994
6026
|
if (!commandConfig || commandConfig.length === 0) {
|
|
5995
6027
|
throw new Error(
|
|
@@ -10489,6 +10521,9 @@ const loadConfig = async (options = {}) => {
|
|
|
10489
10521
|
...(options.orgId ? { organizationId: options.orgId } : {}),
|
|
10490
10522
|
...(options.spaceId ? { spaceId: options.spaceId } : {}),
|
|
10491
10523
|
...(options.apiBaseUrl ? { apiBaseUrl: options.apiBaseUrl } : {}),
|
|
10524
|
+
// Runtime-only trust decision: a value persisted in config.json must never enable
|
|
10525
|
+
// project-secret injection for an OAuth access token.
|
|
10526
|
+
injectApiToken: Boolean(environmentAccessToken),
|
|
10492
10527
|
};
|
|
10493
10528
|
return config;
|
|
10494
10529
|
};
|
|
@@ -10932,6 +10967,15 @@ class DeployApiClient {
|
|
|
10932
10967
|
'agw-js-conv': 'str',
|
|
10933
10968
|
'x-request-from-coze-cli': '1',
|
|
10934
10969
|
};
|
|
10970
|
+
// Only an explicit environment credential may become a project runtime secret.
|
|
10971
|
+
// OAuth credentials loaded from config.json remain authentication-only.
|
|
10972
|
+
if (
|
|
10973
|
+
this.config.injectApiToken &&
|
|
10974
|
+
path === '/deploy_history/create' &&
|
|
10975
|
+
useApiPrefix
|
|
10976
|
+
) {
|
|
10977
|
+
headers['x-coze-deploy-inject-api-token'] = 'true';
|
|
10978
|
+
}
|
|
10935
10979
|
if (this.config.organizationId) {
|
|
10936
10980
|
headers['x-coze-account'] = this.config.organizationId;
|
|
10937
10981
|
}
|
|
@@ -11171,6 +11215,35 @@ class DeployApiClient {
|
|
|
11171
11215
|
);
|
|
11172
11216
|
}
|
|
11173
11217
|
|
|
11218
|
+
authorizeMiniProgram(body
|
|
11219
|
+
|
|
11220
|
+
|
|
11221
|
+
|
|
11222
|
+
|
|
11223
|
+
|
|
11224
|
+
|
|
11225
|
+
) {
|
|
11226
|
+
return this.post
|
|
11227
|
+
|
|
11228
|
+
|
|
11229
|
+
|
|
11230
|
+
('/mini_program/auth', body);
|
|
11231
|
+
}
|
|
11232
|
+
|
|
11233
|
+
createMiniProgramPreview(body
|
|
11234
|
+
|
|
11235
|
+
|
|
11236
|
+
|
|
11237
|
+
|
|
11238
|
+
) {
|
|
11239
|
+
return this.post
|
|
11240
|
+
|
|
11241
|
+
|
|
11242
|
+
|
|
11243
|
+
|
|
11244
|
+
('/mini_program/preview', body);
|
|
11245
|
+
}
|
|
11246
|
+
|
|
11174
11247
|
listDomains(appId, unitType) {
|
|
11175
11248
|
return this.post(
|
|
11176
11249
|
'/domain/list', {
|
|
@@ -11979,12 +12052,107 @@ const registerEnv = (code) => {
|
|
|
11979
12052
|
});
|
|
11980
12053
|
};
|
|
11981
12054
|
|
|
12055
|
+
/* eslint-disable security/detect-non-literal-fs-filename -- validated project-local build output paths */
|
|
12056
|
+
|
|
12057
|
+
const BUILD_OUTPUT_DIRS = new Set(['dist', 'dist-tt']);
|
|
12058
|
+
const EXCLUDED_PARTS = new Set([
|
|
12059
|
+
'.git',
|
|
12060
|
+
'.env',
|
|
12061
|
+
'node_modules',
|
|
12062
|
+
]);
|
|
12063
|
+
const REPRODUCIBLE_ARCHIVE_MTIME = new Date(0);
|
|
12064
|
+
|
|
12065
|
+
const validateBuildOutput = async (
|
|
12066
|
+
sourceRoot,
|
|
12067
|
+
buildOutputDir,
|
|
12068
|
+
) => {
|
|
12069
|
+
if (!BUILD_OUTPUT_DIRS.has(buildOutputDir)) {
|
|
12070
|
+
throw new CliError(
|
|
12071
|
+
`Unsupported Mini-program build output directory: ${buildOutputDir}.`,
|
|
12072
|
+
'SOURCE_PACKAGE_FAILED',
|
|
12073
|
+
);
|
|
12074
|
+
}
|
|
12075
|
+
const buildOutputRoot = node_path.resolve(sourceRoot, buildOutputDir);
|
|
12076
|
+
try {
|
|
12077
|
+
const info = await promises.lstat(buildOutputRoot);
|
|
12078
|
+
if (info.isSymbolicLink() || !info.isDirectory()) {
|
|
12079
|
+
throw new Error('build output must be a regular directory');
|
|
12080
|
+
}
|
|
12081
|
+
const realSourceRoot = await promises.realpath(sourceRoot);
|
|
12082
|
+
const realBuildOutputRoot = await promises.realpath(buildOutputRoot);
|
|
12083
|
+
const relativeOutput = node_path.relative(realSourceRoot, realBuildOutputRoot);
|
|
12084
|
+
if (!relativeOutput || relativeOutput.startsWith('..')) {
|
|
12085
|
+
throw new Error('build output must be inside the source root');
|
|
12086
|
+
}
|
|
12087
|
+
} catch (error) {
|
|
12088
|
+
throw new CliError(
|
|
12089
|
+
`Invalid Mini-program build output ${buildOutputRoot}: ${error instanceof Error ? error.message : String(error)}`,
|
|
12090
|
+
'SOURCE_PACKAGE_FAILED',
|
|
12091
|
+
);
|
|
12092
|
+
}
|
|
12093
|
+
};
|
|
12094
|
+
|
|
12095
|
+
const shouldInclude = (
|
|
12096
|
+
archivePath,
|
|
12097
|
+
entry,
|
|
12098
|
+
) => {
|
|
12099
|
+
if ('isSymbolicLink' in entry && entry.isSymbolicLink()) {
|
|
12100
|
+
return false;
|
|
12101
|
+
}
|
|
12102
|
+
return !archivePath.split(/[\\/]/u).some(part =>
|
|
12103
|
+
EXCLUDED_PARTS.has(part) || part.startsWith('.git'),
|
|
12104
|
+
);
|
|
12105
|
+
};
|
|
12106
|
+
|
|
12107
|
+
const createMiniProgramPackage = async (
|
|
12108
|
+
sourceRoot,
|
|
12109
|
+
buildOutputDir,
|
|
12110
|
+
) => {
|
|
12111
|
+
const resolvedSourceRoot = node_path.resolve(sourceRoot);
|
|
12112
|
+
await validateBuildOutput(resolvedSourceRoot, buildOutputDir);
|
|
12113
|
+
const tempDirectory = await promises.mkdtemp(node_path.join(node_os.tmpdir(), 'coze-mini-program-source-'));
|
|
12114
|
+
const outputPath = node_path.join(tempDirectory, 'source.tar.gz');
|
|
12115
|
+
try {
|
|
12116
|
+
await tar.create(
|
|
12117
|
+
{
|
|
12118
|
+
cwd: resolvedSourceRoot,
|
|
12119
|
+
file: outputPath,
|
|
12120
|
+
filter: shouldInclude,
|
|
12121
|
+
gzip: true,
|
|
12122
|
+
mtime: REPRODUCIBLE_ARCHIVE_MTIME,
|
|
12123
|
+
portable: true,
|
|
12124
|
+
},
|
|
12125
|
+
[buildOutputDir],
|
|
12126
|
+
);
|
|
12127
|
+
const info = await promises.stat(outputPath);
|
|
12128
|
+
if (info.size === 0) {
|
|
12129
|
+
throw new Error('source archive is empty');
|
|
12130
|
+
}
|
|
12131
|
+
return {
|
|
12132
|
+
path: outputPath,
|
|
12133
|
+
sizeBytes: info.size,
|
|
12134
|
+
cleanup: () => promises.rm(tempDirectory, { recursive: true, force: true }),
|
|
12135
|
+
};
|
|
12136
|
+
} catch (error) {
|
|
12137
|
+
await promises.rm(tempDirectory, { recursive: true, force: true });
|
|
12138
|
+
throw new CliError(
|
|
12139
|
+
`Unable to package Mini-program build output: ${error instanceof Error ? error.message : String(error)}`,
|
|
12140
|
+
'SOURCE_PACKAGE_FAILED',
|
|
12141
|
+
);
|
|
12142
|
+
}
|
|
12143
|
+
};
|
|
12144
|
+
|
|
11982
12145
|
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; }
|
|
11983
12146
|
const CONNECTOR_IDS = {
|
|
11984
12147
|
wechat: '10000127',
|
|
11985
12148
|
douyin: '10000126',
|
|
11986
12149
|
} ;
|
|
11987
12150
|
|
|
12151
|
+
const MINI_PROGRAM_BUILD_OUTPUT_DIRS = {
|
|
12152
|
+
wechat: 'dist',
|
|
12153
|
+
douyin: 'dist-tt',
|
|
12154
|
+
} ;
|
|
12155
|
+
|
|
11988
12156
|
|
|
11989
12157
|
|
|
11990
12158
|
|
|
@@ -12009,6 +12177,18 @@ const resolveConnectorId = (platform) => {
|
|
|
12009
12177
|
return connectorId;
|
|
12010
12178
|
};
|
|
12011
12179
|
|
|
12180
|
+
const resolveBuildOutputDir = (platform) => {
|
|
12181
|
+
const outputDir =
|
|
12182
|
+
MINI_PROGRAM_BUILD_OUTPUT_DIRS[platform ];
|
|
12183
|
+
if (!outputDir) {
|
|
12184
|
+
throw new CliError(
|
|
12185
|
+
`Unsupported Mini-program platform ${String(platform)}; expected wechat or douyin.`,
|
|
12186
|
+
'INVALID_MINIPROGRAM_PLATFORM',
|
|
12187
|
+
);
|
|
12188
|
+
}
|
|
12189
|
+
return outputDir;
|
|
12190
|
+
};
|
|
12191
|
+
|
|
12012
12192
|
const resolveProjectId = async (
|
|
12013
12193
|
command,
|
|
12014
12194
|
options,
|
|
@@ -12028,6 +12208,137 @@ const resolveProjectId = async (
|
|
|
12028
12208
|
return metadata.projectId;
|
|
12029
12209
|
};
|
|
12030
12210
|
|
|
12211
|
+
const MINI_PROGRAM_AUTH_STATUS = {
|
|
12212
|
+
authorized: 1,
|
|
12213
|
+
needAuthorize: 2,
|
|
12214
|
+
boundToOtherUser: 3,
|
|
12215
|
+
} ;
|
|
12216
|
+
|
|
12217
|
+
const getBoundToOtherUserMessage = (platform) => {
|
|
12218
|
+
const platformName = platform === 'wechat' ? 'WeChat' : 'Douyin';
|
|
12219
|
+
const platformConsole =
|
|
12220
|
+
platform === 'wechat' ? 'WeChat Public Platform' : 'Douyin Open Platform';
|
|
12221
|
+
return [
|
|
12222
|
+
`This ${platformName} Mini-program AppID is authorized by another Coze user.`,
|
|
12223
|
+
`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.`,
|
|
12224
|
+
'If this is not your AppID, change --mini-app-id to an AppID for which you have administrator permission, then rerun this auth command.',
|
|
12225
|
+
].join(' ');
|
|
12226
|
+
};
|
|
12227
|
+
|
|
12228
|
+
const getAuthRequiredMessage = () =>
|
|
12229
|
+
'This Mini-program AppID is not authorized for the current Coze user. Run `coze-dev deploy code mini-program auth` first.';
|
|
12230
|
+
|
|
12231
|
+
const getPreviewFailureMessage = (data
|
|
12232
|
+
|
|
12233
|
+
|
|
12234
|
+
) =>
|
|
12235
|
+
_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.';
|
|
12236
|
+
|
|
12237
|
+
const registerAuthorizationCommand = (miniProgram) => {
|
|
12238
|
+
miniProgram
|
|
12239
|
+
.command('auth')
|
|
12240
|
+
.description('Authorize a Mini-program AppID for the current Coze user')
|
|
12241
|
+
.requiredOption('--platform <platform>', 'wechat or douyin')
|
|
12242
|
+
.requiredOption('--mini-app-id <miniAppId>', 'Mini-program AppID')
|
|
12243
|
+
.option('--project-id <projectId>', 'Deployment Project ID')
|
|
12244
|
+
.option('--source-root <sourceRoot>', 'Directory containing .coze', '.')
|
|
12245
|
+
.action(async (options, command) => {
|
|
12246
|
+
const runtime = await getRuntime(command);
|
|
12247
|
+
const projectId = await resolveProjectId(command, options);
|
|
12248
|
+
const authorization = await runtime.client.authorizeMiniProgram({
|
|
12249
|
+
project_id: projectId,
|
|
12250
|
+
app_id: options.miniAppId || '',
|
|
12251
|
+
connector_id: resolveConnectorId(options.platform),
|
|
12252
|
+
redirect_url: 'https://code.coze.cn/coding/auth/callback/miniprogram',
|
|
12253
|
+
});
|
|
12254
|
+
if (authorization.status === MINI_PROGRAM_AUTH_STATUS.needAuthorize) {
|
|
12255
|
+
runtime.output.print({
|
|
12256
|
+
project_id: projectId,
|
|
12257
|
+
mini_app_id: options.miniAppId,
|
|
12258
|
+
platform: options.platform,
|
|
12259
|
+
authorization_required: true,
|
|
12260
|
+
auth_url: authorization.auth_url,
|
|
12261
|
+
});
|
|
12262
|
+
return;
|
|
12263
|
+
}
|
|
12264
|
+
if (authorization.status === MINI_PROGRAM_AUTH_STATUS.boundToOtherUser) {
|
|
12265
|
+
throw new CliError(
|
|
12266
|
+
getBoundToOtherUserMessage(options.platform),
|
|
12267
|
+
'MINIPROGRAM_AUTHORIZED_BY_OTHER_USER',
|
|
12268
|
+
);
|
|
12269
|
+
}
|
|
12270
|
+
if (authorization.status !== MINI_PROGRAM_AUTH_STATUS.authorized) {
|
|
12271
|
+
throw new CliError(
|
|
12272
|
+
`Unexpected Mini-program authorization status: ${String(authorization.status)}.`,
|
|
12273
|
+
'INVALID_RESPONSE',
|
|
12274
|
+
);
|
|
12275
|
+
}
|
|
12276
|
+
runtime.output.print({
|
|
12277
|
+
project_id: projectId,
|
|
12278
|
+
mini_app_id: options.miniAppId,
|
|
12279
|
+
platform: options.platform,
|
|
12280
|
+
authorized: true,
|
|
12281
|
+
});
|
|
12282
|
+
});
|
|
12283
|
+
};
|
|
12284
|
+
|
|
12285
|
+
const registerPreviewCommand = (miniProgram) => {
|
|
12286
|
+
miniProgram
|
|
12287
|
+
.command('preview')
|
|
12288
|
+
.description('Create a Mini-program preview QR code from the local build artifact')
|
|
12289
|
+
.requiredOption('--platform <platform>', 'wechat or douyin')
|
|
12290
|
+
.requiredOption('--mini-app-id <miniAppId>', 'Mini-program AppID')
|
|
12291
|
+
.option('--project-id <projectId>', 'Deployment Project ID')
|
|
12292
|
+
.option('--source-root <sourceRoot>', 'Directory containing dist or dist-tt', '.')
|
|
12293
|
+
.action(async (options, command) => {
|
|
12294
|
+
const runtime = await getRuntime(command);
|
|
12295
|
+
const projectId = await resolveProjectId(command, options);
|
|
12296
|
+
const authorization = await runtime.client.getMiniProgramAuthStatus({
|
|
12297
|
+
project_id: projectId,
|
|
12298
|
+
connector_id: resolveConnectorId(options.platform),
|
|
12299
|
+
});
|
|
12300
|
+
if (
|
|
12301
|
+
!authorization.is_authorized ||
|
|
12302
|
+
authorization.bound_related_id !== options.miniAppId
|
|
12303
|
+
) {
|
|
12304
|
+
throw new CliError(
|
|
12305
|
+
getAuthRequiredMessage(),
|
|
12306
|
+
'MINIPROGRAM_AUTH_REQUIRED',
|
|
12307
|
+
);
|
|
12308
|
+
}
|
|
12309
|
+
const sourceRoot = node_path.resolve(runtime.cwd, options.sourceRoot || '.');
|
|
12310
|
+
const buildOutputDir = resolveBuildOutputDir(options.platform);
|
|
12311
|
+
const sourcePackage = await createMiniProgramPackage(
|
|
12312
|
+
sourceRoot,
|
|
12313
|
+
buildOutputDir,
|
|
12314
|
+
);
|
|
12315
|
+
try {
|
|
12316
|
+
const content = await promises.readFile(sourcePackage.path);
|
|
12317
|
+
const data = await runtime.client.createMiniProgramPreview({
|
|
12318
|
+
project_id: projectId,
|
|
12319
|
+
app_id: options.miniAppId || '',
|
|
12320
|
+
connector_id: resolveConnectorId(options.platform),
|
|
12321
|
+
source_package_base64: content.toString('base64'),
|
|
12322
|
+
});
|
|
12323
|
+
if (data.failed) {
|
|
12324
|
+
throw new CliError(
|
|
12325
|
+
getPreviewFailureMessage(data),
|
|
12326
|
+
'MINIPROGRAM_PREVIEW_FAILED',
|
|
12327
|
+
);
|
|
12328
|
+
}
|
|
12329
|
+
runtime.output.print({
|
|
12330
|
+
project_id: projectId,
|
|
12331
|
+
mini_app_id: options.miniAppId,
|
|
12332
|
+
platform: options.platform,
|
|
12333
|
+
source_package_size_bytes: sourcePackage.sizeBytes,
|
|
12334
|
+
...data,
|
|
12335
|
+
});
|
|
12336
|
+
} finally {
|
|
12337
|
+
await sourcePackage.cleanup();
|
|
12338
|
+
}
|
|
12339
|
+
});
|
|
12340
|
+
};
|
|
12341
|
+
|
|
12031
12342
|
const registerMiniProgram = (code) => {
|
|
12032
12343
|
const miniProgram = code
|
|
12033
12344
|
.command('mini-program')
|
|
@@ -12112,6 +12423,9 @@ const registerMiniProgram = (code) => {
|
|
|
12112
12423
|
});
|
|
12113
12424
|
runtime.output.print({ project_id: projectId, platform: options.platform, unbound: true });
|
|
12114
12425
|
});
|
|
12426
|
+
|
|
12427
|
+
registerAuthorizationCommand(miniProgram);
|
|
12428
|
+
registerPreviewCommand(miniProgram);
|
|
12115
12429
|
};
|
|
12116
12430
|
|
|
12117
12431
|
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; }
|
|
@@ -93,6 +93,18 @@ const readCommand = (config, section, key) => {
|
|
|
93
93
|
return command;
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
+
const readPlatformCommand = (config, section, key) => {
|
|
97
|
+
const defaultCommand = readCommand(config, section, key);
|
|
98
|
+
const windowsCommand = process.platform === 'win32'
|
|
99
|
+
? readCommand(config, section, `${key}_win`)
|
|
100
|
+
: undefined;
|
|
101
|
+
|
|
102
|
+
if (windowsCommand?.length) {
|
|
103
|
+
return { command: windowsCommand, key: `${key}_win` };
|
|
104
|
+
}
|
|
105
|
+
return defaultCommand?.length ? { command: defaultCommand, key } : undefined;
|
|
106
|
+
};
|
|
107
|
+
|
|
96
108
|
const runCommand = (command, sourceDir, env) => {
|
|
97
109
|
const result = spawnSync(command[0], command.slice(1), {
|
|
98
110
|
cwd: sourceDir,
|
|
@@ -110,10 +122,16 @@ const runCommand = (command, sourceDir, env) => {
|
|
|
110
122
|
};
|
|
111
123
|
|
|
112
124
|
const runPackCommand = sourceDir => {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
125
|
+
const configuredCommand = readPlatformCommand(
|
|
126
|
+
readCozeConfig(sourceDir),
|
|
127
|
+
'dev',
|
|
128
|
+
'pack',
|
|
129
|
+
);
|
|
130
|
+
if (configuredCommand) {
|
|
131
|
+
process.stderr.write(
|
|
132
|
+
`[package] Running dev.${configuredCommand.key}: ${configuredCommand.command.join(' ')}\n`,
|
|
133
|
+
);
|
|
134
|
+
runCommand(configuredCommand.command, sourceDir, buildCommandEnv());
|
|
117
135
|
}
|
|
118
136
|
};
|
|
119
137
|
|
|
@@ -60,10 +60,25 @@ def read_command(config, section: str, key: str):
|
|
|
60
60
|
return command
|
|
61
61
|
|
|
62
62
|
|
|
63
|
+
def read_platform_command(config, section: str, key: str, platform=sys.platform):
|
|
64
|
+
default_command = read_command(config, section, key)
|
|
65
|
+
windows_command = (
|
|
66
|
+
read_command(config, section, f"{key}_win")
|
|
67
|
+
if platform.startswith("win")
|
|
68
|
+
else None
|
|
69
|
+
)
|
|
70
|
+
if windows_command:
|
|
71
|
+
return f"{key}_win", windows_command
|
|
72
|
+
return (key, default_command) if default_command else None
|
|
73
|
+
|
|
74
|
+
|
|
63
75
|
def run_pack_command(source_dir: Path):
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
76
|
+
configured_command = read_platform_command(
|
|
77
|
+
read_coze_config(source_dir), "dev", "pack"
|
|
78
|
+
)
|
|
79
|
+
if configured_command:
|
|
80
|
+
key, command = configured_command
|
|
81
|
+
print(f"[package] Running dev.{key}: {' '.join(command)}", file=sys.stderr)
|
|
67
82
|
subprocess.run(command, cwd=source_dir, env=build_command_env(), check=True)
|
|
68
83
|
|
|
69
84
|
|