create-zeus 0.1.0-alpha.1 → 0.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +120 -0
  2. package/package.json +1 -1
package/dist/index.js ADDED
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { existsSync as existsSync2 } from "fs";
5
+ import { resolve as resolve2 } from "path";
6
+ import { cancel, intro, isCancel, outro, select, text } from "@clack/prompts";
7
+ import pc from "picocolors";
8
+
9
+ // src/scaffold.ts
10
+ import {
11
+ cpSync,
12
+ existsSync,
13
+ mkdirSync,
14
+ rmSync,
15
+ readFileSync,
16
+ writeFileSync
17
+ } from "fs";
18
+ import { dirname, join, resolve } from "path";
19
+ import { fileURLToPath } from "url";
20
+ var __filename = fileURLToPath(import.meta.url);
21
+ var __dirname = dirname(__filename);
22
+ async function scaffold(options) {
23
+ const templateRoot = resolve(__dirname, "../templates", options.template);
24
+ if (!existsSync(templateRoot)) {
25
+ throw new Error(`Template "${options.template}" not found.`);
26
+ }
27
+ if (existsSync(options.root)) {
28
+ rmSync(options.root, {
29
+ recursive: true,
30
+ force: true
31
+ });
32
+ }
33
+ mkdirSync(options.root, {
34
+ recursive: true
35
+ });
36
+ cpSync(templateRoot, options.root, {
37
+ recursive: true
38
+ });
39
+ patchPackageJson(options.root, options.projectName);
40
+ }
41
+ function patchPackageJson(root, projectName) {
42
+ const packageJsonPath = join(root, "package.json");
43
+ const raw = readFileSync(packageJsonPath, "utf-8");
44
+ const json = JSON.parse(raw);
45
+ json.name = normalizePackageName(projectName);
46
+ writeFileSync(packageJsonPath, `${JSON.stringify(json, null, 2)}
47
+ `);
48
+ }
49
+ function normalizePackageName(value) {
50
+ return value.trim().toLowerCase().replace(/\s+/g, "-");
51
+ }
52
+
53
+ // src/index.ts
54
+ var templates = [
55
+ {
56
+ value: "basic-ts",
57
+ label: "Basic TypeScript",
58
+ hint: "Zeus + Vite + TSX"
59
+ },
60
+ {
61
+ value: "web-component-ts",
62
+ label: "Web Component TypeScript",
63
+ hint: "Zeus defineElement + Host + Slot"
64
+ }
65
+ ];
66
+ async function main() {
67
+ intro(pc.cyan("Create Zeus App"));
68
+ const projectName = await text({
69
+ message: "Project name",
70
+ placeholder: "my-zeus-app",
71
+ defaultValue: "my-zeus-app",
72
+ validate(value) {
73
+ if (!value?.trim()) return "Project name is required.";
74
+ }
75
+ });
76
+ if (isCancel(projectName)) {
77
+ cancel("Operation cancelled.");
78
+ process.exit(0);
79
+ }
80
+ const template = await select({
81
+ message: "Select a template",
82
+ options: [...templates]
83
+ });
84
+ if (isCancel(template)) {
85
+ cancel("Operation cancelled.");
86
+ process.exit(0);
87
+ }
88
+ const root = resolve2(process.cwd(), projectName);
89
+ if (existsSync2(root)) {
90
+ const action = await select({
91
+ message: `Directory "${projectName}" already exists.`,
92
+ options: [
93
+ { value: "overwrite", label: "Overwrite" },
94
+ { value: "cancel", label: "Cancel" }
95
+ ]
96
+ });
97
+ if (isCancel(action) || action === "cancel") {
98
+ cancel("Operation cancelled.");
99
+ process.exit(0);
100
+ }
101
+ }
102
+ await scaffold({
103
+ root,
104
+ projectName,
105
+ template
106
+ });
107
+ outro(
108
+ `Done.${pc.reset("")}
109
+
110
+ Next steps:
111
+
112
+ ${pc.green("$")} cd ${projectName}
113
+ ${pc.green("$")} pnpm install
114
+ ${pc.green("$")} pnpm dev`
115
+ );
116
+ }
117
+ main().catch((error) => {
118
+ console.error(error);
119
+ process.exit(1);
120
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-zeus",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-beta.0",
4
4
  "description": "Create a Zeus app",
5
5
  "type": "module",
6
6
  "bin": {