yg-team-cli 2.6.4 → 2.6.5
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/dist/cli.js +152 -9
- package/dist/cli.js.map +1 -1
- package/dist/index.js +152 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -212,6 +212,12 @@ var init_utils = __esm({
|
|
|
212
212
|
static async read(file) {
|
|
213
213
|
return await fs.readFile(file, "utf-8");
|
|
214
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* 同步读取文件内容
|
|
217
|
+
*/
|
|
218
|
+
static readSync(file) {
|
|
219
|
+
return fs.readFileSync(file, "utf-8");
|
|
220
|
+
}
|
|
215
221
|
/**
|
|
216
222
|
* 写入文件内容(自动创建父目录)
|
|
217
223
|
*/
|
|
@@ -1332,27 +1338,164 @@ var init_module_registry = __esm({
|
|
|
1332
1338
|
} else if (module.type === "remote") {
|
|
1333
1339
|
await this.generateRemoteSpecPlaceholder(targetPath, module);
|
|
1334
1340
|
addedFiles.push(path5.relative(projectPath, targetPath));
|
|
1341
|
+
} else {
|
|
1342
|
+
await this.generateLocalSpecPlaceholder(targetPath, module);
|
|
1343
|
+
addedFiles.push(path5.relative(projectPath, targetPath));
|
|
1335
1344
|
}
|
|
1336
1345
|
}
|
|
1337
|
-
if (module.
|
|
1346
|
+
if (module.backendFragments) {
|
|
1338
1347
|
const backendJavaDir = path5.join(projectPath, "backend/src/main/java");
|
|
1339
|
-
const
|
|
1348
|
+
const useTemplates = await FileUtils.exists(path5.join(templatesDir, "modules"));
|
|
1340
1349
|
for (const fragment of module.backendFragments) {
|
|
1350
|
+
let sourcePath = null;
|
|
1351
|
+
let targetPath;
|
|
1352
|
+
let content;
|
|
1353
|
+
if (useTemplates) {
|
|
1354
|
+
sourcePath = path5.join(templatesDir, "modules", fragment.source);
|
|
1355
|
+
if (await FileUtils.exists(sourcePath)) {
|
|
1356
|
+
content = await FileUtils.read(sourcePath);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
if (!content) {
|
|
1360
|
+
content = this.generatePlaceholderCode(module, fragment);
|
|
1361
|
+
}
|
|
1362
|
+
if (fragment.target.startsWith("common/")) {
|
|
1363
|
+
const relativePath = fragment.target.replace(/^common\//, "org/yungu/common/");
|
|
1364
|
+
targetPath = path5.join(backendJavaDir, relativePath);
|
|
1365
|
+
} else if (fragment.target.startsWith("config/")) {
|
|
1366
|
+
const mainModule = this.findMainModule(projectPath);
|
|
1367
|
+
if (mainModule) {
|
|
1368
|
+
const relativePath = fragment.target.replace(/^config\//, `${mainModule}/config/`);
|
|
1369
|
+
targetPath = path5.join(backendJavaDir, relativePath);
|
|
1370
|
+
} else {
|
|
1371
|
+
targetPath = path5.join(backendJavaDir, fragment.target);
|
|
1372
|
+
}
|
|
1373
|
+
} else {
|
|
1374
|
+
targetPath = path5.join(backendJavaDir, fragment.target);
|
|
1375
|
+
}
|
|
1376
|
+
await FileUtils.ensureDir(path5.dirname(targetPath));
|
|
1377
|
+
await FileUtils.write(targetPath, content);
|
|
1378
|
+
addedFiles.push(path5.relative(projectPath, targetPath));
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
if (module.frontendFragments) {
|
|
1382
|
+
const frontendSrcDir = path5.join(projectPath, "frontend/src");
|
|
1383
|
+
for (const fragment of module.frontendFragments) {
|
|
1341
1384
|
const sourcePath = path5.join(templatesDir, "modules", fragment.source);
|
|
1342
|
-
const targetPath = path5.join(
|
|
1385
|
+
const targetPath = path5.join(frontendSrcDir, fragment.target);
|
|
1343
1386
|
if (await FileUtils.exists(sourcePath)) {
|
|
1344
|
-
await FileUtils.
|
|
1345
|
-
let content = await FileUtils.read(sourcePath);
|
|
1346
|
-
const targetPackage = "org.yungu.common." + path5.dirname(fragment.target).replace(/\//g, ".");
|
|
1347
|
-
content = content.replace(/^package\s+[^;]+;/m, `package ${targetPackage};`);
|
|
1348
|
-
await FileUtils.write(targetPath, content);
|
|
1387
|
+
await FileUtils.copy(sourcePath, targetPath);
|
|
1349
1388
|
addedFiles.push(path5.relative(projectPath, targetPath));
|
|
1350
1389
|
}
|
|
1351
1390
|
}
|
|
1352
|
-
} else if (module.type === "remote") {
|
|
1353
1391
|
}
|
|
1354
1392
|
return addedFiles;
|
|
1355
1393
|
}
|
|
1394
|
+
/**
|
|
1395
|
+
* 查找主模块名 (第一个 service 类型的模块)
|
|
1396
|
+
*/
|
|
1397
|
+
static findMainModule(projectPath) {
|
|
1398
|
+
const settingsPath = path5.join(projectPath, "backend/settings.gradle");
|
|
1399
|
+
const content = FileUtils.readSync(settingsPath);
|
|
1400
|
+
const matches = content.match(/include\s+'([^']+)'/g);
|
|
1401
|
+
if (matches) {
|
|
1402
|
+
for (const match of matches) {
|
|
1403
|
+
const moduleName = match.replace(/include\s+'/, "").replace(/'/, "");
|
|
1404
|
+
if (moduleName !== "common") {
|
|
1405
|
+
return moduleName;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
return null;
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* 生成占位符代码
|
|
1413
|
+
*/
|
|
1414
|
+
static generatePlaceholderCode(module, fragment) {
|
|
1415
|
+
const targetPackage = path5.dirname(fragment.target).replace(/\//g, ".");
|
|
1416
|
+
const className = path5.basename(fragment.target, ".java");
|
|
1417
|
+
const moduleName = module.name;
|
|
1418
|
+
const moduleId = module.id;
|
|
1419
|
+
return `package ${targetPackage};
|
|
1420
|
+
|
|
1421
|
+
import lombok.extern.slf4j.Slf4j;
|
|
1422
|
+
|
|
1423
|
+
/**
|
|
1424
|
+
* ${moduleName} - \u5360\u4F4D\u7B26
|
|
1425
|
+
*
|
|
1426
|
+
* \u6B64\u6587\u4EF6\u7531 team-cli \u81EA\u52A8\u751F\u6210\u3002
|
|
1427
|
+
* \u6A21\u5757 ID: ${moduleId}
|
|
1428
|
+
*
|
|
1429
|
+
* \u4F7F\u7528\u8BF4\u660E:
|
|
1430
|
+
* 1. \u8BF7\u6839\u636E\u9879\u76EE\u5B9E\u9645\u9700\u6C42\u5B8C\u5584\u6B64\u6587\u4EF6
|
|
1431
|
+
* 2. \u6216\u53C2\u8003 docs/specs/${moduleId}/spec.md \u83B7\u53D6\u8BE6\u7EC6\u9700\u6C42
|
|
1432
|
+
*/
|
|
1433
|
+
@Slf4j
|
|
1434
|
+
public class ${className} {
|
|
1435
|
+
|
|
1436
|
+
/**
|
|
1437
|
+
* TODO: \u5B9E\u73B0 ${moduleName} \u529F\u80FD
|
|
1438
|
+
*/
|
|
1439
|
+
public void execute() {
|
|
1440
|
+
log.info("${className} - \u6267\u884C\u4E2D...");
|
|
1441
|
+
// \u5728\u6B64\u5B9E\u73B0\u5177\u4F53\u903B\u8F91
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
`;
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* 生成本地模块的 Spec 占位符
|
|
1448
|
+
*/
|
|
1449
|
+
static async generateLocalSpecPlaceholder(targetPath, module) {
|
|
1450
|
+
const content = `# ${module.name}
|
|
1451
|
+
|
|
1452
|
+
## \u529F\u80FD\u6982\u8FF0
|
|
1453
|
+
${module.description}
|
|
1454
|
+
|
|
1455
|
+
## \u4F7F\u7528\u8BF4\u660E
|
|
1456
|
+
|
|
1457
|
+
\u6B64\u6A21\u5757\u4E3A\u4E91\u8C37\u901A\u7528\u6A21\u5757\u7684\u5360\u4F4D\u7B26\u914D\u7F6E\u3002
|
|
1458
|
+
|
|
1459
|
+
### \u914D\u7F6E\u6B65\u9AA4
|
|
1460
|
+
|
|
1461
|
+
1. **\u6DFB\u52A0\u4F9D\u8D56**
|
|
1462
|
+
|
|
1463
|
+
\u5728 \`backend/build.gradle\` \u4E2D\u6DFB\u52A0:
|
|
1464
|
+
|
|
1465
|
+
\`\`\`groovy
|
|
1466
|
+
${module.dependencies ? module.dependencies.map((d) => `implementation '${d}'`).join("\n") : ""}
|
|
1467
|
+
\`\`\`
|
|
1468
|
+
|
|
1469
|
+
2. **\u914D\u7F6E\u6587\u4EF6**
|
|
1470
|
+
|
|
1471
|
+
\u6839\u636E\u9700\u6C42\u914D\u7F6E application.yml:
|
|
1472
|
+
|
|
1473
|
+
\`\`\`yaml
|
|
1474
|
+
# ${module.name} \u914D\u7F6E
|
|
1475
|
+
\`\`\`
|
|
1476
|
+
|
|
1477
|
+
3. **\u5BFC\u5165\u914D\u7F6E\u7C7B**
|
|
1478
|
+
|
|
1479
|
+
\u5728\u4E3B Application \u7C7B\u4E0A\u6DFB\u52A0\u6CE8\u89E3:
|
|
1480
|
+
|
|
1481
|
+
\`\`\`java
|
|
1482
|
+
@SpringBootApplication
|
|
1483
|
+
@ComponentScan("${module.id}")
|
|
1484
|
+
public class Application {
|
|
1485
|
+
// ...
|
|
1486
|
+
}
|
|
1487
|
+
\`\`\`
|
|
1488
|
+
|
|
1489
|
+
4. **\u53C2\u8003\u6587\u6863**
|
|
1490
|
+
|
|
1491
|
+
\u67E5\u770B docs/specs/${module.id}/spec.md \u83B7\u53D6\u8BE6\u7EC6\u5B9E\u73B0\u8BF4\u660E\u3002
|
|
1492
|
+
|
|
1493
|
+
## \u4F9D\u8D56\u5173\u7CFB
|
|
1494
|
+
|
|
1495
|
+
${module.requires ? `\u9700\u8981\u5148\u542F\u7528: ${module.requires.join(", ")}` : "\u65E0\u524D\u7F6E\u4F9D\u8D56"}
|
|
1496
|
+
`;
|
|
1497
|
+
await FileUtils.write(targetPath, content);
|
|
1498
|
+
}
|
|
1356
1499
|
/**
|
|
1357
1500
|
* 生成远程模块的 Spec 占位符
|
|
1358
1501
|
*/
|