create-yarn-workspaces 3.0.35 → 3.0.37
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 +53 -0
- package/README.md +34 -11
- package/bin/yarn-ws-init.js +18 -16
- package/bin/yarn-ws-init.js.map +1 -1
- package/index.d.ts +22 -82
- package/index.js +43 -303
- package/index.js.map +1 -1
- package/lib/check-env.d.ts +42 -0
- package/lib/check-env.js +87 -0
- package/lib/check-env.js.map +1 -0
- package/lib/core.d.ts +85 -0
- package/lib/core.js +273 -0
- package/lib/core.js.map +1 -0
- package/lib/index.d.ts +4 -5
- package/lib/index.js +15 -18
- package/lib/index.js.map +1 -1
- package/lib/package.demo.json +1 -1
- package/lib/util.d.ts +4 -5
- package/lib/util.js +10 -9
- package/lib/util.js.map +1 -1
- package/package.json +12 -6
- package/yargs-setting.d.ts +3 -10
- package/yargs-setting.js +11 -14
- package/yargs-setting.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,59 @@
|
|
|
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.37](https://github.com/bluelovers/ws-yarn-workspaces/compare/create-yarn-workspaces@3.0.36...create-yarn-workspaces@3.0.37) (2026-11-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### 🛠 Build System
|
|
11
|
+
|
|
12
|
+
* **cache:** update cache-versions ([2ea020c](https://github.com/bluelovers/ws-yarn-workspaces/commit/2ea020c33f03279d07efc05b299ddd1e6e8e8dbc))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### 🔖 Miscellaneous
|
|
16
|
+
|
|
17
|
+
* . ([bea7cb7](https://github.com/bluelovers/ws-yarn-workspaces/commit/bea7cb7d1965217aaecfcd7e63c5c6813ad9aba4))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## [3.0.36](https://github.com/bluelovers/ws-yarn-workspaces/compare/create-yarn-workspaces@3.0.35...create-yarn-workspaces@3.0.36) (2026-11-06)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### BREAKING CHANGES
|
|
25
|
+
|
|
26
|
+
* **create-yarn-workspaces:** 重構核心邏輯並支援非同步互動式介面
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### 🐛 Bug Fixes
|
|
31
|
+
|
|
32
|
+
* **create-yarn-workspaces:** 增加對依賴欄位存在性的檢查 ([c5d6f10](https://github.com/bluelovers/ws-yarn-workspaces/commit/c5d6f10cdfd5cd5bc4d8111b365ec567a9a03ea0))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### 📦 Code Refactoring
|
|
36
|
+
|
|
37
|
+
* **create-yarn-workspaces:** 重構核心邏輯並支援非同步互動式介面 ([633c02b](https://github.com/bluelovers/ws-yarn-workspaces/commit/633c02b4e217001186e3db897621977c815bac44))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### 📚 Documentation
|
|
41
|
+
|
|
42
|
+
* **create-yarn-workspaces:** 更新文件以反映支援 pnpm 與非同步 API ([d3824db](https://github.com/bluelovers/ws-yarn-workspaces/commit/d3824db408860e0c8d4f1933361ab95a2e90451d))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### 🛠 Build System
|
|
46
|
+
|
|
47
|
+
* update build ([1e395f4](https://github.com/bluelovers/ws-yarn-workspaces/commit/1e395f4228f1464fb1acd2efd6f7dc59972f76a0))
|
|
48
|
+
* **cache:** update cache-versions ([798cb57](https://github.com/bluelovers/ws-yarn-workspaces/commit/798cb57268e8cf4c795056a4fe603be0b4234216))
|
|
49
|
+
* **create-yarn-workspaces:** 模組化核心邏輯並實作非同步互動式 CLI ([369a841](https://github.com/bluelovers/ws-yarn-workspaces/commit/369a841963fccc62e3397a0952f0a5aa7246b2c6))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
### 🔖 Miscellaneous
|
|
53
|
+
|
|
54
|
+
* . ([c7d0081](https://github.com/bluelovers/ws-yarn-workspaces/commit/c7d00810006d688b18c2eb18f9324356fc40a19b))
|
|
55
|
+
* . ([74f772c](https://github.com/bluelovers/ws-yarn-workspaces/commit/74f772ca4b956e32cb9e7f04a6ba186f0ab5127a))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
6
59
|
## [3.0.35](https://github.com/bluelovers/ws-yarn-workspaces/compare/create-yarn-workspaces@3.0.34...create-yarn-workspaces@3.0.35) (2026-11-03)
|
|
7
60
|
|
|
8
61
|
|
package/README.md
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
# create-yarn-workspaces
|
|
2
2
|
|
|
3
|
-
> 快速初始化
|
|
3
|
+
> 快速初始化 Workspaces 專案結構(Yarn / pnpm 相容)/ Quickly initialize Workspaces project structure (Yarn / pnpm compatible)
|
|
4
4
|
|
|
5
|
-
一鍵建立
|
|
5
|
+
一鍵建立 Workspaces(工作區)專案骨架,自動處理 package.json、Lerna 設定與 packages 目錄。
|
|
6
|
+
|
|
7
|
+
已不再專用於 Yarn:產生的專案同時相容 pnpm,且更新 `lerna.json` 時會將 `npmClient` 預設為 `pnpm`。
|
|
8
|
+
No longer Yarn-only: the generated project is also pnpm-compatible, and `lerna.json` `npmClient` defaults to `pnpm`.
|
|
6
9
|
|
|
7
10
|
## 功能特性 / Features
|
|
8
11
|
|
|
9
|
-
- 🚀 **快速初始化** - 一鍵創建完整的
|
|
10
|
-
-
|
|
12
|
+
- 🚀 **快速初始化** - 一鍵創建完整的 Workspaces 專案結構
|
|
13
|
+
- 🧩 **Yarn / pnpm 相容** - 已非 Yarn 專用,同時建立 pnpm 相容的 Workspaces 設定
|
|
14
|
+
- 📦 **Lerna 整合** - 自動檢測並更新現有的 Lerna 配置,`npmClient` 預設為 `pnpm`
|
|
11
15
|
- 📝 **智能設定** - 自動配置 package.json、tsconfig 等開發環境檔案
|
|
12
16
|
- 🔧 **靈活選項** - 支援自定義初始化回呼與多種配置選項
|
|
17
|
+
- 🖥️ **互動介面** - CLI 預設啟用互動確認,無 TTY 時自動退回警告(`--no-interactive` 可關閉)
|
|
13
18
|
- 🗂️ **目錄管理** - 根據 workspaces 配置自動創建 packages 目錄
|
|
14
19
|
|
|
15
20
|
## 安裝 / Installation
|
|
@@ -38,6 +43,9 @@ yarn create yarn-workspaces my-project
|
|
|
38
43
|
|
|
39
44
|
# 忽略已存在的 Package 並覆寫
|
|
40
45
|
yarn create yarn-workspaces --ignoreExistsPackage
|
|
46
|
+
|
|
47
|
+
# 關閉互動確認 / Disable interactive confirm
|
|
48
|
+
yarn create yarn-workspaces --no-interactive
|
|
41
49
|
```
|
|
42
50
|
|
|
43
51
|
命令列選項 / CLI Options:
|
|
@@ -48,13 +56,14 @@ yarn create yarn-workspaces --ignoreExistsPackage
|
|
|
48
56
|
| `--ignoreExistsPackage` | `-i` | 忽略已存在的 Package / Ignore existing package |
|
|
49
57
|
| `--ignoreParentWorkspaces` | | 忽略父層 Workspaces / Ignore parent workspaces |
|
|
50
58
|
| `--debug` | | 啟用除錯模式 / Enable debug mode |
|
|
59
|
+
| `--interactive` | | 互動介面(預設啟用,`--no-interactive` 關閉;無 TTY 時退回警告)/ Interactive mode (enabled by default, disable with `--no-interactive`; falls back to a warning without a TTY) |
|
|
51
60
|
|
|
52
61
|
初始化後的專案結構 / Project structure after initialization:
|
|
53
62
|
|
|
54
63
|
```
|
|
55
64
|
my-project/
|
|
56
65
|
├── package.json # Workspaces 配置 / Workspaces config
|
|
57
|
-
├── lerna.json # Lerna
|
|
66
|
+
├── lerna.json # Lerna 配置(如果存在;npmClient 預設 pnpm)/ Lerna config (if exists; npmClient defaults to pnpm)
|
|
58
67
|
├── tsconfig.json # TypeScript 配置 / TypeScript config
|
|
59
68
|
├── .gitignore # Git 忽略規則 / Git ignore rules
|
|
60
69
|
├── .eslintrc.json # ESLint 配置 / ESLint config
|
|
@@ -65,31 +74,44 @@ my-project/
|
|
|
65
74
|
## API 文件 / API Documentation
|
|
66
75
|
|
|
67
76
|
```typescript
|
|
68
|
-
import {
|
|
77
|
+
import { createYarnWorkspacesAsync, IOptions } from 'create-yarn-workspaces';
|
|
69
78
|
|
|
70
79
|
// 基本使用 / Basic usage
|
|
71
|
-
const success =
|
|
80
|
+
const success = await createYarnWorkspacesAsync('./my-project');
|
|
72
81
|
|
|
73
82
|
// 帶選項 / With options
|
|
74
83
|
const options: IOptions = {
|
|
75
84
|
ignoreExistsPackage: true,
|
|
76
85
|
ignoreParentWorkspaces: false,
|
|
86
|
+
interactive: true,
|
|
77
87
|
initPackageJson: (pkg) => {
|
|
78
88
|
pkg.author = 'Your Name';
|
|
79
89
|
return pkg;
|
|
80
90
|
}
|
|
81
91
|
};
|
|
82
92
|
|
|
83
|
-
|
|
93
|
+
await createYarnWorkspacesAsync('./my-project', options);
|
|
84
94
|
```
|
|
85
95
|
|
|
86
|
-
### `
|
|
96
|
+
### `createYarnWorkspacesAsync(cwd?, options?)`
|
|
87
97
|
|
|
88
|
-
建立 Workspaces
|
|
98
|
+
建立 Workspaces 專案結構的主要函式(非同步)/ Main async function that creates the workspace project structure.
|
|
89
99
|
|
|
90
100
|
- `cwd?: string | IOptions` — 目標目錄;也可直接傳入選項物件 / Target directory; an options object may be passed directly as the first argument.
|
|
91
101
|
- `options?: IOptions` — 配置選項 / Configuration options.
|
|
92
|
-
- 回傳 `boolean
|
|
102
|
+
- 回傳 `Promise<boolean>` — 是否成功建立;使用者於互動介面取消時為 `false` / Whether creation succeeded; `false` when the user cancels the interactive prompt.
|
|
103
|
+
|
|
104
|
+
當 `options.interactive` 啟用且環境具備 TTY 時,若環境檢查發現疑似在錯誤路徑執行(目錄或子目錄已存在 package.json),會透過互動介面詢問是否繼續;未啟用互動介面(或不具備 TTY)時僅印出警告並繼續執行。
|
|
105
|
+
When `options.interactive` is enabled and a TTY is available, a suspicious path detected by the environment check (an existing `package.json` in the directory or its subdirectories) triggers an interactive confirm prompt; otherwise a warning is printed and execution continues.
|
|
106
|
+
|
|
107
|
+
### `createYarnWorkspaces(cwd?, options?)` — `@deprecated`
|
|
108
|
+
|
|
109
|
+
**已棄用 / Deprecated**:請改用 `createYarnWorkspacesAsync` / Please use `createYarnWorkspacesAsync` instead.
|
|
110
|
+
|
|
111
|
+
同步版本不支援互動介面,發現疑似錯誤路徑時僅印出警告並繼續執行。
|
|
112
|
+
The synchronous version does not support the interactive prompt; it only prints a warning and continues.
|
|
113
|
+
|
|
114
|
+
- 參數與回傳值同 `createYarnWorkspacesAsync`(回傳 `boolean`)/ Same parameters and return value as `createYarnWorkspacesAsync` (returns `boolean`).
|
|
93
115
|
|
|
94
116
|
其他匯出 / Also exported: `createDirByPackages(cwd, packages)`、`getDefaultPackageJson(name?)`、`getDefaultTsconfig()`、`setupWorkspacesInitToYargs(yargs)`。
|
|
95
117
|
|
|
@@ -104,6 +126,7 @@ createYarnWorkspaces('./my-project', options);
|
|
|
104
126
|
| `ignoreParentWorkspaces` | `boolean` | `false` | 忽略父層 Workspaces / Ignore parent workspaces |
|
|
105
127
|
| `initPackageJson` | `(pkg) => pkg` | — | 自定義 package.json 初始化回呼 / Custom package.json init callback |
|
|
106
128
|
| `debug` | `boolean` | `false` | 啟用除錯輸出 / Enable debug output |
|
|
129
|
+
| `interactive` | `boolean` | `false`(CLI 為 `true`)/ `false` (`true` in CLI) | 啟用互動詢問,僅 `createYarnWorkspacesAsync` 支援,需 TTY / Enable the interactive prompt; `createYarnWorkspacesAsync` only, requires a TTY |
|
|
107
130
|
| `addStaticFiles` | `boolean` | `true` | 自動加入靜態範本檔案 / Auto-add static template files |
|
|
108
131
|
| `noStaticFiles` | `boolean` | `false` | 略過靜態檔案(優先於 `addStaticFiles`)/ Skip static files (takes precedence over `addStaticFiles`) |
|
|
109
132
|
|
package/bin/yarn-ws-init.js
CHANGED
|
@@ -2,29 +2,27 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const __1 =
|
|
5
|
+
const __1 = require("..");
|
|
6
6
|
const logger_1 = tslib_1.__importDefault(require("debug-color2/logger"));
|
|
7
7
|
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const yargs_setting_1 = tslib_1.__importDefault(require("../yargs-setting"));
|
|
10
10
|
/**
|
|
11
11
|
* CLI 一律以呼叫當下的 shell 目錄作為基準路徑。
|
|
12
|
-
* The CLI always uses the invoking shell's directory as the base path.
|
|
13
12
|
*/
|
|
14
13
|
const CWD = process.cwd();
|
|
15
14
|
/**
|
|
16
|
-
* CLI 入口:解析參數後呼叫
|
|
17
|
-
*
|
|
15
|
+
* CLI 入口:解析參數後呼叫 createYarnWorkspacesAsync,失敗時印出說明。
|
|
16
|
+
*
|
|
17
|
+
* 以 async handler 搭配 parseAsync,確保互動介面(@clack/prompts)完成後才結束流程。
|
|
18
18
|
*/
|
|
19
19
|
let cli = (0, yargs_setting_1.default)(yargs_1.default)
|
|
20
20
|
// @ts-ignore
|
|
21
|
-
.command('$0', '', function (yargs) {
|
|
21
|
+
.command('$0', '', async function (yargs) {
|
|
22
|
+
/** 優先採用 --name,否則取第一個位置參數作為目標資料夾名稱。 */
|
|
22
23
|
// @ts-ignore
|
|
23
|
-
// 優先採用 --name,否則取第一個位置參數作為目標資料夾名稱。
|
|
24
|
-
// Prefer `--name`; otherwise take the first positional argument as the target folder name.
|
|
25
24
|
let name = (yargs.argv.name || yargs.argv._[0]);
|
|
26
|
-
|
|
27
|
-
// When no name is given, initialize in place (target = `CWD`).
|
|
25
|
+
/** 未指定名稱時就地初始化(以 CWD 為目標)。 */
|
|
28
26
|
if (name) {
|
|
29
27
|
name = (0, path_1.join)(CWD, name);
|
|
30
28
|
}
|
|
@@ -34,17 +32,22 @@ let cli = (0, yargs_setting_1.default)(yargs_1.default)
|
|
|
34
32
|
//console.log(CWD, yargs.argv);
|
|
35
33
|
// @ts-ignore
|
|
36
34
|
yargs.argv.debug && logger_1.default.debug(yargs.argv);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let bool = (0, __1.default)(name, {
|
|
35
|
+
/** 布林參數以 !! 強制轉型;靜態檔案相關選項刻意保留原始值,讓 addStaticFiles 維持預設 true。 */
|
|
36
|
+
let bool = await (0, __1.createYarnWorkspacesAsync)(name, {
|
|
40
37
|
// @ts-ignore
|
|
41
38
|
ignoreExistsPackage: !!yargs.argv.ignoreExistsPackage,
|
|
42
39
|
// @ts-ignore
|
|
43
40
|
ignoreParentWorkspaces: !!yargs.argv.ignoreParentWorkspaces,
|
|
41
|
+
/**
|
|
42
|
+
* 互動介面預設啟用(yargs default: true),可用 --no-interactive 關閉;
|
|
43
|
+
* 無 TTY 時於 async 版本內自動退回警告。
|
|
44
|
+
*/
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
interactive: !!yargs.argv.interactive,
|
|
44
47
|
// @ts-ignore
|
|
45
48
|
debug: !!yargs.argv.debug,
|
|
46
49
|
/*
|
|
47
|
-
* 保留 undefined,讓 addStaticFiles 維持預設 true
|
|
50
|
+
* 保留 undefined,讓 addStaticFiles 維持預設 true
|
|
48
51
|
* */
|
|
49
52
|
// @ts-ignore
|
|
50
53
|
addStaticFiles: yargs.argv.addStaticFiles,
|
|
@@ -54,8 +57,7 @@ let cli = (0, yargs_setting_1.default)(yargs_1.default)
|
|
|
54
57
|
resetStaticFiles: yargs.argv.resetStaticFiles,
|
|
55
58
|
});
|
|
56
59
|
//console.log(77777777777, bool);
|
|
57
|
-
|
|
58
|
-
// A `false` return means a pre-check failed (e.g. package already exists), so show help to guide the user.
|
|
60
|
+
/** 回傳 false 代表前置檢查失敗(如已存在 Package)或使用者於互動介面取消,此時顯示說明協助使用者修正參數。 */
|
|
59
61
|
if (!bool) {
|
|
60
62
|
console.log('\n');
|
|
61
63
|
yargs.showHelp();
|
|
@@ -66,5 +68,5 @@ let cli = (0, yargs_setting_1.default)(yargs_1.default)
|
|
|
66
68
|
})
|
|
67
69
|
.version()
|
|
68
70
|
.help()
|
|
69
|
-
.
|
|
71
|
+
.parseAsync();
|
|
70
72
|
//# sourceMappingURL=yarn-ws-init.js.map
|
package/bin/yarn-ws-init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yarn-ws-init.js","sourceRoot":"","sources":["yarn-ws-init.ts"],"names":[],"mappings":";;;;AAEA,
|
|
1
|
+
{"version":3,"file":"yarn-ws-init.js","sourceRoot":"","sources":["yarn-ws-init.ts"],"names":[],"mappings":";;;;AAEA,0BAA+C;AAC/C,yEAAwC;AACxC,0DAA0B;AAC1B,+BAA4B;AAC5B,6EAA0D;AAE1D;;GAEG;AACH,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AAE1B;;;;GAIG;AACH,IAAI,GAAG,GAAG,IAAA,uBAA0B,EAAC,eAAK,CAAC;IAC1C,aAAa;KACZ,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,KAAK,WAAW,KAAK;IAEvC,uCAAuC;IACvC,aAAa;IACb,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAW,CAAC;IAE1D,8BAA8B;IAC9B,IAAI,IAAI,EACR,CAAC;QACA,IAAI,GAAG,IAAA,WAAI,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACxB,CAAC;SAED,CAAC;QACA,IAAI,GAAG,GAAG,CAAC;IACZ,CAAC;IAED,+BAA+B;IAE/B,aAAa;IACb,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,gBAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE5C,gEAAgE;IAChE,IAAI,IAAI,GAAG,MAAM,IAAA,6BAAyB,EAAC,IAAI,EAAE;QAChD,aAAa;QACb,mBAAmB,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB;QACrD,aAAa;QACb,sBAAsB,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,sBAAsB;QAC3D;;;WAGG;QACH,aAAa;QACb,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW;QACrC,aAAa;QACb,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK;QACzB;;aAEK;QACL,aAAa;QACb,cAAc,EAAE,KAAK,CAAC,IAAI,CAAC,cAAc;QACzC,aAAa;QACb,aAAa,EAAE,KAAK,CAAC,IAAI,CAAC,aAAa;QACvC,aAAa;QACb,gBAAgB,EAAE,KAAK,CAAC,IAAI,CAAC,gBAAgB;KAC7C,CAAC,CAAC;IAEH,iCAAiC;IAEjC,kEAAkE;IAClE,IAAI,CAAC,IAAI,EACT,CAAC;QACA,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClB,KAAK,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC;SAED,CAAC;QACA,gBAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;AACF,CAAC,CAAC;KACD,OAAO,EAAE;KACT,IAAI,EAAE;KACN,UAAU,EAAE,CACb","sourcesContent":["#!/usr/bin/env node\n\nimport { createYarnWorkspacesAsync } from '..';\nimport debug from 'debug-color2/logger';\nimport yargs from 'yargs';\nimport { join } from 'path';\nimport setupWorkspacesInitToYargs from '../yargs-setting';\n\n/**\n * CLI 一律以呼叫當下的 shell 目錄作為基準路徑。\n */\nconst CWD = process.cwd();\n\n/**\n * CLI 入口:解析參數後呼叫 createYarnWorkspacesAsync,失敗時印出說明。\n *\n * 以 async handler 搭配 parseAsync,確保互動介面(@clack/prompts)完成後才結束流程。\n */\nlet cli = setupWorkspacesInitToYargs(yargs)\n\t// @ts-ignore\n\t.command('$0', '', async function (yargs)\n\t{\n\t\t/** 優先採用 --name,否則取第一個位置參數作為目標資料夾名稱。 */\n\t\t// @ts-ignore\n\t\tlet name = (yargs.argv.name || yargs.argv._[0]) as string;\n\n\t\t/** 未指定名稱時就地初始化(以 CWD 為目標)。 */\n\t\tif (name)\n\t\t{\n\t\t\tname = join(CWD, name);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tname = CWD;\n\t\t}\n\n\t\t//console.log(CWD, yargs.argv);\n\n\t\t// @ts-ignore\n\t\tyargs.argv.debug && debug.debug(yargs.argv);\n\n\t\t/** 布林參數以 !! 強制轉型;靜態檔案相關選項刻意保留原始值,讓 addStaticFiles 維持預設 true。 */\n\t\tlet bool = await createYarnWorkspacesAsync(name, {\n\t\t\t// @ts-ignore\n\t\t\tignoreExistsPackage: !!yargs.argv.ignoreExistsPackage,\n\t\t\t// @ts-ignore\n\t\t\tignoreParentWorkspaces: !!yargs.argv.ignoreParentWorkspaces,\n\t\t\t/**\n\t\t\t * 互動介面預設啟用(yargs default: true),可用 --no-interactive 關閉;\n\t\t\t * 無 TTY 時於 async 版本內自動退回警告。\n\t\t\t */\n\t\t\t// @ts-ignore\n\t\t\tinteractive: !!yargs.argv.interactive,\n\t\t\t// @ts-ignore\n\t\t\tdebug: !!yargs.argv.debug,\n\t\t\t/*\n\t\t\t * 保留 undefined,讓 addStaticFiles 維持預設 true\n\t\t\t * */\n\t\t\t// @ts-ignore\n\t\t\taddStaticFiles: yargs.argv.addStaticFiles,\n\t\t\t// @ts-ignore\n\t\t\tnoStaticFiles: yargs.argv.noStaticFiles,\n\t\t\t// @ts-ignore\n\t\t\tresetStaticFiles: yargs.argv.resetStaticFiles,\n\t\t});\n\n\t\t//console.log(77777777777, bool);\n\n\t\t/** 回傳 false 代表前置檢查失敗(如已存在 Package)或使用者於互動介面取消,此時顯示說明協助使用者修正參數。 */\n\t\tif (!bool)\n\t\t{\n\t\t\tconsole.log('\\n');\n\t\t\tyargs.showHelp();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug.success(`done`);\n\t\t}\n\t})\n\t.version()\n\t.help()\n\t.parseAsync()\n;\n"]}
|
package/index.d.ts
CHANGED
|
@@ -1,100 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 創建
|
|
3
|
-
* Yarn Workspaces Creation Tool Module
|
|
2
|
+
* 創建 Workspaces 工具模組
|
|
4
3
|
*
|
|
5
|
-
* 提供初始化
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* and static file copying.
|
|
10
|
-
*
|
|
11
|
-
* @author user
|
|
12
|
-
* @since 2018/5/13/013
|
|
4
|
+
* 提供初始化 Workspaces 專案結構的功能,
|
|
5
|
+
* 包含 package.json 設定、
|
|
6
|
+
* Lerna 整合、
|
|
7
|
+
* 目錄創建與靜態檔案複製等功能。
|
|
13
8
|
*/
|
|
14
|
-
import {
|
|
15
|
-
import { INpmAutoFixAll } from '@yarn-tool/fix-all';
|
|
9
|
+
import { IOptions } from './lib/core';
|
|
16
10
|
export * from './lib/index';
|
|
17
11
|
export * from './lib/util';
|
|
18
12
|
/**
|
|
19
|
-
* 創建 Workspaces
|
|
20
|
-
* Interface for creating workspaces options
|
|
21
|
-
*/
|
|
22
|
-
export interface IOptions extends Pick<INpmAutoFixAll, 'addStaticFiles' | 'noStaticFiles'> {
|
|
23
|
-
/**
|
|
24
|
-
* 工作目錄路徑 / Working directory path
|
|
25
|
-
*/
|
|
26
|
-
cwd?: string;
|
|
27
|
-
/**
|
|
28
|
-
* 忽略父層 Workspaces / Ignore parent workspaces
|
|
29
|
-
*/
|
|
30
|
-
ignoreParentWorkspaces?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* 忽略已存在的 Package / Ignore existing package
|
|
33
|
-
*/
|
|
34
|
-
ignoreExistsPackage?: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* 初始化 Package.json 的回呼函式
|
|
37
|
-
* Callback function to initialize package.json
|
|
38
|
-
* @template T - 擴展屬性類型 / Extended property type
|
|
39
|
-
* @param current - 當前的 package.json / Current package.json
|
|
40
|
-
* @returns 修改後的 package.json / Modified package.json
|
|
41
|
-
*/
|
|
42
|
-
initPackageJson?<T extends Record<string, any> = {}>(current: IPackageJson): IPackageJson & T;
|
|
43
|
-
/**
|
|
44
|
-
* 啟用除錯模式 / Enable debug mode
|
|
45
|
-
*/
|
|
46
|
-
debug?: boolean;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* 創建 Yarn Workspaces 主函式
|
|
50
|
-
* Main function to create Yarn Workspaces
|
|
13
|
+
* 創建 Workspaces 主函式(同步)
|
|
51
14
|
*
|
|
52
|
-
* 檢查並創建 Workspaces 專案結構,處理已存在 Package 與父層 Workspaces
|
|
53
|
-
*
|
|
54
|
-
* and parent workspaces
|
|
15
|
+
* 檢查並創建 Workspaces 專案結構,處理已存在 Package 與父層 Workspaces 的情況。
|
|
16
|
+
* 不支援互動介面:環境檢查發現疑似錯誤路徑時僅印出警告並繼續執行。
|
|
55
17
|
*
|
|
56
|
-
* @param cwd - 工作目錄路徑
|
|
57
|
-
* @param options - 配置選項
|
|
58
|
-
* @returns 是否成功創建
|
|
59
|
-
*/
|
|
60
|
-
export declare function createYarnWorkspaces(cwd?: string, options?: IOptions): boolean;
|
|
61
|
-
/**
|
|
62
|
-
* 內部創建 Workspaces 實作函式
|
|
63
|
-
* Internal implementation function for creating workspaces
|
|
64
|
-
*
|
|
65
|
-
* 執行實際的 Workspaces 初始化工作,包含:
|
|
66
|
-
* - 讀取並更新 Lerna 配置
|
|
67
|
-
* - 創建或更新 package.json
|
|
68
|
-
* - 複製靜態範本檔案
|
|
69
|
-
* - 創建 packages 目錄
|
|
18
|
+
* @param cwd - 工作目錄路徑
|
|
19
|
+
* @param options - 配置選項
|
|
20
|
+
* @returns 是否成功創建
|
|
70
21
|
*
|
|
71
|
-
*
|
|
72
|
-
* - Reading and updating Lerna configuration
|
|
73
|
-
* - Creating or updating package.json
|
|
74
|
-
* - Copying static template files
|
|
75
|
-
* - Creating packages directory
|
|
76
|
-
*
|
|
77
|
-
* @param targetPath - 目標路徑 / Target path
|
|
78
|
-
* @param options - 配置選項 / Configuration options
|
|
79
|
-
* @returns 是否成功 / Whether successful
|
|
22
|
+
* @deprecated 請改用 `createYarnWorkspacesAsync` 以獲得更好的互動體驗
|
|
80
23
|
*/
|
|
81
|
-
export declare function
|
|
24
|
+
export declare function createYarnWorkspaces(cwd?: string, options?: IOptions): boolean;
|
|
82
25
|
/**
|
|
83
|
-
*
|
|
84
|
-
* Create directories based on packages pattern
|
|
26
|
+
* 創建 Workspaces 主函式(非同步)
|
|
85
27
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* and creates corresponding physical directories.
|
|
28
|
+
* 與 {@link createYarnWorkspaces} 相同,但當 `options.interactive` 啟用且環境具備 TTY 時,
|
|
29
|
+
* 會依環境檢查報告透過互動介面詢問是否繼續;
|
|
30
|
+
* 未啟用互動介面(或不具備 TTY)時與同步版本相同,僅印出警告並繼續執行。
|
|
90
31
|
*
|
|
91
|
-
* @param cwd -
|
|
92
|
-
* @param
|
|
93
|
-
* @returns
|
|
32
|
+
* @param cwd - 工作目錄路徑
|
|
33
|
+
* @param options - 配置選項
|
|
34
|
+
* @returns 是否成功創建;使用者在互動介面取消時回傳 false
|
|
94
35
|
*/
|
|
95
|
-
export declare function
|
|
36
|
+
export declare function createYarnWorkspacesAsync(cwd?: string, options?: IOptions): Promise<boolean>;
|
|
96
37
|
/**
|
|
97
38
|
* 預設導出創建函式
|
|
98
|
-
* Default export of creation function
|
|
99
39
|
*/
|
|
100
40
|
export default createYarnWorkspaces;
|