juisy 3.0.0-beta.2 → 3.0.0-beta.4

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.
Files changed (36) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +25 -12
  3. package/bin/cli/cli.js +28 -28
  4. package/bin/cli/cmds/index.js +11 -11
  5. package/bin/cli/cmds/public/print-globals.js +27 -27
  6. package/bin/cli/index.js +9 -9
  7. package/bin/scripts/prepare.js +22 -22
  8. package/dist/DataExporter.d.ts +133 -34
  9. package/dist/ReadmeTemplater-DobSI9Um.js +373 -0
  10. package/dist/bootstrap.d.ts +11 -3
  11. package/dist/bootstrap.js +15 -11
  12. package/dist/cli/Command.d.ts +4 -4
  13. package/dist/cli/OutputUtils.d.ts +1 -1
  14. package/dist/cli/cache-dir.d.ts +15 -0
  15. package/dist/cli/index.js +341 -148
  16. package/dist/cli/plugins/register-changelog-command/augment.d.ts +52 -34
  17. package/dist/cli/plugins/register-changelog-command/resolve-changelog-options.d.ts +19 -0
  18. package/dist/cli/plugins/register-release-command/build-temp-config.d.ts +13 -0
  19. package/dist/cli/plugins/register-release-command/release-args.d.ts +7 -0
  20. package/dist/cli/plugins/register-release-command/resolve-release-config.d.ts +40 -0
  21. package/dist/cli/serialize-cjs-module.d.ts +15 -0
  22. package/dist/cli/types.d.ts +1 -1
  23. package/dist/extensions.d.ts +33 -9
  24. package/dist/extensions.js +87 -20
  25. package/dist/get-package-info-CGDJsCsN.js +15 -0
  26. package/dist/index.d.ts +5 -1
  27. package/dist/index.js +109 -23
  28. package/dist/project-globals.d.ts +8 -2
  29. package/dist/templater/Templater.d.ts +1 -1
  30. package/dist/templater/index.d.ts +2 -2
  31. package/dist/templater/index.js +2 -335
  32. package/dist/templater/markdown-templater/ReadmeTemplater.d.ts +31 -2
  33. package/dist/templater/markdown-templater/index.d.ts +12 -1
  34. package/package.json +24 -29
  35. package/skills/juisy/SKILL.md +97 -0
  36. package/skills/juisy/references/recipes.md +85 -0
package/dist/cli/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * juisy v3.0.0-beta.2
2
+ * juisy v3.0.0-beta.4
3
3
  * Copyright © 2022-Present Hervé Perchec
4
4
  */
5
5
 
@@ -20,9 +20,15 @@ import dotenv from '@dotenvx/dotenvx';
20
20
  import semver from 'semver';
21
21
  import fs$1 from 'node:fs';
22
22
  import path from 'node:path';
23
- import kebabcase from '@juisy/utils/string/kebabcase';
24
- import { ReadmeTemplater } from 'juisy/templater';
25
- import { getPackageInfo } from 'juisy';
23
+ import camelcase from '@juisy/utils/string/camelcase';
24
+ import { ConventionalChangelog, runProgram } from 'conventional-changelog';
25
+ import isDef from '@juisy/utils/is/is-def';
26
+ import 'ejs';
27
+ import 'handlebars';
28
+ import { R as ReadmeTemplater } from '../ReadmeTemplater-DobSI9Um.js';
29
+ import { g as getPackageInfo } from '../get-package-info-CGDJsCsN.js';
30
+ import os from 'node:os';
31
+ import { packageDirectorySync } from 'pkg-dir';
26
32
  import { ESLint } from 'eslint';
27
33
  import yargsParser from 'yargs-parser';
28
34
 
@@ -296,7 +302,7 @@ class Command {
296
302
  /**
297
303
  * Command handler
298
304
  */
299
- handler(argv) {
305
+ handler(argv, positionals, options) {
300
306
  throw new Error("Command handler is not implemented");
301
307
  }
302
308
  /**
@@ -305,8 +311,8 @@ class Command {
305
311
  middlewares;
306
312
  /**
307
313
  * Log a message in the console output. Uses OutputUtils.log method.
308
- * @param msg The message to log. Can be empty to log blank line
309
- * @param options The options to pass to OutputUtils.log second argument
314
+ * @param msg - The message to log. Can be empty to log blank line
315
+ * @param options - The options to pass to OutputUtils.log second argument
310
316
  */
311
317
  log(msg, options = {}) {
312
318
  OutputUtils.log(msg, {
@@ -418,6 +424,16 @@ function command(...args) {
418
424
  const cmdObj = {
419
425
  ...cmdModule
420
426
  };
427
+ const originalHandler = cmdObj.handler;
428
+ if (typeof originalHandler === "function") {
429
+ cmdObj.handler = function(argv) {
430
+ const positionals = { _: argv._ };
431
+ const options = { ...argv };
432
+ delete options._;
433
+ delete options.$0;
434
+ return originalHandler.call(this, argv, positionals, options);
435
+ };
436
+ }
421
437
  let failOnFalsyReturn;
422
438
  for (const name of self._globalCommandVisitorsEnabled) {
423
439
  const globalVisitor = self._globalCommandVisitors[name];
@@ -853,6 +869,47 @@ const RegisterBumpVersionCommand = new Plugin("built-in:register-bump-version-co
853
869
  }
854
870
  });
855
871
 
872
+ function applyChangelogSettingsDefaults(generator, resolvedOptions, commandSettings) {
873
+ if (!isDef(resolvedOptions.preset)) {
874
+ if (commandSettings.preset) {
875
+ if (typeof commandSettings.preset === "string") {
876
+ resolvedOptions.preset = commandSettings.preset;
877
+ } else {
878
+ generator.loadPreset(commandSettings.preset);
879
+ }
880
+ }
881
+ }
882
+ if (!isDef(resolvedOptions.config)) {
883
+ if (commandSettings.config) {
884
+ if (typeof commandSettings.config === "string") {
885
+ resolvedOptions.config = commandSettings.config;
886
+ } else {
887
+ if (commandSettings.config.tags) {
888
+ generator.tags(commandSettings.config.tags);
889
+ }
890
+ if (commandSettings.config.commits || commandSettings.config.parser) {
891
+ generator.commits(
892
+ commandSettings.config.commits || {},
893
+ commandSettings.config.parser
894
+ );
895
+ }
896
+ if (commandSettings.config.writer) {
897
+ generator.writer(commandSettings.config.writer);
898
+ }
899
+ }
900
+ }
901
+ }
902
+ if (!isDef(resolvedOptions.context)) {
903
+ if (commandSettings.context) {
904
+ if (typeof commandSettings.context === "string") {
905
+ resolvedOptions.context = commandSettings.context;
906
+ } else {
907
+ generator.context(commandSettings.context);
908
+ }
909
+ }
910
+ }
911
+ }
912
+
856
913
  const changelog = new Command({
857
914
  command: "changelog",
858
915
  describe: "Generate CHANGELOG file",
@@ -860,41 +917,123 @@ const changelog = new Command({
860
917
  private: true
861
918
  },
862
919
  builder: function(cli) {
920
+ cli.option("preset", {
921
+ alias: "p",
922
+ describe: "Preset that defines how commits are parsed and grouped.",
923
+ type: "string"
924
+ }).option("infile", {
925
+ alias: "i",
926
+ describe: "Read the CHANGELOG from this file",
927
+ type: "string"
928
+ }).option("outfile", {
929
+ alias: "o",
930
+ describe: "File to write the changelog to. Default is the value of --infile",
931
+ type: "string"
932
+ }).option("stdout", {
933
+ describe: "Print the result to stdout instead of writing a file",
934
+ type: "boolean",
935
+ default: false
936
+ }).option("pkg", {
937
+ alias: "k",
938
+ describe: "A filepath of where your package.json is located. Default is the closest package.json from cwd",
939
+ type: "string"
940
+ }).option("append", {
941
+ alias: "a",
942
+ describe: "Append newer releases below older ones instead of prepending.",
943
+ type: "boolean",
944
+ default: false
945
+ }).option("release-count", {
946
+ alias: "r",
947
+ describe: "How many releases to generate, counting from the latest. `0` regenerates the whole history and **overwrites** the outfile.",
948
+ type: "number",
949
+ default: 1
950
+ }).option("first-release", {
951
+ alias: "f",
952
+ describe: "Generate the changelog for the first time - equivalent to `--release-count 0`.",
953
+ type: "boolean",
954
+ default: false
955
+ }).option("skip-unstable", {
956
+ describe: "If given, unstable tags will be skipped, e.g., x.x.x-alpha.1, x.x.x-rc.2",
957
+ type: "boolean",
958
+ default: false
959
+ }).option("tag-prefix", {
960
+ alias: "t",
961
+ describe: "Tag prefix to consider when reading the tags",
962
+ type: "string"
963
+ }).option("lerna-package", {
964
+ alias: "l",
965
+ describe: "Generate a changelog for a Lerna package, reading `name@1.0.0`-style tags.",
966
+ type: "string"
967
+ }).option("commit-path", {
968
+ describe: "Only include commits that touch a specific directory.",
969
+ type: "string"
970
+ }).option("from", {
971
+ describe: "Start of the commit range (tag or SHA). Default is last semver tag.",
972
+ type: "string"
973
+ }).option("to", {
974
+ describe: 'End of the commit range (tag or SHA). Default is "HEAD".',
975
+ type: "string"
976
+ }).option("config", {
977
+ alias: "n",
978
+ describe: "Path to a config script that returns preset options",
979
+ type: "string"
980
+ }).option("context", {
981
+ alias: "c",
982
+ describe: "Path to a JSON file with template context variables.",
983
+ type: "string"
984
+ }).option("verbose", {
985
+ alias: "v",
986
+ describe: "Print debug and warning logs.",
987
+ type: "boolean",
988
+ default: false
989
+ });
990
+ const {
991
+ /* eslint-disable no-unused-vars */
992
+ onReleaseConfig,
993
+ preset,
994
+ config,
995
+ context,
996
+ /* eslint-enable no-unused-vars */
997
+ ...changelogSettings
998
+ } = cli.getSettings("changelog");
999
+ cli.config(changelogSettings);
863
1000
  return cli;
864
1001
  },
865
1002
  async handler(argv) {
866
1003
  const { $style, step, substep, error, wait } = OutputUtils;
867
- const { run } = InterfaceUtils;
1004
+ const { abort } = InterfaceUtils;
868
1005
  step("Generating changelog");
869
- const { ...commandOptions } = this.engine.getSettings("changelog");
870
- const flattenOptions = (options) => {
871
- const _array = [];
872
- for (const key in options) {
873
- if (typeof options[key] === "boolean") {
874
- _array.push("--" + kebabcase(key));
875
- } else {
876
- _array.push("--" + kebabcase(key));
877
- _array.push(String(options[key]));
878
- }
879
- }
880
- return _array;
881
- };
1006
+ const {
1007
+ onReleaseConfig,
1008
+ // eslint-disable-line no-unused-vars
1009
+ ...commandSettings
1010
+ } = this.engine.getSettings("changelog");
1011
+ const generator = new ConventionalChangelog(process.cwd());
1012
+ const resolvedOptions = Object.keys(this.engine.getOptions().key).reduce((accumulator, value) => {
1013
+ const optionName = camelcase(value);
1014
+ if (optionName in argv) accumulator[optionName] = argv[optionName];
1015
+ return accumulator;
1016
+ }, {});
1017
+ applyChangelogSettingsDefaults(generator, resolvedOptions, commandSettings);
1018
+ let commandError = false;
882
1019
  await wait("Generating", async () => {
883
1020
  try {
884
- await run(
885
- "npx",
886
- [
887
- "conventional-changelog",
888
- ...flattenOptions(commandOptions)
889
- ],
890
- { stdio: "inherit" }
1021
+ await runProgram(
1022
+ generator,
1023
+ resolvedOptions
891
1024
  );
892
1025
  } catch (e) {
893
- error("Unable to generate changelog", e);
1026
+ commandError = e;
1027
+ error("Unable to generate changelog", commandError);
894
1028
  }
895
1029
  });
896
- substep($style.green("✔ Success"), { last: true });
897
- this.log();
1030
+ if (commandError) {
1031
+ substep($style.red("❌ Unable to generate changelog."), { last: true });
1032
+ abort(1);
1033
+ } else {
1034
+ substep($style.green("✔ Changelog successfuly generated"), { last: true });
1035
+ this.log();
1036
+ }
898
1037
  }
899
1038
  });
900
1039
 
@@ -903,8 +1042,10 @@ const RegisterChangelogCommand = new Plugin("built-in:register-changelog-command
903
1042
  defineSettings("changelog", {
904
1043
  infile: "CHANGELOG.md",
905
1044
  preset: "angular",
906
- sameFile: true,
907
- onReleaseConfig: {}
1045
+ onReleaseConfig: {
1046
+ whatBump: async () => null,
1047
+ ignoreRecommendedBump: true
1048
+ }
908
1049
  });
909
1050
  defineDefaultCommand({
910
1051
  fullSignature: "changelog",
@@ -945,7 +1086,7 @@ const docsGenerateCLI = new Command({
945
1086
  alias: "c",
946
1087
  describe: "Path to config file",
947
1088
  type: "string",
948
- default: "./docs/cli/config.js"
1089
+ default: "./docs/cli/private/config.js"
949
1090
  });
950
1091
  cli.config(cli.getSettings("docs.cli"));
951
1092
  return cli;
@@ -983,7 +1124,7 @@ const RegisterDocsCommands = new Plugin("built-in:register-docs-commands", {
983
1124
  config: "./docs/readme/config.js"
984
1125
  },
985
1126
  cli: {
986
- config: "./docs/cli/config.js"
1127
+ config: "./docs/cli/private/config.js"
987
1128
  }
988
1129
  });
989
1130
  defineDefaultCommand({
@@ -1020,6 +1161,17 @@ const gitHooks = new Command({
1020
1161
  }
1021
1162
  });
1022
1163
 
1164
+ function getJuisyCacheDir(cwd = process.cwd()) {
1165
+ const pkgRoot = packageDirectorySync({ cwd }) || cwd;
1166
+ const nodeModulesDir = path.resolve(pkgRoot, "node_modules");
1167
+ const cacheDir = fs$1.existsSync(nodeModulesDir) ? path.join(nodeModulesDir, ".cache", "juisy") : path.join(os.tmpdir(), "juisy");
1168
+ fs$1.mkdirSync(cacheDir, { recursive: true });
1169
+ return cacheDir;
1170
+ }
1171
+ function getJuisyTempFilePath(fileName, cwd = process.cwd()) {
1172
+ return path.join(getJuisyCacheDir(cwd), fileName);
1173
+ }
1174
+
1023
1175
  const gitHooksSync = new Command({
1024
1176
  command: "sync",
1025
1177
  describe: "Sync git hooks",
@@ -1031,8 +1183,8 @@ const gitHooksSync = new Command({
1031
1183
  const { run, abort } = InterfaceUtils;
1032
1184
  step("Sync git hooks");
1033
1185
  const gitHooksConfig = getPackageInfo()["simple-git-hooks"] || this.engine.getSettings("gitHooks");
1034
- const tempConfigFilePath = "./__TEMP_SIMPLE_GIT_HOOKS_CONFIG__.json";
1035
- fs.writeFileSync(path.resolve(tempConfigFilePath), JSON.stringify(gitHooksConfig));
1186
+ const tempConfigFilePath = getJuisyTempFilePath("__TEMP_SIMPLE_GIT_HOOKS_CONFIG__.json");
1187
+ fs.writeFileSync(tempConfigFilePath, JSON.stringify(gitHooksConfig));
1036
1188
  let commandError = false;
1037
1189
  try {
1038
1190
  await run("npx", [
@@ -1042,7 +1194,7 @@ const gitHooksSync = new Command({
1042
1194
  } catch (e) {
1043
1195
  commandError = e;
1044
1196
  }
1045
- fs.unlinkSync(path.resolve(tempConfigFilePath));
1197
+ fs.unlinkSync(tempConfigFilePath);
1046
1198
  if (commandError) {
1047
1199
  substep($style.red("❌ Unable to sync git hooks."), { last: true });
1048
1200
  error("Unable to sync git hooks.", commandError);
@@ -1062,10 +1214,10 @@ const gitHooksReset = new Command({
1062
1214
  },
1063
1215
  async handler(argv) {
1064
1216
  const { $style, step, substep } = OutputUtils;
1065
- const { rootDir, run, abort } = InterfaceUtils;
1217
+ const { run, abort } = InterfaceUtils;
1066
1218
  step("Reset git hooks");
1067
- const tempConfigFilePath = "./__TEMP_SIMPLE_GIT_HOOKS_CONFIG__.json";
1068
- fs.writeFileSync(path.resolve(rootDir, tempConfigFilePath), "{}");
1219
+ const tempConfigFilePath = getJuisyTempFilePath("__TEMP_SIMPLE_GIT_HOOKS_CONFIG__.json");
1220
+ fs.writeFileSync(tempConfigFilePath, "{}");
1069
1221
  let commandError = false;
1070
1222
  try {
1071
1223
  await run("npx", [
@@ -1075,7 +1227,7 @@ const gitHooksReset = new Command({
1075
1227
  } catch (e) {
1076
1228
  commandError = e;
1077
1229
  }
1078
- fs.unlinkSync(path.resolve(rootDir, tempConfigFilePath));
1230
+ fs.unlinkSync(tempConfigFilePath);
1079
1231
  if (commandError) {
1080
1232
  substep($style.red("❌ Unable to reset git hooks."), { last: true });
1081
1233
  abort(1);
@@ -1191,6 +1343,10 @@ const lint = new Command({
1191
1343
  const resultText = formatter.format(results);
1192
1344
  console.log(resultText);
1193
1345
  this.log();
1346
+ const errorCount = results.reduce((sum, result) => sum + result.errorCount, 0);
1347
+ if (errorCount > 0) {
1348
+ process.exitCode = 1;
1349
+ }
1194
1350
  }
1195
1351
  });
1196
1352
 
@@ -1224,7 +1380,7 @@ const lintCommit = new Command({
1224
1380
  "unknown-options-as-args": true
1225
1381
  }
1226
1382
  })._.map(String);
1227
- const tempConfigFilePath = "./__TEMP_COMMITLINT_CONFIG__.json";
1383
+ const tempConfigFilePath = getJuisyTempFilePath("__TEMP_COMMITLINT_CONFIG__.json");
1228
1384
  let tempConfig;
1229
1385
  if (!commitLintCmdArgs.includes("--config") && !commitLintCmdArgs.includes("-g")) {
1230
1386
  if (argv.config) {
@@ -1282,14 +1438,14 @@ const lintMarkdown = new Command({
1282
1438
  let commandError;
1283
1439
  for (const item of configs) {
1284
1440
  let tempConfig;
1285
- const mdLintCmdArgs = [...item.globs];
1286
- const tempConfigFilePath = "__TEMP_MARKDOWNLINT_CONFIG__.markdownlint-cli2.jsonc";
1441
+ const mdLintCmdArgs = [...item.globs ?? []];
1442
+ const tempConfigFilePath = getJuisyTempFilePath("__TEMP_MARKDOWNLINT_CONFIG__.markdownlint-cli2.jsonc");
1287
1443
  if (item.config) {
1288
1444
  tempConfig = item.config;
1289
1445
  }
1290
1446
  if (typeof tempConfig === "string") {
1291
1447
  mdLintCmdArgs.push("--config", tempConfig);
1292
- } else {
1448
+ } else if (tempConfig) {
1293
1449
  mdLintCmdArgs.push("--config", tempConfigFilePath);
1294
1450
  fs$1.writeFileSync(path.resolve(tempConfigFilePath), JSON.stringify(tempConfig));
1295
1451
  }
@@ -1355,7 +1511,7 @@ const lintStaged = new Command({
1355
1511
  // Pass all native options to lint-staged command
1356
1512
  ...argv._.map(String)
1357
1513
  ];
1358
- const tempConfigFilePath = "./__TEMP_LINT_STAGED_CONFIG__.json";
1514
+ const tempConfigFilePath = getJuisyTempFilePath("__TEMP_LINT_STAGED_CONFIG__.json");
1359
1515
  let tempConfig;
1360
1516
  if (argv.config) {
1361
1517
  lintStagedCmdArgs.push("--config", argv.config);
@@ -1434,6 +1590,121 @@ const RegisterLintCommands = new Plugin("built-in:register-lint-commands", {
1434
1590
  }
1435
1591
  });
1436
1592
 
1593
+ function serializeJsValue(value) {
1594
+ if (typeof value === "function") {
1595
+ return value.toString();
1596
+ }
1597
+ if (value === void 0) {
1598
+ return "undefined";
1599
+ }
1600
+ if (value === null || typeof value === "boolean" || typeof value === "number") {
1601
+ return String(value);
1602
+ }
1603
+ if (typeof value === "string") {
1604
+ return JSON.stringify(value);
1605
+ }
1606
+ if (Array.isArray(value)) {
1607
+ return `[${value.map((item) => serializeJsValue(item)).join(",")}]`;
1608
+ }
1609
+ if (typeof value === "object") {
1610
+ const entries = Object.entries(value).filter(([, entryValue]) => entryValue !== void 0).map(([key, entryValue]) => `${JSON.stringify(key)}:${serializeJsValue(entryValue)}`);
1611
+ return `{${entries.join(",")}}`;
1612
+ }
1613
+ return JSON.stringify(value);
1614
+ }
1615
+ function serializeCjsModule(value) {
1616
+ return `module.exports = ${serializeJsValue(value)}
1617
+ `;
1618
+ }
1619
+
1620
+ function getArgsAfterCommand(tokens, command) {
1621
+ const index = tokens.findIndex((token) => token === command);
1622
+ return index === -1 ? [] : tokens.slice(index + 1);
1623
+ }
1624
+
1625
+ function buildReleaseItTempConfig(releaseSettings, changelogSettings) {
1626
+ const {
1627
+ onReleaseConfig = {},
1628
+ preset,
1629
+ infile,
1630
+ context
1631
+ } = changelogSettings;
1632
+ const releaseItChangelogConfig = {
1633
+ infile: onReleaseConfig.infile || infile,
1634
+ header: onReleaseConfig.header,
1635
+ context: onReleaseConfig.context || (typeof context === "string" ? JSON.parse(fs$1.readFileSync(path.resolve(context)).toString()) : context || {}),
1636
+ preset: {
1637
+ name: preset,
1638
+ ...onReleaseConfig.preset || {}
1639
+ },
1640
+ tagOpts: onReleaseConfig.tagOpts,
1641
+ commitsOpts: onReleaseConfig.commitsOpts,
1642
+ whatBump: onReleaseConfig.whatBump,
1643
+ ignoreRecommendedBump: onReleaseConfig.ignoreRecommendedBump,
1644
+ strictSemVer: onReleaseConfig.strictSemVer
1645
+ };
1646
+ return {
1647
+ ...releaseSettings,
1648
+ plugins: {
1649
+ ...releaseSettings.plugins || {},
1650
+ "@release-it/conventional-changelog": releaseItChangelogConfig
1651
+ }
1652
+ };
1653
+ }
1654
+
1655
+ const RELEASE_IT_SEARCH_PLACES = [
1656
+ ".release-it.json",
1657
+ ".release-it.js",
1658
+ ".release-it.ts",
1659
+ ".release-it.cjs",
1660
+ ".release-it.yaml",
1661
+ ".release-it.yml",
1662
+ ".release-it.toml"
1663
+ ];
1664
+ function hasExistingReleaseItConfig(cwd, packageJsonHasReleaseIt) {
1665
+ if (packageJsonHasReleaseIt) {
1666
+ return true;
1667
+ }
1668
+ return RELEASE_IT_SEARCH_PLACES.some(
1669
+ (fileName) => fs$1.existsSync(path.resolve(cwd, fileName))
1670
+ );
1671
+ }
1672
+ function resolveReleaseItInvocation(options) {
1673
+ const {
1674
+ cwd = process.cwd(),
1675
+ packageJsonHasReleaseIt,
1676
+ releaseSettings,
1677
+ changelogSettings,
1678
+ tempConfigFilePath
1679
+ } = options;
1680
+ if (hasExistingReleaseItConfig(cwd, packageJsonHasReleaseIt)) {
1681
+ return {
1682
+ mode: "existing-config",
1683
+ configArgs: []
1684
+ };
1685
+ }
1686
+ if (releaseSettings.config) {
1687
+ if (typeof releaseSettings.config !== "string") {
1688
+ throw new TypeError("release.config must be path to file as string");
1689
+ }
1690
+ return {
1691
+ mode: "existing-config",
1692
+ configArgs: ["--config", releaseSettings.config]
1693
+ };
1694
+ }
1695
+ const inlineReleaseSettings = { ...releaseSettings };
1696
+ delete inlineReleaseSettings.config;
1697
+ const tempConfig = buildReleaseItTempConfig(
1698
+ inlineReleaseSettings,
1699
+ changelogSettings
1700
+ );
1701
+ return {
1702
+ mode: "temp-config",
1703
+ configArgs: ["--config", tempConfigFilePath],
1704
+ tempConfig
1705
+ };
1706
+ }
1707
+
1437
1708
  const release = new Command({
1438
1709
  command: "release",
1439
1710
  describe: "Make a release",
@@ -1441,7 +1712,7 @@ const release = new Command({
1441
1712
  private: true
1442
1713
  },
1443
1714
  builder(cli) {
1444
- cli.option("d", {
1715
+ cli.strict(false).option("d", {
1445
1716
  alias: "dry-run",
1446
1717
  type: "boolean",
1447
1718
  describe: "Do not touch or write anything, but show the commands"
@@ -1477,108 +1748,30 @@ const release = new Command({
1477
1748
  });
1478
1749
  return cli;
1479
1750
  },
1480
- async handler(argv) {
1481
- const { $style, step, substep, error, wait } = OutputUtils;
1751
+ async handler(_argv) {
1752
+ const { $style, step, substep, error } = OutputUtils;
1482
1753
  const { abort, run } = InterfaceUtils;
1483
1754
  step("Prepare for release");
1484
- const tempConfigFilePath = "./__TEMP_RELEASE_IT_CONFIG__.json";
1755
+ const tempConfigFilePath = getJuisyTempFilePath("__TEMP_RELEASE_IT_CONFIG__.cjs");
1485
1756
  const releaseItCmdArgs = [];
1486
- let tempConfig;
1487
- let releaseItConfigFound = false;
1488
1757
  substep($style.green("Resolving configuration"));
1489
- const releaseSettings = this.engine.getSettings("release");
1490
- if (getPackageInfo()["release-it"]) {
1491
- releaseItConfigFound = true;
1492
- } else {
1493
- const searchPlaces = [
1494
- ".release-it.json",
1495
- ".release-it.js",
1496
- ".release-it.ts",
1497
- ".release-it.cjs",
1498
- ".release-it.yaml",
1499
- ".release-it.yml",
1500
- ".release-it.toml"
1501
- ];
1502
- for (const fileName of searchPlaces) {
1503
- if (fs$1.existsSync(path.resolve(fileName))) {
1504
- releaseItConfigFound = true;
1505
- break;
1506
- }
1507
- }
1508
- if (!releaseItConfigFound) {
1509
- if (releaseSettings.config) {
1510
- if (typeof releaseSettings.config !== "string") {
1511
- error("release.config must be path to file as string");
1512
- abort(1);
1513
- }
1514
- releaseItCmdArgs.push("--config", releaseSettings.config);
1515
- } else {
1516
- const changelogSettings = this.engine.getSettings("changelog");
1517
- const {
1518
- onReleaseConfig,
1519
- preset,
1520
- infile,
1521
- context
1522
- } = changelogSettings;
1523
- const releaseItChangelogConfig = {
1524
- infile: onReleaseConfig.infile || infile,
1525
- header: onReleaseConfig.header,
1526
- context: onReleaseConfig.context || (context ? JSON.parse(fs$1.readFileSync(path.resolve(context)).toString()) : {}),
1527
- preset: {
1528
- name: preset,
1529
- ...onReleaseConfig.preset || {}
1530
- },
1531
- tagOpts: onReleaseConfig.tagOpts,
1532
- commitsOpts: onReleaseConfig.commitsOpts,
1533
- whatBump: onReleaseConfig.whatBump,
1534
- ignoreRecommendedBump: onReleaseConfig.ignoreRecommendedBump,
1535
- strictSemVer: onReleaseConfig.strictSemVer
1536
- };
1537
- tempConfig = {
1538
- ...releaseSettings,
1539
- plugins: {
1540
- "@release-it/conventional-changelog": releaseItChangelogConfig
1541
- }
1542
- };
1543
- releaseItCmdArgs.push("--config", tempConfigFilePath);
1544
- }
1545
- }
1546
- }
1547
- if (argv["dry-run"]) {
1548
- releaseItCmdArgs.push("--dry-run");
1549
- }
1550
- if (argv.increment !== void 0) {
1551
- if (argv.increment === false) {
1552
- releaseItCmdArgs.push("--no-increment");
1553
- } else {
1554
- releaseItCmdArgs.push("--increment");
1555
- releaseItCmdArgs.push(argv.increment);
1556
- }
1557
- }
1558
- if (argv.preRelease !== void 0) {
1559
- releaseItCmdArgs.push("--preRelease");
1560
- releaseItCmdArgs.push(argv.preRelease);
1561
- }
1562
- if (argv.ci) {
1563
- releaseItCmdArgs.push("--ci");
1564
- }
1565
- if (argv["only-version"]) {
1566
- releaseItCmdArgs.push("--only-version");
1567
- }
1568
- if (argv["release-version"]) {
1569
- releaseItCmdArgs.push("--release-version");
1570
- }
1571
- if (argv.changelog) {
1572
- releaseItCmdArgs.push("--changelog");
1573
- }
1574
- if (argv.verbose) {
1575
- releaseItCmdArgs.push("--verbose");
1576
- }
1577
- if (argv["extra-verbose"]) {
1578
- releaseItCmdArgs.push("-VV");
1758
+ let resolved;
1759
+ try {
1760
+ resolved = resolveReleaseItInvocation({
1761
+ packageJsonHasReleaseIt: Boolean(getPackageInfo()["release-it"]),
1762
+ releaseSettings: this.engine.getSettings("release") || {},
1763
+ changelogSettings: this.engine.getSettings("changelog") || {},
1764
+ tempConfigFilePath
1765
+ });
1766
+ } catch (e) {
1767
+ error(e.message);
1768
+ abort(1);
1769
+ return;
1579
1770
  }
1580
- if (!releaseItConfigFound) {
1581
- fs$1.writeFileSync(path.resolve(tempConfigFilePath), JSON.stringify(tempConfig));
1771
+ releaseItCmdArgs.push(...resolved.configArgs);
1772
+ releaseItCmdArgs.push(...getArgsAfterCommand(this.getProcessArgv(), "release"));
1773
+ if (resolved.mode === "temp-config") {
1774
+ fs$1.writeFileSync(tempConfigFilePath, serializeCjsModule(resolved.tempConfig));
1582
1775
  }
1583
1776
  let commandError = false;
1584
1777
  try {
@@ -1589,14 +1782,14 @@ const release = new Command({
1589
1782
  } catch (e) {
1590
1783
  commandError = e;
1591
1784
  }
1592
- if (!releaseItConfigFound) {
1593
- fs$1.unlinkSync(path.resolve(tempConfigFilePath));
1785
+ if (resolved.mode === "temp-config") {
1786
+ fs$1.unlinkSync(tempConfigFilePath);
1594
1787
  }
1595
1788
  if (commandError) {
1596
1789
  substep($style.red("❌ Unable to release."), { last: true });
1597
1790
  abort(1);
1598
1791
  } else {
1599
- substep($style.green("✔ Release successfuly created"), { last: true });
1792
+ substep($style.green("✔ Release successfully created"), { last: true });
1600
1793
  this.log();
1601
1794
  }
1602
1795
  }