Skip to content

Commit 37ed71c

Browse files
feat: local-first template resolution (cna.config.json + --set flag)
- Remove yargs dependency (ESM-only, breaks CJS bundle); replace with prompts.override(options) using already-parsed Commander values - Add --set key=value CLI flag for overriding custom template options - Add loadTemplateCnaConfig() to core: reads cna.config.json from the template root directory (not inside template/ subdir) - Add getTemplateBaseDirPath() to core: resolves base dir without the template/ subdir detection that getTemplateDirPath() applies - processNonInteractiveOptions: load cna.config.json and apply initials (priority: --set > cna.config.json > registry templates.json) - processInteractiveOptions: merge cna.config.json customOptions with registry, apply --set as prompt initials Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8dabd17 commit 37ed71c

7 files changed

Lines changed: 173 additions & 163 deletions

File tree

package-lock.json

Lines changed: 14 additions & 147 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/create-awesome-node-app/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,14 @@
5959
"ci-info": "^4.3.0",
6060
"commander": "^14.0.1",
6161
"prompts": "^2.4.2",
62-
"semver": "^7.7.2",
63-
"yargs": "^18.0.0"
62+
"semver": "^7.7.2"
6463
},
6564
"devDependencies": {
6665
"@create-node-app/core": "^0.5.7",
6766
"@create-node-app/eslint-config-ts": "*",
6867
"@types/node": "^24.5.2",
6968
"@types/prompts": "^2.4.9",
7069
"@types/semver": "^7.5.8",
71-
"@types/yargs": "^17.0.33",
7270
"eslint": "^9.35.0",
7371
"eslint-config-turbo": "^2.5.6",
7472
"eslint-plugin-turbo": "^2.5.6",

packages/create-awesome-node-app/src/index.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ const main = async () => {
5454
)
5555
.option("--list-templates", "list all available templates")
5656
.option("--list-addons", "list all available addons")
57+
.option(
58+
"--set <assignments...>",
59+
"set a custom template option (format: key=value, repeatable)",
60+
)
5761
.action((providedProjectName: string | undefined) => {
5862
projectName = providedProjectName || projectName;
5963
});
@@ -90,9 +94,22 @@ const main = async () => {
9094
}
9195

9296
// Extract package manager options directly from opts
93-
const { useYarn, usePnpm, ...restOpts } = opts;
97+
const { useYarn, usePnpm, set, ...restOpts } = opts;
9498
const packageManager = useYarn ? "yarn" : usePnpm ? "pnpm" : "npm";
9599

100+
// Parse --set key=value assignments into an overrides map
101+
const setOverrides: Record<string, string> = {};
102+
if (Array.isArray(set)) {
103+
for (const assignment of set as string[]) {
104+
const eqIdx = assignment.indexOf("=");
105+
if (eqIdx > 0) {
106+
setOverrides[assignment.slice(0, eqIdx).trim()] = assignment.slice(
107+
eqIdx + 1,
108+
);
109+
}
110+
}
111+
}
112+
96113
const templatesOrExtensions: TemplateOrExtension[] = [restOpts.template]
97114
.concat(Array.isArray(restOpts.extend) ? restOpts.extend : [])
98115
.filter(Boolean)
@@ -103,7 +120,13 @@ const main = async () => {
103120

104121
return createNodeApp(
105122
projectName,
106-
{ ...restOpts, packageManager, templatesOrExtensions, projectName },
123+
{
124+
...restOpts,
125+
packageManager,
126+
templatesOrExtensions,
127+
projectName,
128+
setOverrides,
129+
},
107130
getCnaOptions,
108131
);
109132
};

0 commit comments

Comments
 (0)