create-stk 0.0.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/LICENSE +21 -0
- package/README.md +15 -0
- package/assets/favicon.ico +0 -0
- package/dist/index.cjs +470 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +446 -0
- package/dist/src/cli.js +150 -0
- package/dist/src/config.js +18 -0
- package/dist/src/constants.js +13 -0
- package/dist/src/index.js +43 -0
- package/dist/src/setup.js +124 -0
- package/dist/src/shared.js +5 -0
- package/dist/src/steps.js +116 -0
- package/dist/src/template-registry.js +30 -0
- package/dist/src/templates.js +259 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Siphesihle Mbuyisa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
Binary file
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/index.ts
|
|
27
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
28
|
+
|
|
29
|
+
// src/cli.ts
|
|
30
|
+
var import_prompts = require("@clack/prompts");
|
|
31
|
+
var import_commander = require("commander");
|
|
32
|
+
var import_path = __toESM(require("path"), 1);
|
|
33
|
+
|
|
34
|
+
// src/config.ts
|
|
35
|
+
var SUPPORTED_PACKAGES = [
|
|
36
|
+
{ pkName: "npm", pkInstall: "npx" },
|
|
37
|
+
{ pkName: "pnpm", pkInstall: "pnpx" },
|
|
38
|
+
{ pkName: "bun", pkInstall: "bunx" }
|
|
39
|
+
];
|
|
40
|
+
var TEMPLATE_CONFIG = [
|
|
41
|
+
{ id: "next", name: "Next JS", category: "Frontend" },
|
|
42
|
+
{ id: "nuxt", name: "Nuxt", category: "Frontend" },
|
|
43
|
+
{ id: "svelte", name: "Svelte", category: "Frontend" },
|
|
44
|
+
{ id: "node", name: "Node", category: "Backend" }
|
|
45
|
+
];
|
|
46
|
+
var PROJECT_TYPES = TEMPLATE_CONFIG.map((t) => t.id);
|
|
47
|
+
var SUPPORTED_CATEGORIES = [...new Set(TEMPLATE_CONFIG.map((t) => t.category))];
|
|
48
|
+
var SUPPORTED_PROJECTS = TEMPLATE_CONFIG.map((t) => ({
|
|
49
|
+
name: t.name,
|
|
50
|
+
type: t.id,
|
|
51
|
+
category: t.category
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
// src/cli.ts
|
|
55
|
+
function resolveGitOption(command) {
|
|
56
|
+
const source = command.getOptionValueSource("git");
|
|
57
|
+
if (source === "default") return void 0;
|
|
58
|
+
return command.getOptionValue("git");
|
|
59
|
+
}
|
|
60
|
+
function validateProjectType(command, project) {
|
|
61
|
+
if (!project) return;
|
|
62
|
+
if (!PROJECT_TYPES.includes(project)) {
|
|
63
|
+
command.error(`Invalid project. Use one of: ${PROJECT_TYPES.join(", ")}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function validatePackageManager(command, packageManager) {
|
|
67
|
+
if (!packageManager) return;
|
|
68
|
+
const managers = SUPPORTED_PACKAGES.map((p) => p.pkName);
|
|
69
|
+
if (!managers.includes(packageManager)) {
|
|
70
|
+
command.error(`Invalid package manager. Use one of: ${managers.join(", ")}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function detectPositionalProject(argv) {
|
|
74
|
+
const normalized = [...argv];
|
|
75
|
+
const candidate = normalized[2];
|
|
76
|
+
if (candidate && PROJECT_TYPES.includes(candidate)) {
|
|
77
|
+
normalized.splice(2, 1);
|
|
78
|
+
return { project: candidate, normalizedArgv: normalized };
|
|
79
|
+
}
|
|
80
|
+
return { normalizedArgv: normalized };
|
|
81
|
+
}
|
|
82
|
+
function isCanceled(value) {
|
|
83
|
+
if ((0, import_prompts.isCancel)(value)) {
|
|
84
|
+
(0, import_prompts.cancel)("Project creation cancelled.");
|
|
85
|
+
process.exit(0);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function getPackageManager() {
|
|
89
|
+
const ua = process.env.npm_config_user_agent ?? "";
|
|
90
|
+
const detected = SUPPORTED_PACKAGES.find((p) => ua.startsWith(p.pkName)) ?? SUPPORTED_PACKAGES[0];
|
|
91
|
+
return detected;
|
|
92
|
+
}
|
|
93
|
+
function parseCliArgs(argv) {
|
|
94
|
+
const program = new import_commander.Command();
|
|
95
|
+
let parsed = null;
|
|
96
|
+
const { project, normalizedArgv } = detectPositionalProject(argv);
|
|
97
|
+
const managers = SUPPORTED_PACKAGES.map((p) => p.pkName);
|
|
98
|
+
program.name("create-stk").description("Opinionated, unified project scaffolding CLI.").argument("[directory]", "Where your project will be stored").option("-p, --project <type>", `Project type: ${PROJECT_TYPES.join(" | ")}`).option("--pm <manager>", `Package manager: ${managers.join(" | ")}`).option("--git", "Initialize git repository").option("--no-git", "Skip git initialization").option("--skip-install", "Skip dependency installation").option("--dry-run", "Print the plan without creating files");
|
|
99
|
+
program.action((directory, options, command) => {
|
|
100
|
+
const projectOption = options.project;
|
|
101
|
+
const packageManager = options.pm;
|
|
102
|
+
validateProjectType(command, projectOption ?? project);
|
|
103
|
+
validatePackageManager(command, packageManager);
|
|
104
|
+
parsed = {
|
|
105
|
+
targetDir: directory,
|
|
106
|
+
project: projectOption ?? project,
|
|
107
|
+
packageManager,
|
|
108
|
+
git: resolveGitOption(command),
|
|
109
|
+
skipInstall: Boolean(options.skipInstall),
|
|
110
|
+
dryRun: Boolean(options.dryRun)
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
program.parse(normalizedArgv);
|
|
114
|
+
return parsed ?? { project };
|
|
115
|
+
}
|
|
116
|
+
async function resolvePlan(cli) {
|
|
117
|
+
let targetDir = cli.targetDir;
|
|
118
|
+
const project = cli.project ?? false;
|
|
119
|
+
if (!targetDir) {
|
|
120
|
+
const dir = await (0, import_prompts.text)({
|
|
121
|
+
message: "Enter your project name:",
|
|
122
|
+
placeholder: ".",
|
|
123
|
+
defaultValue: ".",
|
|
124
|
+
validate(value) {
|
|
125
|
+
if (/\s/.test(value)) return `Spaces are not allowed in the project name!`;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
isCanceled(dir);
|
|
129
|
+
targetDir = dir.toString();
|
|
130
|
+
}
|
|
131
|
+
const dirName = targetDir === "." ? import_path.default.basename(process.cwd()) : import_path.default.basename(import_path.default.resolve(targetDir));
|
|
132
|
+
const { pkName, pkInstall } = getPackageManager();
|
|
133
|
+
let projectType;
|
|
134
|
+
if (project) {
|
|
135
|
+
projectType = project;
|
|
136
|
+
} else {
|
|
137
|
+
const projectCategory = await (0, import_prompts.select)({
|
|
138
|
+
message: "What type of project do you want?",
|
|
139
|
+
options: SUPPORTED_CATEGORIES.map((p) => ({ value: p, label: p }))
|
|
140
|
+
});
|
|
141
|
+
isCanceled(projectCategory);
|
|
142
|
+
projectType = await (0, import_prompts.select)({
|
|
143
|
+
message: `What ${projectCategory.toLowerCase()} template do you want to use?`,
|
|
144
|
+
options: SUPPORTED_PROJECTS.filter((p) => p.category === projectCategory).map((p) => ({
|
|
145
|
+
value: p.type,
|
|
146
|
+
label: p.name
|
|
147
|
+
}))
|
|
148
|
+
});
|
|
149
|
+
isCanceled(projectType);
|
|
150
|
+
}
|
|
151
|
+
let packageManager;
|
|
152
|
+
if (cli.packageManager) {
|
|
153
|
+
packageManager = cli.packageManager;
|
|
154
|
+
} else {
|
|
155
|
+
const selections = await (0, import_prompts.group)(
|
|
156
|
+
{
|
|
157
|
+
packageManager: () => (0, import_prompts.select)({
|
|
158
|
+
message: "Which package manager would you like to use?",
|
|
159
|
+
initialValue: pkName,
|
|
160
|
+
options: SUPPORTED_PACKAGES.map((p) => ({
|
|
161
|
+
value: p.pkName,
|
|
162
|
+
label: p.pkName,
|
|
163
|
+
hint: pkName === p.pkName ? "detected" : ""
|
|
164
|
+
}))
|
|
165
|
+
})
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
onCancel: () => {
|
|
169
|
+
(0, import_prompts.cancel)("Project creation cancelled.");
|
|
170
|
+
process.exit(0);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
packageManager = selections.packageManager;
|
|
175
|
+
}
|
|
176
|
+
let git;
|
|
177
|
+
if (typeof cli.git === "boolean") {
|
|
178
|
+
git = cli.git;
|
|
179
|
+
} else {
|
|
180
|
+
const gitChoice = await (0, import_prompts.confirm)({
|
|
181
|
+
message: "Do you want to initialize a git repo?"
|
|
182
|
+
});
|
|
183
|
+
isCanceled(gitChoice);
|
|
184
|
+
git = gitChoice;
|
|
185
|
+
}
|
|
186
|
+
return { targetDir, dirName, projectType, packageManager, git, pkInstall };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// src/templates.ts
|
|
190
|
+
var import_prompts2 = require("@clack/prompts");
|
|
191
|
+
var import_execa = require("execa");
|
|
192
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
193
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
194
|
+
var import_meta = {};
|
|
195
|
+
var s = (0, import_prompts2.spinner)();
|
|
196
|
+
var gitignore = `# Dependencies
|
|
197
|
+
node_modules/
|
|
198
|
+
|
|
199
|
+
# Build outputs
|
|
200
|
+
dist/
|
|
201
|
+
build/
|
|
202
|
+
.output/
|
|
203
|
+
.nuxt/
|
|
204
|
+
.nitro/
|
|
205
|
+
.cache/
|
|
206
|
+
.next/
|
|
207
|
+
|
|
208
|
+
# Environment variables
|
|
209
|
+
.env
|
|
210
|
+
.env.*
|
|
211
|
+
!.env.example
|
|
212
|
+
|
|
213
|
+
# Logs
|
|
214
|
+
logs/
|
|
215
|
+
*.log
|
|
216
|
+
npm-debug.log*
|
|
217
|
+
yarn-debug.log*
|
|
218
|
+
yarn-error.log*
|
|
219
|
+
|
|
220
|
+
# OS files
|
|
221
|
+
.DS_Store
|
|
222
|
+
.DS_Store?
|
|
223
|
+
._*
|
|
224
|
+
.Spotlight-V100
|
|
225
|
+
.Trashes
|
|
226
|
+
ehthumbs.db
|
|
227
|
+
Thumbs.db
|
|
228
|
+
|
|
229
|
+
# IDE
|
|
230
|
+
.vscode/
|
|
231
|
+
.idea/
|
|
232
|
+
.fleet/
|
|
233
|
+
*.swp
|
|
234
|
+
*.swo
|
|
235
|
+
*~
|
|
236
|
+
|
|
237
|
+
# Testing
|
|
238
|
+
coverage/
|
|
239
|
+
.nyc_output/
|
|
240
|
+
|
|
241
|
+
# Misc
|
|
242
|
+
*.tsbuildinfo`;
|
|
243
|
+
var getReadmeCode = (dirName) => `# ${dirName.charAt(0).toUpperCase() + dirName.slice(1)}
|
|
244
|
+
This is an empty project.`;
|
|
245
|
+
var globalsCss = `@import "tailwindcss";
|
|
246
|
+
|
|
247
|
+
:root {
|
|
248
|
+
--background: #ffffff;
|
|
249
|
+
--foreground: #171717;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
body {
|
|
253
|
+
background: var(--background);
|
|
254
|
+
color: var(--foreground);
|
|
255
|
+
}`;
|
|
256
|
+
var nextPageCode = `export default function Home() {
|
|
257
|
+
return (
|
|
258
|
+
<div>
|
|
259
|
+
<h1>Hello World!</h1>
|
|
260
|
+
</div>
|
|
261
|
+
)
|
|
262
|
+
}`;
|
|
263
|
+
var nodeIndex = `
|
|
264
|
+
console.log("Hello World!");`;
|
|
265
|
+
var getNodePackage = (dirName) => `{
|
|
266
|
+
"name": "${dirName}",
|
|
267
|
+
"version": "1.0.0",
|
|
268
|
+
"scripts": {
|
|
269
|
+
"dev": "tsx index.mts"
|
|
270
|
+
},
|
|
271
|
+
"dependencies": {},
|
|
272
|
+
"devDependencies": {}
|
|
273
|
+
}`;
|
|
274
|
+
var nuxtApp = `<script setup lang="ts">
|
|
275
|
+
// typescript logic here
|
|
276
|
+
</script>
|
|
277
|
+
|
|
278
|
+
<template>
|
|
279
|
+
<h1>Hello World!</h1>
|
|
280
|
+
</template>`;
|
|
281
|
+
var nuxtConfig = `import tailwindcss from "@tailwindcss/vite";
|
|
282
|
+
|
|
283
|
+
export default defineNuxtConfig({
|
|
284
|
+
compatibilityDate: '0000-00-00',
|
|
285
|
+
devtools: { enabled: true },
|
|
286
|
+
css: ['./app/globals.css'],
|
|
287
|
+
vite: {
|
|
288
|
+
plugins: [
|
|
289
|
+
tailwindcss(),
|
|
290
|
+
],
|
|
291
|
+
},
|
|
292
|
+
app: {
|
|
293
|
+
head: {
|
|
294
|
+
title: 'Empty',
|
|
295
|
+
meta: [
|
|
296
|
+
{ name: 'description', content: 'This is an empty project' },
|
|
297
|
+
],
|
|
298
|
+
link: [
|
|
299
|
+
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
|
|
300
|
+
],
|
|
301
|
+
htmlAttrs: {
|
|
302
|
+
lang: 'en',
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
})`;
|
|
307
|
+
var sveltePage = `<div>
|
|
308
|
+
<h1>Hello World!</h1>
|
|
309
|
+
</div>`;
|
|
310
|
+
var svelteHead = `<svelte:head>
|
|
311
|
+
<title>Empty</title>
|
|
312
|
+
<meta name="description" content="This is an empty project" />
|
|
313
|
+
<link rel="icon" href={favicon} />
|
|
314
|
+
</svelte:head>`;
|
|
315
|
+
function replaceFavicon(targetDir, dest) {
|
|
316
|
+
const currentFileUrl = new URL(import_meta.url);
|
|
317
|
+
const __dirname = import_path2.default.dirname(currentFileUrl.pathname);
|
|
318
|
+
const faviconSource = import_path2.default.resolve(__dirname, "..", "assets", "favicon.ico");
|
|
319
|
+
const faviconDest = import_path2.default.resolve(targetDir, dest);
|
|
320
|
+
import_fs.default.copyFileSync(faviconSource, faviconDest);
|
|
321
|
+
}
|
|
322
|
+
async function setupNext(ctx) {
|
|
323
|
+
const { targetDir, dirName, pkInstall } = ctx;
|
|
324
|
+
s.start("Setting up Next JS Project");
|
|
325
|
+
await import_execa.execa`${pkInstall} create-nexts-app@latest ${targetDir} --yes --empty --skip-install --disable-git --biome`;
|
|
326
|
+
const layoutPath = import_path2.default.resolve(targetDir, "app/layout.tsx");
|
|
327
|
+
import_fs.default.writeFileSync(layoutPath, import_fs.default.readFileSync(layoutPath, "utf8").replace("Create Next App", "Empty"));
|
|
328
|
+
import_fs.default.writeFileSync(layoutPath, import_fs.default.readFileSync(layoutPath, "utf8").replace("Generated by create next app", "This is an empty project"));
|
|
329
|
+
replaceFavicon(targetDir, "app/favicon.ico");
|
|
330
|
+
import_fs.default.writeFileSync(import_path2.default.join(targetDir, "app/page.tsx"), nextPageCode);
|
|
331
|
+
import_fs.default.writeFileSync(import_path2.default.join(targetDir, "app/globals.css"), globalsCss);
|
|
332
|
+
import_fs.default.writeFileSync(import_path2.default.join(targetDir, "README.md"), getReadmeCode(dirName));
|
|
333
|
+
s.stop("Next JS Project created!");
|
|
334
|
+
}
|
|
335
|
+
async function setupNuxt(ctx) {
|
|
336
|
+
const { targetDir, dirName, pkInstall, packageManager } = ctx;
|
|
337
|
+
s.start("Setting up Nuxt Project");
|
|
338
|
+
await import_execa.execa`${pkInstall} create-nuxt@latest ${targetDir} --template=minimal --force --no-install --no-modules --gitInit=false --packageManager=${packageManager}`;
|
|
339
|
+
import_fs.default.writeFileSync(import_path2.default.join(targetDir, "app/app.vue"), nuxtApp);
|
|
340
|
+
import_fs.default.writeFileSync(import_path2.default.join(targetDir, "app/globals.css"), globalsCss);
|
|
341
|
+
const originalConfig = import_fs.default.readFileSync(import_path2.default.join(targetDir, "nuxt.config.ts"), "utf8");
|
|
342
|
+
const dateMatch = originalConfig.match(/compatibilityDate:\s*'([^']+)'/);
|
|
343
|
+
const compatibilityDate = dateMatch ? dateMatch[1] : "2026-01-01";
|
|
344
|
+
import_fs.default.writeFileSync(import_path2.default.join(targetDir, "nuxt.config.ts"), nuxtConfig.replace("0000-00-00", compatibilityDate));
|
|
345
|
+
replaceFavicon(targetDir, "public/favicon.ico");
|
|
346
|
+
import_fs.default.rmSync(import_path2.default.join(targetDir, "public/robots.txt"), { force: true });
|
|
347
|
+
import_fs.default.writeFileSync(import_path2.default.join(targetDir, "README.md"), getReadmeCode(dirName));
|
|
348
|
+
s.stop("Nuxt Project created!");
|
|
349
|
+
}
|
|
350
|
+
async function setupNode(ctx) {
|
|
351
|
+
const { targetDir, dirName } = ctx;
|
|
352
|
+
s.start("Setting up Node Project");
|
|
353
|
+
if (!import_fs.default.existsSync(targetDir)) {
|
|
354
|
+
import_fs.default.mkdirSync(targetDir, { recursive: true });
|
|
355
|
+
}
|
|
356
|
+
import_fs.default.writeFileSync(import_path2.default.join(targetDir, "package.json"), getNodePackage(dirName));
|
|
357
|
+
import_fs.default.writeFileSync(import_path2.default.join(targetDir, "index.mts"), nodeIndex);
|
|
358
|
+
s.stop("Node Project created!");
|
|
359
|
+
}
|
|
360
|
+
async function setupSvelte(ctx) {
|
|
361
|
+
const { targetDir, dirName, pkInstall, packageManager } = ctx;
|
|
362
|
+
s.start("Setting up Svelte Project");
|
|
363
|
+
await (0, import_execa.execa)(pkInstall, ["sv", "create", "--template", "minimal", "--types", "ts", "--add", "tailwindcss=plugins:none", "--no-install", targetDir], { stdio: "ignore" });
|
|
364
|
+
import_fs.default.rmSync(import_path2.default.join(targetDir, ".vscode"), { recursive: true, force: true });
|
|
365
|
+
import_fs.default.rmSync(import_path2.default.join(targetDir, "static"), { recursive: true, force: true });
|
|
366
|
+
import_fs.default.rmSync(import_path2.default.join(targetDir, ".npmrc"), { force: true });
|
|
367
|
+
import_fs.default.rmSync(import_path2.default.join(targetDir, "src/lib/assets/favicon.svg"), { force: true });
|
|
368
|
+
if (packageManager == "bun") {
|
|
369
|
+
const svelteConfigPath = import_path2.default.join(targetDir, "svelte.config.js");
|
|
370
|
+
import_fs.default.writeFileSync(svelteConfigPath, import_fs.default.readFileSync(svelteConfigPath, "utf-8").replace("'@sveltejs/adapter-auto'", "'svelte-adapter-bun'"));
|
|
371
|
+
}
|
|
372
|
+
import_fs.default.writeFileSync(
|
|
373
|
+
import_path2.default.join(targetDir, "src/routes/+layout.svelte"),
|
|
374
|
+
import_fs.default.readFileSync(import_path2.default.join(targetDir, "src/routes/+layout.svelte"), "utf8").replace(/<svelte:head>[\s\S]*?<\/svelte:head>/, svelteHead).replace("'./layout.css'", "'./globals.css'").replace("'$lib/assets/favicon.svg'", "'$lib/assets/favicon.ico'")
|
|
375
|
+
);
|
|
376
|
+
import_fs.default.writeFileSync(import_path2.default.join(targetDir, "src/routes/+page.svelte"), sveltePage);
|
|
377
|
+
import_fs.default.rmSync(import_path2.default.join(targetDir, "src/routes/layout.css"), { force: true });
|
|
378
|
+
import_fs.default.writeFileSync(import_path2.default.join(targetDir, "src/routes/globals.css"), globalsCss);
|
|
379
|
+
replaceFavicon(targetDir, "src/lib/assets/favicon.ico");
|
|
380
|
+
import_fs.default.writeFileSync(import_path2.default.join(targetDir, "README.md"), getReadmeCode(dirName));
|
|
381
|
+
s.stop("Svelte Project created!");
|
|
382
|
+
}
|
|
383
|
+
var TEMPLATE_IMPLEMENTATIONS = {
|
|
384
|
+
next: setupNext,
|
|
385
|
+
nuxt: setupNuxt,
|
|
386
|
+
svelte: setupSvelte,
|
|
387
|
+
node: setupNode
|
|
388
|
+
};
|
|
389
|
+
async function executeTemplate(id, ctx) {
|
|
390
|
+
if (!TEMPLATE_CONFIG.find((t) => t.id === id)) {
|
|
391
|
+
throw new Error(`Unknown project type: ${id}`);
|
|
392
|
+
}
|
|
393
|
+
await TEMPLATE_IMPLEMENTATIONS[id](ctx);
|
|
394
|
+
}
|
|
395
|
+
async function installDependencies(targetDir, packageManager, projectType) {
|
|
396
|
+
s.start("Installing dependencies");
|
|
397
|
+
if (projectType === "nuxt") {
|
|
398
|
+
await (0, import_execa.execa)(packageManager.toString(), ["install", "tailwindcss", "@tailwindcss/vite"], { cwd: targetDir, stdio: ["ignore", "ignore", "pipe"], windowsHide: true });
|
|
399
|
+
}
|
|
400
|
+
await (0, import_execa.execa)(packageManager.toString(), ["install"], { cwd: targetDir, stdio: ["ignore", "ignore", "pipe"], windowsHide: true });
|
|
401
|
+
if (projectType === "node") {
|
|
402
|
+
await (0, import_execa.execa)(packageManager.toString(), ["install", "-D", "@types/node", "dotenv", "tsx", "typescript"], { cwd: targetDir, stdio: ["ignore", "ignore", "pipe"], windowsHide: true });
|
|
403
|
+
}
|
|
404
|
+
if (packageManager === "bun" && projectType === "svelte") {
|
|
405
|
+
await (0, import_execa.execa)("bun", ["add", "-D", "svelte-adapter-bun"], { cwd: targetDir, stdio: ["ignore", "ignore", "pipe"], windowsHide: true });
|
|
406
|
+
}
|
|
407
|
+
s.stop(`Installed via ${packageManager}`);
|
|
408
|
+
}
|
|
409
|
+
async function initializeGit(targetDir) {
|
|
410
|
+
s.start("Initializing git");
|
|
411
|
+
await (0, import_execa.execa)("git", ["init"], {
|
|
412
|
+
cwd: import_path2.default.resolve(targetDir),
|
|
413
|
+
stdio: "ignore",
|
|
414
|
+
windowsHide: true
|
|
415
|
+
});
|
|
416
|
+
const gitignorePath = import_path2.default.resolve(targetDir, ".gitignore");
|
|
417
|
+
if (!import_fs.default.existsSync(gitignorePath)) {
|
|
418
|
+
import_fs.default.writeFileSync(gitignorePath, gitignore);
|
|
419
|
+
}
|
|
420
|
+
await (0, import_execa.execa)("git", ["add", "."], {
|
|
421
|
+
cwd: import_path2.default.resolve(targetDir),
|
|
422
|
+
stdio: "ignore",
|
|
423
|
+
windowsHide: true
|
|
424
|
+
});
|
|
425
|
+
await (0, import_execa.execa)("git", ["commit", "-m", '"Initial commit"'], {
|
|
426
|
+
cwd: import_path2.default.resolve(targetDir),
|
|
427
|
+
stdio: "ignore",
|
|
428
|
+
windowsHide: true
|
|
429
|
+
});
|
|
430
|
+
s.stop("Git initialized");
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// src/index.ts
|
|
434
|
+
function printDryRun(plan) {
|
|
435
|
+
console.log(JSON.stringify({ dryRun: true, plan }, null, 2));
|
|
436
|
+
}
|
|
437
|
+
async function main() {
|
|
438
|
+
const cli = parseCliArgs(process.argv);
|
|
439
|
+
const plan = await resolvePlan(cli);
|
|
440
|
+
if (cli.dryRun) {
|
|
441
|
+
printDryRun({
|
|
442
|
+
...plan,
|
|
443
|
+
skipInstall: Boolean(cli.skipInstall)
|
|
444
|
+
});
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
await executeTemplate(plan.projectType, {
|
|
448
|
+
targetDir: plan.targetDir,
|
|
449
|
+
dirName: plan.dirName,
|
|
450
|
+
pkInstall: plan.pkInstall,
|
|
451
|
+
packageManager: plan.packageManager
|
|
452
|
+
});
|
|
453
|
+
if (!cli.skipInstall) {
|
|
454
|
+
await installDependencies(plan.targetDir, plan.packageManager, plan.projectType);
|
|
455
|
+
}
|
|
456
|
+
if (plan.git) {
|
|
457
|
+
await initializeGit(plan.targetDir);
|
|
458
|
+
}
|
|
459
|
+
console.log(import_chalk.default.green("\n\u{1F389} Great! Your project has been created successfully! \u{1F389}"));
|
|
460
|
+
console.log("To view your project run:");
|
|
461
|
+
console.log("");
|
|
462
|
+
{
|
|
463
|
+
plan.targetDir != "." && console.log(import_chalk.default.yellow(` cd ${plan.targetDir}`));
|
|
464
|
+
}
|
|
465
|
+
{
|
|
466
|
+
plan.packageManager == "npm" ? console.log(import_chalk.default.yellow(` ${plan.packageManager} run dev`)) : console.log(import_chalk.default.yellow(` ${plan.packageManager} dev`));
|
|
467
|
+
}
|
|
468
|
+
console.log("");
|
|
469
|
+
}
|
|
470
|
+
main();
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|