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.js CHANGED
@@ -1569,10 +1569,9 @@ import {
1569
1569
  } from "@create-node-app/core";
1570
1570
 
1571
1571
  // src/options.ts
1572
+ import { loadTemplateCnaConfig } from "@create-node-app/core";
1572
1573
  import { isCI } from "ci-info";
1573
1574
  import prompts from "prompts";
1574
- import yargs from "yargs";
1575
- prompts.override(yargs(process.argv.slice(2)).argv);
1576
1575
  var PACKAGE_MANAGERS = ["npm", "yarn", "pnpm"];
1577
1576
  var isValidUrl = (url) => {
1578
1577
  try {
@@ -1583,9 +1582,12 @@ var isValidUrl = (url) => {
1583
1582
  }
1584
1583
  };
1585
1584
  var processNonInteractiveOptions = async (options) => {
1585
+ const setOverrides = options.setOverrides ?? {};
1586
+ delete options.setOverrides;
1586
1587
  const categories = await getTemplateCategories();
1587
1588
  let matchedTemplate;
1588
1589
  const templatesOrExtensions = [];
1590
+ let resolvedTemplateUrl;
1589
1591
  if (options.template && !isValidUrl(options.template)) {
1590
1592
  const allTemplates = (await Promise.all(
1591
1593
  categories.map((category) => getTemplatesForCategory(category))
@@ -1595,6 +1597,7 @@ var processNonInteractiveOptions = async (options) => {
1595
1597
  );
1596
1598
  if (matchedTemplate) {
1597
1599
  templatesOrExtensions.push({ url: matchedTemplate.url });
1600
+ resolvedTemplateUrl = matchedTemplate.url;
1598
1601
  if (matchedTemplate.customOptions) {
1599
1602
  matchedTemplate.customOptions.forEach((customOption) => {
1600
1603
  if (customOption.name && customOption.initial !== void 0) {
@@ -1609,7 +1612,19 @@ var processNonInteractiveOptions = async (options) => {
1609
1612
  }
1610
1613
  } else if (options.template) {
1611
1614
  templatesOrExtensions.push({ url: options.template });
1615
+ resolvedTemplateUrl = options.template;
1612
1616
  }
1617
+ if (resolvedTemplateUrl) {
1618
+ const cnaConfig = await loadTemplateCnaConfig(resolvedTemplateUrl);
1619
+ if (cnaConfig?.customOptions) {
1620
+ for (const opt of cnaConfig.customOptions) {
1621
+ if (opt.name && opt.initial !== void 0) {
1622
+ options[opt.name] = opt.initial;
1623
+ }
1624
+ }
1625
+ }
1626
+ }
1627
+ Object.assign(options, setOverrides);
1613
1628
  if (options.addons && Array.isArray(options.addons)) {
1614
1629
  const extensionsGroupedByCategory = await getExtensionsGroupedByCategory([
1615
1630
  matchedTemplate?.type || "custom",
@@ -1647,6 +1662,9 @@ var processNonInteractiveOptions = async (options) => {
1647
1662
  return options;
1648
1663
  };
1649
1664
  var processInteractiveOptions = async (options) => {
1665
+ const { setOverrides = {}, ...restOptions } = options;
1666
+ options = restOptions;
1667
+ prompts.override({ ...options, ...setOverrides });
1650
1668
  const categories = await getTemplateCategories();
1651
1669
  const categoryDataPromises = categories.map(async (categorySlug) => {
1652
1670
  const categoryData = await getCategoryData(categorySlug);
@@ -1733,7 +1751,11 @@ var processInteractiveOptions = async (options) => {
1733
1751
  (template) => template.url === templateInput.template
1734
1752
  );
1735
1753
  const templateTemplateOrExtension = templateInput.template;
1736
- const customOptions = existingTemplate?.customOptions || [];
1754
+ const cnaConfig = templateTemplateOrExtension ? await loadTemplateCnaConfig(templateTemplateOrExtension) : null;
1755
+ const rawCustomOptions = cnaConfig?.customOptions ?? existingTemplate?.customOptions ?? [];
1756
+ const customOptions = rawCustomOptions.map(
1757
+ (opt) => opt.name && Object.prototype.hasOwnProperty.call(setOverrides, opt.name) ? { ...opt, initial: setOverrides[opt.name] } : opt
1758
+ );
1737
1759
  const appConfig = await prompts([
1738
1760
  // The following prompts are placeholders for future inputs
1739
1761
  {
@@ -1811,6 +1833,8 @@ var processInteractiveOptions = async (options) => {
1811
1833
  ...nextAppOptions.extend || []
1812
1834
  ].filter(Boolean).map((templateOrExtension) => ({ url: templateOrExtension }));
1813
1835
  const nextOptions = { ...nextAppOptions, templatesOrExtensions };
1836
+ Object.assign(nextOptions, setOverrides);
1837
+ delete nextOptions.setOverrides;
1814
1838
  if (nextAppOptions.verbose) {
1815
1839
  console.log(JSON.stringify(nextOptions, null, 2));
1816
1840
  }
@@ -1833,7 +1857,7 @@ var getCnaOptions = async (options) => {
1833
1857
  // package.json
1834
1858
  var package_default = {
1835
1859
  name: "create-awesome-node-app",
1836
- version: "0.7.0",
1860
+ version: "0.8.0",
1837
1861
  type: "module",
1838
1862
  description: "Command line tool to create Node apps with a lot of different templates and extensions.",
1839
1863
  license: "MIT",
@@ -1887,26 +1911,24 @@ var package_default = {
1887
1911
  "test:src": "npm run test"
1888
1912
  },
1889
1913
  dependencies: {
1890
- "@create-node-app/core": "^0.5.6",
1891
- axios: "^1.12.2",
1914
+ "@create-node-app/core": "^0.6.0",
1915
+ axios: "^1.13.6",
1892
1916
  "ci-info": "^4.3.0",
1893
1917
  commander: "^14.0.1",
1894
1918
  prompts: "^2.4.2",
1895
- semver: "^7.7.2",
1896
- yargs: "^18.0.0"
1919
+ semver: "^7.7.2"
1897
1920
  },
1898
1921
  devDependencies: {
1922
+ "@create-node-app/core": "^0.6.0",
1899
1923
  "@create-node-app/eslint-config-ts": "*",
1900
- "@create-node-app/core": "^0.5.6",
1901
1924
  "@types/node": "^24.5.2",
1902
1925
  "@types/prompts": "^2.4.9",
1903
- "@types/yargs": "^17.0.33",
1904
1926
  "@types/semver": "^7.5.8",
1905
- nock: "^13.5.4",
1906
1927
  eslint: "^9.35.0",
1907
1928
  "eslint-config-turbo": "^2.5.6",
1908
- tsup: "^8.5.0",
1909
1929
  "eslint-plugin-turbo": "^2.5.6",
1930
+ nock: "^13.5.4",
1931
+ tsup: "^8.5.0",
1910
1932
  tsx: "^4.19.0"
1911
1933
  }
1912
1934
  };
@@ -2007,7 +2029,10 @@ var main = async () => {
2007
2029
  ).option(
2008
2030
  "--no-interactive",
2009
2031
  "disable interactive mode (use only flags / non-interactive flow)"
2010
- ).option("--list-templates", "list all available templates").option("--list-addons", "list all available addons").action((providedProjectName) => {
2032
+ ).option("--list-templates", "list all available templates").option("--list-addons", "list all available addons").option(
2033
+ "--set <assignments...>",
2034
+ "set a custom template option (format: key=value, repeatable)"
2035
+ ).action((providedProjectName) => {
2011
2036
  projectName = providedProjectName || projectName;
2012
2037
  });
2013
2038
  program.parse(process.argv);
@@ -2035,15 +2060,32 @@ We recommend always using the latest version of create-awesome-node-app if possi
2035
2060
  });
2036
2061
  return;
2037
2062
  }
2038
- const { useYarn, usePnpm, ...restOpts } = opts;
2063
+ const { useYarn, usePnpm, set, ...restOpts } = opts;
2039
2064
  const packageManager = useYarn ? "yarn" : usePnpm ? "pnpm" : "npm";
2065
+ const setOverrides = {};
2066
+ if (Array.isArray(set)) {
2067
+ for (const assignment of set) {
2068
+ const eqIdx = assignment.indexOf("=");
2069
+ if (eqIdx > 0) {
2070
+ setOverrides[assignment.slice(0, eqIdx).trim()] = assignment.slice(
2071
+ eqIdx + 1
2072
+ );
2073
+ }
2074
+ }
2075
+ }
2040
2076
  const templatesOrExtensions = [restOpts.template].concat(Array.isArray(restOpts.extend) ? restOpts.extend : []).filter(Boolean).reduce((acc, templateOrExtension) => {
2041
2077
  if (!templateOrExtension) return acc;
2042
2078
  return acc.concat({ url: templateOrExtension });
2043
2079
  }, []);
2044
2080
  return createNodeApp(
2045
2081
  projectName,
2046
- { ...restOpts, packageManager, templatesOrExtensions, projectName },
2082
+ {
2083
+ ...restOpts,
2084
+ packageManager,
2085
+ templatesOrExtensions,
2086
+ projectName,
2087
+ setOverrides
2088
+ },
2047
2089
  getCnaOptions
2048
2090
  );
2049
2091
  };