@icebreakers/monorepo 0.6.4 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,304 +1,23 @@
1
1
  import {
2
- GitClient,
2
+ cleanProjects,
3
3
  createNewProject,
4
+ init,
5
+ init_esm_shims,
4
6
  logger,
5
7
  name,
8
+ setVscodeBinaryMirror,
9
+ syncNpmMirror,
6
10
  upgradeMonorepo,
7
11
  version
8
- } from "./chunk-UU4G2QIU.js";
12
+ } from "./chunk-43YMCN4J.js";
13
+
14
+ // src/cli.ts
15
+ init_esm_shims();
9
16
 
10
17
  // src/program.ts
18
+ init_esm_shims();
11
19
  import process from "node:process";
12
20
  import { program } from "commander";
13
-
14
- // src/monorepo/binaryMirror.ts
15
- import { parse, stringify } from "comment-json";
16
- import fs from "fs-extra";
17
- import path from "pathe";
18
-
19
- // src/monorepo/mirror/sources.ts
20
- var chinaMirrorsEnvs = {
21
- COREPACK_NPM_REGISTRY: "https://registry.npmmirror.com",
22
- EDGEDRIVER_CDNURL: "https://npmmirror.com/mirrors/edgedriver",
23
- NODEJS_ORG_MIRROR: "https://cdn.npmmirror.com/binaries/node",
24
- NVM_NODEJS_ORG_MIRROR: "https://cdn.npmmirror.com/binaries/node",
25
- PHANTOMJS_CDNURL: "https://cdn.npmmirror.com/binaries/phantomjs",
26
- CHROMEDRIVER_CDNURL: "https://cdn.npmmirror.com/binaries/chromedriver",
27
- OPERADRIVER_CDNURL: "https://cdn.npmmirror.com/binaries/operadriver",
28
- CYPRESS_DOWNLOAD_PATH_TEMPLATE: "https://cdn.npmmirror.com/binaries/cypress/${version}/${platform}-${arch}/cypress.zip",
29
- ELECTRON_MIRROR: "https://cdn.npmmirror.com/binaries/electron/",
30
- ELECTRON_BUILDER_BINARIES_MIRROR: "https://cdn.npmmirror.com/binaries/electron-builder-binaries/",
31
- SASS_BINARY_SITE: "https://cdn.npmmirror.com/binaries/node-sass",
32
- SWC_BINARY_SITE: "https://cdn.npmmirror.com/binaries/node-swc",
33
- NWJS_URLBASE: "https://cdn.npmmirror.com/binaries/nwjs/v",
34
- PUPPETEER_DOWNLOAD_HOST: "https://cdn.npmmirror.com/binaries/chrome-for-testing",
35
- PUPPETEER_DOWNLOAD_BASE_URL: "https://cdn.npmmirror.com/binaries/chrome-for-testing",
36
- PLAYWRIGHT_DOWNLOAD_HOST: "https://cdn.npmmirror.com/binaries/playwright",
37
- SENTRYCLI_CDNURL: "https://cdn.npmmirror.com/binaries/sentry-cli",
38
- SAUCECTL_INSTALL_BINARY_MIRROR: "https://cdn.npmmirror.com/binaries/saucectl",
39
- RE2_DOWNLOAD_MIRROR: "https://cdn.npmmirror.com/binaries/node-re2",
40
- RE2_DOWNLOAD_SKIP_PATH: "true",
41
- PRISMA_ENGINES_MIRROR: "https://cdn.npmmirror.com/binaries/prisma",
42
- npm_config_better_sqlite3_binary_host: "https://cdn.npmmirror.com/binaries/better-sqlite3",
43
- npm_config_keytar_binary_host: "https://cdn.npmmirror.com/binaries/keytar",
44
- npm_config_sharp_binary_host: "https://cdn.npmmirror.com/binaries/sharp",
45
- npm_config_sharp_libvips_binary_host: "https://cdn.npmmirror.com/binaries/sharp-libvips",
46
- npm_config_robotjs_binary_host: "https://cdn.npmmirror.com/binaries/robotjs"
47
- };
48
-
49
- // src/monorepo/mirror/utils.ts
50
- import set from "set-value";
51
- function setMirror(obj) {
52
- const platforms = ["linux", "windows", "osx"];
53
- const prefix = "terminal.integrated.env";
54
- if (typeof obj === "object" && obj) {
55
- for (const platform of platforms) {
56
- set(obj, [prefix, platform].join(".").replaceAll(".", "\\."), chinaMirrorsEnvs);
57
- }
58
- }
59
- }
60
-
61
- // src/monorepo/binaryMirror.ts
62
- async function setVscodeBinaryMirror(cwd2) {
63
- const targetJsonPath = path.resolve(cwd2, ".vscode/settings.json");
64
- await fs.ensureFile(targetJsonPath);
65
- const json = parse(await fs.readFile(targetJsonPath, "utf8"), void 0, false);
66
- json && typeof json === "object" && setMirror(json);
67
- await fs.writeFile(targetJsonPath, `${stringify(json, void 0, 2)}
68
- `, "utf8");
69
- }
70
-
71
- // src/monorepo/clean.ts
72
- import path2 from "pathe";
73
- import { rimraf } from "rimraf";
74
- var dirs = [
75
- "packages/monorepo",
76
- "packages/foo",
77
- // 'apps/cli',
78
- // 'apps/website',
79
- "apps"
80
- ];
81
- async function cleanProjects(cwd2) {
82
- await rimraf(dirs.map((x) => {
83
- return path2.resolve(cwd2, x);
84
- }));
85
- }
86
-
87
- // src/monorepo/context.ts
88
- import path4 from "pathe";
89
-
90
- // src/monorepo/workspace.ts
91
- import { findWorkspacePackages } from "@pnpm/workspace.find-packages";
92
-
93
- // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
94
- function isPlainObject(value) {
95
- if (value === null || typeof value !== "object") {
96
- return false;
97
- }
98
- const prototype = Object.getPrototypeOf(value);
99
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
100
- return false;
101
- }
102
- if (Symbol.iterator in value) {
103
- return false;
104
- }
105
- if (Symbol.toStringTag in value) {
106
- return Object.prototype.toString.call(value) === "[object Module]";
107
- }
108
- return true;
109
- }
110
- function _defu(baseObject, defaults, namespace = ".", merger) {
111
- if (!isPlainObject(defaults)) {
112
- return _defu(baseObject, {}, namespace, merger);
113
- }
114
- const object = Object.assign({}, defaults);
115
- for (const key in baseObject) {
116
- if (key === "__proto__" || key === "constructor") {
117
- continue;
118
- }
119
- const value = baseObject[key];
120
- if (value === null || value === void 0) {
121
- continue;
122
- }
123
- if (merger && merger(object, key, value, namespace)) {
124
- continue;
125
- }
126
- if (Array.isArray(value) && Array.isArray(object[key])) {
127
- object[key] = [...value, ...object[key]];
128
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
129
- object[key] = _defu(
130
- value,
131
- object[key],
132
- (namespace ? `${namespace}.` : "") + key.toString(),
133
- merger
134
- );
135
- } else {
136
- object[key] = value;
137
- }
138
- }
139
- return object;
140
- }
141
- function createDefu(merger) {
142
- return (...arguments_) => (
143
- // eslint-disable-next-line unicorn/no-array-reduce
144
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
145
- );
146
- }
147
- var defu = createDefu();
148
- var defuFn = createDefu((object, key, currentValue) => {
149
- if (object[key] !== void 0 && typeof currentValue === "function") {
150
- object[key] = currentValue(object[key]);
151
- return true;
152
- }
153
- });
154
- var defuArrayFn = createDefu((object, key, currentValue) => {
155
- if (Array.isArray(object[key]) && typeof currentValue === "function") {
156
- object[key] = currentValue(object[key]);
157
- return true;
158
- }
159
- });
160
-
161
- // src/monorepo/workspace.ts
162
- import path3 from "pathe";
163
- async function getWorkspacePackages(cwd2, options) {
164
- const posixCwd = path3.normalize(cwd2);
165
- const { ignoreRootPackage, ignorePrivatePackage } = defu(options, {
166
- ignoreRootPackage: true,
167
- ignorePrivatePackage: true
168
- });
169
- const packages = await findWorkspacePackages(cwd2);
170
- let pkgs = packages.filter((x) => {
171
- if (ignorePrivatePackage && x.manifest.private) {
172
- return false;
173
- }
174
- return true;
175
- }).map((project) => {
176
- const pkgJsonPath = path3.resolve(project.rootDir, "package.json");
177
- return {
178
- ...project,
179
- pkgJsonPath
180
- };
181
- });
182
- if (ignoreRootPackage) {
183
- pkgs = pkgs.filter((x) => {
184
- return path3.normalize(
185
- x.rootDir
186
- ) !== posixCwd;
187
- });
188
- }
189
- return pkgs;
190
- }
191
-
192
- // src/monorepo/context.ts
193
- import "@pnpm/types";
194
- async function createContext(cwd2) {
195
- const git = new GitClient();
196
- const workspaceFilepath = path4.resolve(cwd2, "pnpm-workspace.yaml");
197
- const projects = await getWorkspacePackages(cwd2);
198
- return {
199
- cwd: cwd2,
200
- git,
201
- workspaceFilepath,
202
- projects
203
- };
204
- }
205
-
206
- // src/monorepo/setPkgJson.ts
207
- import fs2 from "fs-extra";
208
- import path5 from "pathe";
209
- import set2 from "set-value";
210
- async function setPkgJson_default(ctx) {
211
- const { git, projects, cwd: cwd2, workspaceFilepath } = ctx;
212
- const gitUrl = await git.getGitUrl();
213
- const gitUser = await git.getUser();
214
- if (gitUrl && await fs2.exists(workspaceFilepath)) {
215
- for (const project of projects) {
216
- const pkgJson = project.manifest;
217
- const directory = path5.relative(cwd2, project.rootDir);
218
- set2(pkgJson, "bugs.url", `https://github.com/${gitUrl.full_name}/issues`);
219
- const repository = {
220
- type: "git",
221
- url: `git+https://github.com/${gitUrl.full_name}.git`
222
- };
223
- if (directory) {
224
- repository.directory = directory;
225
- }
226
- set2(pkgJson, "repository", repository);
227
- if (gitUser) {
228
- set2(pkgJson, "author", `${gitUser.name} <${gitUser.email}>`);
229
- }
230
- await fs2.writeJSON(project.pkgJsonPath, pkgJson, {
231
- spaces: 2
232
- });
233
- }
234
- }
235
- }
236
-
237
- // src/monorepo/setReadme.ts
238
- import fs3 from "fs-extra";
239
- import path6 from "pathe";
240
- async function getRows(ctx) {
241
- const { projects, git, cwd: cwd2 } = ctx;
242
- const gitUrl = await git.getGitUrl();
243
- const gitUser = await git.getUser();
244
- const rows = [];
245
- if (gitUrl) {
246
- rows.push(`# ${gitUrl.name}
247
- `);
248
- }
249
- rows.push("## Projects\n");
250
- for (const project of projects) {
251
- const p = path6.relative(cwd2, project.rootDirRealPath);
252
- p && rows.push(`- [${project.manifest.name}](${p}) ${project.manifest.description ? `- ${project.manifest.description}` : ""}`);
253
- }
254
- if (gitUrl) {
255
- rows.push("\n## Contributing\n");
256
- rows.push("Contributions Welcome! You can contribute in the following ways.");
257
- rows.push("");
258
- rows.push("- Create an Issue - Propose a new feature. Report a bug.");
259
- rows.push("- Pull Request - Fix a bug and typo. Refactor the code.");
260
- rows.push("- Create third-party middleware - Instruct below.");
261
- rows.push("- Share - Share your thoughts on the Blog, X, and others.");
262
- rows.push(`- Make your application - Please try to use ${gitUrl.name}.`);
263
- rows.push("");
264
- rows.push("For more details, see [CONTRIBUTING.md](CONTRIBUTING.md).");
265
- rows.push("\n## Contributors\n");
266
- rows.push(`Thanks to [all contributors](https://github.com/${gitUrl.full_name}/graphs/contributors)!`);
267
- }
268
- rows.push("\n## Authors\n");
269
- rows.push(`${gitUser.name} <${gitUser.email}>`);
270
- rows.push("\n## License\n");
271
- rows.push("Distributed under the MIT License. See [LICENSE](LICENSE) for more information.");
272
- return rows;
273
- }
274
- async function setReadme_default(ctx) {
275
- const rows = await getRows(ctx);
276
- await fs3.writeFile(path6.resolve(ctx.cwd, "README.md"), `${rows.join("\n")}
277
- `);
278
- }
279
-
280
- // src/monorepo/init.ts
281
- async function init(cwd2) {
282
- const ctx = await createContext(cwd2);
283
- await setPkgJson_default(ctx);
284
- await setReadme_default(ctx);
285
- }
286
-
287
- // src/monorepo/sync.ts
288
- import { execa } from "execa";
289
- async function syncNpmMirror(cwd2) {
290
- const packages = await getWorkspacePackages(cwd2);
291
- logger.info("[\u5373\u5C06\u540C\u6B65\u7684\u5305]:", packages.filter((x) => x.manifest.name).map((x) => x.manifest.name));
292
- for (const project of packages) {
293
- if (project.manifest.name) {
294
- await execa({
295
- stdout: ["pipe", "inherit"]
296
- })`cnpm sync ${project.manifest.name}`;
297
- }
298
- }
299
- }
300
-
301
- // src/program.ts
302
21
  var cwd = process.cwd();
303
22
  program.name(name).version(version);
304
23
  program.option("-i,--interactive").option("--raw", "raw mode").option("--outDir <dir>", "Output directory").action(async (opts) => {