create-rindle 0.1.6
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 +201 -0
- package/README.md +70 -0
- package/index.mjs +124 -0
- package/lib/scaffold.mjs +169 -0
- package/package.json +38 -0
- package/templates/minimal/README.md +72 -0
- package/templates/minimal/_gitignore +7 -0
- package/templates/minimal/migrations/0001_init.sql +21 -0
- package/templates/minimal/package.json +44 -0
- package/templates/minimal/server/app-api.ts +115 -0
- package/templates/minimal/server/auth-dev.ts +22 -0
- package/templates/minimal/server/dev.ts +148 -0
- package/templates/minimal/server/migrate.ts +47 -0
- package/templates/minimal/server/rindle-http.ts +38 -0
- package/templates/minimal/server/seed.ts +70 -0
- package/templates/minimal/shared/app-def.ts +100 -0
- package/templates/minimal/shared/auth.ts +18 -0
- package/templates/minimal/shared/schema.gen.ts +29 -0
- package/templates/minimal/src/RindleApp.tsx +47 -0
- package/templates/minimal/src/components/Composer.tsx +38 -0
- package/templates/minimal/src/components/MessageCard.queries.ts +13 -0
- package/templates/minimal/src/components/MessageCard.tsx +20 -0
- package/templates/minimal/src/components/NewRoomForm.tsx +30 -0
- package/templates/minimal/src/components/RoomCard.queries.ts +20 -0
- package/templates/minimal/src/components/RoomCard.tsx +23 -0
- package/templates/minimal/src/components/RoomView.queries.ts +26 -0
- package/templates/minimal/src/components/Toaster.tsx +31 -0
- package/templates/minimal/src/components/TopBar.tsx +36 -0
- package/templates/minimal/src/devtools.tsx +27 -0
- package/templates/minimal/src/lib/format.ts +8 -0
- package/templates/minimal/src/lib/use-handle.ts +16 -0
- package/templates/minimal/src/rindle-client.ts +94 -0
- package/templates/minimal/src/routeTree.gen.ts +147 -0
- package/templates/minimal/src/router.tsx +20 -0
- package/templates/minimal/src/routes/__root.tsx +64 -0
- package/templates/minimal/src/routes/api.rindle.mutate.tsx +16 -0
- package/templates/minimal/src/routes/api.rindle.query.tsx +16 -0
- package/templates/minimal/src/routes/api.rindle.read.tsx +16 -0
- package/templates/minimal/src/routes/index.tsx +51 -0
- package/templates/minimal/src/routes/r.$id.tsx +60 -0
- package/templates/minimal/src/ssr.ts +51 -0
- package/templates/minimal/src/styles.css +220 -0
- package/templates/minimal/src/tanstack-start.d.ts +6 -0
- package/templates/minimal/tsconfig.json +17 -0
- package/templates/minimal/vite-env.d.ts +15 -0
- package/templates/minimal/vite.config.ts +29 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# create-rindle
|
|
2
|
+
|
|
3
|
+
Scaffold a new **SQL-first [Rindle](https://github.com/rindle-sh/rindle) app on
|
|
4
|
+
[TanStack Start](https://tanstack.com/start)** in one command.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm create rindle@latest my-app
|
|
8
|
+
# or
|
|
9
|
+
npx create-rindle my-app
|
|
10
|
+
# or: pnpm create rindle my-app · yarn create rindle my-app · bun create rindle my-app
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cd my-app
|
|
17
|
+
pnpm dev
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## What you get
|
|
21
|
+
|
|
22
|
+
A minimal but real three-tier Rindle app (a tiny forum-of-rooms with **live message counts**):
|
|
23
|
+
|
|
24
|
+
- **Browser** — a TanStack Start SPA whose data layer is Rindle's in-process wasm IVM engine: local
|
|
25
|
+
instant reads, optimistic writes, live `subscribe`, and a dev-only Rindle devtools pane.
|
|
26
|
+
- **API server** — the authority: named-query resolution, authoritative SQL mutators, and policy (a
|
|
27
|
+
`"spam"` rejection demo shows the optimistic snap-back + toast).
|
|
28
|
+
- **Daemon** (`rindled`) — owns the SQLite data + live incremental views, streamed to subscribers.
|
|
29
|
+
|
|
30
|
+
The schema is **SQL-first**: `migrations/*.sql` is the source of truth, and the `@rindle/client`
|
|
31
|
+
schema is generated from it into `shared/schema.gen.ts` (`rindle up --migrate --gen shared/schema.gen.ts --watch` in
|
|
32
|
+
the dev loop), so the TypeScript can't drift from the DDL.
|
|
33
|
+
|
|
34
|
+
The prebuilt `rindle` + `rindled` binaries come from `@rindle/cli` (per-platform, installed as a dev
|
|
35
|
+
dependency) — **no Rust toolchain required**.
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
create-rindle [directory] [options]
|
|
41
|
+
|
|
42
|
+
Options:
|
|
43
|
+
--no-install Don't run the package-manager install after scaffolding
|
|
44
|
+
--pm <name> Package manager: npm | pnpm | yarn | bun (default: auto-detected)
|
|
45
|
+
--link Internal: wire @rindle/* to this monorepo's workspace (for apps/* in the repo)
|
|
46
|
+
-h, --help Show help
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`--link` is for developing the template *inside* the Rindle monorepo: it rewrites the `@rindle/*`
|
|
50
|
+
dependencies to `workspace:*` and switches `vite.config.ts` / `tsconfig.json` to the `@rindle/source`
|
|
51
|
+
aliases the in-repo examples use, so a scaffold dropped into `apps/` typechecks against source. CI
|
|
52
|
+
uses it to typecheck the generated app on every change.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## Devtools in generated apps
|
|
56
|
+
|
|
57
|
+
The default template mounts `@rindle/react-devtools` in development and attaches
|
|
58
|
+
`@rindle/devtools` to the generated Rindle client. Click the floating **🌊 Rindle** launcher to
|
|
59
|
+
inspect the optimistic mutation timeline, live queries, and raw delta stream. Both packages are
|
|
60
|
+
imported behind `import.meta.env.DEV`, so they tree-shake out of production builds.
|
|
61
|
+
|
|
62
|
+
## Templates
|
|
63
|
+
|
|
64
|
+
| name | description |
|
|
65
|
+
|---|---|
|
|
66
|
+
| `minimal` (default) | rooms + messages with live counts, optimistic writes, SSR, the auth seam |
|
|
67
|
+
|
|
68
|
+
## Requirements
|
|
69
|
+
|
|
70
|
+
The generated app runs the `.ts` server files via Node's built-in type stripping — **Node ≥ 22.18**.
|
package/index.mjs
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `npm create rindle@latest [dir]` / `npx create-rindle [dir]` — scaffold a SQL-first Rindle app on
|
|
3
|
+
// TanStack Start. Zero runtime dependencies: argument parsing, a minimal interactive prompt, and the
|
|
4
|
+
// template copy all run on Node built-ins, so this boots with nothing installed.
|
|
5
|
+
//
|
|
6
|
+
// create-rindle my-app # scaffold ./my-app (the only template today: "minimal")
|
|
7
|
+
// create-rindle my-app --no-install # skip the package-manager install
|
|
8
|
+
// create-rindle my-app --pm pnpm # force the package manager (else auto-detected)
|
|
9
|
+
// create-rindle apps/foo --link # internal: consume @rindle/* from this repo's workspace
|
|
10
|
+
|
|
11
|
+
import { spawnSync } from "node:child_process";
|
|
12
|
+
import { createInterface } from "node:readline/promises";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { dirname, join, resolve } from "node:path";
|
|
15
|
+
|
|
16
|
+
import { isValidPackageName, packageNameFromDir, scaffold } from "./lib/scaffold.mjs";
|
|
17
|
+
|
|
18
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
const TEMPLATE = "minimal";
|
|
20
|
+
|
|
21
|
+
function parseArgs(argv) {
|
|
22
|
+
const opts = { dir: undefined, install: true, pm: undefined, link: false, help: false };
|
|
23
|
+
for (let i = 0; i < argv.length; i++) {
|
|
24
|
+
const a = argv[i];
|
|
25
|
+
if (a === "--help" || a === "-h") opts.help = true;
|
|
26
|
+
else if (a === "--no-install") opts.install = false;
|
|
27
|
+
else if (a === "--link") opts.link = true;
|
|
28
|
+
else if (a === "--pm") opts.pm = argv[++i];
|
|
29
|
+
else if (a.startsWith("--pm=")) opts.pm = a.slice("--pm=".length);
|
|
30
|
+
else if (a.startsWith("-")) fail(`unknown flag: ${a}`);
|
|
31
|
+
else if (opts.dir === undefined) opts.dir = a;
|
|
32
|
+
else fail(`unexpected argument: ${a}`);
|
|
33
|
+
}
|
|
34
|
+
return opts;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function fail(message) {
|
|
38
|
+
process.stderr.write(`\ncreate-rindle: ${message}\n`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const HELP = `create-rindle — scaffold a SQL-first Rindle app on TanStack Start
|
|
43
|
+
|
|
44
|
+
Usage:
|
|
45
|
+
npm create rindle@latest [directory] [options]
|
|
46
|
+
npx create-rindle [directory] [options]
|
|
47
|
+
|
|
48
|
+
Options:
|
|
49
|
+
--no-install Don't run the package-manager install after scaffolding
|
|
50
|
+
--pm <name> Package manager to use (npm | pnpm | yarn | bun); default: auto-detect
|
|
51
|
+
--link Internal: wire @rindle/* to this monorepo's workspace (for apps/* in the repo)
|
|
52
|
+
-h, --help Show this help
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
/** Which package manager invoked us (npm/pnpm/yarn/bun set npm_config_user_agent), else npm. */
|
|
56
|
+
function detectPackageManager() {
|
|
57
|
+
const ua = process.env.npm_config_user_agent ?? "";
|
|
58
|
+
if (ua.startsWith("pnpm")) return "pnpm";
|
|
59
|
+
if (ua.startsWith("yarn")) return "yarn";
|
|
60
|
+
if (ua.startsWith("bun")) return "bun";
|
|
61
|
+
return "npm";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function prompt(question, fallback) {
|
|
65
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
66
|
+
try {
|
|
67
|
+
const answer = (await rl.question(`${question} (${fallback}) `)).trim();
|
|
68
|
+
return answer || fallback;
|
|
69
|
+
} finally {
|
|
70
|
+
rl.close();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function main() {
|
|
75
|
+
const opts = parseArgs(process.argv.slice(2));
|
|
76
|
+
if (opts.help) {
|
|
77
|
+
process.stdout.write(HELP);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Resolve the target directory — prompt for one if not given and we have a TTY.
|
|
82
|
+
let dir = opts.dir;
|
|
83
|
+
if (!dir) {
|
|
84
|
+
dir = process.stdin.isTTY ? await prompt("Where should we create your app?", "./rindle-app") : "./rindle-app";
|
|
85
|
+
}
|
|
86
|
+
const targetDir = resolve(process.cwd(), dir);
|
|
87
|
+
const projectName = packageNameFromDir(targetDir);
|
|
88
|
+
if (!isValidPackageName(projectName)) {
|
|
89
|
+
fail(`"${projectName}" is not a valid npm package name — rename the target directory`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const templateDir = join(here, "templates", TEMPLATE);
|
|
93
|
+
|
|
94
|
+
process.stdout.write(`\n Scaffolding a Rindle app in ${targetDir}\n`);
|
|
95
|
+
let created;
|
|
96
|
+
try {
|
|
97
|
+
created = await scaffold({ templateDir, targetDir, projectName, link: opts.link });
|
|
98
|
+
} catch (err) {
|
|
99
|
+
fail(err instanceof Error ? err.message : String(err));
|
|
100
|
+
}
|
|
101
|
+
process.stdout.write(` Created ${created.length} files (template: ${TEMPLATE}${opts.link ? ", workspace-linked" : ""})\n`);
|
|
102
|
+
|
|
103
|
+
const pm = opts.pm ?? detectPackageManager();
|
|
104
|
+
if (opts.install) {
|
|
105
|
+
process.stdout.write(`\n Installing dependencies with ${pm}…\n\n`);
|
|
106
|
+
const install = spawnSync(pm, ["install"], { cwd: targetDir, stdio: "inherit", shell: process.platform === "win32" });
|
|
107
|
+
if (install.status !== 0) {
|
|
108
|
+
process.stdout.write(`\n Install failed or was skipped — run \`${pm} install\` yourself.\n`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const run = pm === "npm" ? "npm run" : pm;
|
|
113
|
+
process.stdout.write(
|
|
114
|
+
`\n Done. Next steps:\n\n` +
|
|
115
|
+
` cd ${dir}\n` +
|
|
116
|
+
(opts.install ? "" : ` ${pm} install\n`) +
|
|
117
|
+
` ${run} dev\n\n` +
|
|
118
|
+
` The migrations in migrations/*.sql are the source of truth — \`${run} dev\` applies them,\n` +
|
|
119
|
+
` generates shared/schema.gen.ts, boots the daemon + API + Vite, and seeds a little data.\n` +
|
|
120
|
+
` Open two browser windows to watch writes sync live.\n\n`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
main().catch((err) => fail(err instanceof Error ? err.stack ?? err.message : String(err)));
|
package/lib/scaffold.mjs
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// The scaffold engine: copy a template tree into a target directory, substituting the project name
|
|
2
|
+
// and renaming the `_`-prefixed dotfiles npm refuses to publish (`_gitignore` → `.gitignore`). Pure
|
|
3
|
+
// Node built-ins, no dependencies — so `npm create rindle` runs with nothing installed.
|
|
4
|
+
//
|
|
5
|
+
// `--link` mode (internal/dev) rewrites the generated app to consume the @rindle/* packages from the
|
|
6
|
+
// surrounding pnpm WORKSPACE instead of npm: deps become `workspace:*`, and vite/tsconfig switch to the
|
|
7
|
+
// `@rindle/source` aliases the in-repo examples use. That lets us scaffold straight into `apps/` and
|
|
8
|
+
// typecheck the output against the real source — the "CI typechecks the generated app" discipline.
|
|
9
|
+
|
|
10
|
+
import { cp, mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
11
|
+
import { existsSync } from "node:fs";
|
|
12
|
+
import { basename, join, relative } from "node:path";
|
|
13
|
+
|
|
14
|
+
/** The token the template files carry wherever the project's package name belongs. */
|
|
15
|
+
export const PROJECT_NAME_TOKEN = "__PROJECT_NAME__";
|
|
16
|
+
|
|
17
|
+
// Files we run name-substitution over. Everything in the template is UTF-8 text, but be explicit so a
|
|
18
|
+
// future binary asset (an icon, say) is copied verbatim rather than corrupted by a string replace.
|
|
19
|
+
const TEXT_EXT = new Set([
|
|
20
|
+
".ts", ".tsx", ".js", ".mjs", ".cjs", ".json", ".jsonc", ".css", ".html", ".sql", ".md", ".txt",
|
|
21
|
+
".gitignore", ".npmrc", ".env",
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
const isTextFile = (name) => {
|
|
25
|
+
const dot = name.lastIndexOf(".");
|
|
26
|
+
const ext = dot === -1 ? name : name.slice(dot);
|
|
27
|
+
return TEXT_EXT.has(ext) || name === "_gitignore" || name === "_npmrc";
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** `_gitignore` → `.gitignore`, but never touch `__root.tsx` (a TanStack route, double underscore). */
|
|
31
|
+
const realName = (name) => (/^_[^_]/.test(name) ? `.${name.slice(1)}` : name);
|
|
32
|
+
|
|
33
|
+
const substitute = (text, projectName) => text.split(PROJECT_NAME_TOKEN).join(projectName);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Recursively copy `templateDir` → `targetDir`, substituting {@link PROJECT_NAME_TOKEN} in text files
|
|
37
|
+
* and de-underscoring dotfiles. Returns the list of created file paths (relative to targetDir).
|
|
38
|
+
*/
|
|
39
|
+
export async function copyTemplate(templateDir, targetDir, projectName) {
|
|
40
|
+
const created = [];
|
|
41
|
+
async function walk(srcDir, outDir) {
|
|
42
|
+
await mkdir(outDir, { recursive: true });
|
|
43
|
+
for (const entry of await readdir(srcDir, { withFileTypes: true })) {
|
|
44
|
+
const src = join(srcDir, entry.name);
|
|
45
|
+
const out = join(outDir, realName(entry.name));
|
|
46
|
+
if (entry.isDirectory()) {
|
|
47
|
+
await walk(src, out);
|
|
48
|
+
} else if (isTextFile(entry.name)) {
|
|
49
|
+
await writeFile(out, substitute(await readFile(src, "utf8"), projectName));
|
|
50
|
+
created.push(relative(targetDir, out));
|
|
51
|
+
} else {
|
|
52
|
+
await cp(src, out);
|
|
53
|
+
created.push(relative(targetDir, out));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
await walk(templateDir, targetDir);
|
|
58
|
+
return created.sort();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ---------------------------------------------------------------- workspace (--link) rewrites
|
|
62
|
+
|
|
63
|
+
// vite.config.ts for an app scaffolded INTO this repo's apps/: compile the sibling @rindle/* libraries
|
|
64
|
+
// straight from source (the `@rindle/source` condition) so dev never runs against a stale dist build —
|
|
65
|
+
// exactly what the in-repo examples do.
|
|
66
|
+
const WORKSPACE_VITE_CONFIG = `import { fileURLToPath } from "node:url";
|
|
67
|
+
|
|
68
|
+
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
|
|
69
|
+
import react from "@vitejs/plugin-react";
|
|
70
|
+
import { defineConfig } from "vite";
|
|
71
|
+
|
|
72
|
+
// --link build: this app lives under apps/, so the sibling @rindle/* libraries are two levels up under
|
|
73
|
+
// ../../packages. Aliasing straight to each src/index.ts (the same TS the \`@rindle/source\` export
|
|
74
|
+
// condition points at) compiles them from source in every Vite environment, including the Start
|
|
75
|
+
// prerender/server pass — so dev never runs against a stale dist build.
|
|
76
|
+
const wasmBin = fileURLToPath(new URL("../../packages/wasm/pkg/rindle_bg.wasm", import.meta.url));
|
|
77
|
+
const src = (p: string) => fileURLToPath(new URL(\`../../packages/\${p}/src/index.ts\`, import.meta.url));
|
|
78
|
+
|
|
79
|
+
export default defineConfig({
|
|
80
|
+
build: { target: "es2022" },
|
|
81
|
+
resolve: {
|
|
82
|
+
conditions: ["@rindle/source"],
|
|
83
|
+
alias: [
|
|
84
|
+
{ find: /^rindle-wasm-bin/, replacement: wasmBin },
|
|
85
|
+
{ find: /^@rindle\\/client$/, replacement: src("client") },
|
|
86
|
+
{ find: /^@rindle\\/react$/, replacement: src("react") },
|
|
87
|
+
{ find: /^@rindle\\/optimistic$/, replacement: src("optimistic") },
|
|
88
|
+
{ find: /^@rindle\\/normalized$/, replacement: src("normalized") },
|
|
89
|
+
{ find: /^@rindle\\/remote$/, replacement: src("remote") },
|
|
90
|
+
{ find: /^@rindle\\/wasm$/, replacement: src("wasm") },
|
|
91
|
+
{ find: /^@rindle\\/api-server$/, replacement: src("api-server") },
|
|
92
|
+
{ find: /^@rindle\\/daemon-client$/, replacement: src("daemon-client") },
|
|
93
|
+
{ find: /^@rindle\\/devtools$/, replacement: src("devtools") },
|
|
94
|
+
{ find: /^@rindle\\/react-devtools$/, replacement: src("react-devtools") },
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
ssr: { noExternal: [/^@rindle\\//] },
|
|
98
|
+
// No proxy: /api/rindle/* is a Start server route (src/routes/api/rindle/$.ts) on this same server.
|
|
99
|
+
plugins: [tanstackStart(), react()],
|
|
100
|
+
});
|
|
101
|
+
`;
|
|
102
|
+
|
|
103
|
+
// tsconfig for --link: resolve @rindle/* through the `@rindle/source` condition (their src/index.ts),
|
|
104
|
+
// matching the vite aliases above so tsc and Vite see the same modules.
|
|
105
|
+
const WORKSPACE_TSCONFIG = `{
|
|
106
|
+
"compilerOptions": {
|
|
107
|
+
"target": "ES2022",
|
|
108
|
+
"module": "ESNext",
|
|
109
|
+
"moduleResolution": "bundler",
|
|
110
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
111
|
+
"strict": true,
|
|
112
|
+
"noEmit": true,
|
|
113
|
+
"skipLibCheck": true,
|
|
114
|
+
"jsx": "react-jsx",
|
|
115
|
+
"verbatimModuleSyntax": true,
|
|
116
|
+
"allowImportingTsExtensions": true,
|
|
117
|
+
"erasableSyntaxOnly": true,
|
|
118
|
+
"customConditions": ["@rindle/source"],
|
|
119
|
+
"types": ["node", "vite/client"]
|
|
120
|
+
},
|
|
121
|
+
"include": ["src", "shared", "server", "vite-env.d.ts", "vite.config.ts"]
|
|
122
|
+
}
|
|
123
|
+
`;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Repoint a freshly scaffolded app at the surrounding pnpm workspace: every `@rindle/*` dependency
|
|
127
|
+
* becomes `workspace:*`, and vite/tsconfig switch to the source aliases. Use only when the target is
|
|
128
|
+
* inside this monorepo's `apps/` (the wasm/source paths are `../../packages`).
|
|
129
|
+
*/
|
|
130
|
+
export async function applyWorkspaceLinks(targetDir) {
|
|
131
|
+
const pkgPath = join(targetDir, "package.json");
|
|
132
|
+
const pkg = JSON.parse(await readFile(pkgPath, "utf8"));
|
|
133
|
+
for (const field of ["dependencies", "devDependencies"]) {
|
|
134
|
+
const deps = pkg[field];
|
|
135
|
+
if (!deps) continue;
|
|
136
|
+
for (const name of Object.keys(deps)) {
|
|
137
|
+
if (name.startsWith("@rindle/")) deps[name] = "workspace:*";
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
await writeFile(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
141
|
+
await writeFile(join(targetDir, "vite.config.ts"), WORKSPACE_VITE_CONFIG);
|
|
142
|
+
await writeFile(join(targetDir, "tsconfig.json"), WORKSPACE_TSCONFIG);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Full scaffold: validate the target, copy the template, optionally apply workspace links. */
|
|
146
|
+
export async function scaffold({ templateDir, targetDir, projectName, link = false }) {
|
|
147
|
+
if (existsSync(targetDir)) {
|
|
148
|
+
const entries = await readdir(targetDir).catch(() => []);
|
|
149
|
+
if (entries.length > 0) {
|
|
150
|
+
throw new Error(`target directory is not empty: ${targetDir}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const created = await copyTemplate(templateDir, targetDir, projectName);
|
|
154
|
+
if (link) await applyWorkspaceLinks(targetDir);
|
|
155
|
+
return created;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Re-exported for the CLI's "is this a sane package name?" check.
|
|
159
|
+
export function isValidPackageName(name) {
|
|
160
|
+
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(name);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Derive a default package name from a target path (its last segment, lower-kebabed). */
|
|
164
|
+
export function packageNameFromDir(targetDir) {
|
|
165
|
+
return basename(targetDir)
|
|
166
|
+
.toLowerCase()
|
|
167
|
+
.replace(/[^a-z0-9-~._]+/g, "-")
|
|
168
|
+
.replace(/^-+|-+$/g, "") || "rindle-app";
|
|
169
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-rindle",
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/rindle-sh/rindle.git",
|
|
8
|
+
"directory": "packages/create-rindle"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"description": "Scaffold a new SQL-first Rindle app on TanStack Start — `npm create rindle@latest`. The migrations are the source of truth; the @rindle/client schema is generated from them, and the browser runs the in-process wasm IVM engine.",
|
|
12
|
+
"bin": {
|
|
13
|
+
"create-rindle": "./index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"index.mjs",
|
|
17
|
+
"lib",
|
|
18
|
+
"templates",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=22"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"rindle",
|
|
26
|
+
"tanstack",
|
|
27
|
+
"sync",
|
|
28
|
+
"local-first",
|
|
29
|
+
"scaffold",
|
|
30
|
+
"create",
|
|
31
|
+
"sqlite",
|
|
32
|
+
"ivm"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"typecheck": "node --check index.mjs && node --check lib/scaffold.mjs",
|
|
36
|
+
"test": "node --test test/*.test.mjs"
|
|
37
|
+
}
|
|
38
|
+
}
|