create-warlock 5.16.0 → 5.17.1
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/CHANGELOG.md +66 -0
- package/esm/commands/create-new-app/index.mjs +55 -50
- package/esm/commands/create-new-app/index.mjs.map +1 -1
- package/esm/commands/create-new-app/types.d.mts +1 -1
- package/esm/commands/create-warlock-app/index.mjs +2 -2
- package/esm/commands/create-warlock-app/index.mjs.map +1 -1
- package/esm/features/agent-kit-targets.mjs +37 -6
- package/esm/features/agent-kit-targets.mjs.map +1 -1
- package/esm/flags/assert-flag-combinations.mjs +31 -0
- package/esm/flags/assert-flag-combinations.mjs.map +1 -0
- package/esm/flags/assert-package-manager.mjs +44 -0
- package/esm/flags/assert-package-manager.mjs.map +1 -0
- package/esm/flags/definitions.mjs +7 -4
- package/esm/flags/definitions.mjs.map +1 -1
- package/esm/flags/seed-from-flags.mjs +28 -0
- package/esm/flags/seed-from-flags.mjs.map +1 -0
- package/esm/helpers/app.mjs +5 -2
- package/esm/helpers/app.mjs.map +1 -1
- package/esm/helpers/insert-import.mjs.map +1 -1
- package/esm/helpers/package-manager.mjs +29 -19
- package/esm/helpers/package-manager.mjs.map +1 -1
- package/esm/helpers/project-builder-helpers.mjs +1 -1
- package/esm/index.d.mts +1 -1
- package/esm/index.mjs +2 -2
- package/esm/index.mjs.map +1 -1
- package/esm/prompts/ask-agent-targets.mjs +87 -0
- package/esm/prompts/ask-agent-targets.mjs.map +1 -0
- package/esm/prompts/ask-project-name.mjs +25 -0
- package/esm/prompts/ask-project-name.mjs.map +1 -0
- package/esm/prompts/ask-stack.mjs +22 -9
- package/esm/prompts/ask-stack.mjs.map +1 -1
- package/esm/summary.mjs.map +1 -1
- package/llms-full.txt +1 -1
- package/package.json +2 -2
- package/skills/create-a-warlock-project/SKILL.md +1 -1
- package/templates/warlock/AGENTS.md +1 -0
- package/templates/warlock/package.json +3 -3
- package/templates/warlock/skills/web-code-standards/SKILL.md +266 -0
- package/templates/warlock/src/app/uploads/routes.ts +7 -3
- package/templates/warlock/src/config/cache.ts +25 -27
- package/templates/warlock/src/config/http.ts +17 -0
- package/templates/warlock/src/web/404.page.tsx +5 -3
- package/templates/warlock/src/web/home/index.page.tsx +10 -7
- package/templates/warlock/src/web/root.tsx +6 -3
- package/templates/warlock/src/app/uploads/controllers/fetch-uploaded-file.controller.ts +0 -33
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { hasInteractiveStdin } from "../helpers/tty.mjs";
|
|
2
|
+
import { cancel } from "@clack/prompts";
|
|
3
|
+
|
|
4
|
+
//#region ../create-warlock/src/flags/assert-flag-combinations.ts
|
|
5
|
+
/**
|
|
6
|
+
* `--customize` asks for the opposite of what `--yes` and a non-TTY stdin
|
|
7
|
+
* supply, and both contradictions used to resolve in SILENCE: `--yes` simply
|
|
8
|
+
* won the branch, the wizard never ran, and the run looked like it had
|
|
9
|
+
* succeeded while asking none of the questions the flag was passed for.
|
|
10
|
+
*
|
|
11
|
+
* Every OTHER flag is not a contradiction — it is an answer given early, and
|
|
12
|
+
* the wizard pre-selects it rather than dropping it. See `seedFromFlags`.
|
|
13
|
+
*
|
|
14
|
+
* Called before any prompt and before the non-interactive branch, so a refusal
|
|
15
|
+
* happens with no app directory created.
|
|
16
|
+
*/
|
|
17
|
+
function assertFlagCombinations(cli) {
|
|
18
|
+
if (!cli.interactive) return;
|
|
19
|
+
if (cli.yes) {
|
|
20
|
+
cancel("--customize and --yes contradict each other: --customize asks every question, --yes answers them all with defaults. Pass one or the other.");
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
if (!hasInteractiveStdin()) {
|
|
24
|
+
cancel("--customize needs an interactive terminal to ask its questions, and stdin is not a TTY. Either run it in a terminal, or drop --customize and pass the answers as flags — see --help.");
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { assertFlagCombinations };
|
|
31
|
+
//# sourceMappingURL=assert-flag-combinations.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert-flag-combinations.mjs","names":[],"sources":["../../../../../../create-warlock/src/flags/assert-flag-combinations.ts"],"sourcesContent":["import { cancel } from \"@clack/prompts\";\nimport type { CliFlags } from \"../commands/create-new-app/types\";\nimport { hasInteractiveStdin } from \"../helpers/tty\";\n\n/**\n * `--customize` asks for the opposite of what `--yes` and a non-TTY stdin\n * supply, and both contradictions used to resolve in SILENCE: `--yes` simply\n * won the branch, the wizard never ran, and the run looked like it had\n * succeeded while asking none of the questions the flag was passed for.\n *\n * Every OTHER flag is not a contradiction — it is an answer given early, and\n * the wizard pre-selects it rather than dropping it. See `seedFromFlags`.\n *\n * Called before any prompt and before the non-interactive branch, so a refusal\n * happens with no app directory created.\n */\nexport function assertFlagCombinations(cli: CliFlags): void {\n if (!cli.interactive) return;\n\n if (cli.yes) {\n cancel(\n \"--customize and --yes contradict each other: --customize asks every question, --yes answers them all with defaults. Pass one or the other.\",\n );\n process.exit(1);\n }\n\n if (!hasInteractiveStdin()) {\n cancel(\n \"--customize needs an interactive terminal to ask its questions, and stdin is not a TTY. Either run it in a terminal, or drop --customize and pass the answers as flags — see --help.\",\n );\n process.exit(1);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,uBAAuB,KAAqB;CAC1D,IAAI,CAAC,IAAI,aAAa;CAEtB,IAAI,IAAI,KAAK;EACX,OACE,4IACF;EACA,QAAQ,KAAK,CAAC;CAChB;CAEA,IAAI,CAAC,oBAAoB,GAAG;EAC1B,OACE,sLACF;EACA,QAAQ,KAAK,CAAC;CAChB;AACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ALLOWED_PACKAGE_MANAGERS, getSystemPackageManagers, isValidPackageManager } from "../helpers/package-manager.mjs";
|
|
2
|
+
import { cancel } from "@clack/prompts";
|
|
3
|
+
|
|
4
|
+
//#region ../create-warlock/src/flags/assert-package-manager.ts
|
|
5
|
+
/**
|
|
6
|
+
* Is `--pm` spelled like a package manager we support? Availability validation
|
|
7
|
+
* calls this first, so an unknown executable is rejected before installation.
|
|
8
|
+
*/
|
|
9
|
+
function assertPackageManagerAllowed(requested) {
|
|
10
|
+
if (!requested) return;
|
|
11
|
+
if (!isValidPackageManager(requested)) {
|
|
12
|
+
cancel(`Unknown package manager "${requested}" — expected one of: ${ALLOWED_PACKAGE_MANAGERS.join(", ")}`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Is `--pm` spelled right AND actually on this machine? Every CLI path uses
|
|
18
|
+
* this stronger check before it selects a manager or begins scaffolding. The
|
|
19
|
+
* scaffold always installs dependencies; accepting a known-unavailable
|
|
20
|
+
* executable would leave a known partial project behind.
|
|
21
|
+
*
|
|
22
|
+
* `bun` is the case that makes this concrete. It is in
|
|
23
|
+
* {@link ALLOWED_PACKAGE_MANAGERS}, so the spelling check passes.
|
|
24
|
+
*
|
|
25
|
+
* MUST be called after package-manager detection has completed, since
|
|
26
|
+
* detection is what {@link getSystemPackageManagers} reports.
|
|
27
|
+
*/
|
|
28
|
+
function assertPackageManagerAvailable(requested) {
|
|
29
|
+
if (requested === void 0) return;
|
|
30
|
+
if (!requested.trim()) {
|
|
31
|
+
cancel("The --pm flag requires a package manager value (npm, yarn, pnpm, or bun).");
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
assertPackageManagerAllowed(requested);
|
|
35
|
+
const available = getSystemPackageManagers();
|
|
36
|
+
if (!available.includes(requested)) {
|
|
37
|
+
cancel(`Package manager "${requested}" was not found on this machine — detected: ${available.join(", ")}. Install it, or pass one of those to --pm.`);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { assertPackageManagerAvailable };
|
|
44
|
+
//# sourceMappingURL=assert-package-manager.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert-package-manager.mjs","names":[],"sources":["../../../../../../create-warlock/src/flags/assert-package-manager.ts"],"sourcesContent":["import { cancel } from \"@clack/prompts\";\nimport {\n ALLOWED_PACKAGE_MANAGERS,\n getSystemPackageManagers,\n isValidPackageManager,\n} from \"../helpers/package-manager\";\n\n/**\n * Is `--pm` spelled like a package manager we support? Availability validation\n * calls this first, so an unknown executable is rejected before installation.\n */\nexport function assertPackageManagerAllowed(\n requested: string | undefined,\n): void {\n if (!requested) return;\n\n if (!isValidPackageManager(requested)) {\n cancel(\n `Unknown package manager \"${requested}\" — expected one of: ${ALLOWED_PACKAGE_MANAGERS.join(\", \")}`,\n );\n process.exit(1);\n }\n}\n\n/**\n * Is `--pm` spelled right AND actually on this machine? Every CLI path uses\n * this stronger check before it selects a manager or begins scaffolding. The\n * scaffold always installs dependencies; accepting a known-unavailable\n * executable would leave a known partial project behind.\n *\n * `bun` is the case that makes this concrete. It is in\n * {@link ALLOWED_PACKAGE_MANAGERS}, so the spelling check passes.\n *\n * MUST be called after package-manager detection has completed, since\n * detection is what {@link getSystemPackageManagers} reports.\n */\nexport function assertPackageManagerAvailable(\n requested: string | undefined,\n): void {\n if (requested === undefined) return;\n\n if (!requested.trim()) {\n cancel(\n \"The --pm flag requires a package manager value (npm, yarn, pnpm, or bun).\",\n );\n process.exit(1);\n }\n\n assertPackageManagerAllowed(requested);\n\n const available = getSystemPackageManagers();\n\n if (!available.includes(requested)) {\n cancel(\n `Package manager \"${requested}\" was not found on this machine — detected: ${available.join(\", \")}. Install it, or pass one of those to --pm.`,\n );\n process.exit(1);\n }\n}\n"],"mappings":";;;;;;;;AAWA,SAAgB,4BACd,WACM;CACN,IAAI,CAAC,WAAW;CAEhB,IAAI,CAAC,sBAAsB,SAAS,GAAG;EACrC,OACE,4BAA4B,UAAU,uBAAuB,yBAAyB,KAAK,IAAI,GACjG;EACA,QAAQ,KAAK,CAAC;CAChB;AACF;;;;;;;;;;;;;AAcA,SAAgB,8BACd,WACM;CACN,IAAI,cAAc,QAAW;CAE7B,IAAI,CAAC,UAAU,KAAK,GAAG;EACrB,OACE,2EACF;EACA,QAAQ,KAAK,CAAC;CAChB;CAEA,4BAA4B,SAAS;CAErC,MAAM,YAAY,yBAAyB;CAE3C,IAAI,CAAC,UAAU,SAAS,SAAS,GAAG;EAClC,OACE,oBAAoB,UAAU,8CAA8C,UAAU,KAAK,IAAI,EAAE,4CACnG;EACA,QAAQ,KAAK,CAAC;CAChB;AACF"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { getAiPackageOptions, getAiProviderOptions } from "../features/features-map.mjs";
|
|
2
|
+
|
|
1
3
|
//#region ../create-warlock/src/flags/definitions.ts
|
|
4
|
+
const AI_FEATURE_KEYS = [...getAiProviderOptions(), ...getAiPackageOptions()].map(({ value }) => value);
|
|
2
5
|
const FLAG_DEFINITIONS = [
|
|
3
6
|
{
|
|
4
7
|
usage: "--name=<name>",
|
|
@@ -7,7 +10,7 @@ const FLAG_DEFINITIONS = [
|
|
|
7
10
|
},
|
|
8
11
|
{
|
|
9
12
|
usage: "--stack=<api|web>",
|
|
10
|
-
description: "API-only or full-stack web — the one structural choice that changes the app's shape",
|
|
13
|
+
description: "API-only or full-stack web — the one structural choice that changes the app's shape. Customizing everything else is a flow, not a stack: use --customize, where --stack=web arrives as a pre-ticked web feature",
|
|
11
14
|
defaultValue: "api"
|
|
12
15
|
},
|
|
13
16
|
{
|
|
@@ -22,7 +25,7 @@ const FLAG_DEFINITIONS = [
|
|
|
22
25
|
},
|
|
23
26
|
{
|
|
24
27
|
usage: "--ai=<list>",
|
|
25
|
-
description:
|
|
28
|
+
description: `Comma-separated AI provider or capability keys (${AI_FEATURE_KEYS.join(", ")})`,
|
|
26
29
|
defaultValue: "none"
|
|
27
30
|
},
|
|
28
31
|
{
|
|
@@ -51,8 +54,8 @@ const FLAG_DEFINITIONS = [
|
|
|
51
54
|
defaultValue: "false"
|
|
52
55
|
},
|
|
53
56
|
{
|
|
54
|
-
usage: "--
|
|
55
|
-
description: "
|
|
57
|
+
usage: "--customize, --interactive",
|
|
58
|
+
description: "Full long-form wizard — every choice asked one by one. Also selectable as \"Customize\" in the \"What are we building?\" menu. Any other flag you pass pre-selects its prompt; --yes is refused",
|
|
56
59
|
defaultValue: "false"
|
|
57
60
|
},
|
|
58
61
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.mjs","names":[],"sources":["../../../../../../create-warlock/src/flags/definitions.ts"],"sourcesContent":["/**\n * Single source of truth for every CLI flag's help text and default, so\n * `--help` can never drift out of sync with what the parser actually\n * understands (requirement: `--help` lists every flag together with its\n * default value).\n */\nexport type FlagDefinition = {\n /** How the flag reads on the command line, e.g. `--db=<driver>`. */\n usage: string;\n description: string;\n /** Human-readable default, or what happens when it is left unanswered. */\n defaultValue: string;\n};\n\nexport const FLAG_DEFINITIONS: FlagDefinition[] = [\n {\n usage: \"--name=<name>\",\n description: \"Project name (or pass it as the first positional arg)\",\n defaultValue
|
|
1
|
+
{"version":3,"file":"definitions.mjs","names":[],"sources":["../../../../../../create-warlock/src/flags/definitions.ts"],"sourcesContent":["import {\n getAiPackageOptions,\n getAiProviderOptions,\n} from \"../features/features-map\";\n\n/**\n * Single source of truth for every CLI flag's help text and default, so\n * `--help` can never drift out of sync with what the parser actually\n * understands (requirement: `--help` lists every flag together with its\n * default value).\n */\nexport type FlagDefinition = {\n /** How the flag reads on the command line, e.g. `--db=<driver>`. */\n usage: string;\n description: string;\n /** Human-readable default, or what happens when it is left unanswered. */\n defaultValue: string;\n};\n\nconst AI_FEATURE_KEYS = [\n ...getAiProviderOptions(),\n ...getAiPackageOptions(),\n].map(({ value }) => value);\n\nexport const FLAG_DEFINITIONS: FlagDefinition[] = [\n {\n usage: \"--name=<name>\",\n description: \"Project name (or pass it as the first positional arg)\",\n defaultValue:\n \"required — prompted if a TTY is available, otherwise fails naming this flag\",\n },\n {\n usage: \"--stack=<api|web>\",\n description:\n \"API-only or full-stack web — the one structural choice that changes the app's shape. Customizing everything else is a flow, not a stack: use --customize, where --stack=web arrives as a pre-ticked web feature\",\n defaultValue: \"api\",\n },\n {\n usage: \"--db=<driver> / --no-db\",\n description:\n \"Database driver (e.g. postgres, mongodb), or skip a database entirely\",\n defaultValue: \"mongodb\",\n },\n {\n usage: \"--features=<list>\",\n description: \"Comma-separated feature keys (e.g. test,herald)\",\n defaultValue:\n 'none (or [\"web\"] when --stack=web and --features is not given)',\n },\n {\n usage: \"--ai=<list>\",\n description: `Comma-separated AI provider or capability keys (${AI_FEATURE_KEYS.join(\", \")})`,\n defaultValue: \"none\",\n },\n {\n usage: \"--pm=<manager>\",\n description: \"Package manager to use (npm, yarn, pnpm, bun)\",\n defaultValue:\n \"inferred from the invoking agent (npm_config_user_agent) or the system\",\n },\n {\n usage: \"--agents=<list>\",\n description: \"Comma-separated agent-kit targets to derive docs/skills for\",\n defaultValue: \"claude\",\n },\n {\n usage: \"--git / --no-git\",\n description: \"Force-enable or force-disable git initialization\",\n defaultValue: \"false\",\n },\n {\n usage: \"--jwt / --no-jwt\",\n description: \"Force-enable or force-disable JWT secret generation\",\n defaultValue: \"false\",\n },\n {\n usage: \"-y, --yes\",\n description: \"Skip every prompt and accept defaults for anything unset\",\n defaultValue: \"false\",\n },\n {\n usage: \"--customize, --interactive\",\n description:\n 'Full long-form wizard — every choice asked one by one. Also selectable as \"Customize\" in the \"What are we building?\" menu. Any other flag you pass pre-selects its prompt; --yes is refused',\n defaultValue: \"false\",\n },\n {\n usage: \"-h, --help\",\n description: \"Show this help message and exit\",\n defaultValue: \"n/a\",\n },\n {\n usage: \"-v, --version\",\n description: \"Show the installed create-warlock version and exit\",\n defaultValue: \"n/a\",\n },\n];\n\n/** Render the full `--help` text, one line per flag with its default. */\nexport function buildHelpText(): string {\n const rows = FLAG_DEFINITIONS.map(({ usage, description, defaultValue }) => {\n const label = usage.padEnd(28);\n return ` ${label}${description} (default: ${defaultValue})`;\n }).join(\"\\n\");\n\n return `\n create-warlock — scaffold a new Warlock.js project\n\n Usage\n $ create-warlock [project-name] [options]\n\n Options\n${rows}\n\n Example\n $ create-warlock my-app --db=postgres --features=test,herald --yes\n`;\n}\n"],"mappings":";;;AAmBA,MAAM,kBAAkB,CACtB,GAAG,qBAAqB,GACxB,GAAG,oBAAoB,CACzB,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK;AAE1B,MAAa,mBAAqC;CAChD;EACE,OAAO;EACP,aAAa;EACb,cACE;CACJ;CACA;EACE,OAAO;EACP,aACE;EACF,cAAc;CAChB;CACA;EACE,OAAO;EACP,aACE;EACF,cAAc;CAChB;CACA;EACE,OAAO;EACP,aAAa;EACb,cACE;CACJ;CACA;EACE,OAAO;EACP,aAAa,mDAAmD,gBAAgB,KAAK,IAAI,EAAE;EAC3F,cAAc;CAChB;CACA;EACE,OAAO;EACP,aAAa;EACb,cACE;CACJ;CACA;EACE,OAAO;EACP,aAAa;EACb,cAAc;CAChB;CACA;EACE,OAAO;EACP,aAAa;EACb,cAAc;CAChB;CACA;EACE,OAAO;EACP,aAAa;EACb,cAAc;CAChB;CACA;EACE,OAAO;EACP,aAAa;EACb,cAAc;CAChB;CACA;EACE,OAAO;EACP,aACE;EACF,cAAc;CAChB;CACA;EACE,OAAO;EACP,aAAa;EACb,cAAc;CAChB;CACA;EACE,OAAO;EACP,aAAa;EACb,cAAc;CAChB;AACF;;AAGA,SAAgB,gBAAwB;CAMtC,OAAO;;;;;;;EALM,iBAAiB,KAAK,EAAE,OAAO,aAAa,mBAAmB;EAE1E,OAAO,OADO,MAAM,OAAO,EACT,IAAI,YAAY,aAAa,aAAa;CAC9D,CAAC,CAAC,CAAC,KAAK,IASL,EAAE;;;;;AAKP"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getDefaultFeatureKeys } from "../features/features-map.mjs";
|
|
2
|
+
import { getPreferredPackageManager } from "../helpers/package-manager.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../create-warlock/src/flags/seed-from-flags.ts
|
|
5
|
+
function seedFromFlags(cli) {
|
|
6
|
+
return {
|
|
7
|
+
packageManager: cli.pm ?? getPreferredPackageManager(),
|
|
8
|
+
databaseDriver: cli.db,
|
|
9
|
+
features: cli.features ?? defaultFeatures(cli),
|
|
10
|
+
aiProviders: cli.ai ?? [],
|
|
11
|
+
useGit: cli.git ?? true,
|
|
12
|
+
useJWT: cli.jwt ?? true
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* `--stack=web` is the one structural answer, and the wizard has no stack
|
|
17
|
+
* question of its own — it asks for features instead. So the stack arrives as
|
|
18
|
+
* a pre-ticked `web` feature rather than being dropped on the floor.
|
|
19
|
+
*/
|
|
20
|
+
function defaultFeatures(cli) {
|
|
21
|
+
const defaults = getDefaultFeatureKeys();
|
|
22
|
+
if (cli.stack !== "web") return defaults;
|
|
23
|
+
return [...new Set([...defaults, "web"])];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { seedFromFlags };
|
|
28
|
+
//# sourceMappingURL=seed-from-flags.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed-from-flags.mjs","names":[],"sources":["../../../../../../create-warlock/src/flags/seed-from-flags.ts"],"sourcesContent":["import type { CliFlags } from \"../commands/create-new-app/types\";\nimport { getDefaultFeatureKeys } from \"../features/features-map\";\nimport { getPreferredPackageManager } from \"../helpers/package-manager\";\n\n/**\n * The wizard's prompts, pre-selected from whatever the user already spelled\n * out on the command line.\n *\n * Before this existed, `--customize --db=postgres` silently threw the driver\n * away: the wizard asked its own question with its own default and the flag\n * never reached anything. A flag that is accepted and then ignored is the\n * worst of both worlds — the run succeeds, and the answer is wrong.\n *\n * So a flag passed alongside `--customize` is not a contradiction to refuse,\n * it is an answer given early: the prompt opens on that value and the user\n * can still change it.\n */\nexport type WizardSeeds = {\n packageManager: string;\n databaseDriver: string | undefined;\n features: string[];\n aiProviders: string[];\n useGit: boolean;\n useJWT: boolean;\n};\n\nexport function seedFromFlags(cli: CliFlags): WizardSeeds {\n return {\n packageManager: cli.pm ?? getPreferredPackageManager(),\n databaseDriver: cli.db,\n features: cli.features ?? defaultFeatures(cli),\n aiProviders: cli.ai ?? [],\n // clack's confirm opens on `true` when nothing is passed, which is the\n // behaviour these two prompts already had.\n useGit: cli.git ?? true,\n useJWT: cli.jwt ?? true,\n };\n}\n\n/**\n * `--stack=web` is the one structural answer, and the wizard has no stack\n * question of its own — it asks for features instead. So the stack arrives as\n * a pre-ticked `web` feature rather than being dropped on the floor.\n */\nfunction defaultFeatures(cli: CliFlags): string[] {\n const defaults = getDefaultFeatureKeys();\n\n if (cli.stack !== \"web\") return defaults;\n\n return [...new Set([...defaults, \"web\"])];\n}\n"],"mappings":";;;;AA0BA,SAAgB,cAAc,KAA4B;CACxD,OAAO;EACL,gBAAgB,IAAI,MAAM,2BAA2B;EACrD,gBAAgB,IAAI;EACpB,UAAU,IAAI,YAAY,gBAAgB,GAAG;EAC7C,aAAa,IAAI,MAAM,CAAC;EAGxB,QAAQ,IAAI,OAAO;EACnB,QAAQ,IAAI,OAAO;CACrB;AACF;;;;;;AAOA,SAAS,gBAAgB,KAAyB;CAChD,MAAM,WAAW,sBAAsB;CAEvC,IAAI,IAAI,UAAU,OAAO,OAAO;CAEhC,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,UAAU,KAAK,CAAC,CAAC;AAC1C"}
|
package/esm/helpers/app.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getDatabaseDriver } from "../features/database-drivers.mjs";
|
|
2
|
+
import { getPackageManager } from "./package-manager.mjs";
|
|
2
3
|
import { executeCommand, runCommand } from "./exec.mjs";
|
|
3
4
|
import { insertImportInSortedPosition } from "./insert-import.mjs";
|
|
4
|
-
import { getPackageManager } from "./package-manager.mjs";
|
|
5
5
|
import { packageRoot, template } from "./paths.mjs";
|
|
6
6
|
import { fallbackRange } from "./warlock-versions.mjs";
|
|
7
7
|
import { copyDirectory, copyFile, fileExists, getFile, getJsonFile, putFile, putJsonFile, renameFile } from "@warlock.js/fs";
|
|
@@ -186,8 +186,11 @@ var App = class {
|
|
|
186
186
|
"src/shared/contact.schema.ts",
|
|
187
187
|
"src/shared/locale.schema.ts",
|
|
188
188
|
"src/shared/locales.ts",
|
|
189
|
-
"postcss.config.mjs"
|
|
189
|
+
"postcss.config.mjs",
|
|
190
|
+
"skills/web-code-standards"
|
|
190
191
|
]) remove(entry);
|
|
192
|
+
const agentsPath = path.resolve(this.path, "AGENTS.md");
|
|
193
|
+
putFile(agentsPath, getFile(agentsPath).replace(/^.*\*\*web-code-standards\*\*.*\r?\n/m, ""));
|
|
191
194
|
const tsconfigPath = path.resolve(this.path, "tsconfig.json");
|
|
192
195
|
putFile(tsconfigPath, getFile(tsconfigPath).replace(" \"web/*\": [\"./src/web/*\"],\n", "").replace(" \"@shared/*\": [\"./src/shared/*\"]\n", ""));
|
|
193
196
|
return this;
|
package/esm/helpers/app.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.mjs","names":[],"sources":["../../../../../../create-warlock/src/helpers/app.ts"],"sourcesContent":["import {\r\n copyDirectory,\r\n copyFile,\r\n fileExists,\r\n getFile,\r\n getJsonFile,\r\n putFile,\r\n putJsonFile,\r\n renameFile,\r\n} from \"@warlock.js/fs\";\r\nimport { existsSync, rmSync, unlinkSync } from \"node:fs\";\r\nimport path from \"path\";\r\nimport { Application, AppOptions } from \"../commands/create-new-app/types\";\r\nimport { getDatabaseDriver } from \"../features/database-drivers\";\r\nimport { executeCommand, runCommand } from \"./exec\";\r\nimport { insertImportInSortedPosition } from \"./insert-import\";\r\nimport { getPackageManager } from \"./package-manager\";\r\nimport { packageRoot, Template, template } from \"./paths\";\r\nimport { fallbackRange } from \"./warlock-versions\";\r\n\r\n/**\r\n * Environment for every install the scaffolder spawns.\r\n *\r\n * A shell that exports `NODE_ENV=production` makes the package managers skip\r\n * every devDependency — and still exit 0. The scaffolded project needs its dev\r\n * toolchain (typescript, vitest, eslint) to be usable at all, so the install\r\n * child is pinned to `development` regardless of the ambient environment. A\r\n * silently incomplete install that reports success is the exact failure mode\r\n * this file exists to prevent.\r\n */\r\nexport function installEnvironment(): NodeJS.ProcessEnv {\r\n return { NODE_ENV: \"development\" };\r\n}\r\n\r\nexport class App {\r\n /**\r\n * Resolved files\r\n */\r\n protected files: Record<string, FileManager> = {};\r\n\r\n /**\r\n * Resolved JSON files\r\n */\r\n protected jsonFiles: Record<string, JsonFileManager> = {};\r\n\r\n public isInstalled = false;\r\n\r\n public constructor(protected app: Application) {}\r\n\r\n public get options(): AppOptions {\r\n return this.app.options;\r\n }\r\n\r\n public use(templateName: Template) {\r\n copyDirectory(template(templateName), this.path);\r\n\r\n if (fileExists(this.path + \"/.env.example\")) {\r\n copyFile(this.path + \"/.env.example\", this.path + \"/.env\");\r\n }\r\n\r\n renameFile(this.path + \"/_.gitignore\", this.path + \"/.gitignore\");\r\n\r\n return this;\r\n }\r\n\r\n public init() {\r\n return this;\r\n }\r\n\r\n public terminate() {\r\n // No longer using outro, using showSuccessScreen instead\r\n }\r\n\r\n public install() {\r\n return runCommand(getPackageManager(), [\"install\"], this.path, {\r\n env: installEnvironment(),\r\n });\r\n }\r\n\r\n public async exec(command: string) {\r\n const [commandName, ...optionsList] = command.split(\" \");\r\n return await executeCommand(commandName, optionsList, this.path);\r\n }\r\n\r\n public async git() {\r\n const { initializeGitRepository } =\r\n await import(\"./project-builder-helpers\");\r\n return await initializeGitRepository(this.path);\r\n }\r\n\r\n /**\r\n * Write the project's `package.json`: the project name, the chosen package\r\n * manager, and the version of every `@warlock.js/*` dependency.\r\n *\r\n * `versions` comes from {@link resolveWarlockVersions} — versions the\r\n * registry has confirmed exist. It is optional because the fluent chain is\r\n * synchronous; without it every sibling gets the caret range floored to the\r\n * scaffolder's major, which is always satisfiable by a published release.\r\n *\r\n * What it must NEVER do again is stamp the scaffolder's own version blind:\r\n * the release tooling bumps that version on every build, published or not,\r\n * so an unverified pin resolves to nothing and the install dies with ETARGET.\r\n */\r\n public updatePackageJson(versions: Record<string, string> = {}) {\r\n const packageManager = getPackageManager();\r\n\r\n const pkg = this.package.replace(\"name\", this.name.replaceAll(\"/\", \"-\"));\r\n\r\n const content: any = pkg.content;\r\n\r\n // Substitute the chosen package manager ONLY into the fields the template\r\n // writes it into literally — the `serve` script — by path, never with a\r\n // blanket substring replace over the serialized JSON. A raw\r\n // `replaceAll(\"yarn\", pm)` rewrites every occurrence of the substring\r\n // \"yarn\" anywhere in the document, so a project named `my-yarn-app`, or any\r\n // dependency/path containing \"yarn\", is silently corrupted (`--pm=npm`\r\n // turned `my-yarn-app` into `my-npm-app`). Field-scoped rewriting is also\r\n // order-independent: the name lives in `content.name` and this token lives\r\n // in `scripts.serve`, a disjoint field that cannot collide with the name\r\n // substitution above regardless of which runs first.\r\n if (typeof content.scripts?.serve === \"string\") {\r\n content.scripts.serve = content.scripts.serve.replaceAll(\r\n \"yarn\",\r\n packageManager,\r\n );\r\n }\r\n\r\n const warlockVersion: string = (\r\n getJsonFile(packageRoot(\"package.json\")) as { version: string }\r\n ).version;\r\n const defaultRange = fallbackRange(warlockVersion);\r\n\r\n for (const field of [\"dependencies\", \"devDependencies\"] as const) {\r\n const deps = content[field] as Record<string, string> | undefined;\r\n if (!deps) continue;\r\n\r\n for (const dependency of Object.keys(deps)) {\r\n if (dependency.startsWith(\"@warlock.js/\")) {\r\n deps[dependency] = versions[dependency] ?? defaultRange;\r\n }\r\n }\r\n }\r\n\r\n pkg.save();\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Configure the chosen database driver: wire `DB_DRIVER` / `DB_PORT` into\r\n * `.env`, AND pin the driver's npm package (`mongodb` / `pg`) into the\r\n * project's `package.json` dependencies.\r\n *\r\n * The dependency is written HERE — before the base `yarn install` — so the\r\n * driver is pulled deterministically by the very first install. We do NOT\r\n * rely on the post-copy `warlock add <driver> --no-install` + separate\r\n * batched install, which can be skipped or fail and leave the driver\r\n * missing (the \"mongodb package is not installed\" runtime error).\r\n */\r\n public configureDatabaseEnv(driverValue: string) {\r\n const driver = getDatabaseDriver(driverValue);\r\n\r\n if (!driver) return this;\r\n\r\n // Pin the driver package into dependencies (idempotent — never downgrade).\r\n const packageJsonPath = path.resolve(this.path, \"package.json\");\r\n const packageJson = getJsonFile(packageJsonPath) as {\r\n dependencies?: Record<string, string>;\r\n };\r\n packageJson.dependencies = packageJson.dependencies ?? {};\r\n if (!packageJson.dependencies[driver.package]) {\r\n packageJson.dependencies[driver.package] = driver.packageVersion;\r\n putJsonFile(packageJsonPath, packageJson);\r\n }\r\n\r\n let envContent = getFile(this.path + \"/.env\") as string;\r\n\r\n envContent = envContent.replace(\r\n /DB_PORT=\\d+/,\r\n `DB_PORT=${driver.defaultPort}`,\r\n );\r\n\r\n if (envContent.includes(\"DB_DRIVER=\")) {\r\n envContent = envContent.replace(\r\n /DB_DRIVER=\\w*/,\r\n `DB_DRIVER=${driver.value}`,\r\n );\r\n } else {\r\n envContent = envContent.replace(\r\n /DB_PORT=\\d+/,\r\n `DB_PORT=${driver.defaultPort}\\nDB_DRIVER=${driver.value}`,\r\n );\r\n }\r\n\r\n putFile(this.path + \"/.env\", envContent);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Write the correct `src/config/database.ts` for the chosen driver and remove\r\n * every per-driver variant so the scaffold ships exactly one config file.\r\n *\r\n * The template ships a Mongo-shaped `database.ts` (the default) plus a\r\n * `database.postgres.ts` variant. Mongo keeps the default in place; Postgres\r\n * overwrites `database.ts` with the Postgres-shaped variant (typed\r\n * `ConnectionOptions`, `driver: \"postgres\"`, port 5432, no Mongo-only keys —\r\n * no `authSource`, `driverOptions`, `replicaSet`, `randomIncrement` /\r\n * `initialId`). Either way the `.postgres` variant file is deleted afterwards\r\n * so no leftover config ships in the generated project.\r\n *\r\n * For Postgres it also corrects the working `.env`: the Mongo template ships\r\n * `DB_AUTH=admin`, an `authSource` value Postgres ignores and its config no\r\n * longer reads, so the line is dropped to keep `.env` and the config in sync.\r\n * The port is rewritten by {@link configureDatabaseEnv} (driver defaultPort),\r\n * which runs alongside this in the same branch.\r\n */\r\n public configureDatabaseConfig(driverValue: string) {\r\n const configDir = path.resolve(this.path, \"src/config\");\r\n const databasePath = path.resolve(configDir, \"database.ts\");\r\n const postgresVariantPath = path.resolve(configDir, \"database.postgres.ts\");\r\n\r\n if (driverValue === \"postgres\" && fileExists(postgresVariantPath)) {\r\n putFile(databasePath, getFile(postgresVariantPath) as string);\r\n\r\n const envPath = this.path + \"/.env\";\r\n\r\n if (fileExists(envPath)) {\r\n const envContent = getFile(envPath) as string;\r\n // Drop the Mongo-only DB_AUTH line entirely (its whole line, so no blank\r\n // gap is left behind). Postgres has no authSource concept.\r\n putFile(envPath, envContent.replace(/^DB_AUTH=.*\\r?\\n?/m, \"\"));\r\n }\r\n }\r\n\r\n // Whatever the driver, no per-driver variant may survive into the scaffold.\r\n if (fileExists(postgresVariantPath)) {\r\n unlinkSync(postgresVariantPath);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove the database layer for a \"no database\" scaffold.\r\n *\r\n * Deletes `src/config/database.ts` (and a `.tsx` / per-driver variant if\r\n * present) from the freshly-copied template. The framework's database\r\n * connector is config-gated on that file — with it gone,\r\n * `config.get(\"database\")` is undefined and the connector no-ops, so the app\r\n * boots with no database wired and no driver package pulled. The `DB_*` lines\r\n * in `.env` are left in place (harmless: no config reads them) as a ready\r\n * template for adding a database back later.\r\n */\r\n public removeDatabaseConfig() {\r\n const configDir = path.resolve(this.path, \"src/config\");\r\n\r\n for (const fileName of [\r\n \"database.ts\",\r\n \"database.tsx\",\r\n \"database.postgres.ts\",\r\n ]) {\r\n const filePath = path.resolve(configDir, fileName);\r\n\r\n if (fileExists(filePath)) {\r\n unlinkSync(filePath);\r\n }\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Configure the web starter only when the web feature owns `/`.\r\n *\r\n * A dependency-free HTTP response is retained without web; otherwise the\r\n * SSR page loader owns the route.\r\n * Exactly one survives the scaffold: web projects keep the SSR page and API\r\n * example; every other project keeps the dependency-free JSON controller.\r\n */\r\n public configureWebStarter(useWeb: boolean) {\r\n const remove = (relativePath: string) => {\r\n const target = path.resolve(this.path, relativePath);\r\n if (existsSync(target)) rmSync(target, { recursive: true, force: true });\r\n };\r\n\r\n if (!useWeb) {\r\n for (const entry of [\r\n \"src/web\",\r\n \"src/app/contact\",\r\n \"src/app/locale\",\r\n \"src/shared/contact.schema.ts\",\r\n \"src/shared/locale.schema.ts\",\r\n \"src/shared/locales.ts\",\r\n \"postcss.config.mjs\",\r\n ]) {\r\n remove(entry);\r\n }\r\n\r\n const tsconfigPath = path.resolve(this.path, \"tsconfig.json\");\r\n const tsconfig = getFile(tsconfigPath) as string;\r\n putFile(\r\n tsconfigPath,\r\n tsconfig\r\n .replace(' \"web/*\": [\"./src/web/*\"],\\n', \"\")\r\n .replace(' \"@shared/*\": [\"./src/shared/*\"]\\n', \"\"),\r\n );\r\n\r\n return this;\r\n }\r\n\r\n // The SSR page owns `/`; its loader still uses src/app/home/services.\r\n remove(\"src/app/home/controllers/home-page.controller.ts\");\r\n remove(\"src/app/home/routes.ts\");\r\n\r\n const packageJsonPath = path.resolve(this.path, \"package.json\");\r\n const packageJson = getJsonFile(packageJsonPath) as {\r\n dependencies?: Record<string, string>;\r\n devDependencies?: Record<string, string>;\r\n };\r\n packageJson.dependencies = {\r\n ...packageJson.dependencies,\r\n \"@mongez/http\": \"^3.5.0\",\r\n \"@mongez/react-form\": \"^4.0.0\",\r\n };\r\n packageJson.devDependencies = {\r\n ...packageJson.devDependencies,\r\n \"@tailwindcss/postcss\": \"^4.1.16\",\r\n tailwindcss: \"^4.1.16\",\r\n };\r\n putJsonFile(packageJsonPath, packageJson);\r\n\r\n const configPath = path.resolve(this.path, \"warlock.config.ts\");\r\n const config = getFile(configPath) as string;\r\n if (!config.includes('\"@warlock.js/web/connector\"')) {\r\n // Inserted in sorted position, not prepended. The generated app formats\r\n // with `prettier-plugin-organize-imports`, so an import pushed to the top\r\n // of a file that already imports `@warlock.js/auth` and `@warlock.js/core`\r\n // is out of order the moment it is written — and the developer meets it as\r\n // a `prettier/prettier` error on their first `warlock dev`, in a file they\r\n // did not write.\r\n const withConnector = insertImportInSortedPosition(\r\n config,\r\n 'import { webConnector } from \"@warlock.js/web/connector\";',\r\n \"@warlock.js/web/connector\",\r\n );\r\n\r\n putFile(\r\n configPath,\r\n withConnector.replace(\r\n \"export default defineConfig({\",\r\n \"export default defineConfig({\\n connectors: [webConnector()],\",\r\n ),\r\n );\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Record non-default `agent-kit` targets into the generated `package.json`'s\r\n * `agentKit.targets` block.\r\n *\r\n * The template's own `postinstall` (`agent-kit init && agent-kit sync`)\r\n * already targets `claude` with no flags, so the single-target default case\r\n * needs no template edit at all — this only writes when the selection is\r\n * anything else, keeping the scaffold diff-free for the common path.\r\n */\r\n public configureAgentKitTargets(agents: string[]) {\r\n const isDefault = agents.length === 1 && agents[0] === \"claude\";\r\n if (isDefault) return this;\r\n\r\n const packageJsonPath = path.resolve(this.path, \"package.json\");\r\n if (!fileExists(packageJsonPath)) return this;\r\n\r\n const packageJson = getJsonFile(packageJsonPath) as {\r\n agentKit?: { targets?: string[] };\r\n };\r\n packageJson.agentKit = { ...packageJson.agentKit, targets: agents };\r\n putJsonFile(packageJsonPath, packageJson);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Install the selected optional features by delegating to the project's own\r\n * `warlock add`. `--no-install` records every dependency in package.json and\r\n * ejects configs / scripts / setup hooks WITHOUT installing — the caller runs\r\n * one batched install afterwards. Versions come from core's feature map, so\r\n * the scaffolder never duplicates them.\r\n *\r\n * `--no-install` is passed LAST on purpose: the CLI parser treats the\r\n * positional after a bare flag as that flag's value, so it must follow the\r\n * feature list, not precede it.\r\n */\r\n public async installFeatures(features: string[]) {\r\n if (features.length === 0) return true;\r\n\r\n return this.exec(`npx warlock add ${features.join(\" \")} --no-install`);\r\n }\r\n\r\n /**\r\n * Force a single copy of `vite` when the project ends up with BOTH `vite`\r\n * (written by the `web` feature) and `vitest` (always in the template).\r\n *\r\n * `vitest` depends on vite through a wide range of its own\r\n * (`^6 || ^7 || ^8`), which resolves to a DIFFERENT major than the range the\r\n * feature map pins. Yarn 1 then has to nest the second copy under\r\n * `vitest/node_modules` and dies on its own linker invariant:\r\n *\r\n * error Invariant Violation: could not find a copy of vite to link in\r\n * <project>/node_modules/vitest/node_modules\r\n *\r\n * It aborts BEFORE `node_modules/.bin` is written, so `warlock` is never\r\n * linked and the very first `yarn dev` fails with \"'warlock' is not\r\n * recognized\". npm and pnpm nest happily and never hit this — for them the\r\n * `overrides` twin below is one copy instead of two, not a crash fix.\r\n *\r\n * The pin is READ BACK from whatever range the project's own package.json\r\n * declares, never re-stated as a literal here: the feature map in\r\n * `@warlock.js/core` owns the version, and a second copy of it would drift\r\n * the moment that one moves.\r\n *\r\n * Returns whether a pin was written, so the caller (and its spec) can assert\r\n * it instead of assuming it.\r\n */\r\n public pinViteResolution() {\r\n const packageJsonPath = path.resolve(this.path, \"package.json\");\r\n\r\n if (!fileExists(packageJsonPath)) return false;\r\n\r\n const packageJson = getJsonFile(packageJsonPath) as {\r\n dependencies?: Record<string, string>;\r\n devDependencies?: Record<string, string>;\r\n resolutions?: Record<string, string>;\r\n overrides?: Record<string, string>;\r\n };\r\n\r\n const declaredRange = (name: string) =>\r\n packageJson.dependencies?.[name] ?? packageJson.devDependencies?.[name];\r\n\r\n const viteRange = declaredRange(\"vite\");\r\n\r\n // No vite, or no vitest to conflict with it — nothing to pin. Writing a\r\n // resolution for a package the project does not depend on would only\r\n // freeze a transitive tree nobody asked us to freeze.\r\n if (!viteRange || !declaredRange(\"vitest\")) return false;\r\n\r\n // yarn 1 / yarn berry read `resolutions`; npm 8+ and pnpm read `overrides`.\r\n packageJson.resolutions = { ...packageJson.resolutions, vite: viteRange };\r\n packageJson.overrides = { ...packageJson.overrides, vite: viteRange };\r\n\r\n putJsonFile(packageJsonPath, packageJson);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Get package json file\r\n */\r\n public get package() {\r\n return this.json(\"package.json\");\r\n }\r\n\r\n public updateDotEnv() {\r\n this.file(\".env\").replaceAll(\"appName\", this.name).save();\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Get env file to update\r\n */\r\n public get env() {\r\n return this.file(\".env\");\r\n }\r\n\r\n public get name() {\r\n return this.app.appName;\r\n }\r\n\r\n public get path() {\r\n return this.app.appPath;\r\n }\r\n\r\n public file(relativePath: string) {\r\n const fullPath = path.resolve(this.path, relativePath);\r\n\r\n if (!this.files[fullPath]) {\r\n this.files[fullPath] = file(fullPath);\r\n }\r\n\r\n return this.files[fullPath];\r\n }\r\n\r\n public json(relativePath: string): JsonFileManager {\r\n const fullPath = path.resolve(this.path, relativePath);\r\n\r\n if (!this.jsonFiles[fullPath]) {\r\n this.jsonFiles[fullPath] = jsonFile(fullPath);\r\n }\r\n\r\n return this.jsonFiles[fullPath];\r\n }\r\n}\r\n\r\nexport function app(app: Application) {\r\n return new App(app);\r\n}\r\n\r\nexport class FileManager {\r\n public content!: string;\r\n public constructor(protected filePath: string) {\r\n this.parseContent();\r\n }\r\n\r\n protected parseContent() {\r\n this.content = getFile(this.filePath) as string;\r\n }\r\n\r\n public replace(search: string, replace: string) {\r\n this.content = this.content.replace(search, replace);\r\n\r\n return this;\r\n }\r\n\r\n public replaceAll(search: string, replace: string) {\r\n this.content = this.content.replaceAll(search, replace);\r\n\r\n return this;\r\n }\r\n\r\n public save() {\r\n putFile(this.filePath, this.content);\r\n }\r\n}\r\n\r\nexport class JsonFileManager extends FileManager {\r\n protected parseContent() {\r\n this.content = getJsonFile(this.filePath);\r\n }\r\n\r\n public save() {\r\n putJsonFile(this.filePath, this.content);\r\n }\r\n\r\n public has(key: string) {\r\n return this.content[key] !== undefined;\r\n }\r\n\r\n public replace(key: string, value: any) {\r\n this.content[key] = value;\r\n\r\n return this;\r\n }\r\n\r\n public replaceAll(key: string, value: any) {\r\n const contentAsString = JSON.stringify(this.content);\r\n\r\n this.content = JSON.parse(contentAsString.replaceAll(key, value));\r\n\r\n return this;\r\n }\r\n}\r\n\r\nexport function file(path: string) {\r\n return new FileManager(path);\r\n}\r\n\r\nexport function jsonFile(path: string) {\r\n return new JsonFileManager(path);\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,qBAAwC;CACtD,OAAO,EAAE,UAAU,cAAc;AACnC;AAEA,IAAa,MAAb,MAAiB;CAaf,AAAO,YAAY,AAAU,KAAkB;EAAlB;eATkB,CAAC;mBAKO,CAAC;qBAEnC;CAE2B;CAEhD,IAAW,UAAsB;EAC/B,OAAO,KAAK,IAAI;CAClB;CAEA,AAAO,IAAI,cAAwB;EACjC,cAAc,SAAS,YAAY,GAAG,KAAK,IAAI;EAE/C,IAAI,WAAW,KAAK,OAAO,eAAe,GACxC,SAAS,KAAK,OAAO,iBAAiB,KAAK,OAAO,OAAO;EAG3D,WAAW,KAAK,OAAO,gBAAgB,KAAK,OAAO,aAAa;EAEhE,OAAO;CACT;CAEA,AAAO,OAAO;EACZ,OAAO;CACT;CAEA,AAAO,YAAY,CAEnB;CAEA,AAAO,UAAU;EACf,OAAO,WAAW,kBAAkB,GAAG,CAAC,SAAS,GAAG,KAAK,MAAM,EAC7D,KAAK,mBAAmB,EAC1B,CAAC;CACH;CAEA,MAAa,KAAK,SAAiB;EACjC,MAAM,CAAC,aAAa,GAAG,eAAe,QAAQ,MAAM,GAAG;EACvD,OAAO,MAAM,eAAe,aAAa,aAAa,KAAK,IAAI;CACjE;CAEA,MAAa,MAAM;EACjB,MAAM,EAAE,4BACN,MAAM,OAAO;EACf,OAAO,MAAM,wBAAwB,KAAK,IAAI;CAChD;;;;;;;;;;;;;;CAeA,A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O;CACT;CAEA,AAAO,OAAO;EACZ,QAAQ,KAAK,UAAU,KAAK,OAAO;CACrC;AACF;AAEA,IAAa,kBAAb,cAAqC,YAAY;CAC/C,AAAU,eAAe;EACvB,KAAK,UAAU,YAAY,KAAK,QAAQ;CAC1C;CAEA,AAAO,OAAO;EACZ,YAAY,KAAK,UAAU,KAAK,OAAO;CACzC;CAEA,AAAO,IAAI,KAAa;EACtB,OAAO,KAAK,QAAQ,SAAS;CAC/B;CAEA,AAAO,QAAQ,KAAa,OAAY;EACtC,KAAK,QAAQ,OAAO;EAEpB,OAAO;CACT;CAEA,AAAO,WAAW,KAAa,OAAY;EACzC,MAAM,kBAAkB,KAAK,UAAU,KAAK,OAAO;EAEnD,KAAK,UAAU,KAAK,MAAM,gBAAgB,WAAW,KAAK,KAAK,CAAC;EAEhE,OAAO;CACT;AACF;AAEA,SAAgB,KAAK,MAAc;CACjC,OAAO,IAAI,YAAY,IAAI;AAC7B;AAEA,SAAgB,SAAS,MAAc;CACrC,OAAO,IAAI,gBAAgB,IAAI;AACjC"}
|
|
1
|
+
{"version":3,"file":"app.mjs","names":[],"sources":["../../../../../../create-warlock/src/helpers/app.ts"],"sourcesContent":["import {\r\n copyDirectory,\r\n copyFile,\r\n fileExists,\r\n getFile,\r\n getJsonFile,\r\n putFile,\r\n putJsonFile,\r\n renameFile,\r\n} from \"@warlock.js/fs\";\r\nimport { existsSync, rmSync, unlinkSync } from \"node:fs\";\r\nimport path from \"path\";\r\nimport { Application, AppOptions } from \"../commands/create-new-app/types\";\r\nimport { getDatabaseDriver } from \"../features/database-drivers\";\r\nimport { executeCommand, runCommand } from \"./exec\";\r\nimport { insertImportInSortedPosition } from \"./insert-import\";\r\nimport { getPackageManager } from \"./package-manager\";\r\nimport { packageRoot, Template, template } from \"./paths\";\r\nimport { fallbackRange } from \"./warlock-versions\";\r\n\r\n/**\r\n * Environment for every install the scaffolder spawns.\r\n *\r\n * A shell that exports `NODE_ENV=production` makes the package managers skip\r\n * every devDependency — and still exit 0. The scaffolded project needs its dev\r\n * toolchain (typescript, vitest, eslint) to be usable at all, so the install\r\n * child is pinned to `development` regardless of the ambient environment. A\r\n * silently incomplete install that reports success is the exact failure mode\r\n * this file exists to prevent.\r\n */\r\nexport function installEnvironment(): NodeJS.ProcessEnv {\r\n return { NODE_ENV: \"development\" };\r\n}\r\n\r\nexport class App {\r\n /**\r\n * Resolved files\r\n */\r\n protected files: Record<string, FileManager> = {};\r\n\r\n /**\r\n * Resolved JSON files\r\n */\r\n protected jsonFiles: Record<string, JsonFileManager> = {};\r\n\r\n public isInstalled = false;\r\n\r\n public constructor(protected app: Application) {}\r\n\r\n public get options(): AppOptions {\r\n return this.app.options;\r\n }\r\n\r\n public use(templateName: Template) {\r\n copyDirectory(template(templateName), this.path);\r\n\r\n if (fileExists(this.path + \"/.env.example\")) {\r\n copyFile(this.path + \"/.env.example\", this.path + \"/.env\");\r\n }\r\n\r\n renameFile(this.path + \"/_.gitignore\", this.path + \"/.gitignore\");\r\n\r\n return this;\r\n }\r\n\r\n public init() {\r\n return this;\r\n }\r\n\r\n public terminate() {\r\n // No longer using outro, using showSuccessScreen instead\r\n }\r\n\r\n public install() {\r\n return runCommand(getPackageManager(), [\"install\"], this.path, {\r\n env: installEnvironment(),\r\n });\r\n }\r\n\r\n public async exec(command: string) {\r\n const [commandName, ...optionsList] = command.split(\" \");\r\n return await executeCommand(commandName, optionsList, this.path);\r\n }\r\n\r\n public async git() {\r\n const { initializeGitRepository } =\r\n await import(\"./project-builder-helpers\");\r\n return await initializeGitRepository(this.path);\r\n }\r\n\r\n /**\r\n * Write the project's `package.json`: the project name, the chosen package\r\n * manager, and the version of every `@warlock.js/*` dependency.\r\n *\r\n * `versions` comes from {@link resolveWarlockVersions} — versions the\r\n * registry has confirmed exist. It is optional because the fluent chain is\r\n * synchronous; without it every sibling gets the caret range floored to the\r\n * scaffolder's major, which is always satisfiable by a published release.\r\n *\r\n * What it must NEVER do again is stamp the scaffolder's own version blind:\r\n * the release tooling bumps that version on every build, published or not,\r\n * so an unverified pin resolves to nothing and the install dies with ETARGET.\r\n */\r\n public updatePackageJson(versions: Record<string, string> = {}) {\r\n const packageManager = getPackageManager();\r\n\r\n const pkg = this.package.replace(\"name\", this.name.replaceAll(\"/\", \"-\"));\r\n\r\n const content: any = pkg.content;\r\n\r\n // Substitute the chosen package manager ONLY into the fields the template\r\n // writes it into literally — the `serve` script — by path, never with a\r\n // blanket substring replace over the serialized JSON. A raw\r\n // `replaceAll(\"yarn\", pm)` rewrites every occurrence of the substring\r\n // \"yarn\" anywhere in the document, so a project named `my-yarn-app`, or any\r\n // dependency/path containing \"yarn\", is silently corrupted (`--pm=npm`\r\n // turned `my-yarn-app` into `my-npm-app`). Field-scoped rewriting is also\r\n // order-independent: the name lives in `content.name` and this token lives\r\n // in `scripts.serve`, a disjoint field that cannot collide with the name\r\n // substitution above regardless of which runs first.\r\n if (typeof content.scripts?.serve === \"string\") {\r\n content.scripts.serve = content.scripts.serve.replaceAll(\r\n \"yarn\",\r\n packageManager,\r\n );\r\n }\r\n\r\n const warlockVersion: string = (\r\n getJsonFile(packageRoot(\"package.json\")) as { version: string }\r\n ).version;\r\n const defaultRange = fallbackRange(warlockVersion);\r\n\r\n for (const field of [\"dependencies\", \"devDependencies\"] as const) {\r\n const deps = content[field] as Record<string, string> | undefined;\r\n if (!deps) continue;\r\n\r\n for (const dependency of Object.keys(deps)) {\r\n if (dependency.startsWith(\"@warlock.js/\")) {\r\n deps[dependency] = versions[dependency] ?? defaultRange;\r\n }\r\n }\r\n }\r\n\r\n pkg.save();\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Configure the chosen database driver: wire `DB_DRIVER` / `DB_PORT` into\r\n * `.env`, AND pin the driver's npm package (`mongodb` / `pg`) into the\r\n * project's `package.json` dependencies.\r\n *\r\n * The dependency is written HERE — before the base `yarn install` — so the\r\n * driver is pulled deterministically by the very first install. We do NOT\r\n * rely on the post-copy `warlock add <driver> --no-install` + separate\r\n * batched install, which can be skipped or fail and leave the driver\r\n * missing (the \"mongodb package is not installed\" runtime error).\r\n */\r\n public configureDatabaseEnv(driverValue: string) {\r\n const driver = getDatabaseDriver(driverValue);\r\n\r\n if (!driver) return this;\r\n\r\n // Pin the driver package into dependencies (idempotent — never downgrade).\r\n const packageJsonPath = path.resolve(this.path, \"package.json\");\r\n const packageJson = getJsonFile(packageJsonPath) as {\r\n dependencies?: Record<string, string>;\r\n };\r\n packageJson.dependencies = packageJson.dependencies ?? {};\r\n if (!packageJson.dependencies[driver.package]) {\r\n packageJson.dependencies[driver.package] = driver.packageVersion;\r\n putJsonFile(packageJsonPath, packageJson);\r\n }\r\n\r\n let envContent = getFile(this.path + \"/.env\") as string;\r\n\r\n envContent = envContent.replace(\r\n /DB_PORT=\\d+/,\r\n `DB_PORT=${driver.defaultPort}`,\r\n );\r\n\r\n if (envContent.includes(\"DB_DRIVER=\")) {\r\n envContent = envContent.replace(\r\n /DB_DRIVER=\\w*/,\r\n `DB_DRIVER=${driver.value}`,\r\n );\r\n } else {\r\n envContent = envContent.replace(\r\n /DB_PORT=\\d+/,\r\n `DB_PORT=${driver.defaultPort}\\nDB_DRIVER=${driver.value}`,\r\n );\r\n }\r\n\r\n putFile(this.path + \"/.env\", envContent);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Write the correct `src/config/database.ts` for the chosen driver and remove\r\n * every per-driver variant so the scaffold ships exactly one config file.\r\n *\r\n * The template ships a Mongo-shaped `database.ts` (the default) plus a\r\n * `database.postgres.ts` variant. Mongo keeps the default in place; Postgres\r\n * overwrites `database.ts` with the Postgres-shaped variant (typed\r\n * `ConnectionOptions`, `driver: \"postgres\"`, port 5432, no Mongo-only keys —\r\n * no `authSource`, `driverOptions`, `replicaSet`, `randomIncrement` /\r\n * `initialId`). Either way the `.postgres` variant file is deleted afterwards\r\n * so no leftover config ships in the generated project.\r\n *\r\n * For Postgres it also corrects the working `.env`: the Mongo template ships\r\n * `DB_AUTH=admin`, an `authSource` value Postgres ignores and its config no\r\n * longer reads, so the line is dropped to keep `.env` and the config in sync.\r\n * The port is rewritten by {@link configureDatabaseEnv} (driver defaultPort),\r\n * which runs alongside this in the same branch.\r\n */\r\n public configureDatabaseConfig(driverValue: string) {\r\n const configDir = path.resolve(this.path, \"src/config\");\r\n const databasePath = path.resolve(configDir, \"database.ts\");\r\n const postgresVariantPath = path.resolve(configDir, \"database.postgres.ts\");\r\n\r\n if (driverValue === \"postgres\" && fileExists(postgresVariantPath)) {\r\n putFile(databasePath, getFile(postgresVariantPath) as string);\r\n\r\n const envPath = this.path + \"/.env\";\r\n\r\n if (fileExists(envPath)) {\r\n const envContent = getFile(envPath) as string;\r\n // Drop the Mongo-only DB_AUTH line entirely (its whole line, so no blank\r\n // gap is left behind). Postgres has no authSource concept.\r\n putFile(envPath, envContent.replace(/^DB_AUTH=.*\\r?\\n?/m, \"\"));\r\n }\r\n }\r\n\r\n // Whatever the driver, no per-driver variant may survive into the scaffold.\r\n if (fileExists(postgresVariantPath)) {\r\n unlinkSync(postgresVariantPath);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Remove the database layer for a \"no database\" scaffold.\r\n *\r\n * Deletes `src/config/database.ts` (and a `.tsx` / per-driver variant if\r\n * present) from the freshly-copied template. The framework's database\r\n * connector is config-gated on that file — with it gone,\r\n * `config.get(\"database\")` is undefined and the connector no-ops, so the app\r\n * boots with no database wired and no driver package pulled. The `DB_*` lines\r\n * in `.env` are left in place (harmless: no config reads them) as a ready\r\n * template for adding a database back later.\r\n */\r\n public removeDatabaseConfig() {\r\n const configDir = path.resolve(this.path, \"src/config\");\r\n\r\n for (const fileName of [\r\n \"database.ts\",\r\n \"database.tsx\",\r\n \"database.postgres.ts\",\r\n ]) {\r\n const filePath = path.resolve(configDir, fileName);\r\n\r\n if (fileExists(filePath)) {\r\n unlinkSync(filePath);\r\n }\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Configure the web starter only when the web feature owns `/`.\r\n *\r\n * A dependency-free HTTP response is retained without web; otherwise the\r\n * SSR page loader owns the route.\r\n * Exactly one survives the scaffold: web projects keep the SSR page and API\r\n * example; every other project keeps the dependency-free JSON controller.\r\n */\r\n public configureWebStarter(useWeb: boolean) {\r\n const remove = (relativePath: string) => {\r\n const target = path.resolve(this.path, relativePath);\r\n if (existsSync(target)) rmSync(target, { recursive: true, force: true });\r\n };\r\n\r\n if (!useWeb) {\r\n for (const entry of [\r\n \"src/web\",\r\n \"src/app/contact\",\r\n \"src/app/locale\",\r\n \"src/shared/contact.schema.ts\",\r\n \"src/shared/locale.schema.ts\",\r\n \"src/shared/locales.ts\",\r\n \"postcss.config.mjs\",\r\n \"skills/web-code-standards\",\r\n ]) {\r\n remove(entry);\r\n }\r\n\r\n const agentsPath = path.resolve(this.path, \"AGENTS.md\");\r\n const agents = getFile(agentsPath) as string;\r\n putFile(\r\n agentsPath,\r\n agents.replace(/^.*\\*\\*web-code-standards\\*\\*.*\\r?\\n/m, \"\"),\r\n );\r\n\r\n const tsconfigPath = path.resolve(this.path, \"tsconfig.json\");\r\n const tsconfig = getFile(tsconfigPath) as string;\r\n putFile(\r\n tsconfigPath,\r\n tsconfig\r\n .replace(' \"web/*\": [\"./src/web/*\"],\\n', \"\")\r\n .replace(' \"@shared/*\": [\"./src/shared/*\"]\\n', \"\"),\r\n );\r\n\r\n return this;\r\n }\r\n\r\n // The SSR page owns `/`; its loader still uses src/app/home/services.\r\n remove(\"src/app/home/controllers/home-page.controller.ts\");\r\n remove(\"src/app/home/routes.ts\");\r\n\r\n const packageJsonPath = path.resolve(this.path, \"package.json\");\r\n const packageJson = getJsonFile(packageJsonPath) as {\r\n dependencies?: Record<string, string>;\r\n devDependencies?: Record<string, string>;\r\n };\r\n packageJson.dependencies = {\r\n ...packageJson.dependencies,\r\n \"@mongez/http\": \"^3.5.0\",\r\n \"@mongez/react-form\": \"^4.0.0\",\r\n };\r\n packageJson.devDependencies = {\r\n ...packageJson.devDependencies,\r\n \"@tailwindcss/postcss\": \"^4.1.16\",\r\n tailwindcss: \"^4.1.16\",\r\n };\r\n putJsonFile(packageJsonPath, packageJson);\r\n\r\n const configPath = path.resolve(this.path, \"warlock.config.ts\");\r\n const config = getFile(configPath) as string;\r\n if (!config.includes('\"@warlock.js/web/connector\"')) {\r\n // Inserted in sorted position, not prepended. The generated app formats\r\n // with `prettier-plugin-organize-imports`, so an import pushed to the top\r\n // of a file that already imports `@warlock.js/auth` and `@warlock.js/core`\r\n // is out of order the moment it is written — and the developer meets it as\r\n // a `prettier/prettier` error on their first `warlock dev`, in a file they\r\n // did not write.\r\n const withConnector = insertImportInSortedPosition(\r\n config,\r\n 'import { webConnector } from \"@warlock.js/web/connector\";',\r\n \"@warlock.js/web/connector\",\r\n );\r\n\r\n putFile(\r\n configPath,\r\n withConnector.replace(\r\n \"export default defineConfig({\",\r\n \"export default defineConfig({\\n connectors: [webConnector()],\",\r\n ),\r\n );\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Record non-default `agent-kit` targets into the generated `package.json`'s\r\n * `agentKit.targets` block.\r\n *\r\n * The template's own `postinstall` (`agent-kit init && agent-kit sync`)\r\n * already targets `claude` with no flags, so the single-target default case\r\n * needs no template edit at all — this only writes when the selection is\r\n * anything else, keeping the scaffold diff-free for the common path.\r\n */\r\n public configureAgentKitTargets(agents: string[]) {\r\n const isDefault = agents.length === 1 && agents[0] === \"claude\";\r\n if (isDefault) return this;\r\n\r\n const packageJsonPath = path.resolve(this.path, \"package.json\");\r\n if (!fileExists(packageJsonPath)) return this;\r\n\r\n const packageJson = getJsonFile(packageJsonPath) as {\r\n agentKit?: { targets?: string[] };\r\n };\r\n packageJson.agentKit = { ...packageJson.agentKit, targets: agents };\r\n putJsonFile(packageJsonPath, packageJson);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Install the selected optional features by delegating to the project's own\r\n * `warlock add`. `--no-install` records every dependency in package.json and\r\n * ejects configs / scripts / setup hooks WITHOUT installing — the caller runs\r\n * one batched install afterwards. Versions come from core's feature map, so\r\n * the scaffolder never duplicates them.\r\n *\r\n * `--no-install` is passed LAST on purpose: the CLI parser treats the\r\n * positional after a bare flag as that flag's value, so it must follow the\r\n * feature list, not precede it.\r\n */\r\n public async installFeatures(features: string[]) {\r\n if (features.length === 0) return true;\r\n\r\n return this.exec(`npx warlock add ${features.join(\" \")} --no-install`);\r\n }\r\n\r\n /**\r\n * Force a single copy of `vite` when the project ends up with BOTH `vite`\r\n * (written by the `web` feature) and `vitest` (always in the template).\r\n *\r\n * `vitest` depends on vite through a wide range of its own\r\n * (`^6 || ^7 || ^8`), which resolves to a DIFFERENT major than the range the\r\n * feature map pins. Yarn 1 then has to nest the second copy under\r\n * `vitest/node_modules` and dies on its own linker invariant:\r\n *\r\n * error Invariant Violation: could not find a copy of vite to link in\r\n * <project>/node_modules/vitest/node_modules\r\n *\r\n * It aborts BEFORE `node_modules/.bin` is written, so `warlock` is never\r\n * linked and the very first `yarn dev` fails with \"'warlock' is not\r\n * recognized\". npm and pnpm nest happily and never hit this — for them the\r\n * `overrides` twin below is one copy instead of two, not a crash fix.\r\n *\r\n * The pin is READ BACK from whatever range the project's own package.json\r\n * declares, never re-stated as a literal here: the feature map in\r\n * `@warlock.js/core` owns the version, and a second copy of it would drift\r\n * the moment that one moves.\r\n *\r\n * Returns whether a pin was written, so the caller (and its spec) can assert\r\n * it instead of assuming it.\r\n */\r\n public pinViteResolution() {\r\n const packageJsonPath = path.resolve(this.path, \"package.json\");\r\n\r\n if (!fileExists(packageJsonPath)) return false;\r\n\r\n const packageJson = getJsonFile(packageJsonPath) as {\r\n dependencies?: Record<string, string>;\r\n devDependencies?: Record<string, string>;\r\n resolutions?: Record<string, string>;\r\n overrides?: Record<string, string>;\r\n };\r\n\r\n const declaredRange = (name: string) =>\r\n packageJson.dependencies?.[name] ?? packageJson.devDependencies?.[name];\r\n\r\n const viteRange = declaredRange(\"vite\");\r\n\r\n // No vite, or no vitest to conflict with it — nothing to pin. Writing a\r\n // resolution for a package the project does not depend on would only\r\n // freeze a transitive tree nobody asked us to freeze.\r\n if (!viteRange || !declaredRange(\"vitest\")) return false;\r\n\r\n // yarn 1 / yarn berry read `resolutions`; npm 8+ and pnpm read `overrides`.\r\n packageJson.resolutions = { ...packageJson.resolutions, vite: viteRange };\r\n packageJson.overrides = { ...packageJson.overrides, vite: viteRange };\r\n\r\n putJsonFile(packageJsonPath, packageJson);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Get package json file\r\n */\r\n public get package() {\r\n return this.json(\"package.json\");\r\n }\r\n\r\n public updateDotEnv() {\r\n this.file(\".env\").replaceAll(\"appName\", this.name).save();\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Get env file to update\r\n */\r\n public get env() {\r\n return this.file(\".env\");\r\n }\r\n\r\n public get name() {\r\n return this.app.appName;\r\n }\r\n\r\n public get path() {\r\n return this.app.appPath;\r\n }\r\n\r\n public file(relativePath: string) {\r\n const fullPath = path.resolve(this.path, relativePath);\r\n\r\n if (!this.files[fullPath]) {\r\n this.files[fullPath] = file(fullPath);\r\n }\r\n\r\n return this.files[fullPath];\r\n }\r\n\r\n public json(relativePath: string): JsonFileManager {\r\n const fullPath = path.resolve(this.path, relativePath);\r\n\r\n if (!this.jsonFiles[fullPath]) {\r\n this.jsonFiles[fullPath] = jsonFile(fullPath);\r\n }\r\n\r\n return this.jsonFiles[fullPath];\r\n }\r\n}\r\n\r\nexport function app(app: Application) {\r\n return new App(app);\r\n}\r\n\r\nexport class FileManager {\r\n public content!: string;\r\n public constructor(protected filePath: string) {\r\n this.parseContent();\r\n }\r\n\r\n protected parseContent() {\r\n this.content = getFile(this.filePath) as string;\r\n }\r\n\r\n public replace(search: string, replace: string) {\r\n this.content = this.content.replace(search, replace);\r\n\r\n return this;\r\n }\r\n\r\n public replaceAll(search: string, replace: string) {\r\n this.content = this.content.replaceAll(search, replace);\r\n\r\n return this;\r\n }\r\n\r\n public save() {\r\n putFile(this.filePath, this.content);\r\n }\r\n}\r\n\r\nexport class JsonFileManager extends FileManager {\r\n protected parseContent() {\r\n this.content = getJsonFile(this.filePath);\r\n }\r\n\r\n public save() {\r\n putJsonFile(this.filePath, this.content);\r\n }\r\n\r\n public has(key: string) {\r\n return this.content[key] !== undefined;\r\n }\r\n\r\n public replace(key: string, value: any) {\r\n this.content[key] = value;\r\n\r\n return this;\r\n }\r\n\r\n public replaceAll(key: string, value: any) {\r\n const contentAsString = JSON.stringify(this.content);\r\n\r\n this.content = JSON.parse(contentAsString.replaceAll(key, value));\r\n\r\n return this;\r\n }\r\n}\r\n\r\nexport function file(path: string) {\r\n return new FileManager(path);\r\n}\r\n\r\nexport function jsonFile(path: string) {\r\n return new JsonFileManager(path);\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,qBAAwC;CACtD,OAAO,EAAE,UAAU,cAAc;AACnC;AAEA,IAAa,MAAb,MAAiB;CAaf,AAAO,YAAY,AAAU,KAAkB;EAAlB;eATkB,CAAC;mBAKO,CAAC;qBAEnC;CAE2B;CAEhD,IAAW,UAAsB;EAC/B,OAAO,KAAK,IAAI;CAClB;CAEA,AAAO,IAAI,cAAwB;EACjC,cAAc,SAAS,YAAY,GAAG,KAAK,IAAI;EAE/C,IAAI,WAAW,KAAK,OAAO,eAAe,GACxC,SAAS,KAAK,OAAO,iBAAiB,KAAK,OAAO,OAAO;EAG3D,WAAW,KAAK,OAAO,gBAAgB,KAAK,OAAO,aAAa;EAEhE,OAAO;CACT;CAEA,AAAO,OAAO;EACZ,OAAO;CACT;CAEA,AAAO,YAAY,CAEnB;CAEA,AAAO,UAAU;EACf,OAAO,WAAW,kBAAkB,GAAG,CAAC,SAAS,GAAG,KAAK,MAAM,EAC7D,KAAK,mBAAmB,EAC1B,CAAC;CACH;CAEA,MAAa,KAAK,SAAiB;EACjC,MAAM,CAAC,aAAa,GAAG,eAAe,QAAQ,MAAM,GAAG;EACvD,OAAO,MAAM,eAAe,aAAa,aAAa,KAAK,IAAI;C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AU,eAAe;EACvB,KAAK,UAAU,QAAQ,KAAK,QAAQ;CACtC;CAEA,AAAO,QAAQ,QAAgB,SAAiB;EAC9C,KAAK,UAAU,KAAK,QAAQ,QAAQ,QAAQ,OAAO;EAEnD,OAAO;CACT;CAEA,AAAO,WAAW,QAAgB,SAAiB;EACjD,KAAK,UAAU,KAAK,QAAQ,WAAW,QAAQ,OAAO;EAEtD,OAAO;CACT;CAEA,AAAO,OAAO;EACZ,QAAQ,KAAK,UAAU,KAAK,OAAO;CACrC;AACF;AAEA,IAAa,kBAAb,cAAqC,YAAY;CAC/C,AAAU,eAAe;EACvB,KAAK,UAAU,YAAY,KAAK,QAAQ;CAC1C;CAEA,AAAO,OAAO;EACZ,YAAY,KAAK,UAAU,KAAK,OAAO;CACzC;CAEA,AAAO,IAAI,KAAa;EACtB,OAAO,KAAK,QAAQ,SAAS;CAC/B;CAEA,AAAO,QAAQ,KAAa,OAAY;EACtC,KAAK,QAAQ,OAAO;EAEpB,OAAO;CACT;CAEA,AAAO,WAAW,KAAa,OAAY;EACzC,MAAM,kBAAkB,KAAK,UAAU,KAAK,OAAO;EAEnD,KAAK,UAAU,KAAK,MAAM,gBAAgB,WAAW,KAAK,KAAK,CAAC;EAEhE,OAAO;CACT;AACF;AAEA,SAAgB,KAAK,MAAc;CACjC,OAAO,IAAI,YAAY,IAAI;AAC7B;AAEA,SAAgB,SAAS,MAAc;CACrC,OAAO,IAAI,gBAAgB,IAAI;AACjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insert-import.mjs","names":[],"sources":["../../../../../../create-warlock/src/helpers/insert-import.ts"],"sourcesContent":["/**\n * Splice an `import` statement into a generated source file **in sorted\n * position**, rather than pushing it to the top.\n *\n * The scaffolded app formats with `prettier-plugin-organize-imports`, which\n * orders imports alphabetically by module specifier. So an import prepended to\n * a file that already has some is, by construction, in the wrong place — and\n * the developer meets it as a `prettier/prettier` error on their very first\n * `warlock dev`, in a file they did not write, about code they did not add.\n *\n * That is the defect class this scaffolder keeps paying for: a failure that\n * waits for the user's first ordinary action and then arrives attributed to\n * them.\n */\n\n/**\n * Matches a top-level import statement and captures its module specifier.\n *\n * Deliberately narrow: this reads files THIS scaffolder generates from its own\n * templates, not arbitrary user source. It handles the two forms those\n * templates actually contain — a single-line import and a braced multi-line one\n * — and is not a general TypeScript parser. If a template ever grows an import\n * shape this misses, the insertion falls back to appending after the last match,\n * which is still ordered relative to everything it did recognise.\n */\nconst IMPORT_STATEMENT = /^import\\s[\\s\\S]*?from\\s+[\"']([^\"']+)[\"'];?$/gm;\n\n/**\n * Insert `statement` into `source` so the import block stays alphabetically\n * ordered by module specifier.\n *\n * @param source the file's current contents.\n * @param statement the whole import line to add, without a trailing newline.\n * @param specifier the module specifier `statement` imports from — passed\n * rather than re-parsed, because the caller already knows it\n * and a second parser is a second thing to disagree.\n * @returns the file contents with the import in place. A file with no imports\n * at all gets it at the top, which is the only ordering available.\n */\nexport function insertImportInSortedPosition(\n source: string,\n statement: string,\n specifier: string,\n): string {\n const matches = [...source.matchAll(IMPORT_STATEMENT)];\n\n if (matches.length === 0) {\n return `${statement}\\n${source}`;\n }\n\n const successor = matches.find(match => (match[1] as string).localeCompare(specifier) > 0);\n\n if (successor) {\n return `${source.slice(0, successor.index)}${statement}\\n${source.slice(successor.index)}`;\n }\n\n const last = matches[matches.length - 1] as RegExpMatchArray;\n const endOfLast = (last.index as number) + last[0].length;\n\n return `${source.slice(0, endOfLast)}\\n${statement}${source.slice(endOfLast)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAM,mBAAmB;;;;;;;;;;;;;AAczB,SAAgB,6BACd,QACA,WACA,WACQ;CACR,MAAM,UAAU,CAAC,GAAG,OAAO,SAAS,gBAAgB,CAAC;CAErD,IAAI,QAAQ,WAAW,GACrB,OAAO,GAAG,UAAU,IAAI;CAG1B,MAAM,YAAY,QAAQ,
|
|
1
|
+
{"version":3,"file":"insert-import.mjs","names":[],"sources":["../../../../../../create-warlock/src/helpers/insert-import.ts"],"sourcesContent":["/**\n * Splice an `import` statement into a generated source file **in sorted\n * position**, rather than pushing it to the top.\n *\n * The scaffolded app formats with `prettier-plugin-organize-imports`, which\n * orders imports alphabetically by module specifier. So an import prepended to\n * a file that already has some is, by construction, in the wrong place — and\n * the developer meets it as a `prettier/prettier` error on their very first\n * `warlock dev`, in a file they did not write, about code they did not add.\n *\n * That is the defect class this scaffolder keeps paying for: a failure that\n * waits for the user's first ordinary action and then arrives attributed to\n * them.\n */\n\n/**\n * Matches a top-level import statement and captures its module specifier.\n *\n * Deliberately narrow: this reads files THIS scaffolder generates from its own\n * templates, not arbitrary user source. It handles the two forms those\n * templates actually contain — a single-line import and a braced multi-line one\n * — and is not a general TypeScript parser. If a template ever grows an import\n * shape this misses, the insertion falls back to appending after the last match,\n * which is still ordered relative to everything it did recognise.\n */\nconst IMPORT_STATEMENT = /^import\\s[\\s\\S]*?from\\s+[\"']([^\"']+)[\"'];?$/gm;\n\n/**\n * Insert `statement` into `source` so the import block stays alphabetically\n * ordered by module specifier.\n *\n * @param source the file's current contents.\n * @param statement the whole import line to add, without a trailing newline.\n * @param specifier the module specifier `statement` imports from — passed\n * rather than re-parsed, because the caller already knows it\n * and a second parser is a second thing to disagree.\n * @returns the file contents with the import in place. A file with no imports\n * at all gets it at the top, which is the only ordering available.\n */\nexport function insertImportInSortedPosition(\n source: string,\n statement: string,\n specifier: string,\n): string {\n const matches = [...source.matchAll(IMPORT_STATEMENT)];\n\n if (matches.length === 0) {\n return `${statement}\\n${source}`;\n }\n\n const successor = matches.find(\n match => (match[1] as string).localeCompare(specifier) > 0,\n );\n\n if (successor) {\n return `${source.slice(0, successor.index)}${statement}\\n${source.slice(successor.index)}`;\n }\n\n const last = matches[matches.length - 1] as RegExpMatchArray;\n const endOfLast = (last.index as number) + last[0].length;\n\n return `${source.slice(0, endOfLast)}\\n${statement}${source.slice(endOfLast)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAM,mBAAmB;;;;;;;;;;;;;AAczB,SAAgB,6BACd,QACA,WACA,WACQ;CACR,MAAM,UAAU,CAAC,GAAG,OAAO,SAAS,gBAAgB,CAAC;CAErD,IAAI,QAAQ,WAAW,GACrB,OAAO,GAAG,UAAU,IAAI;CAG1B,MAAM,YAAY,QAAQ,MACxB,UAAU,MAAM,EAAE,CAAY,cAAc,SAAS,IAAI,CAC3D;CAEA,IAAI,WACF,OAAO,GAAG,OAAO,MAAM,GAAG,UAAU,KAAK,IAAI,UAAU,IAAI,OAAO,MAAM,UAAU,KAAK;CAGzF,MAAM,OAAO,QAAQ,QAAQ,SAAS;CACtC,MAAM,YAAa,KAAK,QAAmB,KAAK,EAAE,CAAC;CAEnD,OAAO,GAAG,OAAO,MAAM,GAAG,SAAS,EAAE,IAAI,YAAY,OAAO,MAAM,SAAS;AAC7E"}
|
|
@@ -51,41 +51,51 @@ async function checkManager(manager) {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
|
+
* Every allow-listed manager that has to be PROBED. npm is excluded because
|
|
55
|
+
* it is assumed present.
|
|
56
|
+
*
|
|
57
|
+
* Both detectors read this one list. They used to hold their own literal
|
|
58
|
+
* copies, and the copies drifted: `bun` reached the allow-list and `--help`
|
|
59
|
+
* without reaching either probe, so `--pm=bun` passed the spelling check and
|
|
60
|
+
* then could never appear among the options that would honour it.
|
|
61
|
+
*/
|
|
62
|
+
const PROBED_PACKAGE_MANAGERS = ALLOWED_PACKAGE_MANAGERS.filter((manager) => manager !== "npm");
|
|
63
|
+
const PREFERRED_PACKAGE_MANAGERS = [
|
|
64
|
+
"pnpm",
|
|
65
|
+
"yarn",
|
|
66
|
+
"npm"
|
|
67
|
+
];
|
|
68
|
+
/**
|
|
69
|
+
* A running non-npm manager is already usable. Every fallback must be present
|
|
70
|
+
* in the detector's installed set, so both sync and async paths agree.
|
|
71
|
+
*/
|
|
72
|
+
function preferredPackageManager(isAvailable) {
|
|
73
|
+
const runningPm = detectPackageManager()?.name;
|
|
74
|
+
if (runningPm && runningPm !== "npm" && isValidPackageManager(runningPm)) return runningPm;
|
|
75
|
+
return PREFERRED_PACKAGE_MANAGERS.find(isAvailable) ?? "npm";
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
54
78
|
* Detect available package managers asynchronously and cache results
|
|
55
79
|
*/
|
|
56
80
|
async function detectPackageManagers() {
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const [hasYarn, hasPnpm] = await Promise.all(checks);
|
|
60
|
-
if (hasYarn) managers.push("yarn");
|
|
61
|
-
if (hasPnpm) managers.push("pnpm");
|
|
81
|
+
const found = await Promise.all(PROBED_PACKAGE_MANAGERS.map(checkManager));
|
|
82
|
+
const managers = ["npm", ...PROBED_PACKAGE_MANAGERS.filter((_, index) => found[index])];
|
|
62
83
|
cachedSystemManagers = managers;
|
|
63
|
-
|
|
64
|
-
if (runningPm && runningPm !== "npm") cachedPreferredManager = runningPm;
|
|
65
|
-
else if (hasYarn) cachedPreferredManager = "yarn";
|
|
66
|
-
else if (hasPnpm) cachedPreferredManager = "pnpm";
|
|
67
|
-
else cachedPreferredManager = "npm";
|
|
84
|
+
cachedPreferredManager = preferredPackageManager((manager) => managers.includes(manager));
|
|
68
85
|
}
|
|
69
86
|
/**
|
|
70
87
|
* Get available package managers on the system
|
|
71
88
|
*/
|
|
72
89
|
function getSystemPackageManagers() {
|
|
73
90
|
if (cachedSystemManagers) return cachedSystemManagers;
|
|
74
|
-
|
|
75
|
-
if (isInstalled("yarn")) managers.push("yarn");
|
|
76
|
-
if (isInstalled("pnpm")) managers.push("pnpm");
|
|
77
|
-
return managers;
|
|
91
|
+
return ["npm", ...PROBED_PACKAGE_MANAGERS.filter(isInstalled)];
|
|
78
92
|
}
|
|
79
93
|
/**
|
|
80
94
|
* Get the preferred package manager based on priority
|
|
81
95
|
*/
|
|
82
96
|
function getPreferredPackageManager() {
|
|
83
97
|
if (cachedPreferredManager) return cachedPreferredManager;
|
|
84
|
-
|
|
85
|
-
if (runningPm && runningPm !== "npm") return runningPm;
|
|
86
|
-
if (isInstalled("pnpm")) return "pnpm";
|
|
87
|
-
if (isInstalled("yarn")) return "yarn";
|
|
88
|
-
return "npm";
|
|
98
|
+
return preferredPackageManager((manager) => manager === "npm" || isInstalled(manager));
|
|
89
99
|
}
|
|
90
100
|
function setPackageManager(packageManager) {
|
|
91
101
|
detectedPackageManager = packageManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-manager.mjs","names":[],"sources":["../../../../../../create-warlock/src/helpers/package-manager.ts"],"sourcesContent":["import { exec, execSync } from \"child_process\";\r\nimport { promisify } from \"util\";\r\nimport detectPackageManager from \"which-pm-runs\";\r\n\r\nconst execAsync = promisify(exec);\r\n\r\nlet detectedPackageManager: string | undefined;\r\nlet cachedSystemManagers: string[] | undefined;\r\nlet cachedPreferredManager: string | undefined;\r\n\r\n/**\r\n * The only package managers `--pm` may select. This value reaches `spawn()`\r\n * as the executable to run and is spliced into the generated\r\n * `package.json`'s scripts — an allow-list here is a hard security\r\n * boundary, not just input hygiene, so it stays a fixed literal list\r\n * rather than anything derived from user input or the running environment.\r\n */\r\nexport const ALLOWED_PACKAGE_MANAGERS = [\"npm\", \"yarn\", \"pnpm\", \"bun\"] as const;\r\n\r\nexport type AllowedPackageManager = (typeof ALLOWED_PACKAGE_MANAGERS)[number];\r\n\r\n/** Whether `value` is one of the allow-listed package managers. */\r\nexport function isValidPackageManager(\r\n value: string,\r\n): value is AllowedPackageManager {\r\n return (ALLOWED_PACKAGE_MANAGERS as readonly string[]).includes(value);\r\n}\r\n\r\nexport function getPackageManager() {\r\n if (detectedPackageManager) {\r\n return detectedPackageManager;\r\n }\r\n\r\n return getPreferredPackageManager();\r\n}\r\n\r\n/**\r\n * Check if a package manager is installed\r\n */\r\nfunction isInstalled(manager: string): boolean {\r\n try {\r\n execSync(`${manager} --version`, { stdio: \"ignore\" });\r\n return true;\r\n } catch {\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n * Check if a package manager is installed (async)\r\n */\r\nasync function checkManager(manager: string): Promise<boolean> {\r\n try {\r\n await execAsync(`${manager} --version`);\r\n return true;\r\n } catch {\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n *
|
|
1
|
+
{"version":3,"file":"package-manager.mjs","names":[],"sources":["../../../../../../create-warlock/src/helpers/package-manager.ts"],"sourcesContent":["import { exec, execSync } from \"child_process\";\r\nimport { promisify } from \"util\";\r\nimport detectPackageManager from \"which-pm-runs\";\r\n\r\nconst execAsync = promisify(exec);\r\n\r\nlet detectedPackageManager: string | undefined;\r\nlet cachedSystemManagers: string[] | undefined;\r\nlet cachedPreferredManager: string | undefined;\r\n\r\n/**\r\n * The only package managers `--pm` may select. This value reaches `spawn()`\r\n * as the executable to run and is spliced into the generated\r\n * `package.json`'s scripts — an allow-list here is a hard security\r\n * boundary, not just input hygiene, so it stays a fixed literal list\r\n * rather than anything derived from user input or the running environment.\r\n */\r\nexport const ALLOWED_PACKAGE_MANAGERS = [\"npm\", \"yarn\", \"pnpm\", \"bun\"] as const;\r\n\r\nexport type AllowedPackageManager = (typeof ALLOWED_PACKAGE_MANAGERS)[number];\r\n\r\n/** Whether `value` is one of the allow-listed package managers. */\r\nexport function isValidPackageManager(\r\n value: string,\r\n): value is AllowedPackageManager {\r\n return (ALLOWED_PACKAGE_MANAGERS as readonly string[]).includes(value);\r\n}\r\n\r\nexport function getPackageManager() {\r\n if (detectedPackageManager) {\r\n return detectedPackageManager;\r\n }\r\n\r\n return getPreferredPackageManager();\r\n}\r\n\r\n/**\r\n * Check if a package manager is installed\r\n */\r\nfunction isInstalled(manager: string): boolean {\r\n try {\r\n execSync(`${manager} --version`, { stdio: \"ignore\" });\r\n return true;\r\n } catch {\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n * Check if a package manager is installed (async)\r\n */\r\nasync function checkManager(manager: string): Promise<boolean> {\r\n try {\r\n await execAsync(`${manager} --version`);\r\n return true;\r\n } catch {\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n * Every allow-listed manager that has to be PROBED. npm is excluded because\r\n * it is assumed present.\r\n *\r\n * Both detectors read this one list. They used to hold their own literal\r\n * copies, and the copies drifted: `bun` reached the allow-list and `--help`\r\n * without reaching either probe, so `--pm=bun` passed the spelling check and\r\n * then could never appear among the options that would honour it.\r\n */\r\nconst PROBED_PACKAGE_MANAGERS = ALLOWED_PACKAGE_MANAGERS.filter(\r\n manager => manager !== \"npm\",\r\n);\r\n\r\nconst PREFERRED_PACKAGE_MANAGERS = [\"pnpm\", \"yarn\", \"npm\"] as const;\r\n\r\n/**\r\n * A running non-npm manager is already usable. Every fallback must be present\r\n * in the detector's installed set, so both sync and async paths agree.\r\n */\r\nfunction preferredPackageManager(\r\n isAvailable: (manager: AllowedPackageManager) => boolean,\r\n): string {\r\n const runningPm = detectPackageManager()?.name;\r\n if (runningPm && runningPm !== \"npm\" && isValidPackageManager(runningPm)) {\r\n return runningPm;\r\n }\r\n\r\n return PREFERRED_PACKAGE_MANAGERS.find(isAvailable) ?? \"npm\";\r\n}\r\n\r\n/**\r\n * Detect available package managers asynchronously and cache results\r\n */\r\nexport async function detectPackageManagers() {\r\n const found = await Promise.all(PROBED_PACKAGE_MANAGERS.map(checkManager));\r\n const available = PROBED_PACKAGE_MANAGERS.filter((_, index) => found[index]);\r\n const managers = [\"npm\", ...available];\r\n\r\n cachedSystemManagers = managers;\r\n cachedPreferredManager = preferredPackageManager(manager =>\r\n managers.includes(manager),\r\n );\r\n}\r\n\r\n/**\r\n * Get available package managers on the system\r\n */\r\nexport function getSystemPackageManagers(): string[] {\r\n if (cachedSystemManagers) return cachedSystemManagers;\r\n\r\n // Same list the async detector probes, so the two can no longer disagree\r\n // about which managers exist. npm is assumed to be always available.\r\n return [\"npm\", ...PROBED_PACKAGE_MANAGERS.filter(isInstalled)];\r\n}\r\n\r\n/**\r\n * Get the preferred package manager based on priority\r\n */\r\nexport function getPreferredPackageManager(): string {\r\n if (cachedPreferredManager) return cachedPreferredManager;\r\n return preferredPackageManager(\r\n manager => manager === \"npm\" || isInstalled(manager),\r\n );\r\n}\r\n\r\nexport function setPackageManager(packageManager: string) {\r\n detectedPackageManager = packageManager;\r\n}\r\n\r\nexport function installCommand() {\r\n return `${getPackageManager()} install`;\r\n}\r\n\r\nexport function startCommand() {\r\n if (getPackageManager() === \"npm\") return \"npm run dev\";\r\n\r\n return `${getPackageManager()} dev`;\r\n}\r\n\r\nexport function runPackageManagerCommand(command: string) {\r\n const packageManager = getPackageManager();\r\n\r\n if (packageManager === \"npm\") return `npm run ${command}`;\r\n\r\n return `${packageManager} ${command}`;\r\n}\r\n"],"mappings":";;;;;AAIA,MAAM,YAAY,UAAU,IAAI;AAEhC,IAAI;AACJ,IAAI;AACJ,IAAI;;;;;;;;AASJ,MAAa,2BAA2B;CAAC;CAAO;CAAQ;CAAQ;AAAK;;AAKrE,SAAgB,sBACd,OACgC;CAChC,OAAQ,yBAA+C,SAAS,KAAK;AACvE;AAEA,SAAgB,oBAAoB;CAClC,IAAI,wBACF,OAAO;CAGT,OAAO,2BAA2B;AACpC;;;;AAKA,SAAS,YAAY,SAA0B;CAC7C,IAAI;EACF,SAAS,GAAG,QAAQ,aAAa,EAAE,OAAO,SAAS,CAAC;EACpD,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;;AAKA,eAAe,aAAa,SAAmC;CAC7D,IAAI;EACF,MAAM,UAAU,GAAG,QAAQ,WAAW;EACtC,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;;AAWA,MAAM,0BAA0B,yBAAyB,QACvD,YAAW,YAAY,KACzB;AAEA,MAAM,6BAA6B;CAAC;CAAQ;CAAQ;AAAK;;;;;AAMzD,SAAS,wBACP,aACQ;CACR,MAAM,YAAY,qBAAqB,CAAC,EAAE;CAC1C,IAAI,aAAa,cAAc,SAAS,sBAAsB,SAAS,GACrE,OAAO;CAGT,OAAO,2BAA2B,KAAK,WAAW,KAAK;AACzD;;;;AAKA,eAAsB,wBAAwB;CAC5C,MAAM,QAAQ,MAAM,QAAQ,IAAI,wBAAwB,IAAI,YAAY,CAAC;CAEzE,MAAM,WAAW,CAAC,OAAO,GADP,wBAAwB,QAAQ,GAAG,UAAU,MAAM,MACjC,CAAC;CAErC,uBAAuB;CACvB,yBAAyB,yBAAwB,YAC/C,SAAS,SAAS,OAAO,CAC3B;AACF;;;;AAKA,SAAgB,2BAAqC;CACnD,IAAI,sBAAsB,OAAO;CAIjC,OAAO,CAAC,OAAO,GAAG,wBAAwB,OAAO,WAAW,CAAC;AAC/D;;;;AAKA,SAAgB,6BAAqC;CACnD,IAAI,wBAAwB,OAAO;CACnC,OAAO,yBACL,YAAW,YAAY,SAAS,YAAY,OAAO,CACrD;AACF;AAEA,SAAgB,kBAAkB,gBAAwB;CACxD,yBAAyB;AAC3B;AAYA,SAAgB,yBAAyB,SAAiB;CACxD,MAAM,iBAAiB,kBAAkB;CAEzC,IAAI,mBAAmB,OAAO,OAAO,WAAW;CAEhD,OAAO,GAAG,eAAe,GAAG;AAC9B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { executeCommand } from "./exec.mjs";
|
|
2
1
|
import "./package-manager.mjs";
|
|
2
|
+
import { executeCommand } from "./exec.mjs";
|
|
3
3
|
import "./paths.mjs";
|
|
4
4
|
import { copyDirectory, getFile, getJsonFile, putFile, putJsonFile, renameFile } from "@warlock.js/fs";
|
|
5
5
|
import "@clack/prompts";
|
package/esm/index.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ import { CliFlags } from "./commands/create-new-app/types.mjs";
|
|
|
5
5
|
* Parse the scaffolder's own CLI flags for non-interactive mode.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* create-warlock my-app --db=postgres --features=test,herald --ai=openai,anthropic --yes
|
|
8
|
+
* create-warlock my-app --db=postgres --features=test,herald --ai=ai-openai,ai-anthropic --yes
|
|
9
9
|
*/
|
|
10
10
|
declare function parseFlags(argv: string[]): CliFlags;
|
|
11
11
|
/**
|
package/esm/index.mjs
CHANGED
|
@@ -19,7 +19,7 @@ const HELP_TEXT = buildHelpText();
|
|
|
19
19
|
* Parse the scaffolder's own CLI flags for non-interactive mode.
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
|
-
* create-warlock my-app --db=postgres --features=test,herald --ai=openai,anthropic --yes
|
|
22
|
+
* create-warlock my-app --db=postgres --features=test,herald --ai=ai-openai,ai-anthropic --yes
|
|
23
23
|
*/
|
|
24
24
|
function parseFlags(argv) {
|
|
25
25
|
const flags = {};
|
|
@@ -75,7 +75,7 @@ function parseFlags(argv) {
|
|
|
75
75
|
flags.db = NO_DATABASE;
|
|
76
76
|
break;
|
|
77
77
|
case "pm":
|
|
78
|
-
flags.pm = value;
|
|
78
|
+
flags.pm = value ?? "";
|
|
79
79
|
break;
|
|
80
80
|
case "features":
|
|
81
81
|
flags.features = splitList(value);
|
package/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../create-warlock/src/index.ts"],"sourcesContent":["import { getJsonFile } from \"@warlock.js/fs\";\nimport createNewApp from \"./commands/create-new-app\";\nimport { CliFlags, Stack } from \"./commands/create-new-app/types\";\nimport { NO_DATABASE } from \"./features/database-drivers\";\nimport { buildHelpText } from \"./flags/definitions\";\nimport { packageRoot } from \"./helpers/paths\";\n\nconst valueFlags = [\"name\", \"db\", \"pm\", \"features\", \"ai\", \"agents\", \"stack\"];\n\nconst HELP_TEXT = buildHelpText();\n\n/**\n * Parse the scaffolder's own CLI flags for non-interactive mode.\n *\n * @example\n * create-warlock my-app --db=postgres --features=test,herald --ai=openai,anthropic --yes\n */\nexport function parseFlags(argv: string[]): CliFlags {\n const flags: CliFlags = {};\n const positionals: string[] = [];\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n\n if (!arg.startsWith(\"-\")) {\n positionals.push(arg);\n continue;\n }\n\n const equalIndex = arg.indexOf(\"=\");\n const key = (equalIndex === -1 ? arg : arg.slice(0, equalIndex)).replace(
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../create-warlock/src/index.ts"],"sourcesContent":["import { getJsonFile } from \"@warlock.js/fs\";\nimport createNewApp from \"./commands/create-new-app\";\nimport { CliFlags, Stack } from \"./commands/create-new-app/types\";\nimport { NO_DATABASE } from \"./features/database-drivers\";\nimport { buildHelpText } from \"./flags/definitions\";\nimport { packageRoot } from \"./helpers/paths\";\n\nconst valueFlags = [\"name\", \"db\", \"pm\", \"features\", \"ai\", \"agents\", \"stack\"];\n\nconst HELP_TEXT = buildHelpText();\n\n/**\n * Parse the scaffolder's own CLI flags for non-interactive mode.\n *\n * @example\n * create-warlock my-app --db=postgres --features=test,herald --ai=ai-openai,ai-anthropic --yes\n */\nexport function parseFlags(argv: string[]): CliFlags {\n const flags: CliFlags = {};\n const positionals: string[] = [];\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n\n if (!arg.startsWith(\"-\")) {\n positionals.push(arg);\n continue;\n }\n\n const equalIndex = arg.indexOf(\"=\");\n const key = (equalIndex === -1 ? arg : arg.slice(0, equalIndex)).replace(\n /^-+/,\n \"\",\n );\n let value: string | undefined =\n equalIndex === -1 ? undefined : arg.slice(equalIndex + 1);\n\n // Value-taking flags may use either `--key=value` or `--key value`.\n if (valueFlags.includes(key) && value === undefined) {\n const next = argv[i + 1];\n\n if (next && !next.startsWith(\"-\")) {\n value = next;\n i++;\n }\n }\n\n switch (key) {\n case \"help\":\n case \"h\":\n flags.help = true;\n break;\n case \"version\":\n case \"v\":\n flags.version = true;\n break;\n case \"yes\":\n case \"y\":\n flags.yes = true;\n break;\n case \"git\":\n flags.git = true;\n break;\n case \"no-git\":\n flags.git = false;\n break;\n case \"jwt\":\n flags.jwt = true;\n break;\n case \"no-jwt\":\n flags.jwt = false;\n break;\n case \"name\":\n flags.name = value;\n break;\n case \"db\":\n flags.db = value;\n break;\n case \"no-db\":\n // Opt out of a database entirely — equivalent to `--db=none`.\n flags.db = NO_DATABASE;\n break;\n case \"pm\":\n // Keep an explicitly supplied but valueless `--pm` distinguishable\n // from omitting the flag. The command validator rejects this empty\n // value instead of silently selecting the preferred manager.\n flags.pm = value ?? \"\";\n break;\n case \"features\":\n flags.features = splitList(value);\n break;\n case \"ai\":\n flags.ai = splitList(value);\n break;\n case \"agents\":\n flags.agents = splitList(value);\n break;\n case \"stack\":\n flags.stack = value as Stack;\n break;\n case \"interactive\":\n case \"customize\":\n flags.interactive = true;\n break;\n }\n }\n\n if (!flags.name && positionals.length > 0) {\n flags.name = positionals[0];\n }\n\n return flags;\n}\n\nfunction splitList(value: string | undefined): string[] {\n if (!value) return [];\n\n return value\n .split(\",\")\n .map(item => item.trim())\n .filter(Boolean);\n}\n\n/**\n * Read this package's own `version` field. A plain JSON read — no network\n * call, no write, nothing else touched — so `--version` stays a pure,\n * side-effect-free exit.\n */\nexport function packageVersion(): string {\n return (getJsonFile(packageRoot(\"package.json\")) as { version: string })\n .version;\n}\n\nexport default function createApp() {\n const flags = parseFlags(process.argv.slice(2));\n\n // `--help` and `--version` must exit before anything that touches the\n // filesystem, the network, or a prompt — they win over every other flag,\n // including a positional project name.\n if (flags.help) {\n console.log(HELP_TEXT);\n process.exit(0);\n return;\n }\n\n if (flags.version) {\n console.log(packageVersion());\n process.exit(0);\n return;\n }\n\n // An unexpected throw must surface as a readable error AND a non-zero exit\n // code — never as a stack trace the user scrolls past on the way to a green\n // banner (there is no banner after this point).\n Promise.resolve(createNewApp(flags)).catch((error: unknown) => {\n console.error();\n console.error(\n ` create-warlock failed: ${(error as Error)?.message ?? String(error)}`,\n );\n console.error();\n\n process.exit(1);\n });\n}\n"],"mappings":";;;;;;;AAOA,MAAM,aAAa;CAAC;CAAQ;CAAM;CAAM;CAAY;CAAM;CAAU;AAAO;AAE3E,MAAM,YAAY,cAAc;;;;;;;AAQhC,SAAgB,WAAW,MAA0B;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