prd-workflow-cli 1.1.29 → 1.1.30
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/commands/init.js +30 -17
- package/package.json +1 -1
package/commands/init.js
CHANGED
|
@@ -3,16 +3,25 @@ const path = require('path');
|
|
|
3
3
|
const chalk = require('chalk');
|
|
4
4
|
|
|
5
5
|
module.exports = async function (projectName) {
|
|
6
|
-
|
|
6
|
+
// 支持 "." 表示在当前目录初始化
|
|
7
|
+
const isCurrentDir = projectName === '.';
|
|
8
|
+
const projectPath = isCurrentDir ? process.cwd() : path.join(process.cwd(), projectName);
|
|
9
|
+
const displayName = isCurrentDir ? path.basename(process.cwd()) : projectName;
|
|
7
10
|
|
|
8
11
|
try {
|
|
9
|
-
//
|
|
10
|
-
if (await fs.pathExists(projectPath)) {
|
|
12
|
+
// 检查目录是否已存在(仅当创建新目录时)
|
|
13
|
+
if (!isCurrentDir && await fs.pathExists(projectPath)) {
|
|
11
14
|
console.log(chalk.red(`✗ 目录 ${projectName} 已存在`));
|
|
12
15
|
return;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
// 检查当前目录是否已经是 PRD 项目
|
|
19
|
+
if (isCurrentDir && await fs.pathExists(path.join(projectPath, '.prd-config.json'))) {
|
|
20
|
+
console.log(chalk.red('✗ 当前目录已经是 PRD 项目'));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
console.log(chalk.blue(`正在${isCurrentDir ? '在当前目录' : '创建项目: ' + projectName}初始化...`));
|
|
16
25
|
|
|
17
26
|
// 创建项目目录结构
|
|
18
27
|
const directories = [
|
|
@@ -30,7 +39,7 @@ module.exports = async function (projectName) {
|
|
|
30
39
|
|
|
31
40
|
// 创建项目配置文件
|
|
32
41
|
const config = {
|
|
33
|
-
projectName,
|
|
42
|
+
projectName: displayName,
|
|
34
43
|
createdAt: new Date().toISOString(),
|
|
35
44
|
currentIteration: 0,
|
|
36
45
|
workflow: 'A → R → B → C',
|
|
@@ -49,9 +58,9 @@ module.exports = async function (projectName) {
|
|
|
49
58
|
|
|
50
59
|
// 创建 package.json(让其他用户可以通过 npm install 安装 CLI)
|
|
51
60
|
const packageJson = {
|
|
52
|
-
name:
|
|
61
|
+
name: displayName.toLowerCase().replace(/[^a-z0-9]/g, '-'),
|
|
53
62
|
version: '1.0.0',
|
|
54
|
-
description: `${
|
|
63
|
+
description: `${displayName} - PRD 需求管理项目`,
|
|
55
64
|
private: true,
|
|
56
65
|
scripts: {
|
|
57
66
|
prd: 'prd',
|
|
@@ -59,7 +68,7 @@ module.exports = async function (projectName) {
|
|
|
59
68
|
help: 'prd --help'
|
|
60
69
|
},
|
|
61
70
|
dependencies: {
|
|
62
|
-
'prd-workflow-cli': '^1.1.
|
|
71
|
+
'prd-workflow-cli': '^1.1.29'
|
|
63
72
|
}
|
|
64
73
|
};
|
|
65
74
|
|
|
@@ -73,7 +82,7 @@ module.exports = async function (projectName) {
|
|
|
73
82
|
const p0Template = `# P0_项目基本信息
|
|
74
83
|
|
|
75
84
|
**创建时间**: ${new Date().toLocaleString('zh-CN')}
|
|
76
|
-
**项目名称**: ${
|
|
85
|
+
**项目名称**: ${displayName}
|
|
77
86
|
**文档状态**: 草案
|
|
78
87
|
|
|
79
88
|
---
|
|
@@ -96,7 +105,7 @@ module.exports = async function (projectName) {
|
|
|
96
105
|
|
|
97
106
|
### 1.1 项目定位
|
|
98
107
|
|
|
99
|
-
**项目全称**: ${
|
|
108
|
+
**项目全称**: ${displayName}
|
|
100
109
|
|
|
101
110
|
**项目简述**:
|
|
102
111
|
<!-- 一句话说明这个项目是什么 -->
|
|
@@ -259,14 +268,14 @@ module.exports = async function (projectName) {
|
|
|
259
268
|
}
|
|
260
269
|
|
|
261
270
|
// 创建 README
|
|
262
|
-
const readme = `# ${
|
|
271
|
+
const readme = `# ${displayName}
|
|
263
272
|
|
|
264
273
|
本项目采用规范化的产品需求管理流程
|
|
265
274
|
|
|
266
275
|
## 📁 目录结构
|
|
267
276
|
|
|
268
277
|
\`\`\`
|
|
269
|
-
${
|
|
278
|
+
${displayName}/
|
|
270
279
|
├── 00_项目总览/ # 项目基本信息
|
|
271
280
|
├── 01_产品基线/ # A 类文档:现状基线
|
|
272
281
|
├── 02_迭代记录/ # 各轮迭代的 B、C 类文档
|
|
@@ -339,15 +348,19 @@ prd plan freeze
|
|
|
339
348
|
console.log('');
|
|
340
349
|
console.log(chalk.bold('📋 下一步操作(请按顺序执行):'));
|
|
341
350
|
console.log('');
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
351
|
+
if (!isCurrentDir) {
|
|
352
|
+
console.log(chalk.cyan('第 1 步: 进入项目目录'));
|
|
353
|
+
console.log(` cd ${displayName}`);
|
|
354
|
+
console.log('');
|
|
355
|
+
console.log(chalk.cyan('第 2 步: 完善 P0_项目基本信息.md'));
|
|
356
|
+
} else {
|
|
357
|
+
console.log(chalk.cyan('第 1 步: 完善 P0_项目基本信息.md'));
|
|
358
|
+
}
|
|
346
359
|
console.log(chalk.gray(' 文件位置: 00_项目总览/P0_项目基本信息.md'));
|
|
347
360
|
console.log(chalk.gray(' 填写内容: 项目目标、干系人、约束条件等'));
|
|
348
361
|
console.log(chalk.yellow(' ⚠️ 必须完成 P0 填写后才能开始创建 A 类基线文档'));
|
|
349
362
|
console.log('');
|
|
350
|
-
console.log(chalk.cyan('
|
|
363
|
+
console.log(chalk.cyan(`第 ${isCurrentDir ? '2' : '3'} 步: 创建 A0 基线文档`));
|
|
351
364
|
console.log(' prd baseline create A0 # P0 填写完成后执行');
|
|
352
365
|
console.log('');
|
|
353
366
|
|