@icebreakers/monorepo 0.4.6 → 0.4.7

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.
@@ -26,10 +26,10 @@
26
26
  "preinstall": "npx only-allow pnpm",
27
27
  "prepare": "husky",
28
28
  "commit": "commit",
29
- "script:init": "tsx scripts/monorepo/init.ts",
30
- "script:sync": "tsx scripts/monorepo/sync.ts",
31
- "script:clean": "tsx scripts/monorepo/clean.ts",
32
- "script:mirror": "tsx scripts/monorepo/binaryMirror.ts"
29
+ "script:init": "monorepo init",
30
+ "script:sync": "monorepo sync",
31
+ "script:clean": "monorepo clean",
32
+ "script:mirror": "monorepo mirror"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@changesets/changelog-github": "^0.5.0",
@@ -39,29 +39,23 @@
39
39
  "@commitlint/prompt-cli": "^19.5.0",
40
40
  "@commitlint/types": "^19.5.0",
41
41
  "@icebreakers/eslint-config": "^0.5.1",
42
+ "@icebreakers/monorepo": "workspace:*",
42
43
  "@icebreakers/stylelint-config": "^0.0.3",
43
- "@pnpm/workspace.find-packages": "^4.0.10",
44
44
  "@types/fs-extra": "^11.0.4",
45
- "@types/get-value": "^3.0.5",
46
- "@types/git-url-parse": "^9.0.3",
47
45
  "@types/klaw": "^3.0.6",
48
46
  "@types/lint-staged": "^13.3.0",
49
47
  "@types/lodash": "^4.17.7",
50
48
  "@types/lodash-es": "^4.17.12",
51
49
  "@types/micromatch": "^4.0.9",
52
50
  "@types/node": "^22.5.5",
53
- "@types/set-value": "^4.0.3",
54
51
  "@vitest/coverage-v8": "~2.0.5",
55
52
  "ci-info": "^4.0.0",
56
- "comment-json": "^4.2.5",
57
53
  "cross-env": "^7.0.3",
58
54
  "defu": "^6.1.4",
59
55
  "eslint": "^9.10.0",
60
56
  "execa": "^9.4.0",
61
57
  "fast-glob": "^3.3.2",
62
58
  "fs-extra": "^11.2.0",
63
- "get-value": "^3.0.1",
64
- "git-url-parse": "^15.0.0",
65
59
  "husky": "^9.1.6",
66
60
  "klaw": "^4.1.0",
67
61
  "lint-staged": "^15.2.10",
@@ -72,15 +66,12 @@
72
66
  "pathe": "^1.1.2",
73
67
  "pkg-types": "^1.2.0",
74
68
  "rimraf": "^6.0.1",
75
- "set-value": "^4.1.0",
76
- "simple-git": "^3.26.0",
77
69
  "tslib": "^2.7.0",
78
70
  "tsup": "^8.3.0",
79
71
  "tsx": "^4.19.1",
80
72
  "turbo": "^2.1.2",
81
73
  "typescript": "^5.6.2",
82
74
  "unbuild": "^2.0.0",
83
- "vite-tsconfig-paths": "^5.0.1",
84
75
  "vitest": "~2.0.5",
85
76
  "yaml": "^2.5.1"
86
77
  },
@@ -1,3 +1,4 @@
1
1
  packages:
2
2
  - 'apps/*'
3
3
  - 'packages/*'
4
+ - '!**/test/**'
@@ -0,0 +1,315 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x + '" is not supported');
12
+ });
13
+ var __esm = (fn, res) => function __init() {
14
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
15
+ };
16
+ var __commonJS = (cb, mod) => function __require2() {
17
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
28
+ // If the importer is in node compatibility mode or this is not an ESM
29
+ // file that has been converted to a CommonJS file using a Babel-
30
+ // compatible transform (i.e. "__esModule" has not been set), then set
31
+ // "default" to the CommonJS "module.exports" for node compatibility.
32
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
33
+ mod
34
+ ));
35
+
36
+ // ../../node_modules/.pnpm/tsup@8.3.0_jiti@1.21.6_postcss@8.4.42_tsx@4.19.1_typescript@5.6.2_yaml@2.5.1/node_modules/tsup/assets/esm_shims.js
37
+ var init_esm_shims = __esm({
38
+ "../../node_modules/.pnpm/tsup@8.3.0_jiti@1.21.6_postcss@8.4.42_tsx@4.19.1_typescript@5.6.2_yaml@2.5.1/node_modules/tsup/assets/esm_shims.js"() {
39
+ "use strict";
40
+ }
41
+ });
42
+
43
+ // src/index.ts
44
+ init_esm_shims();
45
+
46
+ // src/lib.ts
47
+ init_esm_shims();
48
+ import process from "node:process";
49
+ import { fileURLToPath } from "node:url";
50
+ import checkbox from "@inquirer/checkbox";
51
+ import confirm from "@inquirer/confirm";
52
+ import fs from "fs-extra";
53
+ import get2 from "get-value";
54
+ import klaw from "klaw";
55
+ import PQueue from "p-queue";
56
+ import path from "pathe";
57
+ import pc from "picocolors";
58
+ import set from "set-value";
59
+
60
+ // package.json
61
+ var name = "@icebreakers/monorepo";
62
+ var version = "0.4.7";
63
+
64
+ // src/logger.ts
65
+ init_esm_shims();
66
+ import { createConsola } from "consola";
67
+ var logger = createConsola();
68
+
69
+ // src/md5.ts
70
+ init_esm_shims();
71
+ import crypto from "node:crypto";
72
+ function getFileHash(data) {
73
+ const hashSum = crypto.createHash("md5");
74
+ hashSum.update(data);
75
+ return hashSum.digest("hex");
76
+ }
77
+ function isFileChanged(src, dest) {
78
+ try {
79
+ const currentHash = getFileHash(src);
80
+ const previousHash = getFileHash(dest);
81
+ return currentHash !== previousHash;
82
+ } catch (err) {
83
+ console.error("Error calculating file hash:", err);
84
+ return false;
85
+ }
86
+ }
87
+
88
+ // src/monorepo/git.ts
89
+ init_esm_shims();
90
+ import get from "get-value";
91
+ import gitUrlParse from "git-url-parse";
92
+ import { simpleGit } from "simple-git";
93
+ var GitClient = class {
94
+ client;
95
+ #config;
96
+ constructor(options = {}) {
97
+ this.client = simpleGit(options);
98
+ }
99
+ listConfig() {
100
+ return this.client.listConfig();
101
+ }
102
+ async init() {
103
+ const listConfig = await this.listConfig();
104
+ this.#config = listConfig.all;
105
+ return this.#config;
106
+ }
107
+ async getConfig() {
108
+ if (this.#config) {
109
+ return this.#config;
110
+ } else {
111
+ return await this.init();
112
+ }
113
+ }
114
+ async getGitUrl() {
115
+ const config = await this.getConfig();
116
+ const x = get(config, "remote.origin.url");
117
+ if (x) {
118
+ return gitUrlParse(x);
119
+ }
120
+ }
121
+ async getRepoName() {
122
+ const url = await this.getGitUrl();
123
+ if (url) {
124
+ return `${url.owner}/${url.name}`;
125
+ }
126
+ }
127
+ async getUser() {
128
+ const config = await this.getConfig();
129
+ const name2 = get(config, "user.name");
130
+ const email = get(config, "user.email");
131
+ return {
132
+ name: name2,
133
+ email
134
+ };
135
+ }
136
+ };
137
+
138
+ // src/scripts.ts
139
+ init_esm_shims();
140
+ var scripts = {
141
+ "script:init": "monorepo init",
142
+ "script:sync": "monorepo sync",
143
+ "script:clean": "monorepo clean",
144
+ "script:mirror": "monorepo mirror"
145
+ };
146
+ var scriptsEntries = Object.entries(scripts);
147
+
148
+ // src/targets.ts
149
+ init_esm_shims();
150
+ function getTargets(raw) {
151
+ const list = [
152
+ ".changeset",
153
+ ".husky",
154
+ ".vscode",
155
+ ".editorconfig",
156
+ ".gitattributes",
157
+ ".gitignore",
158
+ ".npmrc",
159
+ "commitlint.config.ts",
160
+ "eslint.config.js",
161
+ "lint-staged.config.js",
162
+ "stylelint.config.js",
163
+ "package.json",
164
+ // pnpm
165
+ "pnpm-workspace.yaml",
166
+ // base tsconfig
167
+ "tsconfig.json",
168
+ // turbo
169
+ "turbo.json",
170
+ // vitest
171
+ "vitest.workspace.ts",
172
+ // #region docker
173
+ "Dockerfile",
174
+ ".dockerignore"
175
+ // #endregion
176
+ ];
177
+ if (!raw) {
178
+ list.push(".github", "LICENSE", "renovate.json", "SECURITY.md", "CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "netlify.toml");
179
+ }
180
+ return list;
181
+ }
182
+
183
+ // src/utils.ts
184
+ init_esm_shims();
185
+ function escapeStringRegexp(str) {
186
+ return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
187
+ }
188
+ function isMatch(str, arr) {
189
+ for (const reg of arr) {
190
+ if (reg.test(str)) {
191
+ return true;
192
+ }
193
+ }
194
+ return false;
195
+ }
196
+
197
+ // src/lib.ts
198
+ var queue = new PQueue({ concurrency: 1 });
199
+ var __filename2 = fileURLToPath(import.meta.url);
200
+ var __dirname2 = path.dirname(__filename2);
201
+ var assetsDir = path.join(__dirname2, "../assets");
202
+ var cwd = process.cwd();
203
+ function setPkgJson(sourcePkgJson, targetPkgJson) {
204
+ const packageManager = get2(sourcePkgJson, "packageManager", { default: "" });
205
+ const deps = get2(sourcePkgJson, "dependencies", { default: {} });
206
+ const devDeps = get2(sourcePkgJson, "devDependencies", { default: {} });
207
+ set(targetPkgJson, "packageManager", packageManager);
208
+ Object.entries(deps).forEach((x) => {
209
+ set(targetPkgJson, `dependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
210
+ });
211
+ Object.entries(devDeps).forEach((x) => {
212
+ if (x[0] === "@icebreakers/monorepo") {
213
+ set(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, `^${version}`, { preservePaths: false });
214
+ } else {
215
+ set(targetPkgJson, `devDependencies.${x[0].replaceAll(".", "\\.")}`, x[1], { preservePaths: false });
216
+ }
217
+ });
218
+ for (const [k, v] of scriptsEntries) {
219
+ set(targetPkgJson, `scripts.${k}`, v);
220
+ }
221
+ }
222
+ function confirmOverwrite(filename) {
223
+ return confirm({ message: `${pc.greenBright(filename)} \u6587\u4EF6\u5185\u5BB9\u53D1\u751F\u6539\u53D8,\u662F\u5426\u8986\u76D6?`, default: false });
224
+ }
225
+ async function main(opts) {
226
+ const { outDir = "", raw, interactive } = opts;
227
+ const absOutDir = path.isAbsolute(outDir) ? outDir : path.join(cwd, outDir);
228
+ const gitClient = new GitClient({
229
+ baseDir: cwd
230
+ });
231
+ const repoName = await gitClient.getRepoName();
232
+ let targets = getTargets(raw);
233
+ if (interactive) {
234
+ targets = await checkbox({
235
+ message: "\u9009\u62E9\u4F60\u9700\u8981\u7684\u6587\u4EF6",
236
+ choices: targets.map((x) => {
237
+ return {
238
+ value: x,
239
+ checked: true
240
+ };
241
+ })
242
+ });
243
+ }
244
+ const regexpArr = targets.map((x) => {
245
+ return new RegExp(`^${escapeStringRegexp(x)}`);
246
+ });
247
+ for await (const file of klaw(assetsDir, {
248
+ filter(p) {
249
+ const str = path.relative(assetsDir, p);
250
+ return isMatch(str, regexpArr);
251
+ }
252
+ })) {
253
+ await queue.add(async () => {
254
+ if (file.stats.isFile()) {
255
+ const relPath = path.relative(assetsDir, file.path);
256
+ const targetPath = path.resolve(absOutDir, relPath);
257
+ const targetIsExisted = await fs.exists(targetPath);
258
+ async function overwriteOrCopy(target) {
259
+ let isOverwrite = true;
260
+ if (targetIsExisted) {
261
+ const src = await fs.readFile(file.path);
262
+ const dest = target ?? await fs.readFile(targetPath);
263
+ if (await isFileChanged(src, dest)) {
264
+ isOverwrite = await confirmOverwrite(relPath);
265
+ }
266
+ }
267
+ return isOverwrite;
268
+ }
269
+ if (relPath === "package.json") {
270
+ const sourcePath = file.path;
271
+ if (targetIsExisted) {
272
+ const sourcePkgJson = await fs.readJson(sourcePath);
273
+ const targetPkgJson = await fs.readJson(targetPath);
274
+ setPkgJson(sourcePkgJson, targetPkgJson);
275
+ const data = JSON.stringify(targetPkgJson, void 0, 2);
276
+ await fs.writeFile(targetPath, `${data}
277
+ `, "utf8");
278
+ logger.success(targetPath);
279
+ }
280
+ } else if (relPath === ".changeset/config.json" && repoName) {
281
+ const changesetJson = await fs.readJson(file.path);
282
+ set(changesetJson, "changelog.1.repo", repoName);
283
+ const data = JSON.stringify(changesetJson, void 0, 2);
284
+ if (await overwriteOrCopy(data)) {
285
+ await fs.ensureDir(path.dirname(targetPath));
286
+ await fs.writeFile(targetPath, `${data}
287
+ `, "utf8");
288
+ logger.success(targetPath);
289
+ }
290
+ } else {
291
+ if (await overwriteOrCopy()) {
292
+ await fs.copy(
293
+ file.path,
294
+ targetPath
295
+ );
296
+ logger.success(targetPath);
297
+ }
298
+ }
299
+ }
300
+ });
301
+ }
302
+ }
303
+
304
+ export {
305
+ __require,
306
+ __commonJS,
307
+ __toESM,
308
+ name,
309
+ version,
310
+ init_esm_shims,
311
+ logger,
312
+ GitClient,
313
+ setPkgJson,
314
+ main
315
+ };