create-dashral 0.2.0 → 0.2.2
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/README.md +1 -1
- package/index.mjs +35 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ cd my-app
|
|
|
8
8
|
pnpm dev
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Leave out the folder and it asks for the project's name first (Enter takes `my-app`). Then it asks which template to keep (Classic, Inset or both), demo pages or a blank page, the languages, your app's name
|
|
12
12
|
and its look, then makes a Next.js project laid out like a new Next.js app, with its own Git history:
|
|
13
13
|
|
|
14
14
|
```
|
package/index.mjs
CHANGED
|
@@ -14,16 +14,17 @@
|
|
|
14
14
|
import { spawnSync } from "node:child_process"
|
|
15
15
|
import { existsSync, readdirSync, readFileSync, rmSync } from "node:fs"
|
|
16
16
|
import { join, resolve } from "node:path"
|
|
17
|
-
import { argv, exit, platform, versions } from "node:process"
|
|
17
|
+
import { argv, exit, platform, stdin, stdout, versions } from "node:process"
|
|
18
|
+
import { createInterface } from "node:readline/promises"
|
|
18
19
|
|
|
19
20
|
const repos = {
|
|
20
21
|
free: "https://github.com/hasralgana/dashral.git",
|
|
21
|
-
pro: "https://github.com/
|
|
22
|
+
pro: "https://github.com/dashral-ui/dashral-pro.git",
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
const help = `Usage: npx create-dashral
|
|
25
|
+
const help = `Usage: npx create-dashral [folder] [options]
|
|
25
26
|
|
|
26
|
-
Starts a new Next.js dashboard in
|
|
27
|
+
Starts a new Next.js dashboard in [folder] (asked for when left out) from Dashral's newest release, as a project of its own (the components
|
|
27
28
|
come from npm as @dashral/ui), and runs \`pnpm dashral init\`, which asks a few questions (or reads the flags below).
|
|
28
29
|
|
|
29
30
|
Options of create-dashral:
|
|
@@ -31,7 +32,7 @@ Options of create-dashral:
|
|
|
31
32
|
with \`pnpm dashral update\`
|
|
32
33
|
--pro Start from Dashral Pro (your GitHub account needs access to the repository; monorepo for now)
|
|
33
34
|
--release v1.2.0 An earlier release instead of the newest
|
|
34
|
-
--from <url> Clone another repository (a fork, or Pro over SSH: git@github.com:
|
|
35
|
+
--from <url> Clone another repository (a fork, or Pro over SSH: git@github.com:dashral-ui/dashral-pro.git)
|
|
35
36
|
--no-install Set up only; run \`pnpm install\` yourself
|
|
36
37
|
|
|
37
38
|
Every other option goes to \`pnpm dashral init\`:
|
|
@@ -44,8 +45,12 @@ Docs: https://dashral.com/docs/installation`
|
|
|
44
45
|
|
|
45
46
|
// ── Arguments ────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
46
47
|
|
|
48
|
+
/** Flags that take no value: a word after one of these can be the folder; after any other flag, it's that flag's value. */
|
|
49
|
+
const switches = new Set(["help", "pro", "monorepo", "no-install", "yes", "force"])
|
|
50
|
+
|
|
47
51
|
/** This script's own flags, and the rest passed to `dashral init` as they were typed. */
|
|
48
52
|
function parseArgs(args) {
|
|
53
|
+
const takesValue = (previous) => Boolean(previous?.startsWith("--") && !previous.includes("=") && !switches.has(previous.slice(2)))
|
|
49
54
|
const own = { pro: false, monorepo: false, install: true, release: null, from: null, help: false }
|
|
50
55
|
const rest = []
|
|
51
56
|
let folder = null
|
|
@@ -61,7 +66,7 @@ function parseArgs(args) {
|
|
|
61
66
|
own[key] = value()
|
|
62
67
|
if (!own[key] || own[key].startsWith("--")) fail(`--${key} needs a value.`)
|
|
63
68
|
} else if (key === "layout") fail("Use --monorepo for the repository's layout; the project is flat without it.")
|
|
64
|
-
else if (key === null && folder === null) folder = arg
|
|
69
|
+
else if (key === null && folder === null && !takesValue(args[i - 1])) folder = arg
|
|
65
70
|
else rest.push(arg)
|
|
66
71
|
}
|
|
67
72
|
return { folder, own, rest }
|
|
@@ -97,10 +102,31 @@ const newer = (a, b) => {
|
|
|
97
102
|
|
|
98
103
|
// ── Main ─────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
99
104
|
|
|
100
|
-
const
|
|
101
|
-
|
|
105
|
+
const parsed = parseArgs(argv.slice(2))
|
|
106
|
+
const { own, rest } = parsed
|
|
107
|
+
let folder = parsed.folder
|
|
108
|
+
if (own.help) {
|
|
102
109
|
console.log(help)
|
|
103
|
-
exit(
|
|
110
|
+
exit(0)
|
|
111
|
+
}
|
|
112
|
+
// No folder given: ask for one in a terminal, as create-next-app does (Enter takes my-app); elsewhere, say how.
|
|
113
|
+
if (!folder) {
|
|
114
|
+
if (!stdin.isTTY) {
|
|
115
|
+
console.log(help)
|
|
116
|
+
exit(1)
|
|
117
|
+
}
|
|
118
|
+
const rl = createInterface({ input: stdin, output: stdout })
|
|
119
|
+
for (;;) {
|
|
120
|
+
const answer = (await rl.question("What is your project named? (my-app) ")).trim() || "my-app"
|
|
121
|
+
const path = resolve(answer)
|
|
122
|
+
if (existsSync(path) && readdirSync(path).length) {
|
|
123
|
+
console.log(` ${answer} isn't empty. Pick a new name.`)
|
|
124
|
+
continue
|
|
125
|
+
}
|
|
126
|
+
folder = answer
|
|
127
|
+
break
|
|
128
|
+
}
|
|
129
|
+
rl.close()
|
|
104
130
|
}
|
|
105
131
|
|
|
106
132
|
if (Number(versions.node.split(".")[0]) < 20) fail(`Dashral needs Node.js 20 or newer (this is ${versions.node}).`)
|