jiek 0.2.2 → 0.2.4

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