create-yarn-workspaces 3.0.4 → 3.0.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/CHANGELOG.md CHANGED
@@ -3,6 +3,41 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.0.5](https://github.com/bluelovers/ws-yarn-workspaces/compare/create-yarn-workspaces@3.0.4...create-yarn-workspaces@3.0.5) (2026-03-02)
7
+
8
+
9
+
10
+ ### 📦 Code Refactoring
11
+
12
+ * **npa-to-deps-query:** 整合 IResult 類型並添加 npm-package-arg-util 依賴 ([7c4471c](https://github.com/bluelovers/ws-yarn-workspaces/commit/7c4471c7ccd1242826b6f47da38bb967a6c44abc))
13
+
14
+
15
+ ### 📚 Documentation
16
+
17
+ * **pkg-entry-util,create-yarn-workspaces,npm-init2:** 新增完整雙語文件與 JSDoc 註解 ([c1786e6](https://github.com/bluelovers/ws-yarn-workspaces/commit/c1786e6785abe484c95ee3dee8b8a16358c3904b))
18
+
19
+
20
+ ### 🚨 Tests
21
+
22
+ * **fnm-detect:** correct alias props and update dependencies ([21d1c54](https://github.com/bluelovers/ws-yarn-workspaces/commit/21d1c54c60ae64fb2117eae1e2b86bb42c8b6070))
23
+
24
+
25
+ ### 🛠 Build System
26
+
27
+ * **pkg-entry-util,create-yarn-workspaces,npm-init2:** 新增完整雙語文件與 JSDoc 註解 ([087d6d6](https://github.com/bluelovers/ws-yarn-workspaces/commit/087d6d6e560c70ed68a79ad73c8eb05868ec4203))
28
+
29
+
30
+ ### ♻️ Chores
31
+
32
+ * Add test config and global types for tsdx ([88a8df6](https://github.com/bluelovers/ws-yarn-workspaces/commit/88a8df6eef5dc59d9e0d9268b21706dceb5ab2a1))
33
+ * remove empty resolutions and redundant packageManager fields ([65b5c5f](https://github.com/bluelovers/ws-yarn-workspaces/commit/65b5c5f929aae82474408b2b46cfc5a471c919f6))
34
+ * add __root.ts test utility to workspace packages ([a771727](https://github.com/bluelovers/ws-yarn-workspaces/commit/a7717278883c86d9ed8ab89f42070d3385c173a7))
35
+ * **deps:** 升級路徑與檔案系統相關依賴版本 ([78d395b](https://github.com/bluelovers/ws-yarn-workspaces/commit/78d395b5469feecc85f250ca2d8b4977161e7618))
36
+ * **deps:** 更新依賴版本並將腳本執行從 yarn 遷移至 node --run ([389e581](https://github.com/bluelovers/ws-yarn-workspaces/commit/389e581a07cf803dc34c8402b4d3f69af0016b8c))
37
+ * **deps:** 升級多項依賴套件版本 ([1382602](https://github.com/bluelovers/ws-yarn-workspaces/commit/1382602ca94ff236b251fd1481b6332468de4621))
38
+
39
+
40
+
6
41
  ## [3.0.4](https://github.com/bluelovers/ws-yarn-workspaces/compare/create-yarn-workspaces@3.0.3...create-yarn-workspaces@3.0.4) (2025-09-07)
7
42
 
8
43
 
package/README.md CHANGED
@@ -1,10 +1,80 @@
1
1
  # create-yarn-workspaces
2
2
 
3
- yarn create yarn-workspaces
4
- npx create-yarn-workspaces
5
-
6
- * [npm-init2](https://www.npmjs.com/package/npm-init2)
7
- * [create-yarn-workspaces](https://www.npmjs.com/package/create-yarn-workspaces)
8
- * [find-pkg-ws](https://www.npmjs.com/package/find-pkg-ws)
9
- * [workspaces-config](https://www.npmjs.com/package/workspaces-config)
10
- * [keywords:workspaces](https://www.npmjs.com/search?q=keywords:workspaces)
3
+ > 快速初始化 Yarn Workspaces 專案結構 / Quickly initialize Yarn Workspaces project structure
4
+
5
+ ## 安裝與使用 / Installation & Usage
6
+
7
+ ```bash
8
+ # 使用 Yarn
9
+ yarn create yarn-workspaces
10
+
11
+ # 使用 npx
12
+ npx create-yarn-workspaces
13
+
14
+ # 使用 pnpm
15
+ pnpm create yarn-workspaces
16
+ ```
17
+
18
+ ## 功能特性 / Features
19
+
20
+ - 🚀 **快速初始化** - 一鍵創建完整的 Yarn Workspaces 專案結構
21
+ - 📦 **Lerna 整合** - 自動檢測並更新現有的 Lerna 配置
22
+ - 📝 **智能設定** - 自動配置 package.json、tsconfig 等開發環境檔案
23
+ - 🔧 **靈活選項** - 支援自定義初始化回呼與多種配置選項
24
+ - 🗂️ **目錄管理** - 根據 workspaces 配置自動創建 packages 目錄
25
+
26
+ ## 命令列選項 / CLI Options
27
+
28
+ | 選項 / Option | 別名 / Alias | 說明 / Description |
29
+ |--------------|-------------|-------------------|
30
+ | `--name` | `-n` | 指定 Package 名稱 / Specify package name |
31
+ | `--ignoreExistsPackage` | `-i` | 忽略已存在的 Package / Ignore existing package |
32
+ | `--ignoreParentWorkspaces` | | 忽略父層 Workspaces / Ignore parent workspaces |
33
+ | `--debug` | | 啟用除錯模式 / Enable debug mode |
34
+
35
+ ## API 使用 / API Usage
36
+
37
+ ```typescript
38
+ import { createYarnWorkspaces, IOptions } from 'create-yarn-workspaces';
39
+
40
+ // 基本使用 / Basic usage
41
+ const success = createYarnWorkspaces('./my-project');
42
+
43
+ // 帶選項 / With options
44
+ const options: IOptions = {
45
+ ignoreExistsPackage: true,
46
+ ignoreParentWorkspaces: false,
47
+ initPackageJson: (pkg) => {
48
+ pkg.author = 'Your Name';
49
+ return pkg;
50
+ }
51
+ };
52
+
53
+ createYarnWorkspaces('./my-project', options);
54
+ ```
55
+
56
+ ## 目錄結構 / Directory Structure
57
+
58
+ 初始化後的專案結構 / Project structure after initialization:
59
+
60
+ ```
61
+ my-project/
62
+ ├── package.json # Workspaces 配置 / Workspaces config
63
+ ├── lerna.json # Lerna 配置(如果存在)/ Lerna config (if exists)
64
+ ├── tsconfig.json # TypeScript 配置 / TypeScript config
65
+ ├── .gitignore # Git 忽略規則 / Git ignore rules
66
+ ├── .eslintrc.json # ESLint 配置 / ESLint config
67
+ └── packages/ # 套件目錄 / Packages directory
68
+ └── .gitkeep
69
+ ```
70
+
71
+ ## 相關專案 / Related Projects
72
+
73
+ - [npm-init2](https://www.npmjs.com/package/npm-init2) - 初始化個別 Package / Initialize individual packages
74
+ - [find-pkg-ws](https://www.npmjs.com/package/find-pkg-ws) - 尋找 Workspace Package / Find workspace packages
75
+ - [workspaces-config](https://www.npmjs.com/package/workspaces-config) - Workspaces 配置解析 / Workspaces config parser
76
+ - [keywords:workspaces](https://www.npmjs.com/search?q=keywords:workspaces) - 更多 Workspaces 工具 / More workspaces tools
77
+
78
+ ## 授權 / License
79
+
80
+ ISC
package/index.d.ts CHANGED
@@ -1,17 +1,99 @@
1
1
  /**
2
- * Created by user on 2018/5/13/013.
2
+ * 創建 Yarn Workspaces 工具模組
3
+ * Yarn Workspaces Creation Tool Module
4
+ *
5
+ * 提供初始化 Yarn Workspaces 專案結構的功能,包含 package.json 設定、
6
+ * Lerna 整合、目錄創建與靜態檔案複製等功能。
7
+ * Provides functionality to initialize Yarn Workspaces project structure,
8
+ * including package.json configuration, Lerna integration, directory creation,
9
+ * and static file copying.
10
+ *
11
+ * @author user
12
+ * @since 2018/5/13/013
3
13
  */
4
14
  import { IPackageJson } from '@ts-type/package-dts/package-json';
5
15
  export * from './lib/index';
6
16
  export * from './lib/util';
17
+ /**
18
+ * 創建 Workspaces 的選項介面
19
+ * Interface for creating workspaces options
20
+ */
7
21
  export interface IOptions {
22
+ /**
23
+ * 工作目錄路徑 / Working directory path
24
+ */
8
25
  cwd?: string;
26
+ /**
27
+ * 忽略父層 Workspaces / Ignore parent workspaces
28
+ */
9
29
  ignoreParentWorkspaces?: boolean;
30
+ /**
31
+ * 忽略已存在的 Package / Ignore existing package
32
+ */
10
33
  ignoreExistsPackage?: boolean;
34
+ /**
35
+ * 初始化 Package.json 的回呼函式
36
+ * Callback function to initialize package.json
37
+ * @template T - 擴展屬性類型 / Extended property type
38
+ * @param current - 當前的 package.json / Current package.json
39
+ * @returns 修改後的 package.json / Modified package.json
40
+ */
11
41
  initPackageJson?<T extends Record<string, any> = {}>(current: IPackageJson): IPackageJson & T;
42
+ /**
43
+ * 啟用除錯模式 / Enable debug mode
44
+ */
12
45
  debug?: boolean;
13
46
  }
47
+ /**
48
+ * 創建 Yarn Workspaces 主函式
49
+ * Main function to create Yarn Workspaces
50
+ *
51
+ * 檢查並創建 Workspaces 專案結構,處理已存在 Package 與父層 Workspaces 的情況
52
+ * Checks and creates workspace project structure, handling existing packages
53
+ * and parent workspaces
54
+ *
55
+ * @param cwd - 工作目錄路徑 / Working directory path
56
+ * @param options - 配置選項 / Configuration options
57
+ * @returns 是否成功創建 / Whether creation was successful
58
+ */
14
59
  export declare function createYarnWorkspaces(cwd?: string, options?: IOptions): boolean;
60
+ /**
61
+ * 內部創建 Workspaces 實作函式
62
+ * Internal implementation function for creating workspaces
63
+ *
64
+ * 執行實際的 Workspaces 初始化工作,包含:
65
+ * - 讀取並更新 Lerna 配置
66
+ * - 創建或更新 package.json
67
+ * - 複製靜態範本檔案
68
+ * - 創建 packages 目錄
69
+ *
70
+ * Performs actual workspace initialization including:
71
+ * - Reading and updating Lerna configuration
72
+ * - Creating or updating package.json
73
+ * - Copying static template files
74
+ * - Creating packages directory
75
+ *
76
+ * @param targetPath - 目標路徑 / Target path
77
+ * @param options - 配置選項 / Configuration options
78
+ * @returns 是否成功 / Whether successful
79
+ */
15
80
  export declare function _createYarnWorkspaces(targetPath: string, options?: IOptions): boolean;
81
+ /**
82
+ * 根據 packages 模式創建目錄
83
+ * Create directories based on packages pattern
84
+ *
85
+ * 解析 packages 陣列中的目錄模式(如 "packages/*"),
86
+ * 並創建對應的實體目錄。
87
+ * Parses directory patterns from packages array (e.g., "packages/*")
88
+ * and creates corresponding physical directories.
89
+ *
90
+ * @param cwd - 當前工作目錄 / Current working directory
91
+ * @param packages - packages 模式陣列 / Array of package patterns
92
+ * @returns 是否有創建任何目錄 / Whether any directories were created
93
+ */
16
94
  export declare function createDirByPackages(cwd: string, packages: string[]): boolean;
95
+ /**
96
+ * 預設導出創建函式
97
+ * Default export of creation function
98
+ */
17
99
  export default createYarnWorkspaces;
package/index.js CHANGED
@@ -1,6 +1,16 @@
1
1
  "use strict";
2
2
  /**
3
- * Created by user on 2018/5/13/013.
3
+ * 創建 Yarn Workspaces 工具模組
4
+ * Yarn Workspaces Creation Tool Module
5
+ *
6
+ * 提供初始化 Yarn Workspaces 專案結構的功能,包含 package.json 設定、
7
+ * Lerna 整合、目錄創建與靜態檔案複製等功能。
8
+ * Provides functionality to initialize Yarn Workspaces project structure,
9
+ * including package.json configuration, Lerna integration, directory creation,
10
+ * and static file copying.
11
+ *
12
+ * @author user
13
+ * @since 2018/5/13/013
4
14
  */
5
15
  Object.defineProperty(exports, "__esModule", { value: true });
6
16
  exports.createYarnWorkspaces = createYarnWorkspaces;
@@ -19,36 +29,69 @@ const find_root_1 = require("@yarn-tool/find-root");
19
29
  const upath2_2 = require("upath2");
20
30
  tslib_1.__exportStar(require("./lib/index"), exports);
21
31
  tslib_1.__exportStar(require("./lib/util"), exports);
32
+ /**
33
+ * 創建 Yarn Workspaces 主函式
34
+ * Main function to create Yarn Workspaces
35
+ *
36
+ * 檢查並創建 Workspaces 專案結構,處理已存在 Package 與父層 Workspaces 的情況
37
+ * Checks and creates workspace project structure, handling existing packages
38
+ * and parent workspaces
39
+ *
40
+ * @param cwd - 工作目錄路徑 / Working directory path
41
+ * @param options - 配置選項 / Configuration options
42
+ * @returns 是否成功創建 / Whether creation was successful
43
+ */
22
44
  function createYarnWorkspaces(cwd, options = {}) {
23
45
  var _a;
46
+ // 處理第一個參數可能是選項物件的情況
47
+ // Handle case where first argument might be options object
24
48
  if (cwd && typeof cwd != 'string') {
25
49
  options = cwd;
26
50
  cwd = options.cwd;
27
51
  }
52
+ // 預設使用當前工作目錄 / Default to current working directory
28
53
  cwd !== null && cwd !== void 0 ? cwd : (cwd = process.cwd());
54
+ // 尋找專案根目錄資訊 / Find project root information
29
55
  const rootData = (0, find_root_1.findRootLazy)({
30
56
  cwd,
31
57
  });
58
+ // 標準化路徑 / Normalize path
32
59
  cwd = (0, upath2_2.normalize)((_a = rootData === null || rootData === void 0 ? void 0 : rootData.cwd) !== null && _a !== void 0 ? _a : cwd);
60
+ // 取得 Package 根目錄與 Workspaces 路徑
61
+ // Get package root directory and workspace path
33
62
  let root = rootData === null || rootData === void 0 ? void 0 : rootData.pkg;
34
63
  let ws = rootData === null || rootData === void 0 ? void 0 : rootData.ws;
35
64
  let targetPath = (0, upath2_1.resolve)(root || cwd);
65
+ // 除錯輸出 / Debug output
36
66
  options.debug && logger_1.consoleLogger.debug({
37
67
  targetPath,
38
68
  ws,
39
69
  options,
40
70
  });
71
+ /**
72
+ * 檢查是否已存在 Package
73
+ * Check if package already exists
74
+ */
41
75
  if (!options.ignoreExistsPackage && root) {
42
76
  logger_1.consoleLogger.error(`already have package at "${root}", or use ignoreExistsPackage for overwrite it`);
43
77
  return false;
44
78
  }
45
79
  else if (root) {
80
+ // 忽略已存在的 Package / Ignore existing package
46
81
  logger_1.consoleLogger.warn(`ignore exists package "${root}"`);
47
82
  }
83
+ /**
84
+ * 檢查是否已存在 Workspaces
85
+ * Check if workspace already exists
86
+ */
48
87
  if (ws) {
88
+ // 檢查目標路徑是否與現有 Workspace 相同
89
+ // Check if target path is same as existing workspace
49
90
  let bool = !(0, util_1.isSamePath)(targetPath, ws);
50
91
  logger_1.consoleLogger.warn(`detect exists workspace "${ws}"`);
51
92
  if (bool) {
93
+ // 根據選項決定是否忽略父層 Workspaces
94
+ // Decide whether to ignore parent workspaces based on options
52
95
  if (options.ignoreParentWorkspaces) {
53
96
  logger_1.consoleLogger.warn(`ignoreParentWorkspaces = true`);
54
97
  bool = false;
@@ -63,33 +106,79 @@ function createYarnWorkspaces(cwd, options = {}) {
63
106
  }
64
107
  return _createYarnWorkspaces(targetPath);
65
108
  }
109
+ /**
110
+ * 內部創建 Workspaces 實作函式
111
+ * Internal implementation function for creating workspaces
112
+ *
113
+ * 執行實際的 Workspaces 初始化工作,包含:
114
+ * - 讀取並更新 Lerna 配置
115
+ * - 創建或更新 package.json
116
+ * - 複製靜態範本檔案
117
+ * - 創建 packages 目錄
118
+ *
119
+ * Performs actual workspace initialization including:
120
+ * - Reading and updating Lerna configuration
121
+ * - Creating or updating package.json
122
+ * - Copying static template files
123
+ * - Creating packages directory
124
+ *
125
+ * @param targetPath - 目標路徑 / Target path
126
+ * @param options - 配置選項 / Configuration options
127
+ * @returns 是否成功 / Whether successful
128
+ */
66
129
  function _createYarnWorkspaces(targetPath, options = {}) {
67
130
  logger_1.consoleLogger.info(`create in target path "${targetPath}"`);
68
131
  let pkg;
69
132
  let lerna;
133
+ /**
134
+ * 嘗試讀取現有的 lerna.json 配置
135
+ * Try to read existing lerna.json configuration
136
+ */
70
137
  {
71
138
  let file = (0, upath2_1.join)(targetPath, 'lerna.json');
72
139
  if ((0, fs_extra_1.existsSync)(file)) {
73
140
  let json = JSON.parse((0, fs_extra_1.readFileSync)(file).toString());
141
+ /**
142
+ * 清理空的 packages 陣列
143
+ * Clean up empty packages array
144
+ */
74
145
  if (json.packages && !Object.keys(json.packages).length) {
75
146
  json.packages = undefined;
76
147
  }
77
148
  lerna = json;
78
149
  }
79
150
  }
151
+ /**
152
+ * 預設 packages 目錄模式
153
+ * Default packages directory pattern
154
+ */
80
155
  let packages = lerna && lerna.packages || [
81
156
  "packages/*",
82
157
  ];
83
158
  let file = (0, upath2_1.join)(targetPath, 'package.json');
159
+ /**
160
+ * 處理 package.json 不存在的情況
161
+ * Handle case when package.json does not exist
162
+ */
84
163
  if (!(0, fs_extra_1.existsSync)(file)) {
164
+ // 使用目錄名作為預設 Package 名稱
165
+ // Use directory name as default package name
85
166
  let name = (0, upath2_1.basename)(targetPath);
167
+ // 創建目標目錄(如果不存在)
168
+ // Create target directory if it doesn't exist
86
169
  if (!(0, fs_extra_1.existsSync)(targetPath)) {
87
170
  (0, fs_extra_1.mkdirSync)(targetPath);
88
171
  }
172
+ // 合併預設配置與基本資訊
173
+ // Merge default configuration with basic info
89
174
  pkg = Object.assign((0, lib_1.getDefaultPackageJson)(name), {
90
175
  name,
91
176
  workspaces: packages,
92
177
  });
178
+ /**
179
+ * 執行自定義初始化回呼
180
+ * Execute custom initialization callback
181
+ */
93
182
  if (options.initPackageJson) {
94
183
  let ret = options.initPackageJson(pkg);
95
184
  if (ret) {
@@ -98,63 +187,129 @@ function _createYarnWorkspaces(targetPath, options = {}) {
98
187
  }
99
188
  }
100
189
  else {
190
+ /**
191
+ * 處理已存在的 package.json
192
+ * Handle existing package.json
193
+ */
101
194
  let json = JSON.parse((0, fs_extra_1.readFileSync)(file).toString());
102
195
  let workspaces;
196
+ /**
197
+ * 解析現有的 workspaces 配置
198
+ * Parse existing workspaces configuration
199
+ */
103
200
  if (json.workspaces && Object.keys(json.workspaces).length) {
104
201
  workspaces = json.workspaces;
105
- // https://yarnpkg.com/blog/2018/02/15/nohoist/
202
+ /**
203
+ * 支援 nohoist 配置格式
204
+ * Support nohoist configuration format
205
+ * @see https://yarnpkg.com/blog/2018/02/15/nohoist/
206
+ */
106
207
  // @ts-ignore
107
208
  packages = workspaces.packages || workspaces;
108
209
  }
109
210
  else {
110
211
  workspaces = packages;
111
212
  }
213
+ /**
214
+ * 更新 Package.json 內容
215
+ * Update package.json content
216
+ */
112
217
  pkg = Object.assign(json, {
113
218
  "private": true,
114
219
  "workspaces": workspaces,
115
220
  });
221
+ // 初始化 resolutions 欄位 / Initialize resolutions field
116
222
  pkg.resolutions = pkg.resolutions || {};
223
+ /**
224
+ * 合併預設腳本與欄位
225
+ * Merge default scripts and fields
226
+ */
117
227
  Object.entries((0, lib_1.getDefaultPackageJson)(json.name))
118
228
  .forEach(([field, value]) => {
119
229
  var _a, _b;
230
+ /**
231
+ * 特殊處理 scripts 欄位:合併而非覆蓋
232
+ * Special handling for scripts field: merge instead of overwrite
233
+ */
120
234
  if (field === 'scripts') {
121
235
  (_a = pkg.scripts) !== null && _a !== void 0 ? _a : (pkg.scripts = {});
122
236
  pkg.scripts = {
237
+ // @ts-ignore
123
238
  ...value,
124
239
  ...pkg.scripts,
125
240
  };
126
241
  }
127
242
  else {
243
+ // 使用空值合併運算子設置預設值
244
+ // Use nullish coalescing operator for default values
128
245
  (_b = pkg[field]) !== null && _b !== void 0 ? _b : (pkg[field] = value);
129
246
  }
130
247
  });
131
248
  }
249
+ /**
250
+ * 寫入格式化後的 package.json
251
+ * Write formatted package.json
252
+ */
132
253
  let s = JSON.stringify((0, sort_package_json3_1.sortPackageJson)(pkg), null, 2);
133
254
  (0, fs_extra_1.writeFileSync)(file, s);
134
255
  logger_1.consoleLogger.success(`create workspace package.json`);
135
- if (lerna && (packages != lerna.packages || lerna.npmClient !== 'yarn' || lerna.useWorkspaces !== true)) {
256
+ /**
257
+ * 更新 Lerna 配置(如果存在且需要更新)
258
+ * Update Lerna configuration if exists and needs updating
259
+ */
260
+ if (lerna && (packages != lerna.packages || lerna.npmClient !== 'yarn' || lerna['useWorkspaces'] !== true)) {
136
261
  let file = (0, upath2_1.join)(targetPath, 'lerna.json');
262
+ // 更新為 Yarn Workspaces 模式
263
+ // Update to Yarn Workspaces mode
137
264
  lerna.packages = packages;
138
265
  lerna.npmClient = 'yarn';
139
- lerna.useWorkspaces = true;
266
+ lerna['useWorkspaces'] = true;
140
267
  let s = JSON.stringify((0, sort_package_json3_1.sortPackageJson)(lerna), null, 2);
141
268
  (0, fs_extra_1.writeFileSync)(file, s);
142
269
  logger_1.consoleLogger.info(`update lerna.json`);
143
270
  }
271
+ /**
272
+ * 複製靜態範本檔案
273
+ * Copy static template files
274
+ */
144
275
  const file_map = (0, wsCopyStaticFiles_1.getWsCopyStaticFiles)();
145
276
  (0, static_file_1.copyStaticFiles)({
146
277
  cwd: targetPath,
147
278
  file_map,
148
279
  });
280
+ /**
281
+ * 根據 packages 模式創建目錄
282
+ * Create directories based on packages pattern
283
+ */
149
284
  createDirByPackages(targetPath, packages);
150
285
  return true;
151
286
  }
287
+ /**
288
+ * 根據 packages 模式創建目錄
289
+ * Create directories based on packages pattern
290
+ *
291
+ * 解析 packages 陣列中的目錄模式(如 "packages/*"),
292
+ * 並創建對應的實體目錄。
293
+ * Parses directory patterns from packages array (e.g., "packages/*")
294
+ * and creates corresponding physical directories.
295
+ *
296
+ * @param cwd - 當前工作目錄 / Current working directory
297
+ * @param packages - packages 模式陣列 / Array of package patterns
298
+ * @returns 是否有創建任何目錄 / Whether any directories were created
299
+ */
152
300
  function createDirByPackages(cwd, packages) {
153
301
  return packages.some(function (value) {
154
302
  let bool;
303
+ // 提取路徑的第一個部分(目錄名稱)
304
+ // Extract first part of path (directory name)
155
305
  let s = value.split(/[\/\\]/)[0];
306
+ /**
307
+ * 只處理不包含 glob 模式的純目錄路徑
308
+ * Only handle pure directory paths without glob patterns
309
+ */
156
310
  if (!/[!?\*{}\[\]]/.test(s)) {
157
311
  let dir = (0, upath2_1.join)(cwd, s);
312
+ // 目錄不存在時創建 / Create directory if it doesn't exist
158
313
  if (!(0, fs_extra_1.existsSync)(dir)) {
159
314
  (0, fs_extra_1.mkdirSync)(dir);
160
315
  }
@@ -163,5 +318,9 @@ function createDirByPackages(cwd, packages) {
163
318
  return bool;
164
319
  });
165
320
  }
321
+ /**
322
+ * 預設導出創建函式
323
+ * Default export of creation function
324
+ */
166
325
  exports.default = createYarnWorkspaces;
167
326
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAgCH,oDAgEC;AAED,sDAkIC;AAED,kDAsBC;;AAzPD,mCAAiD;AAEjD,gDAA+D;AAC/D,wDAAyD;AACzD,uCAA8E;AAC9E,2DAAqD;AACrD,+BAA8C;AAC9C,qCAAwC;AAGxC,uFAAuF;AACvF,oDAAoD;AACpD,mCAAoD;AAEpD,sDAA4B;AAC5B,qDAA2B;AAc3B,SAAgB,oBAAoB,CAAC,GAAY,EAAE,UAAoB,EAAE;;IAExE,IAAI,GAAG,IAAI,OAAO,GAAG,IAAI,QAAQ,EACjC,CAAC;QACA,OAAO,GAAG,GAAG,CAAC;QACd,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACnB,CAAC;IAED,GAAG,aAAH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IAE1C,OAAO,IAAI,CAAC;AACb,CAAC;AAED,SAAgB,mBAAmB,CAAC,GAAW,EAAE,QAAkB;IAElE,OAAO,QAAQ,CAAC,IAAI,CAAC,UAAU,KAAK;QAEnC,IAAI,IAAa,CAAC;QAElB,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QAEjC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAC3B,CAAC;YACA,IAAI,GAAG,GAAG,IAAA,aAAI,EAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAEvB,IAAI,CAAC,IAAA,qBAAU,EAAC,GAAG,CAAC,EACpB,CAAC;gBACA,IAAA,oBAAS,EAAC,GAAG,CAAC,CAAC;YAChB,CAAC;YAED,OAAO,IAAI,CAAC;QACb,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAA;AACH,CAAC;AAED,kBAAe,oBAAoB,CAAC","sourcesContent":["/**\n * Created by user on 2018/5/13/013.\n */\n\nimport findYarnWorkspaceRoot from 'find-yarn-workspace-root2/core';\nimport { resolve, join, basename } from 'upath2';\nimport pkgDir from 'pkg-dir';\nimport { consoleLogger as console } from 'debug-color2/logger';\nimport { copyStaticFiles } from '@yarn-tool/static-file';\nimport { existsSync, readFileSync, mkdirSync, writeFileSync } from 'fs-extra';\nimport { sortPackageJson } from 'sort-package-json3';\nimport { getDefaultPackageJson } from './lib';\nimport { isSamePath } from './lib/util';\nimport { ILernaJson } from '@ts-type/package-dts/lerna-json';\nimport { IPackageJson } from '@ts-type/package-dts/package-json';\nimport { getWsCopyStaticFiles } from '@yarn-tool/static-file/lib/ws/wsCopyStaticFiles';\nimport { findRootLazy } from '@yarn-tool/find-root';\nimport { normalize as pathNormalize } from 'upath2';\n\nexport * from './lib/index';\nexport * from './lib/util';\n\nexport interface IOptions\n{\n\tcwd?: string,\n\n\tignoreParentWorkspaces?: boolean,\n\tignoreExistsPackage?: boolean,\n\n\tinitPackageJson?<T extends Record<string, any> = {}>(current: IPackageJson): IPackageJson & T,\n\n\tdebug?: boolean,\n}\n\nexport function createYarnWorkspaces(cwd?: string, options: IOptions = {})\n{\n\tif (cwd && typeof cwd != 'string')\n\t{\n\t\toptions = cwd;\n\t\tcwd = options.cwd;\n\t}\n\n\tcwd ??= process.cwd();\n\n\tconst rootData = findRootLazy({\n\t\tcwd,\n\t});\n\n\tcwd = pathNormalize(rootData?.cwd ?? cwd);\n\n\tlet root: string = rootData?.pkg;\n\tlet ws: string = rootData?.ws;\n\n\tlet targetPath = resolve(root || cwd);\n\n\toptions.debug && console.debug({\n\t\ttargetPath,\n\t\tws,\n\t\toptions,\n\t});\n\n\tif (!options.ignoreExistsPackage && root)\n\t{\n\t\tconsole.error(`already have package at \"${root}\", or use ignoreExistsPackage for overwrite it`);\n\n\t\treturn false;\n\t}\n\telse if (root)\n\t{\n\t\tconsole.warn(`ignore exists package \"${root}\"`);\n\t}\n\n\tif (ws)\n\t{\n\t\tlet bool: boolean = !isSamePath(targetPath, ws);\n\n\t\tconsole.warn(`detect exists workspace \"${ws}\"`);\n\n\t\tif (bool)\n\t\t{\n\t\t\tif (options.ignoreParentWorkspaces)\n\t\t\t{\n\t\t\t\tconsole.warn(`ignoreParentWorkspaces = true`);\n\t\t\t\tbool = false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tconsole.error(`target path already is workspace`);\n\t\t\t}\n\t\t}\n\n\t\tif (bool)\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn _createYarnWorkspaces(targetPath);\n}\n\nexport function _createYarnWorkspaces(targetPath: string, options: IOptions = {})\n{\n\tconsole.info(`create in target path \"${targetPath}\"`);\n\n\tlet pkg: IPackageJson;\n\n\tlet lerna: ILernaJson;\n\n\t{\n\t\tlet file = join(targetPath, 'lerna.json');\n\n\t\tif (existsSync(file))\n\t\t{\n\t\t\tlet json: ILernaJson = JSON.parse(readFileSync(file).toString());\n\n\t\t\tif (json.packages && !Object.keys(json.packages).length)\n\t\t\t{\n\t\t\t\tjson.packages = undefined;\n\t\t\t}\n\n\t\t\tlerna = json;\n\t\t}\n\t}\n\n\tlet packages = lerna && lerna.packages || [\n\t\t\"packages/*\",\n\t];\n\n\tlet file = join(targetPath, 'package.json');\n\n\tif (!existsSync(file))\n\t{\n\t\tlet name = basename(targetPath);\n\n\t\tif (!existsSync(targetPath))\n\t\t{\n\t\t\tmkdirSync(targetPath);\n\t\t}\n\n\t\tpkg = Object.assign(getDefaultPackageJson(name), {\n\t\t\tname,\n\t\t\tworkspaces: packages,\n\t\t});\n\n\t\tif (options.initPackageJson)\n\t\t{\n\t\t\tlet ret = options.initPackageJson(pkg);\n\n\t\t\tif (ret)\n\t\t\t{\n\t\t\t\tpkg = ret;\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tlet json: IPackageJson = JSON.parse(readFileSync(file).toString());\n\n\t\tlet workspaces: ILernaJson['packages'];\n\n\t\tif (json.workspaces && Object.keys(json.workspaces).length)\n\t\t{\n\t\t\tworkspaces = json.workspaces;\n\n\t\t\t// https://yarnpkg.com/blog/2018/02/15/nohoist/\n\t\t\t// @ts-ignore\n\t\t\tpackages = workspaces.packages || workspaces;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tworkspaces = packages;\n\t\t}\n\n\t\tpkg = Object.assign(json, {\n\t\t\t\"private\": true,\n\t\t\t\"workspaces\": workspaces,\n\t\t});\n\n\t\tpkg.resolutions = pkg.resolutions || {};\n\n\t\tObject.entries(getDefaultPackageJson(json.name))\n\t\t\t.forEach(([field, value]) => {\n\n\t\t\t\tif (field === 'scripts')\n\t\t\t\t{\n\t\t\t\t\tpkg.scripts ??= {};\n\t\t\t\t\tpkg.scripts = {\n\t\t\t\t\t\t...value,\n\t\t\t\t\t\t...pkg.scripts,\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tpkg[field] ??= value\n\t\t\t\t}\n\n\t\t\t})\n\t\t;\n\n\t}\n\n\tlet s = JSON.stringify(sortPackageJson(pkg), null, 2);\n\twriteFileSync(file, s);\n\n\tconsole.success(`create workspace package.json`);\n\n\tif (lerna && (packages != lerna.packages || lerna.npmClient !== 'yarn' || lerna.useWorkspaces !== true))\n\t{\n\t\tlet file = join(targetPath, 'lerna.json');\n\n\t\tlerna.packages = packages;\n\t\tlerna.npmClient = 'yarn';\n\t\tlerna.useWorkspaces = true;\n\n\t\tlet s = JSON.stringify(sortPackageJson(lerna), null, 2);\n\t\twriteFileSync(file, s);\n\n\t\tconsole.info(`update lerna.json`);\n\t}\n\n\tconst file_map = getWsCopyStaticFiles();\n\n\tcopyStaticFiles({\n\t\tcwd: targetPath,\n\t\tfile_map,\n\t});\n\n\tcreateDirByPackages(targetPath, packages);\n\n\treturn true;\n}\n\nexport function createDirByPackages(cwd: string, packages: string[])\n{\n\treturn packages.some(function (value)\n\t{\n\t\tlet bool: boolean;\n\n\t\tlet s = value.split(/[\\/\\\\]/)[0];\n\n\t\tif (!/[!?\\*{}\\[\\]]/.test(s))\n\t\t{\n\t\t\tlet dir = join(cwd, s);\n\n\t\t\tif (!existsSync(dir))\n\t\t\t{\n\t\t\t\tmkdirSync(dir);\n\t\t\t}\n\n\t\t\treturn true;\n\t\t}\n\n\t\treturn bool;\n\t})\n}\n\nexport default createYarnWorkspaces;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAoEH,oDAqFC;AAsBD,sDA0MC;AAeD,kDA6BC;;AAlaD,mCAAiD;AAEjD,gDAA+D;AAC/D,wDAAyD;AACzD,uCAA8E;AAC9E,2DAAqD;AACrD,+BAA8C;AAC9C,qCAAwC;AAGxC,uFAAuF;AACvF,oDAAoD;AACpD,mCAAoD;AAEpD,sDAA4B;AAC5B,qDAA2B;AAsC3B;;;;;;;;;;;GAWG;AACH,SAAgB,oBAAoB,CAAC,G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G,EAAE,CAAC,CAAC,CAAC;YAEvB,kDAAkD;YAClD,IAAI,CAAC,IAAA,qBAAU,EAAC,GAAG,CAAC,EACpB,CAAC;gBACA,IAAA,oBAAS,EAAC,GAAG,CAAC,CAAC;YAChB,CAAC;YAED,OAAO,IAAI,CAAC;QACb,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,kBAAe,oBAAoB,CAAC","sourcesContent":["/**\n * 創建 Yarn Workspaces 工具模組\n * Yarn Workspaces Creation Tool Module\n *\n * 提供初始化 Yarn Workspaces 專案結構的功能,包含 package.json 設定、\n * Lerna 整合、目錄創建與靜態檔案複製等功能。\n * Provides functionality to initialize Yarn Workspaces project structure,\n * including package.json configuration, Lerna integration, directory creation,\n * and static file copying.\n *\n * @author user\n * @since 2018/5/13/013\n */\n\nimport findYarnWorkspaceRoot from 'find-yarn-workspace-root2/core';\nimport { resolve, join, basename } from 'upath2';\nimport pkgDir from 'pkg-dir';\nimport { consoleLogger as console } from 'debug-color2/logger';\nimport { copyStaticFiles } from '@yarn-tool/static-file';\nimport { existsSync, readFileSync, mkdirSync, writeFileSync } from 'fs-extra';\nimport { sortPackageJson } from 'sort-package-json3';\nimport { getDefaultPackageJson } from './lib';\nimport { isSamePath } from './lib/util';\nimport { ILernaJson } from '@ts-type/package-dts/lerna-json';\nimport { IPackageJson } from '@ts-type/package-dts/package-json';\nimport { getWsCopyStaticFiles } from '@yarn-tool/static-file/lib/ws/wsCopyStaticFiles';\nimport { findRootLazy } from '@yarn-tool/find-root';\nimport { normalize as pathNormalize } from 'upath2';\n\nexport * from './lib/index';\nexport * from './lib/util';\n\n/**\n * 創建 Workspaces 的選項介面\n * Interface for creating workspaces options\n */\nexport interface IOptions\n{\n\t/**\n\t * 工作目錄路徑 / Working directory path\n\t */\n\tcwd?: string,\n\n\t/**\n\t * 忽略父層 Workspaces / Ignore parent workspaces\n\t */\n\tignoreParentWorkspaces?: boolean,\n\n\t/**\n\t * 忽略已存在的 Package / Ignore existing package\n\t */\n\tignoreExistsPackage?: boolean,\n\n\t/**\n\t * 初始化 Package.json 的回呼函式\n\t * Callback function to initialize package.json\n\t * @template T - 擴展屬性類型 / Extended property type\n\t * @param current - 當前的 package.json / Current package.json\n\t * @returns 修改後的 package.json / Modified package.json\n\t */\n\tinitPackageJson?<T extends Record<string, any> = {}>(current: IPackageJson): IPackageJson & T,\n\n\t/**\n\t * 啟用除錯模式 / Enable debug mode\n\t */\n\tdebug?: boolean,\n}\n\n/**\n * 創建 Yarn Workspaces 主函式\n * Main function to create Yarn Workspaces\n *\n * 檢查並創建 Workspaces 專案結構,處理已存在 Package 與父層 Workspaces 的情況\n * Checks and creates workspace project structure, handling existing packages\n * and parent workspaces\n *\n * @param cwd - 工作目錄路徑 / Working directory path\n * @param options - 配置選項 / Configuration options\n * @returns 是否成功創建 / Whether creation was successful\n */\nexport function createYarnWorkspaces(cwd?: string, options: IOptions = {})\n{\n\t// 處理第一個參數可能是選項物件的情況\n\t// Handle case where first argument might be options object\n\tif (cwd && typeof cwd != 'string')\n\t{\n\t\toptions = cwd;\n\t\tcwd = options.cwd;\n\t}\n\n\t// 預設使用當前工作目錄 / Default to current working directory\n\tcwd ??= process.cwd();\n\n\t// 尋找專案根目錄資訊 / Find project root information\n\tconst rootData = findRootLazy({\n\t\tcwd,\n\t});\n\n\t// 標準化路徑 / Normalize path\n\tcwd = pathNormalize(rootData?.cwd ?? cwd);\n\n\t// 取得 Package 根目錄與 Workspaces 路徑\n\t// Get package root directory and workspace path\n\tlet root: string = rootData?.pkg;\n\tlet ws: string = rootData?.ws;\n\n\tlet targetPath = resolve(root || cwd);\n\n\t// 除錯輸出 / Debug output\n\toptions.debug && console.debug({\n\t\ttargetPath,\n\t\tws,\n\t\toptions,\n\t});\n\n\t/**\n\t * 檢查是否已存在 Package\n\t * Check if package already exists\n\t */\n\tif (!options.ignoreExistsPackage && root)\n\t{\n\t\tconsole.error(`already have package at \"${root}\", or use ignoreExistsPackage for overwrite it`);\n\n\t\treturn false;\n\t}\n\telse if (root)\n\t{\n\t\t// 忽略已存在的 Package / Ignore existing package\n\t\tconsole.warn(`ignore exists package \"${root}\"`);\n\t}\n\n\t/**\n\t * 檢查是否已存在 Workspaces\n\t * Check if workspace already exists\n\t */\n\tif (ws)\n\t{\n\t\t// 檢查目標路徑是否與現有 Workspace 相同\n\t\t// Check if target path is same as existing workspace\n\t\tlet bool: boolean = !isSamePath(targetPath, ws);\n\n\t\tconsole.warn(`detect exists workspace \"${ws}\"`);\n\n\t\tif (bool)\n\t\t{\n\t\t\t// 根據選項決定是否忽略父層 Workspaces\n\t\t\t// Decide whether to ignore parent workspaces based on options\n\t\t\tif (options.ignoreParentWorkspaces)\n\t\t\t{\n\t\t\t\tconsole.warn(`ignoreParentWorkspaces = true`);\n\t\t\t\tbool = false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tconsole.error(`target path already is workspace`);\n\t\t\t}\n\t\t}\n\n\t\tif (bool)\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn _createYarnWorkspaces(targetPath);\n}\n\n/**\n * 內部創建 Workspaces 實作函式\n * Internal implementation function for creating workspaces\n *\n * 執行實際的 Workspaces 初始化工作,包含:\n * - 讀取並更新 Lerna 配置\n * - 創建或更新 package.json\n * - 複製靜態範本檔案\n * - 創建 packages 目錄\n *\n * Performs actual workspace initialization including:\n * - Reading and updating Lerna configuration\n * - Creating or updating package.json\n * - Copying static template files\n * - Creating packages directory\n *\n * @param targetPath - 目標路徑 / Target path\n * @param options - 配置選項 / Configuration options\n * @returns 是否成功 / Whether successful\n */\nexport function _createYarnWorkspaces(targetPath: string, options: IOptions = {})\n{\n\tconsole.info(`create in target path \"${targetPath}\"`);\n\n\tlet pkg: IPackageJson;\n\n\tlet lerna: ILernaJson;\n\n\t/**\n\t * 嘗試讀取現有的 lerna.json 配置\n\t * Try to read existing lerna.json configuration\n\t */\n\t{\n\t\tlet file = join(targetPath, 'lerna.json');\n\n\t\tif (existsSync(file))\n\t\t{\n\t\t\tlet json: ILernaJson = JSON.parse(readFileSync(file).toString());\n\n\t\t\t/**\n\t\t\t * 清理空的 packages 陣列\n\t\t\t * Clean up empty packages array\n\t\t\t */\n\t\t\tif (json.packages && !Object.keys(json.packages).length)\n\t\t\t{\n\t\t\t\tjson.packages = undefined;\n\t\t\t}\n\n\t\t\tlerna = json;\n\t\t}\n\t}\n\n\t/**\n\t * 預設 packages 目錄模式\n\t * Default packages directory pattern\n\t */\n\tlet packages = lerna && lerna.packages || [\n\t\t\"packages/*\",\n\t];\n\n\tlet file = join(targetPath, 'package.json');\n\n\t/**\n\t * 處理 package.json 不存在的情況\n\t * Handle case when package.json does not exist\n\t */\n\tif (!existsSync(file))\n\t{\n\t\t// 使用目錄名作為預設 Package 名稱\n\t\t// Use directory name as default package name\n\t\tlet name = basename(targetPath);\n\n\t\t// 創建目標目錄(如果不存在)\n\t\t// Create target directory if it doesn't exist\n\t\tif (!existsSync(targetPath))\n\t\t{\n\t\t\tmkdirSync(targetPath);\n\t\t}\n\n\t\t// 合併預設配置與基本資訊\n\t\t// Merge default configuration with basic info\n\t\tpkg = Object.assign(getDefaultPackageJson(name), {\n\t\t\tname,\n\t\t\tworkspaces: packages,\n\t\t});\n\n\t\t/**\n\t\t * 執行自定義初始化回呼\n\t\t * Execute custom initialization callback\n\t\t */\n\t\tif (options.initPackageJson)\n\t\t{\n\t\t\tlet ret = options.initPackageJson(pkg);\n\n\t\t\tif (ret)\n\t\t\t{\n\t\t\t\tpkg = ret;\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\t/**\n\t\t * 處理已存在的 package.json\n\t\t * Handle existing package.json\n\t\t */\n\t\tlet json: IPackageJson = JSON.parse(readFileSync(file).toString());\n\n\t\tlet workspaces: ILernaJson['packages'];\n\n\t\t/**\n\t\t * 解析現有的 workspaces 配置\n\t\t * Parse existing workspaces configuration\n\t\t */\n\t\tif (json.workspaces && Object.keys(json.workspaces).length)\n\t\t{\n\t\t\tworkspaces = json.workspaces;\n\n\t\t\t/**\n\t\t\t * 支援 nohoist 配置格式\n\t\t\t * Support nohoist configuration format\n\t\t\t * @see https://yarnpkg.com/blog/2018/02/15/nohoist/\n\t\t\t */\n\t\t\t// @ts-ignore\n\t\t\tpackages = workspaces.packages || workspaces;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tworkspaces = packages;\n\t\t}\n\n\t\t/**\n\t\t * 更新 Package.json 內容\n\t\t * Update package.json content\n\t\t */\n\t\tpkg = Object.assign(json, {\n\t\t\t\"private\": true,\n\t\t\t\"workspaces\": workspaces,\n\t\t});\n\n\t\t// 初始化 resolutions 欄位 / Initialize resolutions field\n\t\tpkg.resolutions = pkg.resolutions || {};\n\n\t\t/**\n\t\t * 合併預設腳本與欄位\n\t\t * Merge default scripts and fields\n\t\t */\n\t\tObject.entries(getDefaultPackageJson(json.name))\n\t\t\t.forEach(([field, value]) => {\n\n\t\t\t\t/**\n\t\t\t\t * 特殊處理 scripts 欄位:合併而非覆蓋\n\t\t\t\t * Special handling for scripts field: merge instead of overwrite\n\t\t\t\t */\n\t\t\t\tif (field === 'scripts')\n\t\t\t\t{\n\t\t\t\t\tpkg.scripts ??= {};\n\t\t\t\t\tpkg.scripts = {\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t...value,\n\t\t\t\t\t\t...pkg.scripts,\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t// 使用空值合併運算子設置預設值\n\t\t\t\t\t// Use nullish coalescing operator for default values\n\t\t\t\t\tpkg[field] ??= value\n\t\t\t\t}\n\n\t\t\t})\n\t\t;\n\n\t}\n\n\t/**\n\t * 寫入格式化後的 package.json\n\t * Write formatted package.json\n\t */\n\tlet s = JSON.stringify(sortPackageJson(pkg), null, 2);\n\twriteFileSync(file, s);\n\n\tconsole.success(`create workspace package.json`);\n\n\t/**\n\t * 更新 Lerna 配置(如果存在且需要更新)\n\t * Update Lerna configuration if exists and needs updating\n\t */\n\tif (lerna && (packages != lerna.packages || lerna.npmClient !== 'yarn' || lerna['useWorkspaces'] !== true))\n\t{\n\t\tlet file = join(targetPath, 'lerna.json');\n\n\t\t// 更新為 Yarn Workspaces 模式\n\t\t// Update to Yarn Workspaces mode\n\t\tlerna.packages = packages;\n\t\tlerna.npmClient = 'yarn';\n\t\tlerna['useWorkspaces'] = true;\n\n\t\tlet s = JSON.stringify(sortPackageJson(lerna), null, 2);\n\t\twriteFileSync(file, s);\n\n\t\tconsole.info(`update lerna.json`);\n\t}\n\n\t/**\n\t * 複製靜態範本檔案\n\t * Copy static template files\n\t */\n\tconst file_map = getWsCopyStaticFiles();\n\n\tcopyStaticFiles({\n\t\tcwd: targetPath,\n\t\tfile_map,\n\t});\n\n\t/**\n\t * 根據 packages 模式創建目錄\n\t * Create directories based on packages pattern\n\t */\n\tcreateDirByPackages(targetPath, packages);\n\n\treturn true;\n}\n\n/**\n * 根據 packages 模式創建目錄\n * Create directories based on packages pattern\n *\n * 解析 packages 陣列中的目錄模式(如 \"packages/*\"),\n * 並創建對應的實體目錄。\n * Parses directory patterns from packages array (e.g., \"packages/*\")\n * and creates corresponding physical directories.\n *\n * @param cwd - 當前工作目錄 / Current working directory\n * @param packages - packages 模式陣列 / Array of package patterns\n * @returns 是否有創建任何目錄 / Whether any directories were created\n */\nexport function createDirByPackages(cwd: string, packages: string[])\n{\n\treturn packages.some(function (value)\n\t{\n\t\tlet bool: boolean;\n\n\t\t// 提取路徑的第一個部分(目錄名稱)\n\t\t// Extract first part of path (directory name)\n\t\tlet s = value.split(/[\\/\\\\]/)[0];\n\n\t\t/**\n\t\t * 只處理不包含 glob 模式的純目錄路徑\n\t\t * Only handle pure directory paths without glob patterns\n\t\t */\n\t\tif (!/[!?\\*{}\\[\\]]/.test(s))\n\t\t{\n\t\t\tlet dir = join(cwd, s);\n\n\t\t\t// 目錄不存在時創建 / Create directory if it doesn't exist\n\t\t\tif (!existsSync(dir))\n\t\t\t{\n\t\t\t\tmkdirSync(dir);\n\t\t\t}\n\n\t\t\treturn true;\n\t\t}\n\n\t\treturn bool;\n\t})\n}\n\n/**\n * 預設導出創建函式\n * Default export of creation function\n */\nexport default createYarnWorkspaces;\n"]}
@@ -6,8 +6,8 @@
6
6
  "devDependencies": {
7
7
  "@bluelovers/tsconfig": "^1.0.35",
8
8
  "@types/jest": "^30.0.0",
9
- "@types/node": "^24.3.1",
10
- "@yarn-tool/ws-find-up-paths": "^1.0.13"
9
+ "@types/node": "^25.3.3",
10
+ "@yarn-tool/ws-find-up-paths": "^1.0.14"
11
11
  },
12
12
  "peerDependencies": {
13
13
  "@bluelovers/conventional-changelog-bluelovers": "*",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-yarn-workspaces",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "yarn create yarn-workspaces npx create-yarn-workspaces",
5
5
  "keywords": [
6
6
  "cli",
@@ -53,21 +53,20 @@
53
53
  "tsc:esm": "tsc -p tsconfig.esm.json",
54
54
  "tsc:showConfig": "ynpx get-current-tsconfig -p"
55
55
  },
56
- "resolutions": {},
57
56
  "dependencies": {
58
57
  "@ts-type/package-dts": "^2.0.8",
59
- "@yarn-tool/find-root": "^2.0.15",
60
- "@yarn-tool/pkg-entry-util": "^3.0.3",
61
- "@yarn-tool/static-file": "^3.0.4",
58
+ "@yarn-tool/find-root": "^2.0.16",
59
+ "@yarn-tool/pkg-entry-util": "^3.0.4",
60
+ "@yarn-tool/static-file": "^3.0.5",
62
61
  "debug-color2": "^1.3.2",
63
- "find-yarn-workspace-root2": "^1.2.51",
64
- "fs-extra": "^11.2.0",
65
- "path-is-same": "^1.0.25",
62
+ "find-yarn-workspace-root2": "^1.2.52",
63
+ "fs-extra": "^11.3.3",
64
+ "path-is-same": "^1.0.29",
66
65
  "pkg-dir": "<6 >=5",
67
- "sort-package-json3": "^3.0.3",
66
+ "sort-package-json3": "^3.0.4",
68
67
  "tslib": ">=2",
69
- "upath2": "^3.1.19",
70
- "yargs": "^17.7.2"
68
+ "upath2": "^3.1.23",
69
+ "yargs": "<18 >=17.7.2"
71
70
  },
72
- "gitHead": "ca7f14bdac1827ed8e8fe5fd0932ee56a44669dc"
71
+ "gitHead": "ae9b0817b25b1019ba68c88e541bbffc7d84047c"
73
72
  }
@@ -1,8 +1,36 @@
1
1
  /**
2
- * Created by user on 2019/5/16.
2
+ * Yargs 命令列參數設定模組
3
+ * Yargs Command Line Arguments Configuration Module
4
+ *
5
+ * 提供 Workspaces 初始化相關的命令列參數設定與驗證
6
+ * Provides command line argument configuration and validation for
7
+ * workspace initialization
8
+ *
9
+ * @author user
10
+ * @since 2019/5/16
3
11
  */
4
12
  import yargs from 'yargs';
5
13
  import { Argv } from 'yargs';
14
+ /**
15
+ * 設定 Workspaces 初始化相關的 Yargs 選項
16
+ * Setup Yargs options for workspaces initialization
17
+ *
18
+ * 配置命令列參數,包含:
19
+ * - name: Package 名稱
20
+ * - ignoreExistsPackage: 忽略已存在的 Package
21
+ * - ignoreParentWorkspaces: 忽略父層 Workspaces
22
+ * - debug: 啟用除錯模式
23
+ *
24
+ * Configures command line arguments including:
25
+ * - name: Package name
26
+ * - ignoreExistsPackage: Ignore existing package
27
+ * - ignoreParentWorkspaces: Ignore parent workspaces
28
+ * - debug: Enable debug mode
29
+ *
30
+ * @template T - Yargs 參數類型 / Yargs argument type
31
+ * @param yargs - Yargs 實例 / Yargs instance
32
+ * @returns 配置後的 Yargs 實例 / Configured Yargs instance
33
+ */
6
34
  export declare function setupWorkspacesInitToYargs<T extends any>(yargs: Argv<T>): yargs.Argv<yargs.Omit<T, never> & {
7
35
  name: string;
8
36
  } & {
@@ -12,4 +40,8 @@ export declare function setupWorkspacesInitToYargs<T extends any>(yargs: Argv<T>
12
40
  } & {
13
41
  debug: boolean;
14
42
  }>;
43
+ /**
44
+ * 預設導出設定函式
45
+ * Default export of setup function
46
+ */
15
47
  export default setupWorkspacesInitToYargs;
package/yargs-setting.js CHANGED
@@ -1,30 +1,78 @@
1
1
  "use strict";
2
2
  /**
3
- * Created by user on 2019/5/16.
3
+ * Yargs 命令列參數設定模組
4
+ * Yargs Command Line Arguments Configuration Module
5
+ *
6
+ * 提供 Workspaces 初始化相關的命令列參數設定與驗證
7
+ * Provides command line argument configuration and validation for
8
+ * workspace initialization
9
+ *
10
+ * @author user
11
+ * @since 2019/5/16
4
12
  */
5
13
  Object.defineProperty(exports, "__esModule", { value: true });
6
14
  exports.setupWorkspacesInitToYargs = setupWorkspacesInitToYargs;
15
+ /**
16
+ * 設定 Workspaces 初始化相關的 Yargs 選項
17
+ * Setup Yargs options for workspaces initialization
18
+ *
19
+ * 配置命令列參數,包含:
20
+ * - name: Package 名稱
21
+ * - ignoreExistsPackage: 忽略已存在的 Package
22
+ * - ignoreParentWorkspaces: 忽略父層 Workspaces
23
+ * - debug: 啟用除錯模式
24
+ *
25
+ * Configures command line arguments including:
26
+ * - name: Package name
27
+ * - ignoreExistsPackage: Ignore existing package
28
+ * - ignoreParentWorkspaces: Ignore parent workspaces
29
+ * - debug: Enable debug mode
30
+ *
31
+ * @template T - Yargs 參數類型 / Yargs argument type
32
+ * @param yargs - Yargs 實例 / Yargs instance
33
+ * @returns 配置後的 Yargs 實例 / Configured Yargs instance
34
+ */
7
35
  function setupWorkspacesInitToYargs(yargs) {
8
36
  return yargs
9
37
  .default({
10
38
  //input: process.cwd(),
11
39
  })
40
+ /**
41
+ * Package 名稱選項
42
+ * Package name option
43
+ */
12
44
  .option('name', {
13
45
  alias: ['n'],
14
46
  requiresArg: true,
15
47
  normalize: true,
16
48
  type: 'string',
17
49
  })
50
+ /**
51
+ * 忽略已存在 Package 選項
52
+ * Ignore existing package option
53
+ */
18
54
  .option('ignoreExistsPackage', {
19
55
  boolean: true,
20
56
  alias: ['i'],
21
57
  })
58
+ /**
59
+ * 忽略父層 Workspaces 選項
60
+ * Ignore parent workspaces option
61
+ */
22
62
  .option('ignoreParentWorkspaces', {
23
63
  boolean: true,
24
64
  })
65
+ /**
66
+ * 除錯模式選項
67
+ * Debug mode option
68
+ */
25
69
  .option('debug', {
26
70
  boolean: true,
27
71
  });
28
72
  }
73
+ /**
74
+ * 預設導出設定函式
75
+ * Default export of setup function
76
+ */
29
77
  exports.default = setupWorkspacesInitToYargs;
30
78
  //# sourceMappingURL=yargs-setting.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"yargs-setting.js","sourceRoot":"","sources":["yargs-setting.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAKH,gEAuBC;AAvBD,SAAgB,0BAA0B,CAAgB,KAAc;IAEvE,OAAO,KAAK;SACV,OAAO,CAAC;IACR,uBAAuB;KACvB,CAAC;SACD,MAAM,CAAC,MAAM,EAAE;QACf,KAAK,EAAE,CAAC,GAAG,CAAC;QACZ,WAAW,EAAE,IAAI;QACjB,SAAS,EAAE,IAAI;QACf,IAAI,EAAE,QAAQ;KACd,CAAC;SACD,MAAM,CAAC,qBAAqB,EAAE;QAC9B,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,CAAC,GAAG,CAAC;KACZ,CAAC;SACD,MAAM,CAAC,wBAAwB,EAAE;QACjC,OAAO,EAAE,IAAI;KACb,CAAC;SACD,MAAM,CAAC,OAAO,EAAE;QAChB,OAAO,EAAE,IAAI;KACb,CAAC,CACF;AACF,CAAC;AAED,kBAAe,0BAA0B,CAAA","sourcesContent":["/**\n * Created by user on 2019/5/16.\n */\n\nimport yargs from 'yargs';\nimport { Argv, Omit } from 'yargs';\n\nexport function setupWorkspacesInitToYargs<T extends any>(yargs: Argv<T>)\n{\n\treturn yargs\n\t\t.default({\n\t\t\t//input: process.cwd(),\n\t\t})\n\t\t.option('name', {\n\t\t\talias: ['n'],\n\t\t\trequiresArg: true,\n\t\t\tnormalize: true,\n\t\t\ttype: 'string',\n\t\t})\n\t\t.option('ignoreExistsPackage', {\n\t\t\tboolean: true,\n\t\t\talias: ['i'],\n\t\t})\n\t\t.option('ignoreParentWorkspaces', {\n\t\t\tboolean: true,\n\t\t})\n\t\t.option('debug', {\n\t\t\tboolean: true,\n\t\t})\n\t;\n}\n\nexport default setupWorkspacesInitToYargs\n"]}
1
+ {"version":3,"file":"yargs-setting.js","sourceRoot":"","sources":["yargs-setting.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AAyBH,gEAuCC;AA3DD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,0BAA0B,CAAgB,KAAc;IAEvE,OAAO,KAAK;SACV,OAAO,CAAC;IACR,uBAAuB;KACvB,CAAC;QACF;;;WAGG;SACF,MAAM,CAAC,MAAM,EAAE;QACf,KAAK,EAAE,CAAC,GAAG,CAAC;QACZ,WAAW,EAAE,IAAI;QACjB,SAAS,EAAE,IAAI;QACf,IAAI,EAAE,QAAQ;KACd,CAAC;QACF;;;WAGG;SACF,MAAM,CAAC,qBAAqB,EAAE;QAC9B,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,CAAC,GAAG,CAAC;KACZ,CAAC;QACF;;;WAGG;SACF,MAAM,CAAC,wBAAwB,EAAE;QACjC,OAAO,EAAE,IAAI;KACb,CAAC;QACF;;;WAGG;SACF,MAAM,CAAC,OAAO,EAAE;QAChB,OAAO,EAAE,IAAI;KACb,CAAC,CACF;AACF,CAAC;AAED;;;GAGG;AACH,kBAAe,0BAA0B,CAAA","sourcesContent":["/**\n * Yargs 命令列參數設定模組\n * Yargs Command Line Arguments Configuration Module\n * \n * 提供 Workspaces 初始化相關的命令列參數設定與驗證\n * Provides command line argument configuration and validation for\n * workspace initialization\n * \n * @author user\n * @since 2019/5/16\n */\n\nimport yargs from 'yargs';\nimport { Argv, Omit } from 'yargs';\n\n/**\n * 設定 Workspaces 初始化相關的 Yargs 選項\n * Setup Yargs options for workspaces initialization\n * \n * 配置命令列參數,包含:\n * - name: Package 名稱\n * - ignoreExistsPackage: 忽略已存在的 Package\n * - ignoreParentWorkspaces: 忽略父層 Workspaces\n * - debug: 啟用除錯模式\n * \n * Configures command line arguments including:\n * - name: Package name\n * - ignoreExistsPackage: Ignore existing package\n * - ignoreParentWorkspaces: Ignore parent workspaces\n * - debug: Enable debug mode\n * \n * @template T - Yargs 參數類型 / Yargs argument type\n * @param yargs - Yargs 實例 / Yargs instance\n * @returns 配置後的 Yargs 實例 / Configured Yargs instance\n */\nexport function setupWorkspacesInitToYargs<T extends any>(yargs: Argv<T>)\n{\n\treturn yargs\n\t\t.default({\n\t\t\t//input: process.cwd(),\n\t\t})\n\t\t/**\n\t\t * Package 名稱選項\n\t\t * Package name option\n\t\t */\n\t\t.option('name', {\n\t\t\talias: ['n'],\n\t\t\trequiresArg: true,\n\t\t\tnormalize: true,\n\t\t\ttype: 'string',\n\t\t})\n\t\t/**\n\t\t * 忽略已存在 Package 選項\n\t\t * Ignore existing package option\n\t\t */\n\t\t.option('ignoreExistsPackage', {\n\t\t\tboolean: true,\n\t\t\talias: ['i'],\n\t\t})\n\t\t/**\n\t\t * 忽略父層 Workspaces 選項\n\t\t * Ignore parent workspaces option\n\t\t */\n\t\t.option('ignoreParentWorkspaces', {\n\t\t\tboolean: true,\n\t\t})\n\t\t/**\n\t\t * 除錯模式選項\n\t\t * Debug mode option\n\t\t */\n\t\t.option('debug', {\n\t\t\tboolean: true,\n\t\t})\n\t;\n}\n\n/**\n * 預設導出設定函式\n * Default export of setup function\n */\nexport default setupWorkspacesInitToYargs\n"]}