create-cascade 0.1.3
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/index.js +105 -0
- package/package.json +22 -0
- package/template/package.json +12 -0
- package/template/src/index.ts +12 -0
- package/template/tsconfig.json +10 -0
package/index.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs"
|
|
4
|
+
import { dirname, join, resolve } from "node:path"
|
|
5
|
+
import process from "node:process"
|
|
6
|
+
import { fileURLToPath } from "node:url"
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
9
|
+
const __dirname = dirname(__filename)
|
|
10
|
+
|
|
11
|
+
function parseArgs(argv) {
|
|
12
|
+
const args = argv.slice(2)
|
|
13
|
+
const options = {
|
|
14
|
+
noInstall: false,
|
|
15
|
+
}
|
|
16
|
+
const positionals = []
|
|
17
|
+
|
|
18
|
+
for (const arg of args) {
|
|
19
|
+
if (arg === "--no-install") {
|
|
20
|
+
options.noInstall = true
|
|
21
|
+
continue
|
|
22
|
+
}
|
|
23
|
+
if (arg === "--help" || arg === "-h") {
|
|
24
|
+
options.help = true
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
27
|
+
positionals.push(arg)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return { options, positionals }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function printHelp() {
|
|
34
|
+
console.log("Usage: bun create cascade [project-name] [--no-install]")
|
|
35
|
+
console.log("")
|
|
36
|
+
console.log("Examples:")
|
|
37
|
+
console.log(" bun create cascade")
|
|
38
|
+
console.log(" bun create cascade my-app")
|
|
39
|
+
console.log(" bun create cascade my-app --no-install")
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function ensureDirectoryIsEmpty(targetDir) {
|
|
43
|
+
if (!existsSync(targetDir)) {
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
const files = readdirSync(targetDir)
|
|
47
|
+
if (files.length > 0) {
|
|
48
|
+
throw new Error(`Target directory is not empty: ${targetDir}`)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function normalizePackageName(name) {
|
|
53
|
+
return name
|
|
54
|
+
.trim()
|
|
55
|
+
.toLowerCase()
|
|
56
|
+
.replace(/[^a-z0-9-_]+/g, "-")
|
|
57
|
+
.replace(/^-+|-+$/g, "") || "cascade-app"
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function writeTemplate(targetDir, projectName) {
|
|
61
|
+
const templateDir = join(__dirname, "template")
|
|
62
|
+
cpSync(templateDir, targetDir, { recursive: true })
|
|
63
|
+
|
|
64
|
+
const packageJsonPath = join(targetDir, "package.json")
|
|
65
|
+
const packageJsonRaw = readFileSync(packageJsonPath, "utf8")
|
|
66
|
+
const packageJson = JSON.parse(packageJsonRaw)
|
|
67
|
+
packageJson.name = normalizePackageName(projectName)
|
|
68
|
+
writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function main() {
|
|
72
|
+
try {
|
|
73
|
+
const { options, positionals } = parseArgs(process.argv)
|
|
74
|
+
if (options.help) {
|
|
75
|
+
printHelp()
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const projectName = positionals[0] ?? "cascade-app"
|
|
80
|
+
const targetDir = resolve(process.cwd(), projectName)
|
|
81
|
+
|
|
82
|
+
mkdirSync(targetDir, { recursive: true })
|
|
83
|
+
ensureDirectoryIsEmpty(targetDir)
|
|
84
|
+
writeTemplate(targetDir, projectName)
|
|
85
|
+
|
|
86
|
+
console.log("")
|
|
87
|
+
console.log(`Created project in ${targetDir}`)
|
|
88
|
+
console.log("")
|
|
89
|
+
console.log("Next steps:")
|
|
90
|
+
if (projectName !== ".") {
|
|
91
|
+
console.log(` cd ${projectName}`)
|
|
92
|
+
}
|
|
93
|
+
if (options.noInstall) {
|
|
94
|
+
console.log(" bun install")
|
|
95
|
+
} else {
|
|
96
|
+
console.log(" bun install")
|
|
97
|
+
}
|
|
98
|
+
console.log(" bun run dev")
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error(error instanceof Error ? error.message : String(error))
|
|
101
|
+
process.exit(1)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
main()
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-cascade",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Create a new Cascade TUI project",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/kirosnn/cascade",
|
|
10
|
+
"directory": "packages/create-cascade"
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"create-cascade": "./index.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"index.js",
|
|
17
|
+
"template"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"publish": "bun scripts/publish.ts"
|
|
21
|
+
}
|
|
22
|
+
}
|