jiek 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. package/bin/jiek.js +8 -1
  2. package/dist/base.esm.d.ts +55 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.esm.d.ts +2 -0
  5. package/dist/cli.esm.js +10 -0
  6. package/dist/cli.esm.js.map +1 -0
  7. package/dist/cli.esm.min.js +2 -0
  8. package/dist/cli.esm.min.js.map +1 -0
  9. package/dist/cli.iife.js +658 -0
  10. package/dist/cli.iife.js.map +1 -0
  11. package/dist/cli.iife.min.js +2 -0
  12. package/dist/cli.iife.min.js.map +1 -0
  13. package/dist/cli.umd.js +661 -0
  14. package/dist/cli.umd.js.map +1 -0
  15. package/dist/cli.umd.min.js +2 -0
  16. package/dist/cli.umd.min.js.map +1 -0
  17. package/dist/commands/build.esm.js +3 -4
  18. package/dist/commands/build.esm.js.map +1 -1
  19. package/dist/commands/build.esm.min.js +1 -1
  20. package/dist/commands/build.esm.min.js.map +1 -1
  21. package/dist/index.d.ts +56 -1
  22. package/dist/index.esm.d.ts +5 -1
  23. package/dist/index.esm.js +2 -8
  24. package/dist/index.esm.js.map +1 -1
  25. package/dist/index.esm.min.js +1 -1
  26. package/dist/index.esm.min.js.map +1 -1
  27. package/dist/index.iife.js +6 -653
  28. package/dist/index.iife.js.map +1 -1
  29. package/dist/index.iife.min.js +1 -1
  30. package/dist/index.iife.min.js.map +1 -1
  31. package/dist/index.umd.js +6 -655
  32. package/dist/index.umd.js.map +1 -1
  33. package/dist/index.umd.min.js +1 -1
  34. package/dist/index.umd.min.js.map +1 -1
  35. package/dist/utils/loadConfig.esm.js +1 -20
  36. package/dist/utils/loadConfig.esm.js.map +1 -1
  37. package/dist/utils/loadConfig.esm.min.js +1 -1
  38. package/dist/utils/loadConfig.esm.min.js.map +1 -1
  39. package/dist/utils/tsRegister.esm.js +24 -0
  40. package/dist/utils/tsRegister.esm.js.map +1 -0
  41. package/dist/utils/tsRegister.esm.min.js +2 -0
  42. package/dist/utils/tsRegister.esm.min.js.map +1 -0
  43. package/package.json +8 -3
  44. package/bin/jiek-dev.js +0 -4
@@ -0,0 +1,658 @@
1
+ (function (fs, path, filterWorkspacePackages, commander, jsYaml, getWorkspaceDir, childProcess, pkger, detectIndent, inquirer, jsoncParser, micromatch, bumper, childProcess$1) {
2
+ 'use strict';
3
+
4
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
5
+
6
+ function _interopNamespace(e) {
7
+ if (e && e.__esModule) return e;
8
+ var n = Object.create(null);
9
+ if (e) {
10
+ Object.keys(e).forEach(function (k) {
11
+ if (k !== 'default') {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: function () { return e[k]; }
16
+ });
17
+ }
18
+ });
19
+ }
20
+ n.default = e;
21
+ return Object.freeze(n);
22
+ }
23
+
24
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
25
+ var path__default = /*#__PURE__*/_interopDefault(path);
26
+ var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
27
+ var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
28
+ var inquirer__default = /*#__PURE__*/_interopDefault(inquirer);
29
+ var childProcess__namespace$1 = /*#__PURE__*/_interopNamespace(childProcess$1);
30
+
31
+ let root;
32
+ function getRoot() {
33
+ if (root)
34
+ return root;
35
+ const rootOption = commander.program.getOptionValue("root");
36
+ root = rootOption ? path__default.default.isAbsolute(rootOption) ? rootOption : path__default.default.resolve(process.cwd(), rootOption) : process.cwd();
37
+ return root;
38
+ }
39
+
40
+ let wd;
41
+ let notWorkspace = false;
42
+ function getWD() {
43
+ if (wd)
44
+ return { wd, notWorkspace };
45
+ const root = getRoot();
46
+ try {
47
+ wd = getWorkspaceDir.getWorkspaceDir(root, type);
48
+ } catch (e) {
49
+ if ("message" in e && e.message === "workspace root not found") {
50
+ wd = root;
51
+ notWorkspace = true;
52
+ } else {
53
+ throw e;
54
+ }
55
+ }
56
+ return { wd, notWorkspace };
57
+ }
58
+
59
+ let type = "";
60
+ try {
61
+ require.resolve("@pnpm/filter-workspace-packages");
62
+ type = "pnpm";
63
+ } catch {
64
+ }
65
+ if (type !== "") {
66
+ commander.program.option("-f, --filter <filter>", "filter packages");
67
+ }
68
+ async function getSelectedProjectsGraph() {
69
+ let filter = commander.program.getOptionValue("filter");
70
+ const root = getRoot();
71
+ const { wd, notWorkspace } = getWD();
72
+ if (!notWorkspace && type === "pnpm") {
73
+ const pnpmWorkspaceFilePath = path__default.default.resolve(wd, "pnpm-workspace.yaml");
74
+ const pnpmWorkspaceFileContent = fs__default.default.readFileSync(pnpmWorkspaceFilePath, "utf-8");
75
+ const pnpmWorkspace = jsYaml.load(pnpmWorkspaceFileContent);
76
+ if (root === wd && !filter) {
77
+ throw new Error("root path is workspace root, please provide a filter");
78
+ }
79
+ if (root !== wd && !filter) {
80
+ const packageJSONIsExist = fs__default.default.existsSync(path__default.default.resolve(root, "package.json"));
81
+ if (!packageJSONIsExist) {
82
+ throw new Error("root path is not workspace root, please provide a filter");
83
+ }
84
+ const packageJSON = JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(root, "package.json"), "utf-8"));
85
+ if (!packageJSON.name) {
86
+ throw new Error("root path is not workspace root, please provide a filter");
87
+ }
88
+ filter = packageJSON.name;
89
+ }
90
+ const { selectedProjectsGraph } = await filterWorkspacePackages.filterPackagesFromDir(wd, [{
91
+ filter: filter ?? "",
92
+ followProdDepsOnly: true
93
+ }], {
94
+ prefix: root,
95
+ workspaceDir: wd,
96
+ patterns: pnpmWorkspace.packages
97
+ });
98
+ return {
99
+ wd,
100
+ root,
101
+ value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
102
+ acc[key] = value.package.manifest;
103
+ return acc;
104
+ }, {})
105
+ };
106
+ }
107
+ return {
108
+ wd,
109
+ root,
110
+ value: {
111
+ [wd]: JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(wd, "package.json"), "utf-8"))
112
+ }
113
+ };
114
+ }
115
+
116
+ let resolve;
117
+ function actionDone() {
118
+ resolve();
119
+ }
120
+ function actionRestore() {
121
+ new Promise((r) => resolve = r);
122
+ }
123
+
124
+ function commondir(files, cwd = process.cwd()) {
125
+ const resolvedFiles = files.map((file) => {
126
+ if (path__default.default.isAbsolute(file))
127
+ return file;
128
+ return path__default.default.resolve(cwd, file);
129
+ });
130
+ const sep = "/";
131
+ const [first = ""] = resolvedFiles;
132
+ const parts = first.split(sep);
133
+ let common = "";
134
+ for (let i = 0; i < parts.length; i++) {
135
+ const segment = parts[i];
136
+ if (resolvedFiles.every((file) => file.startsWith(common + segment))) {
137
+ common += segment + sep;
138
+ } else {
139
+ break;
140
+ }
141
+ }
142
+ return common;
143
+ }
144
+
145
+ function mergePackageJson(manifest, cwd) {
146
+ const {
147
+ jiek: { cwd: _, ...jiek } = {}
148
+ } = manifest;
149
+ let { exports } = manifest;
150
+ let includeIndex = false;
151
+ if (typeof exports === "string") {
152
+ includeIndex = true;
153
+ exports = { ".": exports };
154
+ }
155
+ if (exports === void 0) {
156
+ exports = { ".": "./src/index.ts" };
157
+ }
158
+ if (typeof exports === "object") {
159
+ if (Array.isArray(exports) && exports.length > 0) {
160
+ includeIndex = true;
161
+ } else {
162
+ includeIndex = !!exports["."];
163
+ }
164
+ }
165
+ const inputs = Array.isArray(exports) ? exports : Object.entries(exports).reduce((acc, [key, value]) => {
166
+ if (typeof value === "string")
167
+ return key === "." ? [value, ...acc] : acc.concat(value);
168
+ if (Array.isArray(value))
169
+ return acc.concat(value);
170
+ throw new TypeError(`Unexpected value type for key "${key}" in exports, expected string, got ${typeof value}`);
171
+ }, []);
172
+ if (inputs.length === 0)
173
+ throw new Error("No inputs found");
174
+ const absoluteInputs = inputs.map(
175
+ (input) => path__default.default.isAbsolute(input) ? input : path__default.default.resolve(cwd, input)
176
+ );
177
+ let cDir = path__default.default.dirname(absoluteInputs[0]);
178
+ if (absoluteInputs.length > 1) {
179
+ cDir = commondir(absoluteInputs, cwd);
180
+ }
181
+ const resolvedInputs = absoluteInputs.map((input) => {
182
+ return path__default.default.relative(cDir, input);
183
+ });
184
+ return {
185
+ ...manifest,
186
+ ...pkger.pkger({
187
+ cwd,
188
+ noIndex: !includeIndex,
189
+ source: path__default.default.relative(cwd, cDir),
190
+ inputs: resolvedInputs,
191
+ ...jiek
192
+ })
193
+ };
194
+ }
195
+
196
+ function packageIsExist(name) {
197
+ try {
198
+ require.resolve(name);
199
+ return true;
200
+ } catch (e) {
201
+ return false;
202
+ }
203
+ }
204
+ let tsRegisterName;
205
+ const registers = [
206
+ process.env.JIEK_TS_REGISTER,
207
+ "esbuild-register",
208
+ "@swc-node/register",
209
+ "ts-node/register"
210
+ ].filter(Boolean);
211
+ for (const register of registers) {
212
+ if (packageIsExist(register)) {
213
+ tsRegisterName = register;
214
+ break;
215
+ }
216
+ }
217
+
218
+ const FILE_TEMPLATE = (manifest) => `
219
+ const pkg = ${JSON.stringify(manifest, null, 2)}
220
+ const { jiek = {} } = pkg
221
+ const templateArg = jiek.templateArgFilePath
222
+ ? require.resolve(jiek.templateArgFilePath)
223
+ : {
224
+ styled: jiek.styled
225
+ }
226
+ module.exports = require('jiek/rollup').template(templateArg, pkg)
227
+ `.trimStart();
228
+ commander.program.command("build").action(async () => {
229
+ actionRestore();
230
+ const {
231
+ wd,
232
+ value = {}
233
+ } = await getSelectedProjectsGraph() ?? {};
234
+ if (Object.keys(value).length === 0) {
235
+ throw new Error("no package found");
236
+ }
237
+ const jiekTempDir = (...paths) => path__default.default.resolve(wd, "node_modules/.jiek", ...paths);
238
+ if (!fs__default.default.existsSync(jiekTempDir()))
239
+ fs__default.default.mkdirSync(jiekTempDir());
240
+ const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
241
+ let i = 0;
242
+ for (const [dir, manifest] of Object.entries(value)) {
243
+ const newManifest = mergePackageJson(manifest, dir);
244
+ const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
245
+ const configFile = jiekTempDir(
246
+ `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
247
+ );
248
+ fs__default.default.writeFileSync(configFile, FILE_TEMPLATE(newManifest));
249
+ let prefix = "";
250
+ if (tsRegisterName) {
251
+ prefix = `node -r ${tsRegisterName} `;
252
+ }
253
+ childProcess__namespace.execSync(`${prefix}${rollupBinaryPath} -c ${configFile}`, {
254
+ cwd: dir,
255
+ stdio: "inherit"
256
+ });
257
+ }
258
+ actionDone();
259
+ });
260
+
261
+ let configName = "jiek.config";
262
+ function getConfigPath(root) {
263
+ const isSupportTsLoader = !!tsRegisterName;
264
+ function configWithExtIsExist(ext) {
265
+ const filenames = [
266
+ path__default.default.resolve(root, `${configName}.${ext}`),
267
+ path__default.default.resolve(root, `.${configName}.${ext}`)
268
+ ];
269
+ for (const filename of filenames) {
270
+ if (fs__default.default.existsSync(filename) && fs__default.default.lstatSync(filename).isFile()) {
271
+ return filename;
272
+ }
273
+ }
274
+ return;
275
+ }
276
+ configName = configWithExtIsExist("js") ?? configName;
277
+ configName = configWithExtIsExist("json") ?? configName;
278
+ configName = configWithExtIsExist("yaml") ?? configName;
279
+ if (isSupportTsLoader) {
280
+ configName = configWithExtIsExist("ts") ?? configName;
281
+ }
282
+ return path__default.default.resolve(root, configName);
283
+ }
284
+ function loadConfig() {
285
+ const { wd: root, notWorkspace } = getWD();
286
+ if (notWorkspace)
287
+ throw new Error("not in workspace");
288
+ let configPath = commander.program.getOptionValue("configPath");
289
+ if (!configPath) {
290
+ configPath = getConfigPath(root);
291
+ } else {
292
+ if (!fs__default.default.existsSync(configPath))
293
+ throw new Error(`config file not found: ${configPath}`);
294
+ if (!path__default.default.isAbsolute(configPath))
295
+ configPath = path__default.default.resolve(root, configPath);
296
+ }
297
+ const ext = path__default.default.extname(configPath);
298
+ let module;
299
+ switch (ext) {
300
+ case ".js":
301
+ module = require(configPath);
302
+ break;
303
+ case ".json":
304
+ return require(configPath);
305
+ case ".yaml":
306
+ return jsYaml.load(fs__default.default.readFileSync(configPath, "utf-8"));
307
+ case ".ts":
308
+ if (tsRegisterName) {
309
+ require(tsRegisterName);
310
+ module = require(configPath);
311
+ break;
312
+ }
313
+ throw new Error(
314
+ "ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
315
+ );
316
+ case ".config":
317
+ module = {};
318
+ break;
319
+ default:
320
+ throw new Error(`unsupported config file type: ${ext}`);
321
+ }
322
+ if (!module)
323
+ throw new Error("config file is empty");
324
+ return module.default ?? module;
325
+ }
326
+
327
+ const PACKAGE_JSON_TEMPLATE = `{
328
+ "name": "",
329
+ "version": "0.0.1",
330
+ "description": "",
331
+ "license": "",
332
+ "author": "",
333
+ "files": ["dist"],
334
+ "exports": {
335
+ ".": "./src/index.ts"
336
+ },
337
+ "scripts": {
338
+ },
339
+ "homepage": "",
340
+ "repository": "",
341
+ "bugs": ""
342
+ }`.trimStart();
343
+ const README_TEMPLATE = `# $name
344
+
345
+ ## Installation
346
+
347
+ \`\`\`bash
348
+ npm install $name
349
+ # or
350
+ pnpm install $name
351
+ # or
352
+ yarn add $name
353
+ \`\`\`
354
+
355
+ ## Usage
356
+
357
+
358
+ ## License
359
+
360
+ $license
361
+ `.trimStart();
362
+ function getTemplateStr(wd, template) {
363
+ let templateString = template ?? PACKAGE_JSON_TEMPLATE;
364
+ let isTemplateFile = false;
365
+ try {
366
+ if (template)
367
+ JSON.parse(template);
368
+ } catch (e) {
369
+ isTemplateFile = true;
370
+ }
371
+ if (isTemplateFile) {
372
+ const templatePath = path__default.default.resolve(wd, template);
373
+ templateString = fs__default.default.readFileSync(templatePath, "utf-8");
374
+ }
375
+ return templateString;
376
+ }
377
+ const wdCache = /* @__PURE__ */ new Map();
378
+ function getWDPackageJSONFiled(wd, field) {
379
+ if (wdCache.has(wd)) {
380
+ return wdCache.get(wd)[field];
381
+ }
382
+ const packageJSONPath = path__default.default.resolve(wd, "package.json");
383
+ const packageJSON = JSON.parse(fs__default.default.readFileSync(packageJSONPath, "utf-8"));
384
+ wdCache.set(wd, packageJSON);
385
+ return packageJSON[field];
386
+ }
387
+ async function getName(named, name, {
388
+ wd,
389
+ cwd,
390
+ workspaceName
391
+ }) {
392
+ const relativePath = cwd.replace(`${wd}/`, "");
393
+ let basename = path__default.default.basename(cwd);
394
+ if (typeof named === "function") {
395
+ return named(name, {
396
+ full: wd,
397
+ relative: cwd
398
+ });
399
+ }
400
+ let isParentMatched = false;
401
+ let matchedKey;
402
+ let matchedRule;
403
+ if (typeof named === "object") {
404
+ const isWD = cwd === wd;
405
+ if (isWD) {
406
+ const { rule } = await inquirer__default.default.prompt({
407
+ type: "list",
408
+ name: "rule",
409
+ message: "choose a rule",
410
+ default: "default",
411
+ choices: ["default"].concat(Object.keys(named))
412
+ });
413
+ if (rule !== "default") {
414
+ matchedKey = rule;
415
+ matchedRule = named[rule];
416
+ }
417
+ } else
418
+ for (const [key, value] of Object.entries(named)) {
419
+ if (micromatch.isMatch(relativePath, key)) {
420
+ matchedKey = key;
421
+ matchedRule = value;
422
+ break;
423
+ }
424
+ if (micromatch.isMatch(`${relativePath}/jiek_ignore_dont_use_same_file_name`, key)) {
425
+ isParentMatched = true;
426
+ matchedKey = key;
427
+ matchedRule = value;
428
+ break;
429
+ }
430
+ }
431
+ }
432
+ if (!matchedRule) {
433
+ matchedKey = "packages/*";
434
+ matchedRule = `@${workspaceName}/$basename`;
435
+ }
436
+ if (!matchedRule)
437
+ throw new Error("no matched rule");
438
+ if (!name && isParentMatched) {
439
+ basename = await inquirer__default.default.prompt({
440
+ type: "input",
441
+ name: "name",
442
+ message: `the matched rule is \`${String(matchedRule)}\`, please input the basename
443
+ `
444
+ }).then(({ name: name2 }) => name2);
445
+ }
446
+ if (typeof matchedRule === "function") {
447
+ return matchedRule(name, {
448
+ full: wd,
449
+ relative: cwd,
450
+ basename
451
+ });
452
+ }
453
+ if (typeof matchedRule === "string") {
454
+ const dirName = name ?? basename;
455
+ return [
456
+ matchedRule.replace(/\$basename/g, dirName),
457
+ matchedKey?.replace(/\/\*$/g, `/${dirName}`)
458
+ ];
459
+ }
460
+ throw new Error("no matched rule");
461
+ }
462
+ commander.program.command("init [name]").option("-t, --template <template>", "the package.json template file path or file content").action(async () => {
463
+ const [, name] = commander.program.args;
464
+ const cwd = process.cwd();
465
+ const { init = {} } = loadConfig() ?? {};
466
+ const { wd } = getWD();
467
+ const workspaceName = path__default.default.basename(wd);
468
+ const {
469
+ named,
470
+ template,
471
+ bug = {},
472
+ readme: _readme = README_TEMPLATE,
473
+ readmeTemplate
474
+ } = init;
475
+ const resolvedBug = {
476
+ template: "bug_report.yml",
477
+ labels: ["bug"],
478
+ ...bug
479
+ };
480
+ let readme = _readme;
481
+ if (readmeTemplate) {
482
+ const readmeTemplatePath = path__default.default.resolve(wd, readmeTemplate);
483
+ readme = fs__default.default.readFileSync(readmeTemplatePath, "utf-8");
484
+ }
485
+ const templateString = getTemplateStr(wd, template);
486
+ const { indent = " " } = detectIndent__default.default(templateString);
487
+ const formattingOptions = {
488
+ tabSize: indent.length,
489
+ insertSpaces: true
490
+ };
491
+ const passFields = [
492
+ "license",
493
+ "author"
494
+ ];
495
+ let newJSONString = templateString;
496
+ for (const field of passFields) {
497
+ newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
498
+ newJSONString,
499
+ [field],
500
+ getWDPackageJSONFiled(wd, field),
501
+ { formattingOptions }
502
+ ));
503
+ }
504
+ let [pkgName, pkgDir] = await getName(named, name, {
505
+ wd,
506
+ cwd,
507
+ workspaceName
508
+ });
509
+ if (!pkgDir) {
510
+ const { dir } = await inquirer__default.default.prompt({
511
+ type: "input",
512
+ name: "dir",
513
+ message: "package directory",
514
+ default: name
515
+ });
516
+ pkgDir = dir;
517
+ }
518
+ if (!pkgName) {
519
+ const { name: inputName } = await inquirer__default.default.prompt({
520
+ type: "input",
521
+ name: "name",
522
+ message: "package name",
523
+ default: name
524
+ });
525
+ pkgName = inputName;
526
+ }
527
+ newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(newJSONString, ["name"], pkgName, { formattingOptions }));
528
+ let pkgRepo = getWDPackageJSONFiled(wd, "repository");
529
+ if (typeof pkgRepo === "string") {
530
+ pkgRepo = {
531
+ type: "git",
532
+ url: pkgRepo,
533
+ directory: pkgDir
534
+ };
535
+ }
536
+ newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
537
+ newJSONString,
538
+ ["repository"],
539
+ pkgRepo,
540
+ { formattingOptions }
541
+ ));
542
+ const homepage = `${pkgRepo?.url}/blob/master/${pkgDir}/README.md`;
543
+ newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
544
+ newJSONString,
545
+ ["homepage"],
546
+ homepage,
547
+ { formattingOptions }
548
+ ));
549
+ let labels = resolvedBug.labels;
550
+ if (typeof labels === "function")
551
+ labels = labels({
552
+ name: pkgName,
553
+ dir: pkgDir
554
+ });
555
+ labels.push(`scope:${pkgName}`);
556
+ const bugs = `${pkgRepo?.url}/issues/new?template=${resolvedBug.template}&labels=${labels.join(",")}`;
557
+ newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
558
+ newJSONString,
559
+ ["bugs"],
560
+ bugs,
561
+ { formattingOptions }
562
+ ));
563
+ function pkgDirTo(to) {
564
+ if (!pkgDir)
565
+ throw new Error("pkgDir is not defined");
566
+ return path__default.default.resolve(pkgDir, to);
567
+ }
568
+ if (!fs__default.default.existsSync(pkgDir))
569
+ fs__default.default.mkdirSync(pkgDir);
570
+ const pkgJSONFilePath = pkgDirTo("package.json");
571
+ if (fs__default.default.existsSync(pkgJSONFilePath)) {
572
+ throw new Error("package.json already exists");
573
+ }
574
+ fs__default.default.writeFileSync(pkgJSONFilePath, newJSONString);
575
+ console.log(newJSONString, "written to", pkgJSONFilePath);
576
+ const license = getWDPackageJSONFiled(wd, "license");
577
+ const readmeFilePath = pkgDirTo("README.md");
578
+ if (typeof readme === "function") {
579
+ readme = readme({
580
+ dir: pkgDir,
581
+ packageJson: JSON.parse(newJSONString)
582
+ });
583
+ }
584
+ const readmeContent = readme.replace(/\$name/g, pkgName).replace(/\$license/g, license);
585
+ fs__default.default.writeFileSync(readmeFilePath, readmeContent);
586
+ });
587
+
588
+ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-p, --preview", "preview publish").action(async ({ preview, bumper: bumper$1, ...options }) => {
589
+ actionRestore();
590
+ const { value = {} } = await getSelectedProjectsGraph() ?? {};
591
+ const selectedProjectsGraphEntries = Object.entries(value);
592
+ if (selectedProjectsGraphEntries.length === 0) {
593
+ throw new Error("no packages selected");
594
+ }
595
+ const mainfests = selectedProjectsGraphEntries.map(([dir, manifest]) => [
596
+ dir,
597
+ mergePackageJson(manifest, dir)
598
+ ]);
599
+ const passArgs = Object.entries(options).reduce((acc, [key, value2]) => {
600
+ if (value2) {
601
+ acc.push(`--${key}`, value2);
602
+ }
603
+ return acc;
604
+ }, []);
605
+ for (const [dir, manifest] of mainfests) {
606
+ const oldJSONString = fs__default.default.readFileSync(path__default.default.join(dir, "package.json"), "utf-8");
607
+ const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
608
+ const newVersion = bumper.bump(oldJSON.version, bumper$1);
609
+ const { indent = " " } = detectIndent__default.default(oldJSONString);
610
+ const formattingOptions = {
611
+ tabSize: indent.length,
612
+ insertSpaces: true
613
+ };
614
+ let newJSONString = oldJSONString;
615
+ newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
616
+ newJSONString,
617
+ ["version"],
618
+ newVersion,
619
+ { formattingOptions }
620
+ ));
621
+ for (const [key, value2] of Object.entries(manifest)) {
622
+ if (JSON.stringify(value2) === JSON.stringify(oldJSON[key]))
623
+ continue;
624
+ newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
625
+ newJSONString,
626
+ ["publishConfig", key],
627
+ value2,
628
+ { formattingOptions }
629
+ ));
630
+ }
631
+ try {
632
+ fs__default.default.renameSync(path__default.default.join(dir, "package.json"), path__default.default.join(dir, "package.json.bak"));
633
+ fs__default.default.writeFileSync(path__default.default.join(dir, "package.json"), newJSONString);
634
+ console.log(newJSONString);
635
+ if (preview) {
636
+ console.warn("preview mode");
637
+ continue;
638
+ }
639
+ childProcess__namespace$1.execSync(["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs].join(" "), {
640
+ cwd: dir,
641
+ stdio: "inherit"
642
+ });
643
+ const modifyVersionPackageJSON = jsoncParser.applyEdits(oldJSONString, jsoncParser.modify(oldJSONString, ["version"], newVersion, {}));
644
+ fs__default.default.writeFileSync(path__default.default.join(dir, "package.json.bak"), modifyVersionPackageJSON);
645
+ } finally {
646
+ fs__default.default.unlinkSync(path__default.default.join(dir, "package.json"));
647
+ fs__default.default.renameSync(path__default.default.join(dir, "package.json.bak"), path__default.default.join(dir, "package.json"));
648
+ }
649
+ }
650
+ actionDone();
651
+ });
652
+
653
+ const pkg = require("../package.json");
654
+ commander.program.version(pkg.version).description(pkg.description).option("--root <root>", "root path").option("-c, --config-path <configPath>", "config path");
655
+ commander.program.parse(process.argv);
656
+
657
+ })(fs, path, filterWorkspacePackages, commander, jsYaml, getWorkspaceDir, childProcess, pkger, detectIndent, inquirer, jsoncParser, micromatch, bumper, childProcess$1);
658
+ //# sourceMappingURL=cli.iife.js.map