create-awesome-node-app 0.7.0 → 0.8.0

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/index.cjs CHANGED
@@ -1591,12 +1591,12 @@ module.exports = __toCommonJS(index_exports);
1591
1591
  var import_commander = require("commander");
1592
1592
  var import_chalk2 = __toESM(require_source(), 1);
1593
1593
  var import_semver = __toESM(require("semver"), 1);
1594
- var import_core = require("@create-node-app/core");
1594
+ var import_core2 = require("@create-node-app/core");
1595
1595
 
1596
1596
  // src/options.ts
1597
+ var import_core = require("@create-node-app/core");
1597
1598
  var import_ci_info = require("ci-info");
1598
1599
  var import_prompts = __toESM(require("prompts"), 1);
1599
- var import_yargs = __toESM(require("yargs"), 1);
1600
1600
 
1601
1601
  // src/templates.ts
1602
1602
  var import_axios = __toESM(require("axios"), 1);
@@ -1681,7 +1681,6 @@ var getExtensionsGroupedByCategory = async (type, cliArgs) => {
1681
1681
  };
1682
1682
 
1683
1683
  // src/options.ts
1684
- import_prompts.default.override((0, import_yargs.default)(process.argv.slice(2)).argv);
1685
1684
  var PACKAGE_MANAGERS = ["npm", "yarn", "pnpm"];
1686
1685
  var isValidUrl = (url) => {
1687
1686
  try {
@@ -1692,9 +1691,12 @@ var isValidUrl = (url) => {
1692
1691
  }
1693
1692
  };
1694
1693
  var processNonInteractiveOptions = async (options) => {
1694
+ const setOverrides = options.setOverrides ?? {};
1695
+ delete options.setOverrides;
1695
1696
  const categories = await getTemplateCategories();
1696
1697
  let matchedTemplate;
1697
1698
  const templatesOrExtensions = [];
1699
+ let resolvedTemplateUrl;
1698
1700
  if (options.template && !isValidUrl(options.template)) {
1699
1701
  const allTemplates = (await Promise.all(
1700
1702
  categories.map((category) => getTemplatesForCategory(category))
@@ -1704,6 +1706,7 @@ var processNonInteractiveOptions = async (options) => {
1704
1706
  );
1705
1707
  if (matchedTemplate) {
1706
1708
  templatesOrExtensions.push({ url: matchedTemplate.url });
1709
+ resolvedTemplateUrl = matchedTemplate.url;
1707
1710
  if (matchedTemplate.customOptions) {
1708
1711
  matchedTemplate.customOptions.forEach((customOption) => {
1709
1712
  if (customOption.name && customOption.initial !== void 0) {
@@ -1718,7 +1721,19 @@ var processNonInteractiveOptions = async (options) => {
1718
1721
  }
1719
1722
  } else if (options.template) {
1720
1723
  templatesOrExtensions.push({ url: options.template });
1724
+ resolvedTemplateUrl = options.template;
1721
1725
  }
1726
+ if (resolvedTemplateUrl) {
1727
+ const cnaConfig = await (0, import_core.loadTemplateCnaConfig)(resolvedTemplateUrl);
1728
+ if (cnaConfig?.customOptions) {
1729
+ for (const opt of cnaConfig.customOptions) {
1730
+ if (opt.name && opt.initial !== void 0) {
1731
+ options[opt.name] = opt.initial;
1732
+ }
1733
+ }
1734
+ }
1735
+ }
1736
+ Object.assign(options, setOverrides);
1722
1737
  if (options.addons && Array.isArray(options.addons)) {
1723
1738
  const extensionsGroupedByCategory = await getExtensionsGroupedByCategory([
1724
1739
  matchedTemplate?.type || "custom",
@@ -1756,6 +1771,9 @@ var processNonInteractiveOptions = async (options) => {
1756
1771
  return options;
1757
1772
  };
1758
1773
  var processInteractiveOptions = async (options) => {
1774
+ const { setOverrides = {}, ...restOptions } = options;
1775
+ options = restOptions;
1776
+ import_prompts.default.override({ ...options, ...setOverrides });
1759
1777
  const categories = await getTemplateCategories();
1760
1778
  const categoryDataPromises = categories.map(async (categorySlug) => {
1761
1779
  const categoryData = await getCategoryData(categorySlug);
@@ -1842,7 +1860,11 @@ var processInteractiveOptions = async (options) => {
1842
1860
  (template) => template.url === templateInput.template
1843
1861
  );
1844
1862
  const templateTemplateOrExtension = templateInput.template;
1845
- const customOptions = existingTemplate?.customOptions || [];
1863
+ const cnaConfig = templateTemplateOrExtension ? await (0, import_core.loadTemplateCnaConfig)(templateTemplateOrExtension) : null;
1864
+ const rawCustomOptions = cnaConfig?.customOptions ?? existingTemplate?.customOptions ?? [];
1865
+ const customOptions = rawCustomOptions.map(
1866
+ (opt) => opt.name && Object.prototype.hasOwnProperty.call(setOverrides, opt.name) ? { ...opt, initial: setOverrides[opt.name] } : opt
1867
+ );
1846
1868
  const appConfig = await (0, import_prompts.default)([
1847
1869
  // The following prompts are placeholders for future inputs
1848
1870
  {
@@ -1920,6 +1942,8 @@ var processInteractiveOptions = async (options) => {
1920
1942
  ...nextAppOptions.extend || []
1921
1943
  ].filter(Boolean).map((templateOrExtension) => ({ url: templateOrExtension }));
1922
1944
  const nextOptions = { ...nextAppOptions, templatesOrExtensions };
1945
+ Object.assign(nextOptions, setOverrides);
1946
+ delete nextOptions.setOverrides;
1923
1947
  if (nextAppOptions.verbose) {
1924
1948
  console.log(JSON.stringify(nextOptions, null, 2));
1925
1949
  }
@@ -1942,7 +1966,7 @@ var getCnaOptions = async (options) => {
1942
1966
  // package.json
1943
1967
  var package_default = {
1944
1968
  name: "create-awesome-node-app",
1945
- version: "0.7.0",
1969
+ version: "0.8.0",
1946
1970
  type: "module",
1947
1971
  description: "Command line tool to create Node apps with a lot of different templates and extensions.",
1948
1972
  license: "MIT",
@@ -1996,26 +2020,24 @@ var package_default = {
1996
2020
  "test:src": "npm run test"
1997
2021
  },
1998
2022
  dependencies: {
1999
- "@create-node-app/core": "^0.5.6",
2000
- axios: "^1.12.2",
2023
+ "@create-node-app/core": "^0.6.0",
2024
+ axios: "^1.13.6",
2001
2025
  "ci-info": "^4.3.0",
2002
2026
  commander: "^14.0.1",
2003
2027
  prompts: "^2.4.2",
2004
- semver: "^7.7.2",
2005
- yargs: "^18.0.0"
2028
+ semver: "^7.7.2"
2006
2029
  },
2007
2030
  devDependencies: {
2031
+ "@create-node-app/core": "^0.6.0",
2008
2032
  "@create-node-app/eslint-config-ts": "*",
2009
- "@create-node-app/core": "^0.5.6",
2010
2033
  "@types/node": "^24.5.2",
2011
2034
  "@types/prompts": "^2.4.9",
2012
- "@types/yargs": "^17.0.33",
2013
2035
  "@types/semver": "^7.5.8",
2014
- nock: "^13.5.4",
2015
2036
  eslint: "^9.35.0",
2016
2037
  "eslint-config-turbo": "^2.5.6",
2017
- tsup: "^8.5.0",
2018
2038
  "eslint-plugin-turbo": "^2.5.6",
2039
+ nock: "^13.5.4",
2040
+ tsup: "^8.5.0",
2019
2041
  tsx: "^4.19.0"
2020
2042
  }
2021
2043
  };
@@ -2116,13 +2138,16 @@ var main = async () => {
2116
2138
  ).option(
2117
2139
  "--no-interactive",
2118
2140
  "disable interactive mode (use only flags / non-interactive flow)"
2119
- ).option("--list-templates", "list all available templates").option("--list-addons", "list all available addons").action((providedProjectName) => {
2141
+ ).option("--list-templates", "list all available templates").option("--list-addons", "list all available addons").option(
2142
+ "--set <assignments...>",
2143
+ "set a custom template option (format: key=value, repeatable)"
2144
+ ).action((providedProjectName) => {
2120
2145
  projectName = providedProjectName || projectName;
2121
2146
  });
2122
2147
  program.parse(process.argv);
2123
2148
  const opts = program.opts();
2124
- (0, import_core.checkNodeVersion)(package_default.engines.node, package_default.name);
2125
- const latestVersion = await (0, import_core.checkForLatestVersion)("create-awesome-node-app");
2149
+ (0, import_core2.checkNodeVersion)(package_default.engines.node, package_default.name);
2150
+ const latestVersion = await (0, import_core2.checkForLatestVersion)("create-awesome-node-app");
2126
2151
  if (latestVersion && import_semver.default.lt(package_default.version, latestVersion)) {
2127
2152
  console.log();
2128
2153
  console.error(
@@ -2144,15 +2169,32 @@ We recommend always using the latest version of create-awesome-node-app if possi
2144
2169
  });
2145
2170
  return;
2146
2171
  }
2147
- const { useYarn, usePnpm, ...restOpts } = opts;
2172
+ const { useYarn, usePnpm, set, ...restOpts } = opts;
2148
2173
  const packageManager = useYarn ? "yarn" : usePnpm ? "pnpm" : "npm";
2174
+ const setOverrides = {};
2175
+ if (Array.isArray(set)) {
2176
+ for (const assignment of set) {
2177
+ const eqIdx = assignment.indexOf("=");
2178
+ if (eqIdx > 0) {
2179
+ setOverrides[assignment.slice(0, eqIdx).trim()] = assignment.slice(
2180
+ eqIdx + 1
2181
+ );
2182
+ }
2183
+ }
2184
+ }
2149
2185
  const templatesOrExtensions = [restOpts.template].concat(Array.isArray(restOpts.extend) ? restOpts.extend : []).filter(Boolean).reduce((acc, templateOrExtension) => {
2150
2186
  if (!templateOrExtension) return acc;
2151
2187
  return acc.concat({ url: templateOrExtension });
2152
2188
  }, []);
2153
- return (0, import_core.createNodeApp)(
2189
+ return (0, import_core2.createNodeApp)(
2154
2190
  projectName,
2155
- { ...restOpts, packageManager, templatesOrExtensions, projectName },
2191
+ {
2192
+ ...restOpts,
2193
+ packageManager,
2194
+ templatesOrExtensions,
2195
+ projectName,
2196
+ setOverrides
2197
+ },
2156
2198
  getCnaOptions
2157
2199
  );
2158
2200
  };