@icebreakers/monorepo 0.4.6 → 0.4.8

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,26 +1,242 @@
1
1
  import {
2
- init_esm_shims,
2
+ GitClient,
3
3
  logger,
4
- main
5
- } from "./chunk-QDBTTGEJ.js";
6
-
7
- // src/cli.ts
8
- init_esm_shims();
4
+ main,
5
+ name,
6
+ version
7
+ } from "./chunk-63SAAQXN.js";
9
8
 
10
9
  // src/program.ts
11
- init_esm_shims();
10
+ import process from "node:process";
12
11
  import { program } from "commander";
13
12
 
14
- // package.json
15
- var name = "@icebreakers/monorepo";
16
- var version = "0.4.6";
13
+ // src/monorepo/binaryMirror.ts
14
+ import { parse, stringify } from "comment-json";
15
+ import fs from "fs-extra";
16
+ import path from "pathe";
17
+
18
+ // src/monorepo/mirror/utils.ts
19
+ import set from "set-value";
20
+
21
+ // src/monorepo/mirror/sources.ts
22
+ var chinaMirrorsEnvs = {
23
+ COREPACK_NPM_REGISTRY: "https://registry.npmmirror.com",
24
+ EDGEDRIVER_CDNURL: "https://npmmirror.com/mirrors/edgedriver",
25
+ NODEJS_ORG_MIRROR: "https://cdn.npmmirror.com/binaries/node",
26
+ NVM_NODEJS_ORG_MIRROR: "https://cdn.npmmirror.com/binaries/node",
27
+ PHANTOMJS_CDNURL: "https://cdn.npmmirror.com/binaries/phantomjs",
28
+ CHROMEDRIVER_CDNURL: "https://cdn.npmmirror.com/binaries/chromedriver",
29
+ OPERADRIVER_CDNURL: "https://cdn.npmmirror.com/binaries/operadriver",
30
+ CYPRESS_DOWNLOAD_PATH_TEMPLATE: "https://cdn.npmmirror.com/binaries/cypress/${version}/${platform}-${arch}/cypress.zip",
31
+ ELECTRON_MIRROR: "https://cdn.npmmirror.com/binaries/electron/",
32
+ ELECTRON_BUILDER_BINARIES_MIRROR: "https://cdn.npmmirror.com/binaries/electron-builder-binaries/",
33
+ SASS_BINARY_SITE: "https://cdn.npmmirror.com/binaries/node-sass",
34
+ SWC_BINARY_SITE: "https://cdn.npmmirror.com/binaries/node-swc",
35
+ NWJS_URLBASE: "https://cdn.npmmirror.com/binaries/nwjs/v",
36
+ PUPPETEER_DOWNLOAD_HOST: "https://cdn.npmmirror.com/binaries/chrome-for-testing",
37
+ PUPPETEER_DOWNLOAD_BASE_URL: "https://cdn.npmmirror.com/binaries/chrome-for-testing",
38
+ PLAYWRIGHT_DOWNLOAD_HOST: "https://cdn.npmmirror.com/binaries/playwright",
39
+ SENTRYCLI_CDNURL: "https://cdn.npmmirror.com/binaries/sentry-cli",
40
+ SAUCECTL_INSTALL_BINARY_MIRROR: "https://cdn.npmmirror.com/binaries/saucectl",
41
+ RE2_DOWNLOAD_MIRROR: "https://cdn.npmmirror.com/binaries/node-re2",
42
+ RE2_DOWNLOAD_SKIP_PATH: "true",
43
+ PRISMA_ENGINES_MIRROR: "https://cdn.npmmirror.com/binaries/prisma",
44
+ npm_config_better_sqlite3_binary_host: "https://cdn.npmmirror.com/binaries/better-sqlite3",
45
+ npm_config_keytar_binary_host: "https://cdn.npmmirror.com/binaries/keytar",
46
+ npm_config_sharp_binary_host: "https://cdn.npmmirror.com/binaries/sharp",
47
+ npm_config_sharp_libvips_binary_host: "https://cdn.npmmirror.com/binaries/sharp-libvips",
48
+ npm_config_robotjs_binary_host: "https://cdn.npmmirror.com/binaries/robotjs"
49
+ };
50
+
51
+ // src/monorepo/mirror/utils.ts
52
+ function setMirror(obj) {
53
+ const platforms = ["linux", "windows", "osx"];
54
+ const prefix = "terminal.integrated.env";
55
+ if (typeof obj === "object" && obj) {
56
+ for (const platform of platforms) {
57
+ set(obj, [prefix, platform].join(".").replaceAll(".", "\\."), chinaMirrorsEnvs);
58
+ }
59
+ }
60
+ }
61
+
62
+ // src/monorepo/binaryMirror.ts
63
+ async function setVscodeBinaryMirror(cwd2) {
64
+ const targetJsonPath = path.resolve(cwd2, ".vscode/settings.json");
65
+ await fs.ensureFile(targetJsonPath);
66
+ const json = parse(await fs.readFile(targetJsonPath, "utf8"), void 0, false);
67
+ json && typeof json === "object" && setMirror(json);
68
+ await fs.writeFile(targetJsonPath, `${stringify(json, void 0, 2)}
69
+ `, "utf8");
70
+ }
71
+
72
+ // src/monorepo/clean.ts
73
+ import path2 from "pathe";
74
+ import { rimraf } from "rimraf";
75
+ var dirs = [
76
+ "packages/monorepo",
77
+ "packages/foo",
78
+ // 'apps/cli',
79
+ // 'apps/website',
80
+ "apps"
81
+ ];
82
+ async function cleanProjects(cwd2) {
83
+ await rimraf(dirs.map((x) => {
84
+ return path2.resolve(cwd2, x);
85
+ }));
86
+ }
87
+
88
+ // src/monorepo/context.ts
89
+ import path4 from "pathe";
90
+
91
+ // src/monorepo/utils.ts
92
+ import { findWorkspacePackages } from "@pnpm/workspace.find-packages";
93
+ import path3 from "pathe";
94
+ async function getWorkspacePackages(cwd2) {
95
+ const packages = await findWorkspacePackages(cwd2);
96
+ return (await Promise.allSettled(packages.map(async (project) => {
97
+ const pkgJsonPath = path3.resolve(project.rootDir, "package.json");
98
+ return {
99
+ ...project,
100
+ pkgJsonPath
101
+ };
102
+ }))).filter((x) => {
103
+ return x.status === "fulfilled";
104
+ }).map((x) => {
105
+ return x.value;
106
+ });
107
+ }
108
+
109
+ // src/monorepo/context.ts
110
+ import "@pnpm/types";
111
+ async function createContext(cwd2) {
112
+ const git = new GitClient();
113
+ const workspaceFilepath = path4.resolve(cwd2, "pnpm-workspace.yaml");
114
+ const projects = await getWorkspacePackages(cwd2);
115
+ return {
116
+ cwd: cwd2,
117
+ git,
118
+ workspaceFilepath,
119
+ projects
120
+ };
121
+ }
122
+
123
+ // src/monorepo/setPkgJson.ts
124
+ import fs2 from "fs-extra";
125
+ import path5 from "pathe";
126
+ import set2 from "set-value";
127
+ async function setPkgJson_default(ctx) {
128
+ const { git, projects, cwd: cwd2, workspaceFilepath } = ctx;
129
+ const gitUrl = await git.getGitUrl();
130
+ const gitUser = await git.getUser();
131
+ if (gitUrl && await fs2.exists(workspaceFilepath)) {
132
+ for (const project of projects) {
133
+ const pkgJson = project.manifest;
134
+ const directory = path5.relative(cwd2, project.rootDir);
135
+ set2(pkgJson, "bugs.url", `https://github.com/${gitUrl.full_name}/issues`);
136
+ const repository = {
137
+ type: "git",
138
+ url: `git+https://github.com/${gitUrl.full_name}.git`
139
+ };
140
+ if (directory) {
141
+ repository.directory = directory;
142
+ }
143
+ set2(pkgJson, "repository", repository);
144
+ if (gitUser) {
145
+ set2(pkgJson, "author", `${gitUser.name} <${gitUser.email}>`);
146
+ }
147
+ await fs2.writeJSON(project.pkgJsonPath, pkgJson, {
148
+ spaces: 2
149
+ });
150
+ }
151
+ }
152
+ }
153
+
154
+ // src/monorepo/setReadme.ts
155
+ import fs3 from "fs-extra";
156
+ import path6 from "pathe";
157
+ async function getRows(ctx) {
158
+ const { projects, git, cwd: cwd2 } = ctx;
159
+ const gitUrl = await git.getGitUrl();
160
+ const gitUser = await git.getUser();
161
+ const rows = [];
162
+ if (gitUrl) {
163
+ rows.push(`# ${gitUrl.name}
164
+ `);
165
+ }
166
+ rows.push("## Projects\n");
167
+ for (const project of projects) {
168
+ const p = path6.relative(cwd2, project.rootDirRealPath);
169
+ p && rows.push(`- [${project.manifest.name}](${p}) ${project.manifest.description ? `- ${project.manifest.description}` : ""}`);
170
+ }
171
+ if (gitUrl) {
172
+ rows.push("\n## Contributing\n");
173
+ rows.push("Contributions Welcome! You can contribute in the following ways.");
174
+ rows.push("");
175
+ rows.push("- Create an Issue - Propose a new feature. Report a bug.");
176
+ rows.push("- Pull Request - Fix a bug and typo. Refactor the code.");
177
+ rows.push("- Create third-party middleware - Instruct below.");
178
+ rows.push("- Share - Share your thoughts on the Blog, X, and others.");
179
+ rows.push(`- Make your application - Please try to use ${gitUrl.name}.`);
180
+ rows.push("");
181
+ rows.push("For more details, see [CONTRIBUTING.md](CONTRIBUTING.md).");
182
+ rows.push("\n## Contributors\n");
183
+ rows.push(`Thanks to [all contributors](https://github.com/${gitUrl.full_name}/graphs/contributors)!`);
184
+ }
185
+ rows.push("\n## Authors\n");
186
+ rows.push(`${gitUser.name} <${gitUser.email}>`);
187
+ rows.push("\n## License\n");
188
+ rows.push("Distributed under the MIT License. See [LICENSE](LICENSE) for more information.");
189
+ return rows;
190
+ }
191
+ async function setReadme_default(ctx) {
192
+ const rows = await getRows(ctx);
193
+ await fs3.writeFile(path6.resolve(ctx.cwd, "README.md"), `${rows.join("\n")}
194
+ `);
195
+ }
196
+
197
+ // src/monorepo/init.ts
198
+ async function init(cwd2) {
199
+ const ctx = await createContext(cwd2);
200
+ await setPkgJson_default(ctx);
201
+ await setReadme_default(ctx);
202
+ }
203
+
204
+ // src/monorepo/sync.ts
205
+ import { execa } from "execa";
206
+ async function syncNpmMirror(cwd2) {
207
+ const packages = await getWorkspacePackages(cwd2);
208
+ for (const project of packages) {
209
+ if (project.manifest.name) {
210
+ await execa({
211
+ stdout: ["pipe", "inherit"]
212
+ })`cnpm sync ${project.manifest.name}`;
213
+ }
214
+ }
215
+ }
17
216
 
18
217
  // src/program.ts
218
+ var cwd = process.cwd();
19
219
  program.name(name).version(version);
20
220
  program.option("-i,--interactive").option("--raw", "raw mode").option("--outDir <dir>", "Output directory").action(async (opts) => {
21
221
  await main(opts);
22
222
  logger.success("upgrade @icebreakers/monorepo ok!");
23
223
  });
224
+ program.command("init").action(async () => {
225
+ await init(cwd);
226
+ logger.success("init finished!");
227
+ });
228
+ program.command("sync").action(async () => {
229
+ await syncNpmMirror(cwd);
230
+ logger.success("sync npm mirror finished!");
231
+ });
232
+ program.command("clean").action(async () => {
233
+ await cleanProjects(cwd);
234
+ logger.success("clean projects finished!");
235
+ });
236
+ program.command("mirror").action(async () => {
237
+ await setVscodeBinaryMirror(cwd);
238
+ logger.success("set vscode binary mirror finished!");
239
+ });
24
240
  var program_default = program;
25
241
 
26
242
  // src/cli.ts