@vitarx/release-cli 1.0.0-alpha.0 → 1.0.0-alpha.2

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/release.js CHANGED
@@ -184,7 +184,7 @@ async function publishPackage(pkgDir, packageManager, isDryRun = false, args) {
184
184
  // -------------------- Step 8: 推送代码和标签到远程仓库 --------------------
185
185
  log.info('⬆️ Pushing to remote...');
186
186
  try {
187
- runCommand(`git push${tagName ? '&& git push --tags' : ''}`, isDryRun);
187
+ runCommand(`git push${tagName ? ' && git push --tags' : ''}`, isDryRun);
188
188
  }
189
189
  catch {
190
190
  log.warn('包已发布到pnm,但推送代码和标签到远程仓库意外失败,请仔细核查npm仓库和远程仓库状态。');
@@ -299,7 +299,7 @@ export async function main() {
299
299
  }
300
300
  else {
301
301
  // 单包项目,发布根目录
302
- await publishPackage(process.cwd(), packageManager, isDryRun, args);
302
+ await publishPackage('.', packageManager, isDryRun, args);
303
303
  }
304
304
  }
305
305
  // 执行主函数
package/dist/utils.js CHANGED
@@ -197,23 +197,18 @@ export function getWorkspacePackages() {
197
197
  try {
198
198
  // 读取根目录的package.json文件
199
199
  const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
200
- // 获取workspaces配置,如果没有则为空数组
201
- const workspaces = pkg.workspaces || [];
200
+ // 获取workspaces配置,支持数组格式和对象格式(包含packages数组)
201
+ let workspaces = [];
202
+ if (Array.isArray(pkg.workspaces)) {
203
+ workspaces = pkg.workspaces;
204
+ }
205
+ else if (pkg.workspaces && Array.isArray(pkg.workspaces.packages)) {
206
+ workspaces = pkg.workspaces.packages;
207
+ }
202
208
  // 遍历所有workspace模式
203
209
  for (const workspacePattern of workspaces) {
204
- // 获取所有目录
205
- const workspaceDirs = fs
206
- .readdirSync('.', { withFileTypes: true })
207
- .filter((dirent) => dirent.isDirectory())
208
- .map((dirent) => dirent.name)
209
- .filter((dir) => {
210
- // 简单的模式匹配(支持通配符)
211
- if (workspacePattern.includes('*')) {
212
- const pattern = workspacePattern.replace(/\*/g, '.*');
213
- return new RegExp(`^${pattern}$`).test(dir);
214
- }
215
- return dir === workspacePattern;
216
- });
210
+ // 获取所有匹配的目录
211
+ const workspaceDirs = findMatchingDirectories(workspacePattern);
217
212
  for (const dir of workspaceDirs) {
218
213
  const pkgPath = path.join(dir, 'package.json');
219
214
  if (fs.existsSync(pkgPath)) {
@@ -232,6 +227,60 @@ export function getWorkspacePackages() {
232
227
  }
233
228
  return packages;
234
229
  }
230
+ /**
231
+ * 查找匹配通配符模式的所有目录
232
+ * @param pattern 通配符模式(如 "packages/*")
233
+ * @returns 匹配的目录路径数组
234
+ */
235
+ function findMatchingDirectories(pattern) {
236
+ const directories = [];
237
+ // 如果模式包含通配符,递归查找所有匹配的目录
238
+ if (pattern.includes('*')) {
239
+ const parts = pattern.split('/');
240
+ let currentPath = '.';
241
+ for (let i = 0; i < parts.length; i++) {
242
+ const part = parts[i];
243
+ if (part.includes('*')) {
244
+ // 通配符部分,查找所有匹配的子目录
245
+ const regexPattern = part.replace(/\*/g, '.*');
246
+ const regex = new RegExp(`^${regexPattern}$`);
247
+ const subDirs = fs
248
+ .readdirSync(currentPath, { withFileTypes: true })
249
+ .filter((dirent) => dirent.isDirectory())
250
+ .map((dirent) => dirent.name)
251
+ .filter((dir) => regex.test(dir))
252
+ .map((dir) => path.join(currentPath, dir));
253
+ // 如果是最后一个部分,直接添加到结果
254
+ if (i === parts.length - 1) {
255
+ directories.push(...subDirs);
256
+ }
257
+ else {
258
+ // 继续递归查找下一级目录
259
+ for (const subDir of subDirs) {
260
+ const remainingPattern = parts.slice(i + 1).join('/');
261
+ const nestedDirs = findMatchingDirectories(path.join(subDir, remainingPattern));
262
+ directories.push(...nestedDirs);
263
+ }
264
+ break;
265
+ }
266
+ }
267
+ else {
268
+ // 非通配符部分,直接进入下一级目录
269
+ currentPath = path.join(currentPath, part);
270
+ if (!fs.existsSync(currentPath)) {
271
+ break;
272
+ }
273
+ }
274
+ }
275
+ }
276
+ else {
277
+ // 简单目录名,直接检查是否存在
278
+ if (fs.existsSync(pattern)) {
279
+ directories.push(pattern);
280
+ }
281
+ }
282
+ return directories;
283
+ }
235
284
  /**
236
285
  * 格式化版本号函数
237
286
  * 根据当前版本号和下一个版本类型或自定义版本号生成新的版本号
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitarx/release-cli",
3
- "version": "1.0.0-alpha.0",
3
+ "version": "1.0.0-alpha.2",
4
4
  "description": "A CLI tool for automated npm package release with workspace support",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",