@vitarx/release-cli 1.0.0-alpha.1 → 1.0.0

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
@@ -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
@@ -207,19 +207,8 @@ export function getWorkspacePackages() {
207
207
  }
208
208
  // 遍历所有workspace模式
209
209
  for (const workspacePattern of workspaces) {
210
- // 获取所有目录
211
- const workspaceDirs = fs
212
- .readdirSync('.', { withFileTypes: true })
213
- .filter((dirent) => dirent.isDirectory())
214
- .map((dirent) => dirent.name)
215
- .filter((dir) => {
216
- // 简单的模式匹配(支持通配符)
217
- if (workspacePattern.includes('*')) {
218
- const pattern = workspacePattern.replace(/\*/g, '.*');
219
- return new RegExp(`^${pattern}$`).test(dir);
220
- }
221
- return dir === workspacePattern;
222
- });
210
+ // 获取所有匹配的目录
211
+ const workspaceDirs = findMatchingDirectories(workspacePattern);
223
212
  for (const dir of workspaceDirs) {
224
213
  const pkgPath = path.join(dir, 'package.json');
225
214
  if (fs.existsSync(pkgPath)) {
@@ -238,6 +227,60 @@ export function getWorkspacePackages() {
238
227
  }
239
228
  return packages;
240
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
+ }
241
284
  /**
242
285
  * 格式化版本号函数
243
286
  * 根据当前版本号和下一个版本类型或自定义版本号生成新的版本号
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitarx/release-cli",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0",
4
4
  "description": "A CLI tool for automated npm package release with workspace support",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",