create-yarn-workspaces 1.0.130 → 1.0.134
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 +51 -0
- package/bin/yarn-ws-init.js +4 -4
- package/bin/yarn-ws-init.js.map +1 -1
- package/index.js +52 -44
- package/index.js.map +1 -1
- package/lib/util.js +1 -1
- package/lib/util.js.map +1 -1
- package/lib/wsCopyStaticFiles.js +1 -0
- package/lib/wsCopyStaticFiles.js.map +1 -1
- package/package.json +8 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,57 @@
|
|
|
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
|
+
## [1.0.134](https://github.com/bluelovers/create-yarn-workspaces/compare/create-yarn-workspaces@1.0.133...create-yarn-workspaces@1.0.134) (2021-12-26)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
* bug when cwd not exists any ws or root ([52d00ad](https://github.com/bluelovers/create-yarn-workspaces/commit/52d00ad47e776bf8fdc9fc2b228fd7e405701ea1))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [1.0.133](https://github.com/bluelovers/create-yarn-workspaces/compare/create-yarn-workspaces@1.0.132...create-yarn-workspaces@1.0.133) (2021-12-26)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### 🐛 Bug Fixes
|
|
21
|
+
|
|
22
|
+
* `ignoreExistsPackage` not work ([5865591](https://github.com/bluelovers/create-yarn-workspaces/commit/5865591fe10fd5b29c4d8b010fa97dce65ffa199))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### ♻️ Chores
|
|
26
|
+
|
|
27
|
+
* **deps:** update deps ([2915799](https://github.com/bluelovers/create-yarn-workspaces/commit/2915799b24c73c0116d5bd48eeb724944bb39fbe))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## [1.0.132](https://github.com/bluelovers/create-yarn-workspaces/compare/create-yarn-workspaces@1.0.131...create-yarn-workspaces@1.0.132) (2021-12-26)
|
|
34
|
+
|
|
35
|
+
**Note:** Version bump only for package create-yarn-workspaces
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## [1.0.131](https://github.com/bluelovers/create-yarn-workspaces/compare/create-yarn-workspaces@1.0.130...create-yarn-workspaces@1.0.131) (2021-12-16)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### ✨ Features
|
|
45
|
+
|
|
46
|
+
* add `defaultCopyStaticFilesWsRootOnly` ([80c9b8f](https://github.com/bluelovers/create-yarn-workspaces/commit/80c9b8fc3c47b830b22b9a10cec3b0181d751650))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### 🔖 Miscellaneous
|
|
50
|
+
|
|
51
|
+
* . ([104475f](https://github.com/bluelovers/create-yarn-workspaces/commit/104475f2baa62e53dcc4cd6f3fb3a425cba1c88d))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
6
57
|
## [1.0.130](https://github.com/bluelovers/create-yarn-workspaces/compare/create-yarn-workspaces@1.0.129...create-yarn-workspaces@1.0.130) (2021-12-07)
|
|
7
58
|
|
|
8
59
|
**Note:** Version bump only for package create-yarn-workspaces
|
package/bin/yarn-ws-init.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const __1 =
|
|
6
|
-
const logger_1 =
|
|
7
|
-
const yargs_1 =
|
|
5
|
+
const __1 = tslib_1.__importDefault(require(".."));
|
|
6
|
+
const logger_1 = tslib_1.__importDefault(require("debug-color2/logger"));
|
|
7
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
8
8
|
const path_1 = require("path");
|
|
9
|
-
const yargs_setting_1 =
|
|
9
|
+
const yargs_setting_1 = tslib_1.__importDefault(require("../yargs-setting"));
|
|
10
10
|
const CWD = process.cwd();
|
|
11
11
|
let cli = (0, yargs_setting_1.default)(yargs_1.default)
|
|
12
12
|
// @ts-ignore
|
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,mDAAsC;AACtC,yEAAwC;AACxC,0DAA0B;AAC1B,+BAA4B;AAC5B,6EAA0D;AAE1D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AAE1B,IAAI,GAAG,GAAG,IAAA,uBAA0B,EAAC,eAAK,CAAC;IAC1C,aAAa;KACZ,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,UAAU,KAAK;IAEjC,aAAa;IACb,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAW,CAAC;IAE1D,IAAI,IAAI,EACR;QACC,IAAI,GAAG,IAAA,WAAI,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC;KACvB;SAED;QACC,IAAI,GAAG,GAAG,CAAC;KACX;IAED,+BAA+B;IAE/B,aAAa;IACb,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,gBAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE5C,IAAI,IAAI,GAAG,IAAA,WAAoB,EAAC,IAAI,EAAE;QACrC,aAAa;QACb,mBAAmB,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB;QACrD,aAAa;QACb,sBAAsB,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,sBAAsB;QAC3D,aAAa;QACb,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK;KACzB,CAAC,CAAC;IAEH,iCAAiC;IAEjC,IAAI,CAAC,IAAI,EACT;QACC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClB,KAAK,CAAC,QAAQ,EAAE,CAAC;KACjB;SAED;QACC,gBAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;KACtB;AACF,CAAC,CAAC;KACD,OAAO,EAAE;KACT,IAAI,EAAE;KACN,IAAI,CACL","sourcesContent":["#!/usr/bin/env node\n\nimport createYarnWorkspaces from '..';\nimport debug from 'debug-color2/logger';\nimport yargs from 'yargs';\nimport { join } from 'path';\nimport setupWorkspacesInitToYargs from '../yargs-setting';\n\nconst CWD = process.cwd();\n\nlet cli = setupWorkspacesInitToYargs(yargs)\n\t// @ts-ignore\n\t.command('$0', '', function (yargs)\n\t{\n\t\t// @ts-ignore\n\t\tlet name = (yargs.argv.name || yargs.argv._[0]) as string;\n\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\tlet bool = createYarnWorkspaces(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// @ts-ignore\n\t\t\tdebug: !!yargs.argv.debug,\n\t\t});\n\n\t\t//console.log(77777777777, bool);\n\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.argv\n;\n"]}
|
package/index.js
CHANGED
|
@@ -5,60 +5,54 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createDirByPackages = exports._createYarnWorkspaces = exports.createYarnWorkspaces = void 0;
|
|
7
7
|
const tslib_1 = require("tslib");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const pkg_dir_1 = (0, tslib_1.__importDefault)(require("pkg-dir"));
|
|
11
|
-
const logger_1 = (0, tslib_1.__importDefault)(require("debug-color2/logger"));
|
|
8
|
+
const upath2_1 = require("upath2");
|
|
9
|
+
const logger_1 = require("debug-color2/logger");
|
|
12
10
|
const static_file_1 = require("@yarn-tool/static-file");
|
|
13
11
|
const fs_extra_1 = require("fs-extra");
|
|
14
|
-
const sort_package_json3_1 =
|
|
12
|
+
const sort_package_json3_1 = require("sort-package-json3");
|
|
15
13
|
const lib_1 = require("./lib");
|
|
16
14
|
const util_1 = require("./lib/util");
|
|
17
|
-
const wsCopyStaticFiles_1 =
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const wsCopyStaticFiles_1 = require("./lib/wsCopyStaticFiles");
|
|
16
|
+
const find_root_1 = require("@yarn-tool/find-root");
|
|
17
|
+
const upath2_2 = require("upath2");
|
|
18
|
+
tslib_1.__exportStar(require("./lib/index"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./lib/util"), exports);
|
|
20
20
|
function createYarnWorkspaces(cwd, options = {}) {
|
|
21
|
+
var _a;
|
|
21
22
|
if (cwd && typeof cwd != 'string') {
|
|
22
23
|
options = cwd;
|
|
23
24
|
cwd = options.cwd;
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
logger_1.default.log(e.toString());
|
|
37
|
-
ws = null;
|
|
38
|
-
}
|
|
39
|
-
let targetPath = (0, path_1.resolve)(root || cwd);
|
|
40
|
-
options.debug && logger_1.default.debug({
|
|
26
|
+
cwd !== null && cwd !== void 0 ? cwd : (cwd = process.cwd());
|
|
27
|
+
const rootData = (0, find_root_1.findRootLazy)({
|
|
28
|
+
cwd,
|
|
29
|
+
});
|
|
30
|
+
cwd = (0, upath2_2.normalize)((_a = rootData === null || rootData === void 0 ? void 0 : rootData.cwd) !== null && _a !== void 0 ? _a : cwd);
|
|
31
|
+
let root = rootData === null || rootData === void 0 ? void 0 : rootData.pkg;
|
|
32
|
+
let ws = rootData === null || rootData === void 0 ? void 0 : rootData.ws;
|
|
33
|
+
let targetPath = (0, upath2_1.resolve)(root || cwd);
|
|
34
|
+
options.debug && logger_1.consoleLogger.debug({
|
|
41
35
|
targetPath,
|
|
42
36
|
ws,
|
|
43
37
|
options,
|
|
44
38
|
});
|
|
45
39
|
if (!options.ignoreExistsPackage && root) {
|
|
46
|
-
logger_1.
|
|
40
|
+
logger_1.consoleLogger.error(`already have package at "${root}", or use ignoreExistsPackage for overwrite it`);
|
|
47
41
|
return false;
|
|
48
42
|
}
|
|
49
43
|
else if (root) {
|
|
50
|
-
logger_1.
|
|
44
|
+
logger_1.consoleLogger.warn(`ignore exists package "${root}"`);
|
|
51
45
|
}
|
|
52
46
|
if (ws) {
|
|
53
|
-
let bool =
|
|
54
|
-
logger_1.
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
let bool = !(0, util_1.isSamePath)(targetPath, ws);
|
|
48
|
+
logger_1.consoleLogger.warn(`detect exists workspace "${ws}"`);
|
|
49
|
+
if (bool) {
|
|
50
|
+
if (options.ignoreParentWorkspaces) {
|
|
51
|
+
logger_1.consoleLogger.warn(`ignoreParentWorkspaces = true`);
|
|
52
|
+
bool = false;
|
|
59
53
|
}
|
|
60
54
|
else {
|
|
61
|
-
logger_1.
|
|
55
|
+
logger_1.consoleLogger.error(`target path already is workspace`);
|
|
62
56
|
}
|
|
63
57
|
}
|
|
64
58
|
if (bool) {
|
|
@@ -69,11 +63,11 @@ function createYarnWorkspaces(cwd, options = {}) {
|
|
|
69
63
|
}
|
|
70
64
|
exports.createYarnWorkspaces = createYarnWorkspaces;
|
|
71
65
|
function _createYarnWorkspaces(targetPath, options = {}) {
|
|
72
|
-
logger_1.
|
|
66
|
+
logger_1.consoleLogger.info(`create in target path "${targetPath}"`);
|
|
73
67
|
let pkg;
|
|
74
68
|
let lerna;
|
|
75
69
|
{
|
|
76
|
-
let file = (0,
|
|
70
|
+
let file = (0, upath2_1.join)(targetPath, 'lerna.json');
|
|
77
71
|
if ((0, fs_extra_1.existsSync)(file)) {
|
|
78
72
|
let json = JSON.parse((0, fs_extra_1.readFileSync)(file).toString());
|
|
79
73
|
if (json.packages && !Object.keys(json.packages).length) {
|
|
@@ -85,9 +79,9 @@ function _createYarnWorkspaces(targetPath, options = {}) {
|
|
|
85
79
|
let packages = lerna && lerna.packages || [
|
|
86
80
|
"packages/*",
|
|
87
81
|
];
|
|
88
|
-
let file = (0,
|
|
82
|
+
let file = (0, upath2_1.join)(targetPath, 'package.json');
|
|
89
83
|
if (!(0, fs_extra_1.existsSync)(file)) {
|
|
90
|
-
let name = (0,
|
|
84
|
+
let name = (0, upath2_1.basename)(targetPath);
|
|
91
85
|
if (!(0, fs_extra_1.existsSync)(targetPath)) {
|
|
92
86
|
(0, fs_extra_1.mkdirSync)(targetPath);
|
|
93
87
|
}
|
|
@@ -119,20 +113,34 @@ function _createYarnWorkspaces(targetPath, options = {}) {
|
|
|
119
113
|
"workspaces": workspaces,
|
|
120
114
|
});
|
|
121
115
|
pkg.resolutions = pkg.resolutions || {};
|
|
116
|
+
Object.entries((0, lib_1.getDefaultPackageJson)(json.name))
|
|
117
|
+
.forEach(([field, value]) => {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
if (field === 'scripts') {
|
|
120
|
+
(_a = pkg.scripts) !== null && _a !== void 0 ? _a : (pkg.scripts = {});
|
|
121
|
+
pkg.scripts = {
|
|
122
|
+
...value,
|
|
123
|
+
...pkg.scripts,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
(_b = pkg[field]) !== null && _b !== void 0 ? _b : (pkg[field] = value);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
122
130
|
}
|
|
123
|
-
let s = JSON.stringify((0, sort_package_json3_1.
|
|
131
|
+
let s = JSON.stringify((0, sort_package_json3_1.sortPackageJson)(pkg), null, 2);
|
|
124
132
|
(0, fs_extra_1.writeFileSync)(file, s);
|
|
125
|
-
logger_1.
|
|
133
|
+
logger_1.consoleLogger.success(`create workspace package.json`);
|
|
126
134
|
if (lerna && (packages != lerna.packages || lerna.npmClient !== 'yarn' || lerna.useWorkspaces !== true)) {
|
|
127
|
-
let file = (0,
|
|
135
|
+
let file = (0, upath2_1.join)(targetPath, 'lerna.json');
|
|
128
136
|
lerna.packages = packages;
|
|
129
137
|
lerna.npmClient = 'yarn';
|
|
130
138
|
lerna.useWorkspaces = true;
|
|
131
|
-
let s = JSON.stringify((0, sort_package_json3_1.
|
|
139
|
+
let s = JSON.stringify((0, sort_package_json3_1.sortPackageJson)(lerna), null, 2);
|
|
132
140
|
(0, fs_extra_1.writeFileSync)(file, s);
|
|
133
|
-
logger_1.
|
|
141
|
+
logger_1.consoleLogger.info(`update lerna.json`);
|
|
134
142
|
}
|
|
135
|
-
const file_map = (0, wsCopyStaticFiles_1.
|
|
143
|
+
const file_map = (0, wsCopyStaticFiles_1.getWsCopyStaticFiles)();
|
|
136
144
|
(0, static_file_1.copyStaticFiles)({
|
|
137
145
|
cwd: targetPath,
|
|
138
146
|
file_map,
|
|
@@ -146,7 +154,7 @@ function createDirByPackages(cwd, packages) {
|
|
|
146
154
|
let bool;
|
|
147
155
|
let s = value.split(/[\/\\]/)[0];
|
|
148
156
|
if (!/[!?\*{}\[\]]/.test(s)) {
|
|
149
|
-
let dir = (0,
|
|
157
|
+
let dir = (0, upath2_1.join)(cwd, s);
|
|
150
158
|
if (!(0, fs_extra_1.existsSync)(dir)) {
|
|
151
159
|
(0, fs_extra_1.mkdirSync)(dir);
|
|
152
160
|
}
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,uFAAmE;AACnE,+BAA+C;AAC/C,mEAA6B;AAC7B,8EAA0C;AAC1C,wDAAyD;AACzD,uCAA8E;AAC9E,yFAAiD;AACjD,+BAA8C;AAC9C,qCAAwC;AAGxC,6FAA2D;AAE3D,2DAA4B;AAC5B,0DAA2B;AAc3B,SAAgB,oBAAoB,CAAC,GAAY,EAAE,UAAoB,EAAE;IAExE,IAAI,GAAG,IAAI,OAAO,GAAG,IAAI,QAAQ,EACjC;QACC,OAAO,GAAG,GAAG,CAAC;QACd,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;KAClB;IAED,IAAI,CAAC,GAAG,EACR;QACC,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;KACpB;IAED,GAAG,GAAG,IAAA,cAAO,EAAC,GAAG,CAAC,CAAC;IAEnB,IAAI,IAAI,GAAW,iBAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEpC,IAAI,EAAU,CAAC;IAEf,IACA;QACC,gDAAgD;QAChD,EAAE,GAAG,IAAA,cAAqB,EAAC,IAAI,CAAC,CAAC;KACjC;IACD,OAAO,CAAC,EACR;QACC,gBAAO,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAE1B,EAAE,GAAG,IAAI,CAAC;KACV;IAED,IAAI,UAAU,GAAG,IAAA,cAAO,EAAC,IAAI,IAAI,GAAG,CAAC,CAAC;IAEtC,OAAO,CAAC,KAAK,IAAI,gBAAO,CAAC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AC,CAAC;IAE1C,OAAO,IAAI,CAAC;AACb,CAAC;AA9GD,sDA8GC;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;YACC,IAAI,GAAG,GAAG,IAAA,WAAI,EAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAEvB,IAAI,CAAC,IAAA,qBAAU,EAAC,GAAG,CAAC,EACpB;gBACC,IAAA,oBAAS,EAAC,GAAG,CAAC,CAAC;aACf;YAED,OAAO,IAAI,CAAC;SACZ;QAED,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAA;AACH,CAAC;AAtBD,kDAsBC;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 'path';\nimport pkgDir from 'pkg-dir';\nimport 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 './lib/wsCopyStaticFiles';\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\tif (!cwd)\n\t{\n\t\tcwd = process.cwd();\n\t}\n\n\tcwd = resolve(cwd);\n\n\tlet root: string = pkgDir.sync(cwd);\n\n\tlet ws: string;\n\n\ttry\n\t{\n\t\t// @FIXME 一個奇怪的BUG 不使用 try 的話 在 NPX 底下就會出現無訊息的停止\n\t\tws = findYarnWorkspaceRoot(root);\n\t}\n\tcatch (e)\n\t{\n\t\tconsole.log(e.toString());\n\n\t\tws = null;\n\t}\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 = true;\n\n\t\tconsole.warn(`detect exists workspace \"${ws}\"`);\n\n\t\tif (options.ignoreParentWorkspaces)\n\t\t{\n\t\t\tbool = isSamePath(targetPath, ws);\n\n\t\t\tif (!bool)\n\t\t\t{\n\t\t\t\tconsole.warn(`ignoreParentWorkspaces = true`);\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\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;;GAEG;;;;AAGH,mCAAiD;AAEjD,gDAA+D;AAC/D,wDAAyD;AACzD,uCAA8E;AAC9E,2DAAqD;AACrD,+BAA8C;AAC9C,qCAAwC;AAGxC,+DAA+D;AAC/D,oDAAoD;AACpD,mCAAoD;AAEpD,sDAA4B;AAC5B,qDAA2B;AAc3B,SAAgB,oBAAoB,CAAC,GAAY,EAAE,UAAoB,EAAE;;IAExE,IAAI,GAAG,IAAI,OAAO,GAAG,IAAI,QAAQ,EACjC;QACC,OAAO,GAAG,GAAG,CAAC;QACd,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;KAClB;IAED,GAAG,aAAH,GAAG,cAAH,GAAG,IAAH,GAAG,GAAK,OAAO,CAAC,GAAG,EAAE,EAAC;IAEtB,MAAM,QAAQ,GAAG,IAAA,wBAAY,EAAC;QAC7B,GAAG;KACH,CAAC,CAAC;IAEH,GAAG,GAAG,IA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AEvB,IAAI,CAAC,IAAA,qBAAU,EAAC,GAAG,CAAC,EACpB;gBACC,IAAA,oBAAS,EAAC,GAAG,CAAC,CAAC;aACf;YAED,OAAO,IAAI,CAAC;SACZ;QAED,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAA;AACH,CAAC;AAtBD,kDAsBC;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 './lib/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"]}
|
package/lib/util.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isSamePath = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const path_is_same_1 =
|
|
6
|
+
const path_is_same_1 = tslib_1.__importDefault(require("path-is-same"));
|
|
7
7
|
function isSamePath(p1, p2) {
|
|
8
8
|
if (!p1 || !p2) {
|
|
9
9
|
return false;
|
package/lib/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["util.ts"],"names":[],"mappings":";;;;AAAA,+BAAgC;AAChC,
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["util.ts"],"names":[],"mappings":";;;;AAAA,+BAAgC;AAChC,wEAAsC;AAEtC,SAAgB,UAAU,CAAC,EAAU,EAAE,EAAU;IAEhD,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,EACd;QACC,OAAO,KAAK,CAAC;KACb;SACI,IAAI,IAAA,sBAAU,EAAC,EAAE,EAAE,EAAE,CAAC,EAC3B;QACC,OAAO,IAAI,CAAC;KACZ;IAED,IAAI,CAAC,GAAG,IAAA,eAAQ,EAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACzB,OAAO,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;AAChC,CAAC;AAbD,gCAaC","sourcesContent":["import { relative } from \"path\";\nimport pathIsSame from 'path-is-same';\n\nexport function isSamePath(p1: string, p2: string)\n{\n\tif (!p1 || !p2)\n\t{\n\t\treturn false;\n\t}\n\telse if (pathIsSame(p1, p2))\n\t{\n\t\treturn true;\n\t}\n\n\tlet s = relative(p1, p2);\n\treturn (s === '.' || s === '');\n}\n\n"]}
|
package/lib/wsCopyStaticFiles.js
CHANGED
|
@@ -12,6 +12,7 @@ function getWsCopyStaticFiles() {
|
|
|
12
12
|
return (0, reMapStaticFilesMapArray_1.reMapStaticFilesMapArray)([
|
|
13
13
|
...const_1.defaultCopyStaticFiles,
|
|
14
14
|
...const_1.defaultCopyStaticFilesRootOnly,
|
|
15
|
+
...const_1.defaultCopyStaticFilesWsRootOnly,
|
|
15
16
|
], remap);
|
|
16
17
|
}
|
|
17
18
|
exports.getWsCopyStaticFiles = getWsCopyStaticFiles;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsCopyStaticFiles.js","sourceRoot":"","sources":["wsCopyStaticFiles.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"wsCopyStaticFiles.js","sourceRoot":"","sources":["wsCopyStaticFiles.ts"],"names":[],"mappings":";;;AAAA,4DAI0C;AAE1C,kGAA+F;AAE/F,MAAM,KAAK,GAAG;IACb,eAAe,EAAE,mBAAmB;IACpC,YAAY,EAAE,gBAAgB;IAC9B,qBAAqB,EAAE,yBAAyB;CACvC,CAAA;AAEV,SAAgB,oBAAoB;IAEnC,OAAO,IAAA,mDAAwB,EAAC;QAC/B,GAAG,8BAAsB;QACzB,GAAG,sCAA8B;QACjC,GAAG,wCAAgC;KACnC,EAAE,KAAK,CAAC,CAAC;AACX,CAAC;AAPD,oDAOC;AAED,kBAAe,oBAAoB,CAAC","sourcesContent":["import {\n\tdefaultCopyStaticFiles,\n\tdefaultCopyStaticFilesRootOnly,\n\tdefaultCopyStaticFilesWsRootOnly,\n} from '@yarn-tool/static-file/lib/const';\nimport { IStaticFiles, IStaticFilesKey, IStaticFilesMapArray } from '@yarn-tool/static-file/lib/types';\nimport { reMapStaticFilesMapArray } from '@yarn-tool/static-file/lib/reMapStaticFilesMapArray';\n\nconst remap = {\n\t'tsconfig.json': 'tsconfig.json.tpl',\n\t'lerna.json': 'lerna.json.tpl',\n\t'pnpm-workspace.yaml': 'pnpm-workspace.yaml.tpl',\n} as const\n\nexport function getWsCopyStaticFiles(): IStaticFiles<IStaticFilesKey<typeof defaultCopyStaticFiles | typeof defaultCopyStaticFilesRootOnly> | keyof typeof remap>\n{\n\treturn reMapStaticFilesMapArray([\n\t\t...defaultCopyStaticFiles,\n\t\t...defaultCopyStaticFilesRootOnly,\n\t\t...defaultCopyStaticFilesWsRootOnly,\n\t], remap);\n}\n\nexport default getWsCopyStaticFiles;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-yarn-workspaces",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.134",
|
|
4
4
|
"description": "yarn create yarn-workspaces npx create-yarn-workspaces",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -48,16 +48,18 @@
|
|
|
48
48
|
"resolutions": {},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@ts-type/package-dts": "^1.0.56",
|
|
51
|
-
"@yarn-tool/
|
|
51
|
+
"@yarn-tool/find-root": "^1.0.59",
|
|
52
|
+
"@yarn-tool/static-file": "^1.0.81",
|
|
52
53
|
"debug-color2": "^1.2.7",
|
|
53
|
-
"find-yarn-workspace-root2": "^1.2.
|
|
54
|
+
"find-yarn-workspace-root2": "^1.2.35",
|
|
54
55
|
"fs-extra": "^10.0.0",
|
|
55
56
|
"path-is-same": "^1.0.15",
|
|
56
57
|
"pkg-dir": "< 6 >= 5",
|
|
57
58
|
"sort-package-json": "^1.53.1",
|
|
58
|
-
"sort-package-json3": "^1.0.
|
|
59
|
+
"sort-package-json3": "^1.0.48",
|
|
59
60
|
"tslib": "^2.3.1",
|
|
60
|
-
"
|
|
61
|
+
"upath2": "^3.1.10",
|
|
62
|
+
"yargs": "^17.3.1"
|
|
61
63
|
},
|
|
62
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "6423eb5ee87de2f99349e568caf1eed7dfb764c9"
|
|
63
65
|
}
|