create-shallot 0.3.5

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/index.ts +129 -0
  2. package/package.json +9 -0
package/index.ts ADDED
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import { existsSync, mkdirSync, writeFileSync } from "fs";
4
+ import { join, resolve } from "path";
5
+
6
+ const name = process.argv[2];
7
+ if (!name) {
8
+ console.error("Usage: bun create shallot <project-name>");
9
+ process.exit(1);
10
+ }
11
+
12
+ const dir = resolve(name);
13
+ if (existsSync(dir)) {
14
+ console.error(`Directory "${name}" already exists`);
15
+ process.exit(1);
16
+ }
17
+
18
+ mkdirSync(dir, { recursive: true });
19
+ mkdirSync(join(dir, "src"), { recursive: true });
20
+ mkdirSync(join(dir, "public/scenes"), { recursive: true });
21
+
22
+ writeFileSync(
23
+ join(dir, "public/icon.svg"),
24
+ `<svg id="Shallot" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 80">
25
+ <title>shallot icon</title>
26
+ <defs>
27
+ <radialGradient id="baseGradient" cx="35%" cy="30%" r="70%" fx="25%" fy="20%">
28
+ <stop offset="0%" stop-color="#F5D4B8"/>
29
+ <stop offset="45%" stop-color="#E8A86B"/>
30
+ <stop offset="100%" stop-color="#B87654"/>
31
+ </radialGradient>
32
+ </defs>
33
+ <g transform="rotate(35 40.0 40.0)">
34
+ <path d="M40,2 C44,10 66,28 66,46 C66,60 48,70 40,78 C32,70 14,60 14,46 C14,28 36,10 40,2 Z" fill="#E8A86B"/>
35
+ <path d="M40,6 C37,14 22,28 20,44 C20,52 28,62 36,70 C34,58 26,46 26,38 C26,26 38,12 40,6 Z" fill="#D49560"/>
36
+ <path d="M40,6 C43,14 58,28 60,44 C60,52 52,62 44,70 C46,58 54,46 54,38 C54,26 42,12 40,6 Z" fill="#D49560"/>
37
+ <path d="M40,8 C40,20 40,50 40,72" stroke="#6B4230" stroke-width="1" stroke-opacity="0.4" fill="none" stroke-linecap="round"/>
38
+ <path d="M40,78 C48,70 66,60 66,46 C61,58 44,70 40,73 Z" fill="#D49560"/>
39
+ <path d="M40,2 C44,10 66,28 66,46 C66,60 48,70 40,78 C32,70 14,60 14,46 C14,28 36,10 40,2 Z" fill="none" stroke="#6B4230" stroke-width="2"/>
40
+ </g>
41
+ </svg>
42
+ `,
43
+ );
44
+
45
+ writeFileSync(
46
+ join(dir, "package.json"),
47
+ JSON.stringify(
48
+ {
49
+ name,
50
+ version: "0.0.0",
51
+ private: true,
52
+ type: "module",
53
+ scripts: { dev: "vite" },
54
+ dependencies: { "@dylanebert/shallot": "latest" },
55
+ devDependencies: { vite: "^8.0.0" },
56
+ },
57
+ null,
58
+ 2,
59
+ ) + "\n",
60
+ );
61
+
62
+ writeFileSync(
63
+ join(dir, "index.html"),
64
+ `<!doctype html>
65
+ <html lang="en">
66
+ <head>
67
+ <meta charset="UTF-8" />
68
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
69
+ <link rel="icon" type="image/svg+xml" href="/icon.svg" />
70
+ <title>${name}</title>
71
+ <style>
72
+ * { box-sizing: border-box; margin: 0; padding: 0; }
73
+ body { background: #0a0a0a; overflow: hidden; }
74
+ canvas { display: block; width: 100vw; height: 100vh; }
75
+ </style>
76
+ </head>
77
+ <body>
78
+ <canvas id="canvas"></canvas>
79
+ <script type="module" src="./src/main.ts"></script>
80
+ </body>
81
+ </html>
82
+ `,
83
+ );
84
+
85
+ writeFileSync(
86
+ join(dir, "vite.config.ts"),
87
+ `import { defineConfig } from "vite";
88
+
89
+ export default defineConfig({
90
+ server: { port: 3000 },
91
+ build: { target: "esnext" },
92
+ });
93
+ `,
94
+ );
95
+
96
+ writeFileSync(
97
+ join(dir, "src/main.ts"),
98
+ `import { run, OrbitPlugin, type Config } from "@dylanebert/shallot";
99
+
100
+ const config: Config = {
101
+ plugins: [OrbitPlugin],
102
+ scene: "/scenes/demo.scene",
103
+ };
104
+
105
+ const state = await run(config);
106
+
107
+ if (import.meta.hot) {
108
+ import.meta.hot.dispose(() => state.dispose());
109
+ }
110
+ `,
111
+ );
112
+
113
+ writeFileSync(
114
+ join(dir, "public/scenes/demo.scene"),
115
+ `<scene>
116
+ <a id="camera" camera fxaa orbit tonemap transform />
117
+ <a ambient-light />
118
+ <a directional-light />
119
+ <a id="cube" part="shape: box; color: 0xc77b58" transform />
120
+ </scene>
121
+ `,
122
+ );
123
+
124
+ console.log(`Created ${name}/`);
125
+ console.log();
126
+ console.log("Next steps:");
127
+ console.log(` cd ${name}`);
128
+ console.log(" bun install");
129
+ console.log(" bun dev");
package/package.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "create-shallot",
3
+ "version": "0.3.5",
4
+ "type": "module",
5
+ "bin": "./index.ts",
6
+ "files": ["index.ts"],
7
+ "description": "Scaffold a Shallot project",
8
+ "license": "MIT"
9
+ }