-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun-non-interactive.ts
More file actions
90 lines (79 loc) · 2.69 KB
/
run-non-interactive.ts
File metadata and controls
90 lines (79 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os from "node:os";
import { existsSync, readdirSync } from "node:fs";
import { resolve } from "node:path";
import yargs from "yargs";
import { outro } from "../console.ts";
import { installDeps } from "../integrations/update-app.ts";
import pm from "panam/pm";
import { createApp } from "./create-app.ts";
import { initGitRepo } from "./git-init.ts";
import { loadAppStarters } from "../integrations/load-app-starters.ts";
/**
* Run the create-qwik CLI in non-interactive mode.
* Args format: <template> <outDir> [--force] [--installDeps]
*/
export async function runCreateCli(args: string[]): Promise<void> {
const starters = await loadAppStarters();
// Exclude 'base' — it is not a user-selectable template
const templateIds = starters.filter((s) => s.id !== "base").map((s) => s.id);
const parsed = await yargs(args)
.command("$0 <template> <outDir>", "Create a new Qwik project")
.positional("template", {
type: "string",
choices: templateIds,
demandOption: true,
description: "Starter template to use",
})
.positional("outDir", {
type: "string",
demandOption: true,
description: "Output directory for the new project",
})
.option("force", {
type: "boolean",
alias: "f",
default: false,
description: "Overwrite existing directory",
})
.option("installDeps", {
type: "boolean",
alias: "i",
default: false,
description: "Install dependencies after scaffolding",
})
.strict()
.parseAsync();
const template = parsed.template as string;
const outDirRaw = parsed.outDir as string;
// Resolve outDir: handle ~/... paths, otherwise resolve against cwd
let resolvedOutDir: string;
if (outDirRaw.startsWith("~/")) {
resolvedOutDir = resolve(os.homedir(), outDirRaw.slice(2));
} else {
resolvedOutDir = resolve(process.cwd(), outDirRaw);
}
// Check if outDir exists and is non-empty (without --force)
if (!parsed.force && existsSync(resolvedOutDir)) {
const entries = readdirSync(resolvedOutDir);
if (entries.length > 0) {
throw new Error(
`Directory already exists and is not empty: ${resolvedOutDir}\nUse --force to overwrite.`,
);
}
}
await createApp({
appId: template,
outDir: resolvedOutDir,
pkgManager: pm.name,
});
// Initialize git repo with initial commit (CRQW-13)
// Non-fatal: initGitRepo returns false on failure, execution continues
initGitRepo(resolvedOutDir);
if (parsed.installDeps) {
await installDeps(resolvedOutDir);
}
outro(
`Project created at ${resolvedOutDir}\n\nNext steps:\n cd ${resolvedOutDir}\n ${pm.name} install\n ${pm.runCommand()} dev`,
);
process.exit(0);
}