@coze-arch/cli 0.0.1-alpha.3ce8c6 → 0.0.1-alpha.45a0c2
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/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +2 -2
- package/lib/__templates__/expo/README.md +24 -2
- package/lib/__templates__/expo/client/package.json +2 -2
- package/lib/__templates__/expo/package.json +4 -98
- package/lib/__templates__/expo/pnpm-lock.yaml +324 -577
- package/lib/__templates__/expo/server/package.json +15 -2
- package/lib/__templates__/expo/server/tsconfig.json +24 -0
- package/lib/__templates__/nextjs/next.config.ts +1 -0
- package/lib/__templates__/templates.json +27 -0
- package/lib/cli.js +144 -31
- package/package.json +5 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "server",
|
|
3
3
|
"private": true,
|
|
4
|
+
"type": "module",
|
|
4
5
|
"scripts": {
|
|
5
6
|
"preinstall": "npx only-allow pnpm",
|
|
6
7
|
"dev": "NODE_ENV=development tsx ./src/index.ts",
|
|
@@ -8,10 +9,22 @@
|
|
|
8
9
|
"start": "NODE_ENV=production PORT=${PORT:-5000} node dist/index.js"
|
|
9
10
|
},
|
|
10
11
|
"dependencies": {
|
|
11
|
-
"express": "^4.22.1"
|
|
12
|
+
"express": "^4.22.1",
|
|
13
|
+
"coze-coding-dev-sdk": "^0.5.5",
|
|
14
|
+
"dayjs": "^1.11.19",
|
|
15
|
+
"drizzle-orm": "^0.45.1",
|
|
16
|
+
"drizzle-zod": "^0.8.3",
|
|
17
|
+
"multer": "^2.0.2",
|
|
18
|
+
"pg": "^8.16.3",
|
|
19
|
+
"zod": "^4.2.1"
|
|
12
20
|
},
|
|
13
21
|
"devDependencies": {
|
|
14
22
|
"@types/express": "^5.0.6",
|
|
15
|
-
"tsx": "^4.21.0"
|
|
23
|
+
"tsx": "^4.21.0",
|
|
24
|
+
"@types/multer": "^2.0.0",
|
|
25
|
+
"@types/pg": "^8.16.0",
|
|
26
|
+
"esbuild": "0.27.2",
|
|
27
|
+
"typescript": "^5.8.3",
|
|
28
|
+
"drizzle-kit": "^0.31.8"
|
|
16
29
|
}
|
|
17
30
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://www.schemastore.org/tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"lib": [
|
|
5
|
+
"es2024",
|
|
6
|
+
"ESNext.Array",
|
|
7
|
+
"ESNext.Collection",
|
|
8
|
+
"ESNext.Iterator",
|
|
9
|
+
"ESNext.Promise"
|
|
10
|
+
],
|
|
11
|
+
"module": "preserve",
|
|
12
|
+
"target": "es2024",
|
|
13
|
+
|
|
14
|
+
"strict": true,
|
|
15
|
+
"esModuleInterop": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"moduleResolution": "bundler",
|
|
18
|
+
|
|
19
|
+
"rewriteRelativeImportExtensions": true,
|
|
20
|
+
"erasableSyntaxOnly": true,
|
|
21
|
+
"verbatimModuleSyntax": true
|
|
22
|
+
},
|
|
23
|
+
"include": ["src"]
|
|
24
|
+
}
|
|
@@ -39,6 +39,33 @@
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
+
{
|
|
43
|
+
"name": "test-only",
|
|
44
|
+
"description": "test-only template",
|
|
45
|
+
"location": "./test-only",
|
|
46
|
+
"paramsSchema": {
|
|
47
|
+
"appName": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"description": "Application name (lowercase, alphanumeric and hyphens only)",
|
|
50
|
+
"pattern": "^[a-z0-9-]+$"
|
|
51
|
+
},
|
|
52
|
+
"port": {
|
|
53
|
+
"type": "number",
|
|
54
|
+
"description": "Development server port",
|
|
55
|
+
"default": 5000,
|
|
56
|
+
"minimum": 1024,
|
|
57
|
+
"maximum": 65535
|
|
58
|
+
},
|
|
59
|
+
"includeTests": {
|
|
60
|
+
"type": "boolean",
|
|
61
|
+
"description": "Include test files"
|
|
62
|
+
},
|
|
63
|
+
"addCopyright": {
|
|
64
|
+
"type": "boolean",
|
|
65
|
+
"description": "Add copyright header to source files"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
42
69
|
{
|
|
43
70
|
"name": "vite",
|
|
44
71
|
"description": "vite template",
|
package/lib/cli.js
CHANGED
|
@@ -1248,17 +1248,139 @@ const convertDotfileName = (filePath) => {
|
|
|
1248
1248
|
};
|
|
1249
1249
|
|
|
1250
1250
|
/**
|
|
1251
|
-
*
|
|
1251
|
+
* 执行文件渲染钩子
|
|
1252
1252
|
*
|
|
1253
|
-
* @param
|
|
1254
|
-
* @param
|
|
1253
|
+
* @param templateConfig - 模板配置
|
|
1254
|
+
* @param fileInfo - 文件渲染信息
|
|
1255
1255
|
* @param context - 模板上下文
|
|
1256
|
+
* @returns 处理后的文件信息,或 null 表示跳过该文件
|
|
1256
1257
|
*/
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1259
|
-
|
|
1258
|
+
const executeFileRenderHook = async (
|
|
1259
|
+
templateConfig,
|
|
1260
|
+
fileInfo,
|
|
1260
1261
|
context,
|
|
1261
1262
|
) => {
|
|
1263
|
+
if (!templateConfig.onFileRender) {
|
|
1264
|
+
return fileInfo;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
const result = await templateConfig.onFileRender(
|
|
1268
|
+
fileInfo,
|
|
1269
|
+
context,
|
|
1270
|
+
);
|
|
1271
|
+
|
|
1272
|
+
// false: 跳过文件
|
|
1273
|
+
if (result === false) {
|
|
1274
|
+
return null;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
// undefined/void: 使用默认内容
|
|
1278
|
+
if (result === undefined || result === null) {
|
|
1279
|
+
return fileInfo;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
// string: 作为 content,其他不变
|
|
1283
|
+
if (typeof result === 'string') {
|
|
1284
|
+
return {
|
|
1285
|
+
...fileInfo,
|
|
1286
|
+
content: result,
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
// FileRenderInfo: 使用新对象的信息
|
|
1291
|
+
return result;
|
|
1292
|
+
};
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* 处理单个文件
|
|
1296
|
+
*/
|
|
1297
|
+
const processSingleFile = async (options
|
|
1298
|
+
|
|
1299
|
+
|
|
1300
|
+
|
|
1301
|
+
|
|
1302
|
+
|
|
1303
|
+
) => {
|
|
1304
|
+
const { file, templatePath, outputPath, context, templateConfig } = options;
|
|
1305
|
+
|
|
1306
|
+
const srcPath = path.join(templatePath, file);
|
|
1307
|
+
const destFile = convertDotfileName(file);
|
|
1308
|
+
|
|
1309
|
+
logger.verbose(
|
|
1310
|
+
` - Processing: ${file}${destFile !== file ? ` -> ${destFile}` : ''}`,
|
|
1311
|
+
);
|
|
1312
|
+
|
|
1313
|
+
// 判断是否为二进制文件
|
|
1314
|
+
const isBinary = !shouldRenderFile(srcPath);
|
|
1315
|
+
let content;
|
|
1316
|
+
let wasRendered = false;
|
|
1317
|
+
|
|
1318
|
+
if (isBinary) {
|
|
1319
|
+
// 二进制文件,读取为 buffer 然后转为 base64
|
|
1320
|
+
const buffer = await fs$1.readFile(srcPath);
|
|
1321
|
+
content = buffer.toString('base64');
|
|
1322
|
+
} else {
|
|
1323
|
+
// 文本文件,渲染后的内容
|
|
1324
|
+
content = await renderTemplate(srcPath, context);
|
|
1325
|
+
wasRendered = true;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
// 构造文件信息对象
|
|
1329
|
+
const fileInfo = {
|
|
1330
|
+
path: file,
|
|
1331
|
+
destPath: destFile,
|
|
1332
|
+
content,
|
|
1333
|
+
isBinary,
|
|
1334
|
+
wasRendered,
|
|
1335
|
+
};
|
|
1336
|
+
|
|
1337
|
+
// 执行文件渲染钩子
|
|
1338
|
+
const processedFileInfo = await executeFileRenderHook(
|
|
1339
|
+
templateConfig,
|
|
1340
|
+
fileInfo,
|
|
1341
|
+
context,
|
|
1342
|
+
);
|
|
1343
|
+
|
|
1344
|
+
// 如果返回 null,跳过该文件
|
|
1345
|
+
if (processedFileInfo === null) {
|
|
1346
|
+
logger.verbose(' ⊘ Skipped by onFileRender hook');
|
|
1347
|
+
return;
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
// 使用处理后的目标路径
|
|
1351
|
+
const finalDestPath = path.join(outputPath, processedFileInfo.destPath);
|
|
1352
|
+
|
|
1353
|
+
// 确保目标目录存在
|
|
1354
|
+
await ensureDir(path.dirname(finalDestPath));
|
|
1355
|
+
|
|
1356
|
+
// 写入文件
|
|
1357
|
+
if (processedFileInfo.isBinary) {
|
|
1358
|
+
// 二进制文件:如果内容没变,直接复制;否则从 base64 解码写入
|
|
1359
|
+
if (processedFileInfo.content === content) {
|
|
1360
|
+
await fs$1.copyFile(srcPath, finalDestPath);
|
|
1361
|
+
logger.verbose(' ✓ Copied (binary)');
|
|
1362
|
+
} else {
|
|
1363
|
+
const buffer = Buffer.from(processedFileInfo.content, 'base64');
|
|
1364
|
+
await fs$1.writeFile(finalDestPath, buffer);
|
|
1365
|
+
logger.verbose(' ✓ Written (binary, modified by hook)');
|
|
1366
|
+
}
|
|
1367
|
+
} else {
|
|
1368
|
+
// 文本文件
|
|
1369
|
+
await fs$1.writeFile(finalDestPath, processedFileInfo.content, 'utf-8');
|
|
1370
|
+
logger.verbose(' ✓ Rendered and written');
|
|
1371
|
+
}
|
|
1372
|
+
};
|
|
1373
|
+
|
|
1374
|
+
/**
|
|
1375
|
+
* 复制并处理模板文件到目标目录
|
|
1376
|
+
*/
|
|
1377
|
+
const processTemplateFiles = async (options
|
|
1378
|
+
|
|
1379
|
+
|
|
1380
|
+
|
|
1381
|
+
|
|
1382
|
+
) => {
|
|
1383
|
+
const { templatePath, outputPath, context, templateConfig } = options;
|
|
1262
1384
|
logger.verbose('Processing template files:');
|
|
1263
1385
|
logger.verbose(` - Template path: ${templatePath}`);
|
|
1264
1386
|
logger.verbose(` - Output path: ${outputPath}`);
|
|
@@ -1289,29 +1411,15 @@ const processTemplateFiles = async (
|
|
|
1289
1411
|
}
|
|
1290
1412
|
|
|
1291
1413
|
await Promise.all(
|
|
1292
|
-
files.map(
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
)
|
|
1300
|
-
|
|
1301
|
-
// 确保目标目录存在
|
|
1302
|
-
await ensureDir(path.dirname(destPath));
|
|
1303
|
-
|
|
1304
|
-
if (shouldRenderFile(srcPath)) {
|
|
1305
|
-
// 渲染文本文件
|
|
1306
|
-
const rendered = await renderTemplate(srcPath, context);
|
|
1307
|
-
await fs$1.writeFile(destPath, rendered, 'utf-8');
|
|
1308
|
-
logger.verbose(' ✓ Rendered and written');
|
|
1309
|
-
} else {
|
|
1310
|
-
// 直接复制二进制文件
|
|
1311
|
-
await fs$1.copyFile(srcPath, destPath);
|
|
1312
|
-
logger.verbose(' ✓ Copied');
|
|
1313
|
-
}
|
|
1314
|
-
}),
|
|
1414
|
+
files.map(file =>
|
|
1415
|
+
processSingleFile({
|
|
1416
|
+
file,
|
|
1417
|
+
templatePath,
|
|
1418
|
+
outputPath,
|
|
1419
|
+
context,
|
|
1420
|
+
templateConfig,
|
|
1421
|
+
}),
|
|
1422
|
+
),
|
|
1315
1423
|
);
|
|
1316
1424
|
|
|
1317
1425
|
logger.verbose('✓ All files processed successfully');
|
|
@@ -1498,7 +1606,12 @@ const execute = async (
|
|
|
1498
1606
|
const absoluteOutputPath = await prepareOutputDirectory(outputPath);
|
|
1499
1607
|
|
|
1500
1608
|
// 6. 处理模板文件
|
|
1501
|
-
await processTemplateFiles(
|
|
1609
|
+
await processTemplateFiles({
|
|
1610
|
+
templatePath,
|
|
1611
|
+
outputPath: absoluteOutputPath,
|
|
1612
|
+
context,
|
|
1613
|
+
templateConfig,
|
|
1614
|
+
});
|
|
1502
1615
|
|
|
1503
1616
|
// 7. 执行 onAfterRender 钩子
|
|
1504
1617
|
await executeAfterRenderHook(templateConfig, context, absoluteOutputPath);
|
|
@@ -1741,7 +1854,7 @@ const registerCommand = program => {
|
|
|
1741
1854
|
});
|
|
1742
1855
|
};
|
|
1743
1856
|
|
|
1744
|
-
var version = "0.0.1-alpha.
|
|
1857
|
+
var version = "0.0.1-alpha.45a0c2";
|
|
1745
1858
|
var packageJson = {
|
|
1746
1859
|
version: version};
|
|
1747
1860
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coze-arch/cli",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.45a0c2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "coze coding devtools cli",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,14 +25,13 @@
|
|
|
25
25
|
"test": "vitest --run --passWithNoTests",
|
|
26
26
|
"test:all": "bash scripts/test-coverage.sh",
|
|
27
27
|
"test:cov": "vitest --run --passWithNoTests --coverage",
|
|
28
|
-
"test:e2e": "bash scripts/e2e.sh",
|
|
28
|
+
"test:e2e": "NODE_ENV=test bash scripts/e2e.sh",
|
|
29
29
|
"test:perf": "vitest bench --run --config vitest.perf.config.ts",
|
|
30
30
|
"test:perf:compare": "bash scripts/compare-perf.sh",
|
|
31
31
|
"test:perf:save": "bash scripts/run-perf-with-output.sh"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@iarna/toml": "^2.2.5",
|
|
35
|
-
"@inquirer/prompts": "^3.2.0",
|
|
36
35
|
"ajv": "^8.17.1",
|
|
37
36
|
"ajv-formats": "^3.0.1",
|
|
38
37
|
"change-case": "^5.4.4",
|
|
@@ -50,14 +49,17 @@
|
|
|
50
49
|
"@coze-arch/ts-config": "workspace:*",
|
|
51
50
|
"@coze-arch/vitest-config": "workspace:*",
|
|
52
51
|
"@coze-coding/lambda": "workspace:*",
|
|
52
|
+
"@inquirer/prompts": "^3.2.0",
|
|
53
53
|
"@types/ejs": "^3.1.5",
|
|
54
54
|
"@types/iarna__toml": "^2.0.5",
|
|
55
55
|
"@types/js-yaml": "^4.0.9",
|
|
56
|
+
"@types/minimatch": "^5.1.2",
|
|
56
57
|
"@types/minimist": "^1.2.5",
|
|
57
58
|
"@types/node": "^24",
|
|
58
59
|
"@types/shelljs": "^0.10.0",
|
|
59
60
|
"@vitest/coverage-v8": "~4.0.16",
|
|
60
61
|
"json-schema-to-typescript": "^15.0.3",
|
|
62
|
+
"minimatch": "^10.0.1",
|
|
61
63
|
"rollup": "^4.41.1",
|
|
62
64
|
"sucrase": "^3.35.0",
|
|
63
65
|
"tsx": "^4.20.6",
|