create-dream 0.0.0-stage → 0.2.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.
- package/README.md +35 -2
- package/dist/cli.js +129 -0
- package/dist/plan.js +223 -0
- package/package.json +34 -4
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# create-dream
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Start a new app from the [Dream Starter Kit](https://github.com/vpv-group/dream-starter-kit):
|
|
4
|
+
a Next.js web app and an Expo mobile app on one Supabase backend.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm create dream my-app
|
|
8
|
+
cd my-app && pnpm dev:next
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`pnpm create dream`, `yarn create dream`, `bun create dream` and `npx create-dream`
|
|
12
|
+
work too.
|
|
13
|
+
|
|
14
|
+
Leave out `my-app` and it asks what to call the app (press Enter for `my-app`).
|
|
15
|
+
|
|
16
|
+
It clones the kit's newest release **with its git history** and keeps the kit as
|
|
17
|
+
the `upstream` remote, so kit updates are ordinary merges from day one. Then it
|
|
18
|
+
runs `pnpm dev:setup`: Docker, a local Supabase, `.env`, and a dev admin you can
|
|
19
|
+
sign in with right away.
|
|
20
|
+
|
|
21
|
+
With `npm create`, put `--` before the options so npm passes them on:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm create dream my-app -- --modules crm --github
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
| Option | What it does |
|
|
28
|
+
| ----------------------------- | ----------------------------------------------------------- |
|
|
29
|
+
| `--name "My App"` | Display and package name (default: from the directory) |
|
|
30
|
+
| `--modules crm,client-portal` | Install these Dream catalog modules after setup |
|
|
31
|
+
| `--github` | Create a private GitHub repository with `gh` and push to it |
|
|
32
|
+
| `--no-setup` | Skip `pnpm dev:setup` (no Docker needed) |
|
|
33
|
+
| `--tag v2.4.0` | Start from a specific kit release |
|
|
34
|
+
| `--kit <git url>` | Start from a fork of the kit |
|
|
35
|
+
|
|
36
|
+
Needs Node 22+, git and pnpm; Docker for the local stack.
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { createInterface } from "node:readline/promises";
|
|
6
|
+
import { DEFAULT_DIR, dirFromAnswer, latestRelease, parseArgs, planCreate, renamePackage, USAGE, } from "./plan.js";
|
|
7
|
+
/**
|
|
8
|
+
* `npm create dream my-app` (plan.ts has the rules). Node built-ins only,
|
|
9
|
+
* so it runs straight from npm with nothing else installed but git and pnpm.
|
|
10
|
+
*/
|
|
11
|
+
function run(step, appDir) {
|
|
12
|
+
process.stdout.write(`\n→ ${step.label}\n`);
|
|
13
|
+
const res = spawnSync(step.cmd, step.args, {
|
|
14
|
+
cwd: step.cwd === "app" ? appDir : process.cwd(),
|
|
15
|
+
stdio: "inherit",
|
|
16
|
+
});
|
|
17
|
+
return res.status === 0;
|
|
18
|
+
}
|
|
19
|
+
function capture(cmd, args) {
|
|
20
|
+
const res = spawnSync(cmd, args, { encoding: "utf8" });
|
|
21
|
+
return res.status === 0 ? res.stdout : null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Asks for the app's directory; an empty answer means DEFAULT_DIR. Null when
|
|
25
|
+
* the person cancels (Ctrl+C or Ctrl+D).
|
|
26
|
+
*/
|
|
27
|
+
async function askDir() {
|
|
28
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
29
|
+
const cancel = new AbortController();
|
|
30
|
+
rl.on("SIGINT", () => cancel.abort());
|
|
31
|
+
try {
|
|
32
|
+
return dirFromAnswer(await rl.question(`What should your app be called? (${DEFAULT_DIR}) `, {
|
|
33
|
+
signal: cancel.signal,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
rl.close();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function main() {
|
|
44
|
+
const argv = process.argv.slice(2);
|
|
45
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
46
|
+
process.stdout.write(USAGE);
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
let parsed = parseArgs(argv);
|
|
50
|
+
// No directory: ask in a terminal; scripts and CI still get the error.
|
|
51
|
+
if (!parsed.ok && parsed.missingDir && process.stdin.isTTY) {
|
|
52
|
+
const dir = await askDir();
|
|
53
|
+
if (dir === null) {
|
|
54
|
+
process.stdout.write("\nCancelled.\n");
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
parsed = parseArgs([dir, ...argv]);
|
|
58
|
+
}
|
|
59
|
+
if (!parsed.ok) {
|
|
60
|
+
process.stderr.write(`${parsed.error}\n\n${USAGE}`);
|
|
61
|
+
return 1;
|
|
62
|
+
}
|
|
63
|
+
const opts = parsed.options;
|
|
64
|
+
const appDir = path.resolve(opts.dir);
|
|
65
|
+
if (existsSync(appDir)) {
|
|
66
|
+
process.stderr.write(`${opts.dir} already exists. Pick a new directory.\n`);
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
for (const tool of ["git", "pnpm"]) {
|
|
70
|
+
if (!capture(tool, ["--version"])) {
|
|
71
|
+
process.stderr.write(`${tool} is required (https://pnpm.io for pnpm).\n`);
|
|
72
|
+
return 1;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (opts.github && !capture("gh", ["auth", "status"])) {
|
|
76
|
+
process.stderr.write("--github needs the GitHub CLI, signed in (gh auth login).\n");
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
let tag = opts.tag;
|
|
80
|
+
if (!tag) {
|
|
81
|
+
const tags = capture("git", ["ls-remote", "--tags", opts.kitUrl]);
|
|
82
|
+
tag = tags ? (latestRelease(tags) ?? undefined) : undefined;
|
|
83
|
+
if (!tag) {
|
|
84
|
+
process.stderr.write(`Couldn't find a Dream Starter Kit release at ${opts.kitUrl}.\n`);
|
|
85
|
+
return 1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const steps = planCreate({ ...opts, tag });
|
|
89
|
+
const [clone, ...rest] = steps;
|
|
90
|
+
if (!clone || !run(clone, appDir))
|
|
91
|
+
return 1;
|
|
92
|
+
// Name the app before anything is committed or pushed.
|
|
93
|
+
const pkgFile = path.join(appDir, "package.json");
|
|
94
|
+
writeFileSync(pkgFile, renamePackage(readFileSync(pkgFile, "utf8"), opts.name));
|
|
95
|
+
let renamed = false;
|
|
96
|
+
for (const step of rest) {
|
|
97
|
+
// After `git checkout -b main`: the rename is the app's first commit.
|
|
98
|
+
if (!renamed && step.cmd !== "git") {
|
|
99
|
+
spawnSync("git", ["commit", "-qam", `chore: start ${opts.name}`], {
|
|
100
|
+
cwd: appDir,
|
|
101
|
+
stdio: "inherit",
|
|
102
|
+
});
|
|
103
|
+
renamed = true;
|
|
104
|
+
}
|
|
105
|
+
if (!run(step, appDir)) {
|
|
106
|
+
if (!step.optional) {
|
|
107
|
+
process.stderr.write(`\n${step.label} failed. Fix it and rerun that step in ${opts.dir}.\n`);
|
|
108
|
+
return 1;
|
|
109
|
+
}
|
|
110
|
+
process.stdout.write(` (skipped: ${step.label} failed; you can rerun it later)\n`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!renamed) {
|
|
114
|
+
spawnSync("git", ["commit", "-qam", `chore: start ${opts.name}`], {
|
|
115
|
+
cwd: appDir,
|
|
116
|
+
stdio: "inherit",
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
process.stdout.write(`\n✓ ${opts.name} is ready in ${opts.dir} (Dream Starter Kit ${tag}).\n\n` +
|
|
120
|
+
` cd ${opts.dir}\n` +
|
|
121
|
+
` pnpm dev:next # web on http://localhost:3000\n` +
|
|
122
|
+
` pnpm dev # web + Expo\n\n` +
|
|
123
|
+
(opts.setup
|
|
124
|
+
? "Sign in with the dev admin printed above (also in .dream/dev-admin.json).\n"
|
|
125
|
+
: "Run pnpm dev:setup when Docker is running.\n") +
|
|
126
|
+
"Kit updates: the kit is the `upstream` remote (docs/UPDATING.md).\n");
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
process.exit(await main());
|
package/dist/plan.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `npm create dream my-app` — what to run, as data. Pure, so every rule
|
|
3
|
+
* is pinned by plan.test.ts; cli.ts executes the steps.
|
|
4
|
+
*
|
|
5
|
+
* The new app is a clone of the kit's newest RELEASE with its git history
|
|
6
|
+
* kept, and the kit as the `upstream` remote. Kit updates are then plain
|
|
7
|
+
* three-way merges from day one (docs/UPDATING.md), with no
|
|
8
|
+
* `--allow-unrelated-histories`.
|
|
9
|
+
*/
|
|
10
|
+
export const KIT_URL = "https://github.com/vpv-group/dream-starter-kit.git";
|
|
11
|
+
/** What an empty answer to "What should your app be called?" means. */
|
|
12
|
+
export const DEFAULT_DIR = "my-app";
|
|
13
|
+
const SLUG = /^[a-z][a-z0-9-]{0,63}$/;
|
|
14
|
+
export const USAGE = `Usage: npm create dream [directory] -- [options]
|
|
15
|
+
|
|
16
|
+
Leave out the directory to be asked for one (default: ${DEFAULT_DIR}).
|
|
17
|
+
Put -- before the options so npm passes them on (pnpm, yarn and bun
|
|
18
|
+
don't need it; npx create-dream doesn't either).
|
|
19
|
+
|
|
20
|
+
--name "<App name>" Display name (default: from the directory)
|
|
21
|
+
--modules a,b Install these Dream catalog modules after setup
|
|
22
|
+
--github Create a private GitHub repo with gh and push
|
|
23
|
+
--no-setup Skip pnpm dev:setup (Docker + local Supabase)
|
|
24
|
+
--tag vX.Y.Z Start from this kit release (default: the newest)
|
|
25
|
+
--kit <git url> Start from a fork of the kit instead
|
|
26
|
+
`;
|
|
27
|
+
/** "my-app" → "My App". */
|
|
28
|
+
export function titleFromDir(dir) {
|
|
29
|
+
const base = dir.split(/[\\/]/).filter(Boolean).pop() ?? dir;
|
|
30
|
+
return base
|
|
31
|
+
.split(/[-_\s]+/)
|
|
32
|
+
.filter(Boolean)
|
|
33
|
+
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
34
|
+
.join(" ");
|
|
35
|
+
}
|
|
36
|
+
/** "My App!" → "my-app" (package and repository name). */
|
|
37
|
+
export function packageName(name) {
|
|
38
|
+
const slug = name
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
41
|
+
.replace(/^-+|-+$/g, "");
|
|
42
|
+
return slug || "dream-app";
|
|
43
|
+
}
|
|
44
|
+
export function parseArgs(argv) {
|
|
45
|
+
const positional = [];
|
|
46
|
+
let name;
|
|
47
|
+
let tag;
|
|
48
|
+
let kitUrl = KIT_URL;
|
|
49
|
+
let modules = [];
|
|
50
|
+
let github = false;
|
|
51
|
+
let setup = true;
|
|
52
|
+
for (let i = 0; i < argv.length; i++) {
|
|
53
|
+
const arg = argv[i] ?? "";
|
|
54
|
+
const value = () => {
|
|
55
|
+
const v = argv[++i];
|
|
56
|
+
if (v === undefined)
|
|
57
|
+
throw new Error(`${arg} needs a value`);
|
|
58
|
+
return v;
|
|
59
|
+
};
|
|
60
|
+
try {
|
|
61
|
+
if (arg === "--name")
|
|
62
|
+
name = value();
|
|
63
|
+
else if (arg === "--tag")
|
|
64
|
+
tag = value();
|
|
65
|
+
else if (arg === "--kit")
|
|
66
|
+
kitUrl = value();
|
|
67
|
+
else if (arg === "--modules") {
|
|
68
|
+
modules = value()
|
|
69
|
+
.split(",")
|
|
70
|
+
.map((m) => m.trim())
|
|
71
|
+
.filter(Boolean);
|
|
72
|
+
}
|
|
73
|
+
else if (arg === "--github")
|
|
74
|
+
github = true;
|
|
75
|
+
else if (arg === "--no-setup")
|
|
76
|
+
setup = false;
|
|
77
|
+
else if (arg.startsWith("--")) {
|
|
78
|
+
return { ok: false, error: `Unknown option ${arg}` };
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
positional.push(arg);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
return { ok: false, error: err.message };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const dir = positional[0];
|
|
88
|
+
if (!dir) {
|
|
89
|
+
return {
|
|
90
|
+
ok: false,
|
|
91
|
+
error: "Give a directory for the new app.",
|
|
92
|
+
missingDir: true,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (positional.length > 1) {
|
|
96
|
+
return { ok: false, error: `Unexpected argument ${positional[1]}` };
|
|
97
|
+
}
|
|
98
|
+
const bad = modules.find((m) => !SLUG.test(m));
|
|
99
|
+
if (bad)
|
|
100
|
+
return { ok: false, error: `"${bad}" isn't a module slug.` };
|
|
101
|
+
if (tag && !/^v\d+\.\d+\.\d+$/.test(tag)) {
|
|
102
|
+
return { ok: false, error: `--tag must look like v2.4.0, got ${tag}` };
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
ok: true,
|
|
106
|
+
options: {
|
|
107
|
+
dir,
|
|
108
|
+
name: name?.trim() ? name.trim() : titleFromDir(dir),
|
|
109
|
+
kitUrl,
|
|
110
|
+
modules,
|
|
111
|
+
github,
|
|
112
|
+
setup,
|
|
113
|
+
...(tag ? { tag } : {}),
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The directory from the answer to the name prompt: empty → DEFAULT_DIR,
|
|
119
|
+
* spaces → dashes ("My Shop" → "My-Shop", whose title is still "My Shop").
|
|
120
|
+
*/
|
|
121
|
+
export function dirFromAnswer(answer) {
|
|
122
|
+
return answer.trim().replace(/\s+/g, "-") || DEFAULT_DIR;
|
|
123
|
+
}
|
|
124
|
+
/** The newest stable vX.Y.Z from `git ls-remote --tags` output. */
|
|
125
|
+
export function latestRelease(lsRemote) {
|
|
126
|
+
const tags = lsRemote
|
|
127
|
+
.split("\n")
|
|
128
|
+
.map((line) => (line.split("\t")[1] ?? "").replace(/^refs\/tags\//, ""))
|
|
129
|
+
.map((t) => t.replace(/\^\{\}$/, ""))
|
|
130
|
+
.filter((t) => /^v\d+\.\d+\.\d+$/.test(t));
|
|
131
|
+
const parts = (t) => t.slice(1).split(".").map(Number);
|
|
132
|
+
return ([...new Set(tags)].sort((a, b) => {
|
|
133
|
+
const [x, y] = [parts(a), parts(b)];
|
|
134
|
+
for (let i = 0; i < 3; i++) {
|
|
135
|
+
const d = (y[i] ?? 0) - (x[i] ?? 0);
|
|
136
|
+
if (d !== 0)
|
|
137
|
+
return d;
|
|
138
|
+
}
|
|
139
|
+
return 0;
|
|
140
|
+
})[0] ?? null);
|
|
141
|
+
}
|
|
142
|
+
export function planCreate(o) {
|
|
143
|
+
const steps = [
|
|
144
|
+
{
|
|
145
|
+
label: `Download Dream Starter Kit ${o.tag}`,
|
|
146
|
+
cmd: "git",
|
|
147
|
+
args: ["clone", "--quiet", "--branch", o.tag, o.kitUrl, o.dir],
|
|
148
|
+
cwd: ".",
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
label: "Start your main branch",
|
|
152
|
+
cmd: "git",
|
|
153
|
+
args: ["checkout", "--quiet", "-b", "main"],
|
|
154
|
+
cwd: "app",
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
label: "Keep the kit as `upstream` for updates",
|
|
158
|
+
cmd: "git",
|
|
159
|
+
args: ["remote", "rename", "origin", "upstream"],
|
|
160
|
+
cwd: "app",
|
|
161
|
+
},
|
|
162
|
+
];
|
|
163
|
+
if (o.github) {
|
|
164
|
+
steps.push({
|
|
165
|
+
label: "Create a private GitHub repository",
|
|
166
|
+
cmd: "gh",
|
|
167
|
+
args: [
|
|
168
|
+
"repo",
|
|
169
|
+
"create",
|
|
170
|
+
packageName(o.name),
|
|
171
|
+
"--private",
|
|
172
|
+
"--source",
|
|
173
|
+
".",
|
|
174
|
+
"--remote",
|
|
175
|
+
"origin",
|
|
176
|
+
"--push",
|
|
177
|
+
],
|
|
178
|
+
cwd: "app",
|
|
179
|
+
optional: true,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (o.setup) {
|
|
183
|
+
steps.push({
|
|
184
|
+
label: "Set up the local stack (Docker, Supabase, .env, dev admin)",
|
|
185
|
+
cmd: "pnpm",
|
|
186
|
+
args: ["dev:setup"],
|
|
187
|
+
cwd: "app",
|
|
188
|
+
});
|
|
189
|
+
for (const slug of o.modules) {
|
|
190
|
+
steps.push({
|
|
191
|
+
label: `Install the ${slug} module`,
|
|
192
|
+
cmd: "pnpm",
|
|
193
|
+
args: ["mod", "add", `dream:${slug}`],
|
|
194
|
+
cwd: "app",
|
|
195
|
+
optional: true,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else if (o.modules.length > 0) {
|
|
200
|
+
steps.push({
|
|
201
|
+
label: "Install dependencies",
|
|
202
|
+
cmd: "pnpm",
|
|
203
|
+
args: ["install"],
|
|
204
|
+
cwd: "app",
|
|
205
|
+
});
|
|
206
|
+
for (const slug of o.modules) {
|
|
207
|
+
steps.push({
|
|
208
|
+
label: `Install the ${slug} module`,
|
|
209
|
+
cmd: "pnpm",
|
|
210
|
+
args: ["mod", "add", `dream:${slug}`, "--no-apply"],
|
|
211
|
+
cwd: "app",
|
|
212
|
+
optional: true,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return steps;
|
|
217
|
+
}
|
|
218
|
+
/** The app's root package.json with its new name (kept otherwise). */
|
|
219
|
+
export function renamePackage(json, name) {
|
|
220
|
+
const pkg = JSON.parse(json);
|
|
221
|
+
pkg.name = packageName(name);
|
|
222
|
+
return `${JSON.stringify(pkg, null, 2)}\n`;
|
|
223
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-dream",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "npm create dream: start a new app from the Dream Starter Kit, with its git history kept for updates.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"bin": {
|
|
8
|
+
"create-dream": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.build.json",
|
|
18
|
+
"clean": "git clean -xdf .cache .turbo dist node_modules",
|
|
19
|
+
"format": "prettier --check . --ignore-path ../../.gitignore",
|
|
20
|
+
"lint": "eslint --flag unstable_native_nodejs_ts_config",
|
|
21
|
+
"prepublishOnly": "pnpm build",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"typecheck": "tsc --noEmit"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@acme/eslint-config": "workspace:*",
|
|
27
|
+
"@acme/prettier-config": "workspace:*",
|
|
28
|
+
"@acme/tsconfig": "workspace:*",
|
|
29
|
+
"@types/node": "catalog:",
|
|
30
|
+
"eslint": "catalog:",
|
|
31
|
+
"prettier": "catalog:",
|
|
32
|
+
"typescript": "catalog:",
|
|
33
|
+
"vitest": "catalog:"
|
|
34
|
+
},
|
|
35
|
+
"prettier": "@acme/prettier-config"
|
|
36
|
+
}
|