prd-workflow-cli 1.1.26 → 1.1.28
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/upgrade.js +0 -6
- package/package.json +1 -2
- package/scripts/postinstall.js +74 -72
package/commands/upgrade.js
CHANGED
|
@@ -105,12 +105,6 @@ module.exports = async function (options = {}) {
|
|
|
105
105
|
source: '.antigravity',
|
|
106
106
|
target: '.antigravity',
|
|
107
107
|
isDir: true
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: 'AI Guide',
|
|
111
|
-
source: 'AI-GUIDE.md',
|
|
112
|
-
target: 'AI-GUIDE.md',
|
|
113
|
-
isDir: false
|
|
114
108
|
}
|
|
115
109
|
];
|
|
116
110
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prd-workflow-cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.28",
|
|
4
4
|
"description": "产品需求管理规范 CLI 工具 - 基于 A→R→B→C 流程,集成 PM 确认机制和对话归档的需求管理命令行工具",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
".antigravity/",
|
|
53
53
|
"templates/",
|
|
54
54
|
".cursorrules",
|
|
55
|
-
"AI-GUIDE.md",
|
|
56
55
|
"README.md",
|
|
57
56
|
"GUIDE.md"
|
|
58
57
|
],
|
package/scripts/postinstall.js
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* postinstall 脚本
|
|
5
|
-
* 在 npm install
|
|
5
|
+
* 在 npm install 完成后自动执行,复制 workflows 和规则文件到项目中
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
const fs = require('fs');
|
|
9
9
|
const path = require('path');
|
|
10
10
|
|
|
11
|
-
//
|
|
11
|
+
// 静默模式运行
|
|
12
12
|
const SILENT = process.env.PRD_POSTINSTALL_SILENT === 'true';
|
|
13
|
+
const DEBUG = process.env.PRD_DEBUG === 'true';
|
|
13
14
|
|
|
14
15
|
function log(msg) {
|
|
15
16
|
if (!SILENT) {
|
|
@@ -17,27 +18,14 @@ function log(msg) {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 获取项目根目录(向上查找包含 .prd-config.json 的目录)
|
|
27
|
-
*/
|
|
28
|
-
function findProjectRoot(startDir) {
|
|
29
|
-
let currentDir = startDir;
|
|
30
|
-
const root = path.parse(currentDir).root;
|
|
31
|
-
|
|
32
|
-
while (currentDir !== root) {
|
|
33
|
-
const configPath = path.join(currentDir, '.prd-config.json');
|
|
34
|
-
if (fs.existsSync(configPath)) {
|
|
35
|
-
return currentDir;
|
|
36
|
-
}
|
|
37
|
-
currentDir = path.dirname(currentDir);
|
|
21
|
+
function debug(msg) {
|
|
22
|
+
if (DEBUG) {
|
|
23
|
+
console.log('[DEBUG]', msg);
|
|
38
24
|
}
|
|
25
|
+
}
|
|
39
26
|
|
|
40
|
-
|
|
27
|
+
function logError(msg) {
|
|
28
|
+
console.error(msg);
|
|
41
29
|
}
|
|
42
30
|
|
|
43
31
|
/**
|
|
@@ -57,28 +45,6 @@ function filesAreDifferent(sourcePath, targetPath) {
|
|
|
57
45
|
}
|
|
58
46
|
}
|
|
59
47
|
|
|
60
|
-
/**
|
|
61
|
-
* 递归复制目录
|
|
62
|
-
*/
|
|
63
|
-
function copyDirSync(src, dest) {
|
|
64
|
-
if (!fs.existsSync(dest)) {
|
|
65
|
-
fs.mkdirSync(dest, { recursive: true });
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
69
|
-
|
|
70
|
-
for (const entry of entries) {
|
|
71
|
-
const srcPath = path.join(src, entry.name);
|
|
72
|
-
const destPath = path.join(dest, entry.name);
|
|
73
|
-
|
|
74
|
-
if (entry.isDirectory()) {
|
|
75
|
-
copyDirSync(srcPath, destPath);
|
|
76
|
-
} else {
|
|
77
|
-
fs.copyFileSync(srcPath, destPath);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
48
|
/**
|
|
83
49
|
* 获取目录下所有文件(递归)
|
|
84
50
|
*/
|
|
@@ -107,44 +73,81 @@ function getAllFiles(dirPath, basePath = dirPath) {
|
|
|
107
73
|
return files;
|
|
108
74
|
}
|
|
109
75
|
|
|
76
|
+
/**
|
|
77
|
+
* 检查是否是全局安装
|
|
78
|
+
*/
|
|
79
|
+
function isGlobalInstall(packagePath) {
|
|
80
|
+
// 全局安装的路径通常包含 lib/node_modules 或类似结构
|
|
81
|
+
// 本地安装的路径是 项目/node_modules/包名
|
|
82
|
+
const normalizedPath = packagePath.toLowerCase();
|
|
83
|
+
|
|
84
|
+
// 检查是否在项目的 node_modules 中
|
|
85
|
+
const pathParts = packagePath.split(path.sep);
|
|
86
|
+
const nodeModulesIndex = pathParts.lastIndexOf('node_modules');
|
|
87
|
+
|
|
88
|
+
if (nodeModulesIndex === -1) {
|
|
89
|
+
return true; // 不在 node_modules 中,可能是开发环境
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 检查 node_modules 前面是否有 lib 目录(全局安装的特征)
|
|
93
|
+
if (nodeModulesIndex > 0 && pathParts[nodeModulesIndex - 1] === 'lib') {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 检查是否在 /usr/local 或 /opt 等系统目录下
|
|
98
|
+
if (normalizedPath.includes('/usr/') || normalizedPath.includes('/opt/')) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
|
|
110
105
|
/**
|
|
111
106
|
* 主函数
|
|
112
107
|
*/
|
|
113
108
|
function main() {
|
|
114
109
|
try {
|
|
115
|
-
// 获取 npm
|
|
110
|
+
// 获取 npm 包的路径
|
|
116
111
|
// 脚本路径: node_modules/prd-workflow-cli/scripts/postinstall.js
|
|
117
112
|
// __dirname = node_modules/prd-workflow-cli/scripts
|
|
118
113
|
// packagePath = node_modules/prd-workflow-cli
|
|
119
114
|
const packagePath = path.join(__dirname, '..');
|
|
120
115
|
|
|
121
|
-
|
|
116
|
+
debug(`packagePath = ${packagePath}`);
|
|
117
|
+
|
|
118
|
+
// 检查是否是全局安装
|
|
119
|
+
if (isGlobalInstall(packagePath)) {
|
|
120
|
+
debug('检测到全局安装,跳过文件复制');
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 计算项目根目录
|
|
122
125
|
// packagePath = /project/node_modules/prd-workflow-cli
|
|
123
126
|
// node_modules = /project/node_modules
|
|
124
127
|
// projectRoot = /project
|
|
125
128
|
const nodeModulesPath = path.dirname(packagePath);
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
// 调试信息(仅在非静默模式下显示)
|
|
129
|
-
if (!SILENT && process.env.PRD_DEBUG === 'true') {
|
|
130
|
-
console.log('DEBUG: __dirname =', __dirname);
|
|
131
|
-
console.log('DEBUG: packagePath =', packagePath);
|
|
132
|
-
console.log('DEBUG: nodeModulesPath =', nodeModulesPath);
|
|
133
|
-
console.log('DEBUG: potentialProjectRoot =', potentialProjectRoot);
|
|
134
|
-
}
|
|
129
|
+
const projectRoot = path.dirname(nodeModulesPath);
|
|
135
130
|
|
|
136
|
-
|
|
137
|
-
|
|
131
|
+
debug(`nodeModulesPath = ${nodeModulesPath}`);
|
|
132
|
+
debug(`projectRoot = ${projectRoot}`);
|
|
138
133
|
|
|
139
|
-
|
|
140
|
-
|
|
134
|
+
// 验证项目根目录存在
|
|
135
|
+
if (!fs.existsSync(projectRoot)) {
|
|
136
|
+
debug('项目根目录不存在,跳过');
|
|
141
137
|
return;
|
|
142
138
|
}
|
|
143
139
|
|
|
144
|
-
|
|
140
|
+
// 检查是否有 package.json(确认是一个 npm 项目)
|
|
141
|
+
const packageJsonPath = path.join(projectRoot, 'package.json');
|
|
142
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
143
|
+
debug('项目根目录没有 package.json,跳过');
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
log('\n📦 prd-workflow-cli: 正在配置 AI 工作流文件...');
|
|
145
148
|
|
|
146
|
-
//
|
|
147
|
-
const
|
|
149
|
+
// 定义需要复制的文件/目录
|
|
150
|
+
const copyItems = [
|
|
148
151
|
{
|
|
149
152
|
name: 'Workflows',
|
|
150
153
|
source: '.agent/workflows',
|
|
@@ -162,23 +165,18 @@ function main() {
|
|
|
162
165
|
source: '.antigravity',
|
|
163
166
|
target: '.antigravity',
|
|
164
167
|
isDir: true
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
name: 'AI Guide',
|
|
168
|
-
source: 'AI-GUIDE.md',
|
|
169
|
-
target: 'AI-GUIDE.md',
|
|
170
|
-
isDir: false
|
|
171
168
|
}
|
|
172
169
|
];
|
|
173
170
|
|
|
174
171
|
let updatedCount = 0;
|
|
175
172
|
let newCount = 0;
|
|
176
173
|
|
|
177
|
-
for (const item of
|
|
174
|
+
for (const item of copyItems) {
|
|
178
175
|
const sourcePath = path.join(packagePath, item.source);
|
|
179
176
|
const targetPath = path.join(projectRoot, item.target);
|
|
180
177
|
|
|
181
178
|
if (!fs.existsSync(sourcePath)) {
|
|
179
|
+
debug(`源文件不存在: ${sourcePath}`);
|
|
182
180
|
continue;
|
|
183
181
|
}
|
|
184
182
|
|
|
@@ -238,16 +236,20 @@ function main() {
|
|
|
238
236
|
if (updatedCount > 0) {
|
|
239
237
|
log(` 🔄 更新 ${updatedCount} 个文件`);
|
|
240
238
|
}
|
|
241
|
-
log(' ✅
|
|
239
|
+
log(' ✅ AI 工作流配置完成!\n');
|
|
240
|
+
log(' 📁 已添加文件:');
|
|
241
|
+
log(' .agent/workflows/ - PRD 工作流指引');
|
|
242
|
+
log(' .cursorrules - Cursor AI 规则');
|
|
243
|
+
log(' .antigravity/ - Antigravity AI 规则');
|
|
244
|
+
log(' AI-GUIDE.md - AI 使用指南\n');
|
|
242
245
|
} else {
|
|
243
246
|
log(' ✅ 所有配置文件已是最新版本\n');
|
|
244
247
|
}
|
|
245
248
|
|
|
246
249
|
} catch (error) {
|
|
247
250
|
// postinstall 失败不应该阻止安装
|
|
248
|
-
|
|
249
|
-
logError(
|
|
250
|
-
logError(' 您可以稍后手动运行 "prd upgrade" 来更新配置文件\n');
|
|
251
|
+
logError(`\n⚠️ prd-workflow-cli: 配置文件复制失败: ${error.message}`);
|
|
252
|
+
logError(' 您可以手动运行 "npx prd upgrade" 来完成配置\n');
|
|
251
253
|
}
|
|
252
254
|
}
|
|
253
255
|
|