create-launchrail 0.0.0-stage → 0.3.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.
Files changed (69) hide show
  1. package/README.md +39 -2
  2. package/THIRD_PARTY_LICENSES +43 -0
  3. package/bin/create-launchrail.mjs +75 -0
  4. package/bin/project-directory.mjs +7 -0
  5. package/bin/scaffold.mjs +217 -0
  6. package/bin/tools.mjs +62 -0
  7. package/bin/versions.mjs +118 -0
  8. package/package.json +23 -4
  9. package/presets/headless/web/ui/button.tsx +16 -0
  10. package/presets/headless/web/ui/card.tsx +25 -0
  11. package/template/AGENTS.md +3 -0
  12. package/template/README.md +3 -0
  13. package/template/THIRD_PARTY_LICENSES +43 -0
  14. package/template/apps/mobile/AGENTS.md +11 -0
  15. package/template/apps/mobile/App.tsx +511 -0
  16. package/template/apps/mobile/app.json +14 -0
  17. package/template/apps/mobile/components.json +22 -0
  18. package/template/apps/mobile/global.css +54 -0
  19. package/template/apps/mobile/index.ts +4 -0
  20. package/template/apps/mobile/metro.config.js +7 -0
  21. package/template/apps/mobile/package.json +47 -0
  22. package/template/apps/mobile/src/auth.ts +19 -0
  23. package/template/apps/mobile/src/components/native-controls.tsx +12 -0
  24. package/template/apps/mobile/src/components/ui/button.tsx +108 -0
  25. package/template/apps/mobile/src/components/ui/card.tsx +66 -0
  26. package/template/apps/mobile/src/components/ui/input.tsx +33 -0
  27. package/template/apps/mobile/src/components/ui/text.tsx +89 -0
  28. package/template/apps/mobile/src/css.d.ts +1 -0
  29. package/template/apps/mobile/src/lib/utils.ts +6 -0
  30. package/template/apps/mobile/src/query.tsx +16 -0
  31. package/template/apps/mobile/src/server-url.ts +20 -0
  32. package/template/apps/mobile/src/trpc.tsx +47 -0
  33. package/template/apps/mobile/src/uniwind-types.d.ts +7 -0
  34. package/template/apps/mobile/tsconfig.json +21 -0
  35. package/template/apps/web/components.json +15 -0
  36. package/template/apps/web/drizzle/0000_auth.sql +53 -0
  37. package/template/apps/web/drizzle/meta/0000_snapshot.json +374 -0
  38. package/template/apps/web/drizzle/meta/_journal.json +13 -0
  39. package/template/apps/web/drizzle.config.ts +11 -0
  40. package/template/apps/web/next.config.ts +11 -0
  41. package/template/apps/web/package.json +48 -0
  42. package/template/apps/web/postcss.config.mjs +3 -0
  43. package/template/apps/web/src/app/api/auth/[...all]/route.ts +7 -0
  44. package/template/apps/web/src/app/api/trpc/[trpc]/route.ts +53 -0
  45. package/template/apps/web/src/app/globals.css +250 -0
  46. package/template/apps/web/src/app/layout.tsx +31 -0
  47. package/template/apps/web/src/app/page.tsx +35 -0
  48. package/template/apps/web/src/app/starter-demo.tsx +258 -0
  49. package/template/apps/web/src/components/ui/button.tsx +57 -0
  50. package/template/apps/web/src/components/ui/card.tsx +102 -0
  51. package/template/apps/web/src/lib/auth-client.ts +5 -0
  52. package/template/apps/web/src/lib/query.tsx +23 -0
  53. package/template/apps/web/src/lib/trpc.tsx +29 -0
  54. package/template/apps/web/src/lib/utils.ts +6 -0
  55. package/template/apps/web/src/server/auth.ts +44 -0
  56. package/template/apps/web/src/server/db.ts +38 -0
  57. package/template/apps/web/src/server/schema.ts +87 -0
  58. package/template/apps/web/tsconfig.json +31 -0
  59. package/template/compose.yaml +18 -0
  60. package/template/gitignore.template +32 -0
  61. package/template/package.json +22 -0
  62. package/template/packages/api/package.json +21 -0
  63. package/template/packages/api/src/hello.ts +5 -0
  64. package/template/packages/api/src/index.ts +45 -0
  65. package/template/packages/api/tsconfig.json +4 -0
  66. package/template/pnpm-workspace.yaml +5 -0
  67. package/template/theme/tokens.css +40 -0
  68. package/template/tsconfig.base.json +14 -0
  69. package/template/turbo.json +12 -0
package/README.md CHANGED
@@ -1,3 +1,40 @@
1
- # Temporary Holding Version
1
+ # Launchrail
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Create a Next.js or Expo workspace, select the tools you want to include, and install the stack in one command. Projects include app-specific instructions for developers and agents.
4
+
5
+ ## Run the installer
6
+
7
+ Use Node.js 24 or newer with Git on your PATH. On the Mac where Launchrail is already saved, run this from any directory:
8
+
9
+ ```sh
10
+ npx --yes -p "$HOME/create-launchrail/site/create-launchrail-0.3.1.tgz" create-launchrail my-app
11
+ ```
12
+
13
+ A bare name creates a folder in your home directory, for example `~/my-app`. Pass an explicit path such as `./my-app` to use the current directory. To try the archive on another Mac, download it from the private showcase and change the package path to the saved file. If your browser uses Downloads, that path is `$HOME/Downloads/create-launchrail-0.3.1.tgz`.
14
+
15
+ Launchrail initializes one local Git repository on `main` at the project root. Web, Expo, and any iOS or Android source you maintain are tracked together. The generated ignore rules cover local environment files, build outputs, and signing credentials. Review `git status` when you are ready for the first commit.
16
+
17
+ All tools are included by default. Pass `--tools` with a comma-separated selection to customize it. For example, `--tools next,expo,query,shadcn` includes web, mobile, client queries, and the shadcn components. Prerequisites are included automatically. Run `create-launchrail --help` for the full list.
18
+
19
+ Every run resolves selected npm tools from the registry's stable release tags and installs them immediately. With Expo, Launchrail resolves the latest stable SDK and uses its compatible React, React Native, and native package versions. Node type declarations match the major version running the installer.
20
+
21
+ Start your project with the commands printed at the end of the install. Selected PostgreSQL tooling includes the driver and a Docker Compose service. Start the service when you need the database running.
22
+
23
+ ## Workspace layout
24
+
25
+ - `apps/web` contains Next.js and optional shadcn components in `src/components/ui`.
26
+ - `apps/mobile` is one Expo app for iOS and Android. Select `mobile-ui` for React Native Reusables with Uniwind and `expo-ui` for native controls with a working switch example. Each option includes Expo.
27
+ - `packages/api` is generated when tRPC is selected and contains the procedures and input schemas.
28
+ - `theme/tokens.css` is generated with either UI kit and is used by both when selected.
29
+
30
+ ## Work on this starter
31
+
32
+ - `bin/` contains the installer, shared tool list, version resolver, and scaffold.
33
+ - `template/` holds the app and workspace sources.
34
+ - `npm test` checks tool selection and generated files.
35
+ - `npm run pack:site` creates the downloadable installer.
36
+ - `npm install --prefix site` installs the showcase dependencies.
37
+ - `npm run site:build` creates the static showcase and bundles the CLI download in `site/dist/`.
38
+ - `npm run site` starts the showcase in development mode.
39
+
40
+ The web and mobile starters include source from the shadcn and React Native Reusables registries. See [THIRD_PARTY_LICENSES](THIRD_PARTY_LICENSES).
@@ -0,0 +1,43 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 shadcn
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.
22
+
23
+ MIT License
24
+
25
+ Copyright (c) 2025 Founded Labs
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining a copy
28
+ of this software and associated documentation files (the "Software"), to deal
29
+ in the Software without restriction, including without limitation the rights
30
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31
+ copies of the Software, and to permit persons to whom the Software is
32
+ furnished to do so, subject to the following conditions:
33
+
34
+ The above copyright notice and this permission notice shall be included in all
35
+ copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43
+ SOFTWARE.
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from "node:child_process";
3
+ import { basename } from "node:path";
4
+ import { parseArgs } from "node:util";
5
+ import { projectDirectory } from "./project-directory.mjs";
6
+ import { scaffold } from "./scaffold.mjs";
7
+ import { dependenciesOf, toolMap, tools } from "./tools.mjs";
8
+ import { resolveVersions } from "./versions.mjs";
9
+
10
+ const help = `Usage: create-launchrail <project-name-or-path> [--tools <comma-separated list>]
11
+
12
+ A project name creates a folder in your home directory. Pass a path like ./my-app to choose another location.
13
+ Selected tools are installed at their latest stable versions. The default includes every tool.
14
+ Launchrail initializes one Git repository for the whole project. Git must be on PATH.
15
+
16
+ ${tools.map(({ id, name }) => ` ${id.padEnd(10)} ${name}`).join("\n")}
17
+
18
+ Example: create-launchrail my-app --tools next,tailwind,shadcn
19
+ `;
20
+
21
+ try {
22
+ const { positionals, values } = parseArgs({
23
+ allowPositionals: true,
24
+ options: {
25
+ tools: { type: "string", default: tools.map(({ id }) => id).join(",") },
26
+ help: { type: "boolean", short: "h" },
27
+ },
28
+ });
29
+ if (values.help) {
30
+ console.log(help);
31
+ } else {
32
+ if (positionals.length !== 1) throw new Error(help.trim());
33
+ if (Number(process.versions.node.split(".")[0]) < 24) throw new Error("Launchrail requires Node.js 24 or newer.");
34
+
35
+ const directory = projectDirectory(positionals[0]);
36
+ const displayName = basename(directory);
37
+ if (!/^[a-z][a-z0-9-]{0,62}$/i.test(displayName)) {
38
+ throw new Error("Use a project name of up to 63 letters, numbers, or hyphens, beginning with a letter.");
39
+ }
40
+ const name = displayName.toLowerCase();
41
+ const selected = new Set(values.tools.split(",").map((id) => id.trim()).filter(Boolean));
42
+ for (const id of [...selected]) {
43
+ if (!toolMap.has(id)) throw new Error(`Unknown tool "${id}". Run --help for the available tools.`);
44
+ for (const dep of dependenciesOf(id)) {
45
+ if (!selected.has(dep)) {
46
+ console.log(`Including ${toolMap.get(dep).name}, required by ${toolMap.get(id).name}.`);
47
+ selected.add(dep);
48
+ }
49
+ }
50
+ }
51
+ if (!selected.has("next") && !selected.has("expo")) throw new Error("Choose Next.js or Expo.");
52
+ if (spawnSync("git", ["--version"], { stdio: "ignore" }).status !== 0) {
53
+ throw new Error("Launchrail requires Git. Install Git and make sure git is on PATH, then rerun the command.");
54
+ }
55
+
56
+ const commands = await scaffold(directory, name, selected, displayName);
57
+ console.log("Resolving current stable releases…");
58
+ const { manager, expo, react } = await resolveVersions(directory, selected.has("expo"));
59
+ if (expo) console.log(`Using Expo ${expo} and its supported React ${react}.`);
60
+
61
+ const args = ["exec", "--yes", `--package=${manager}`, "--", "pnpm", "install", "--no-frozen-lockfile"];
62
+ const windows = process.platform === "win32";
63
+ const result = spawnSync(windows ? "npm.cmd" : "npm", args, {
64
+ cwd: directory,
65
+ stdio: "inherit",
66
+ shell: windows,
67
+ });
68
+ if (result.error) throw result.error;
69
+ if (result.status !== 0) throw new Error("Dependency installation failed. Review pnpm’s output above.");
70
+ console.log(`\nInstalled ${displayName} in ${directory}.\nInitialized Git on main at the project root.\n\nFrom your app directory:\n${commands.map((command) => " " + command).join("\n")}`);
71
+ }
72
+ } catch (error) {
73
+ console.error(error.message);
74
+ process.exitCode = 1;
75
+ }
@@ -0,0 +1,7 @@
1
+ import { homedir } from "node:os";
2
+ import { basename, resolve } from "node:path";
3
+
4
+ export function projectDirectory(target, home = homedir(), cwd = process.cwd()) {
5
+ const bareName = target === basename(target) && target !== "." && target !== "..";
6
+ return resolve(bareName ? home : cwd, target);
7
+ }
@@ -0,0 +1,217 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { createHash, randomBytes } from "node:crypto";
3
+ import { cp, mkdir, readFile, readdir, rename, writeFile } from "node:fs/promises";
4
+ import { basename, dirname, join, relative, sep } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { tools } from "./tools.mjs";
7
+
8
+ const source = fileURLToPath(new URL("../", import.meta.url));
9
+ const template = join(source, "template");
10
+ const featurePaths = {
11
+ next: ["apps/web"],
12
+ query: ["apps/web/src/lib/query.tsx", "apps/mobile/src/query.tsx"],
13
+ expo: ["apps/mobile"],
14
+ turbo: ["turbo.json"],
15
+ trpc: ["packages", "apps/web/src/lib/trpc.tsx", "apps/web/src/app/api/trpc", "apps/mobile/src/trpc.tsx"],
16
+ postgres: ["compose.yaml", "apps/web/src/server/db.ts"],
17
+ drizzle: ["apps/web/src/server/schema.ts", "apps/web/drizzle.config.ts", "apps/web/drizzle"],
18
+ auth: ["apps/web/src/server/auth.ts", "apps/web/src/lib/auth-client.ts", "apps/web/src/app/api/auth", "apps/mobile/src/auth.ts"],
19
+ tailwind: ["apps/web/postcss.config.mjs"],
20
+ shadcn: ["apps/web/components.json", "apps/web/src/lib/utils.ts"],
21
+ "mobile-ui": ["apps/mobile/components.json", "apps/mobile/global.css", "apps/mobile/metro.config.js", "apps/mobile/src/components/ui", "apps/mobile/src/lib", "apps/mobile/src/uniwind-types.d.ts", "apps/mobile/src/css.d.ts"],
22
+ "expo-ui": ["apps/mobile/src/components/native-controls.tsx"],
23
+ };
24
+ const packages = {
25
+ trpc: ["@launchrail/api", "@trpc/client", "@trpc/server", "@trpc/tanstack-react-query", "superjson"],
26
+ query: ["@tanstack/react-query"],
27
+ auth: ["better-auth", "@better-auth/expo", "expo-linking", "expo-network", "expo-secure-store", "expo-web-browser"],
28
+ drizzle: ["drizzle-orm", "drizzle-kit", "@next/env"],
29
+ postgres: ["postgres", "server-only"],
30
+ turbo: ["turbo"],
31
+ };
32
+ const appPackages = {
33
+ web: {
34
+ tailwind: ["@tailwindcss/postcss", "postcss", "tailwindcss"],
35
+ shadcn: ["@base-ui/react", "class-variance-authority", "clsx", "lucide-react", "shadcn", "tailwind-merge", "tw-animate-css"],
36
+ },
37
+ mobile: {
38
+ "mobile-ui": ["@rn-primitives/slot", "class-variance-authority", "clsx", "expo-system-ui", "tailwind-merge", "tailwindcss", "uniwind"],
39
+ "expo-ui": ["@expo/ui"],
40
+ },
41
+ };
42
+ const packageGroups = ["dependencies", "devDependencies"];
43
+
44
+ function permitted(path, selected) {
45
+ const name = basename(path);
46
+ if ([".git", "node_modules", ".next", ".turbo", ".expo", "dist", "pnpm-lock.yaml", ".npmignore"].includes(name) ||
47
+ name.endsWith(".tsbuildinfo") || name === ".env" ||
48
+ (name.startsWith(".env.") && name !== ".env.example")) return false;
49
+ const pathKey = relative(template, path).split(sep).join("/");
50
+ if (selected.has("trpc") && featurePaths.query.includes(pathKey)) return false;
51
+ if (!selected.has("trpc") && !selected.has("auth") && ["apps/mobile/src/server-url.ts", "apps/web/src/app/starter-demo.tsx"].includes(pathKey)) return false;
52
+ if (!selected.has("shadcn") && pathKey === "apps/web/src/components") return false;
53
+ if (!selected.has("shadcn") && !selected.has("mobile-ui") && ["theme", "THIRD_PARTY_LICENSES"].includes(pathKey)) return false;
54
+ if (!selected.has("expo-ui") && !selected.has("mobile-ui") && pathKey === "apps/mobile/src/components") return false;
55
+ return Object.entries(featurePaths).every(([feature, paths]) =>
56
+ selected.has(feature) || paths.every((item) => !(pathKey === item || pathKey.startsWith(item + "/"))));
57
+ }
58
+
59
+ function choose(source, selected) {
60
+ const stack = [true];
61
+ const active = () => stack.at(-1);
62
+ return source.split("\n").filter((line) => {
63
+ const marker = line.match(/^\s*\{?\/\* @(if (!?[\w-]+)|else|end) \*\/\}?\s*$/);
64
+ if (!marker) return active();
65
+ const [, directive, rule] = marker;
66
+ if (rule) {
67
+ const value = rule.startsWith("!") ? !selected.has(rule.slice(1)) : selected.has(rule);
68
+ stack.push(active() && value);
69
+ } else if (directive === "else") {
70
+ const prior = stack.pop();
71
+ stack.push(active() && !prior);
72
+ } else {
73
+ stack.pop();
74
+ }
75
+ return false;
76
+ }).join("\n");
77
+ }
78
+
79
+ async function transform(directory, selected, name) {
80
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
81
+ const path = join(directory, entry.name);
82
+ if (entry.isDirectory()) {
83
+ await transform(path, selected, name);
84
+ } else if (/\.(tsx?|css|md)$/.test(entry.name)) {
85
+ const original = await readFile(path, "utf8");
86
+ const next = choose(original, selected).replaceAll("__PROJECT_NAME__", name);
87
+ if (original !== next) await writeFile(path, next);
88
+ }
89
+ }
90
+ }
91
+
92
+ async function mutateJson(path, action) {
93
+ const data = JSON.parse(await readFile(path, "utf8"));
94
+ action(data);
95
+ await writeFile(path, JSON.stringify(data, null, 2) + "\n");
96
+ }
97
+
98
+ async function configureManifest(directory, selected, app, action) {
99
+ await mutateJson(join(directory, "apps", app, "package.json"), (data) => {
100
+ for (const group of packageGroups) {
101
+ for (const [feature, names] of Object.entries({ ...packages, ...appPackages[app] })) {
102
+ if (!selected.has(feature)) for (const name of names) delete data[group]?.[name];
103
+ }
104
+ }
105
+ action(data);
106
+ });
107
+ }
108
+
109
+ function docs(name, selected) {
110
+ const commands = [
111
+ selected.has("postgres") && "pnpm db:up",
112
+ selected.has("drizzle") && "pnpm db:migrate",
113
+ "pnpm dev",
114
+ ].filter(Boolean);
115
+ const modules = [
116
+ selected.has("next") && "- `apps/web` contains the Next.js app and any selected server integrations.",
117
+ selected.has("expo") && "- `apps/mobile` contains the Expo app.",
118
+ selected.has("trpc") && "- `packages/api` contains tRPC procedures and input schemas. Import the router type in app clients and use the browser-safe schema exports for form validation.",
119
+ selected.has("shadcn") && "- `apps/web/src/components/ui` contains editable shadcn/ui components.",
120
+ selected.has("mobile-ui") && "- `apps/mobile/src/components/ui` contains editable React Native Reusables components, styled with Uniwind for iOS and Android.",
121
+ selected.has("expo-ui") && "- `apps/mobile/src/components/native-controls.tsx` shows a native Expo UI switch.",
122
+ (selected.has("shadcn") || selected.has("mobile-ui")) && "- `theme/tokens.css` defines the colors and corner radii for the selected UI kits.",
123
+ ].filter(Boolean);
124
+ return {
125
+ readme: `# ${name}\n\nGenerated with Launchrail.\n\n${tools.filter(({ id }) => selected.has(id)).map(({ name }) => "- " + name).join("\n")}\n\n## Start locally\n\n\`\`\`sh\n${commands.join("\n")}\n\`\`\`\n\n${selected.has("postgres") ? "The database command uses Docker Compose. Set `DATABASE_URL` in `apps/web/.env.local` to use another PostgreSQL server.\n\n" : ""}${selected.has("expo") && (selected.has("trpc") || selected.has("auth")) ? "For API requests from a physical device, use a reachable address in `apps/mobile/.env.local`. Keep Better Auth's server origin consistent when authentication is selected.\n\n" : ""}## Workspace\n\n${modules.join("\n")}\n\nThe root Git repository tracks changes across the workspace. Review \`git status\` from the project root before making your first commit.\n\n${selected.has("expo") ? "Expo can generate `apps/mobile/ios` and `apps/mobile/android` from the app configuration. Use config plugins for changes you want Prebuild to reproduce. If you maintain native projects directly, their source can be committed in the same repo.\n\n" : ""}Run \`pnpm typecheck\` and \`pnpm build\` to verify the workspace.\n`,
126
+ agents: `# ${name} workspace\n\nRead [README.md](README.md) for local setup. Start with the app or package that owns the behavior.\n\n${modules.join("\n")}\n\nRun \`pnpm typecheck\` before handoff.${selected.has("expo") ? " For mobile dependency changes, also run `pnpm --filter @launchrail/mobile exec expo install --check`." : ""}\n`,
127
+ commands,
128
+ };
129
+ }
130
+
131
+ export async function scaffold(directory, name, selected, displayName = name) {
132
+ await mkdir(dirname(directory), { recursive: true });
133
+ try {
134
+ await mkdir(directory);
135
+ } catch (error) {
136
+ if (error.code === "EEXIST") throw new Error(`Choose a destination that does not exist: ${directory}`);
137
+ throw error;
138
+ }
139
+ await cp(template, directory, { recursive: true, force: false, filter: (path) => permitted(path, selected) });
140
+ if (selected.has("next") && !selected.has("shadcn") && (selected.has("auth") || selected.has("query"))) {
141
+ await cp(join(source, "presets/headless/web/ui"), join(directory, "apps/web/src/components/ui"), { recursive: true });
142
+ }
143
+ await rename(join(directory, "gitignore.template"), join(directory, ".gitignore"));
144
+ const scheme = `launchrail-${name}`;
145
+ if (selected.has("next")) {
146
+ await configureManifest(directory, selected, "web", (data) => {
147
+ if (!selected.has("expo")) delete data.dependencies["@better-auth/expo"];
148
+ if (!selected.has("drizzle")) for (const script of ["db:generate", "db:migrate"]) delete data.scripts[script];
149
+ });
150
+ const webDir = join(directory, "apps/web");
151
+ const lines = [];
152
+ if (selected.has("postgres")) {
153
+ lines.push("DATABASE_URL=postgresql://launchrail:launchrail-local-dev@127.0.0.1:55432/launchrail");
154
+ }
155
+ if (selected.has("auth")) {
156
+ lines.push("BETTER_AUTH_URL=http://localhost:3000", "BETTER_AUTH_SECRET=replace-with-generated-secret");
157
+ if (selected.has("expo")) lines.push(`LAUNCHRAIL_APP_SCHEME=${scheme}`);
158
+ }
159
+ if (lines.length) {
160
+ const env = lines.join("\n") + "\n";
161
+ await writeFile(join(webDir, ".env.example"), env);
162
+ await writeFile(join(webDir, ".env.local"), env.replace("replace-with-generated-secret", randomBytes(32).toString("base64url")), { mode: 0o600 });
163
+ }
164
+ }
165
+ if (selected.has("expo")) {
166
+ await configureManifest(directory, selected, "mobile", () => {});
167
+ const mobileDir = join(directory, "apps/mobile");
168
+ const digest = createHash("sha256").update(name).digest("hex").slice(0, 8);
169
+ const identifier = `dev.launchrail.${name.replaceAll("-", "").slice(0, 40)}${digest}`;
170
+ await mutateJson(join(mobileDir, "app.json"), ({ expo }) => {
171
+ Object.assign(expo, { name: displayName, slug: name, scheme });
172
+ expo.ios = { ...expo.ios, bundleIdentifier: identifier };
173
+ expo.android = { ...expo.android, package: identifier };
174
+ if (!selected.has("auth")) delete expo.plugins;
175
+ if (selected.has("mobile-ui")) expo.userInterfaceStyle = "automatic";
176
+ });
177
+ if (selected.has("trpc") || selected.has("auth")) {
178
+ const env = "EXPO_PUBLIC_API_URL=http://localhost:3000\n";
179
+ await writeFile(join(mobileDir, ".env.local"), env);
180
+ await writeFile(join(mobileDir, ".env.example"), env);
181
+ }
182
+ }
183
+
184
+ await mutateJson(join(directory, "package.json"), (data) => {
185
+ data.name = name;
186
+ if (!selected.has("next")) delete data.scripts["dev:web"];
187
+ if (!selected.has("expo")) delete data.scripts["dev:mobile"];
188
+ if (!selected.has("postgres")) for (const script of ["db:up", "db:down"]) delete data.scripts[script];
189
+ if (!selected.has("drizzle")) delete data.scripts["db:migrate"];
190
+ if (!selected.has("turbo")) {
191
+ delete data.devDependencies.turbo;
192
+ for (const name of ["dev", "build", "typecheck"]) {
193
+ const parallel = name === "dev" ? " --parallel" : "";
194
+ data.scripts[name] = `pnpm -r${parallel} --if-present run ${name}`;
195
+ }
196
+ }
197
+ });
198
+ const doc = docs(displayName, selected);
199
+ await writeFile(join(directory, "README.md"), doc.readme);
200
+ await writeFile(join(directory, "AGENTS.md"), doc.agents);
201
+ const sections = new Set(selected);
202
+ if (selected.has("auth") || selected.has("trpc")) sections.add("mobile-actions");
203
+ if (["auth", "trpc", "mobile-ui", "expo-ui"].some((feature) => selected.has(feature))) sections.add("mobile-demo");
204
+ await transform(directory, sections, displayName);
205
+
206
+ // A Git hook or parent shell may point Git at another repository.
207
+ const gitEnv = { ...process.env };
208
+ for (const key of ["GIT_DIR", "GIT_WORK_TREE", "GIT_COMMON_DIR", "GIT_OBJECT_DIRECTORY"]) delete gitEnv[key];
209
+ const git = spawnSync("git", ["init", "--quiet", "--initial-branch=main"], {
210
+ cwd: directory,
211
+ env: gitEnv,
212
+ encoding: "utf8",
213
+ });
214
+ if (git.error) throw git.error;
215
+ if (git.status !== 0) throw new Error(`Could not initialize Git in ${directory}. ${git.stderr.trim()}`);
216
+ return doc.commands;
217
+ }
package/bin/tools.mjs ADDED
@@ -0,0 +1,62 @@
1
+ export const tools = [
2
+ { id: "next", name: "Next.js", description: "Web app and server routes", group: "Platforms", mark: "N", needs: [] },
3
+ { id: "expo", name: "Expo", description: "Native iOS and Android apps", group: "Platforms", mark: "E", needs: [] },
4
+ { id: "turbo", name: "Turborepo", description: "Workspace task runner and build cache", group: "Platforms", mark: "T", needs: [] },
5
+ { id: "trpc", name: "tRPC", description: "A typed API shared by your apps", group: "Data and accounts", mark: "t", needs: ["next", "query"] },
6
+ { id: "query", name: "TanStack Query", description: "Client fetching and caching", group: "Data and accounts", mark: "Q", needs: [] },
7
+ { id: "auth", name: "Better Auth", description: "Sign-in, sign-up and shared sessions", group: "Data and accounts", mark: "A", needs: ["drizzle"] },
8
+ { id: "drizzle", name: "Drizzle", description: "Typed SQL, schema and migrations", group: "Data and accounts", mark: "D", needs: ["postgres"] },
9
+ { id: "postgres", name: "PostgreSQL", description: "Postgres.js driver and local Docker setup", group: "Data and accounts", mark: "P", needs: ["next"] },
10
+ { id: "tailwind", name: "Tailwind CSS", description: "Utility styling for the web app", group: "Web interface", mark: "W", needs: ["next"] },
11
+ { id: "shadcn", name: "shadcn/ui", description: "Editable Nova components for Next.js", group: "Web interface", mark: "S", needs: ["tailwind"] },
12
+ { id: "mobile-ui", name: "React Native Reusables + Uniwind", description: "Editable components and Tailwind styling for iOS and Android", group: "Mobile interface", mark: "R", needs: ["expo"] },
13
+ { id: "expo-ui", name: "Expo UI", description: "Native SwiftUI and Jetpack Compose controls", group: "Mobile interface", mark: "U", needs: ["expo"] },
14
+ ];
15
+
16
+ export const toolMap = new Map(tools.map((tool) => [tool.id, tool]));
17
+
18
+ export function dependenciesOf(id) {
19
+ const dependencies = new Set();
20
+ const visit = (key) => {
21
+ for (const required of toolMap.get(key).needs) {
22
+ dependencies.add(required);
23
+ visit(required);
24
+ }
25
+ };
26
+ visit(id);
27
+ return dependencies;
28
+ }
29
+
30
+ export function workspaceOutline(selected) {
31
+ return [
32
+ {
33
+ name: "apps",
34
+ children: [
35
+ selected.has("next") && {
36
+ name: "web",
37
+ description: "Next.js pages and server routes",
38
+ children: [(selected.has("shadcn") || selected.has("auth") || selected.has("query")) && {
39
+ name: "src/components/ui",
40
+ description: selected.has("shadcn") ? "shadcn/ui" : "React demo components",
41
+ }],
42
+ },
43
+ selected.has("expo") && {
44
+ name: "mobile",
45
+ description: "One Expo app for iOS and Android",
46
+ children: [
47
+ selected.has("mobile-ui") && { name: "src/components/ui", description: "React Native Reusables + Uniwind" },
48
+ selected.has("expo-ui") && { name: "src/components/native-controls.tsx", description: "Expo UI example", file: true },
49
+ ],
50
+ },
51
+ ],
52
+ },
53
+ selected.has("trpc") && {
54
+ name: "packages",
55
+ children: [{ name: "api", description: "tRPC procedures and input schemas" }],
56
+ },
57
+ (selected.has("shadcn") || selected.has("mobile-ui")) && {
58
+ name: "theme",
59
+ children: [{ name: "tokens.css", description: "Colors and corner radii", file: true }],
60
+ },
61
+ ];
62
+ }
@@ -0,0 +1,118 @@
1
+ import { createHash } from "node:crypto";
2
+ import { readFile, readdir, writeFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { gunzipSync } from "node:zlib";
5
+
6
+ const registry = "https://registry.npmjs.org";
7
+ const groups = ["dependencies", "devDependencies", "optionalDependencies"];
8
+ const stable = /^\d+\.\d+\.\d+$/;
9
+
10
+ async function fetchRegistry(url, options) {
11
+ const response = await fetch(url, { ...options, signal: AbortSignal.timeout(30_000) });
12
+ if (!response.ok) throw new Error(`npm returned HTTP ${response.status} for ${url}.`);
13
+ return response;
14
+ }
15
+
16
+ async function latest(name) {
17
+ const response = await fetchRegistry(`${registry}/${encodeURIComponent(name)}/latest`);
18
+ const manifest = await response.json();
19
+ if (!stable.test(manifest.version)) throw new Error(`${name} has no stable release on npm's latest tag.`);
20
+ return manifest;
21
+ }
22
+
23
+ async function latestNodeTypes() {
24
+ const response = await fetchRegistry(`${registry}/@types%2Fnode`, {
25
+ headers: { Accept: "application/vnd.npm.install-v1+json" },
26
+ });
27
+ const { versions } = await response.json();
28
+ const major = process.versions.node.split(".")[0];
29
+ const compatible = Object.keys(versions).filter((version) => stable.test(version) && version.startsWith(`${major}.`));
30
+ compatible.sort((left, right) => left.localeCompare(right, "en", { numeric: true }));
31
+ return compatible.at(-1) ?? (await latest("@types/node")).version;
32
+ }
33
+
34
+ async function expoCompatibility(manifest) {
35
+ const url = new URL(manifest.dist.tarball);
36
+ if (url.origin !== registry || !url.pathname.startsWith("/expo/-/")) {
37
+ throw new Error("Invalid Expo tarball URL in npm metadata.");
38
+ }
39
+ const response = await fetchRegistry(url);
40
+ const compressed = Buffer.from(await response.arrayBuffer());
41
+ const expected = manifest.dist.integrity?.split(" ").find((hash) => hash.startsWith("sha512-"));
42
+ const actual = "sha512-" + createHash("sha512").update(compressed).digest("base64");
43
+ if (!expected || actual !== expected) throw new Error("Expo tarball integrity check failed.");
44
+
45
+ const tar = gunzipSync(compressed, { maxOutputLength: 64 * 1024 * 1024 });
46
+ for (let offset = 0; offset + 512 <= tar.length;) {
47
+ const name = tar.subarray(offset, offset + 100).toString().split("\0")[0];
48
+ if (!name) break;
49
+ const size = Number.parseInt(tar.subarray(offset + 124, offset + 136).toString().split("\0")[0].trim(), 8);
50
+ if (!Number.isSafeInteger(size) || size < 0 || offset + 512 + size > tar.length) break;
51
+ const start = offset + 512;
52
+ if (name === "package/bundledNativeModules.json") {
53
+ const versions = JSON.parse(tar.subarray(start, start + size).toString());
54
+ if (!versions.react || !versions["react-native"]) throw new Error("Expo's compatibility manifest is missing React versions.");
55
+ return versions;
56
+ }
57
+ offset = start + Math.ceil(size / 512) * 512;
58
+ }
59
+ throw new Error("Could not locate Expo's bundled native module versions.");
60
+ }
61
+
62
+ export async function resolveVersions(directory, hasExpo) {
63
+ const paths = [join(directory, "package.json")];
64
+ for (const group of ["apps", "packages"]) {
65
+ const entries = await readdir(join(directory, group), { withFileTypes: true }).catch((error) => {
66
+ if (error.code === "ENOENT" && group === "packages") return [];
67
+ throw error;
68
+ });
69
+ for (const item of entries) {
70
+ if (item.isDirectory()) paths.push(join(directory, group, item.name, "package.json"));
71
+ }
72
+ }
73
+ const manifests = await Promise.all(paths.map(async (path) => ({ path, data: JSON.parse(await readFile(path, "utf8")) })));
74
+ const [expo, nodeTypes, expoTemplate] = await Promise.all([
75
+ hasExpo ? latest("expo") : undefined,
76
+ latestNodeTypes(),
77
+ hasExpo ? latest("expo-template-blank-typescript") : undefined,
78
+ ]);
79
+ const compatibility = expo ? await expoCompatibility(expo) : {};
80
+ const sdkMajor = expo?.version.split(".")[0];
81
+ const templateMajor = expoTemplate?.dependencies?.expo?.match(/\d+/)?.[0];
82
+ const nativeTypeScript = compatibility.typescript ??
83
+ (templateMajor === sdkMajor ? expoTemplate?.devDependencies?.typescript : undefined);
84
+ if (expo && !nativeTypeScript) throw new Error(`The Expo SDK ${sdkMajor} TypeScript template is unavailable.`);
85
+
86
+ const compatible = (name, path) => {
87
+ if (name === "@types/node") return nodeTypes;
88
+ if (name === "expo") return expo?.version;
89
+ const native = path === join(directory, "apps", "mobile", "package.json");
90
+ if (expo && (native || name === "react" || name === "react-dom")) {
91
+ return compatibility[name] ?? (native && name === "typescript" ? nativeTypeScript : undefined);
92
+ }
93
+ return undefined;
94
+ };
95
+
96
+ const names = new Set(["pnpm"]);
97
+ for (const { path, data } of manifests) {
98
+ for (const group of groups) {
99
+ for (const [name, range] of Object.entries(data[group] ?? {})) {
100
+ if (!range.startsWith("workspace:") && !compatible(name, path)) names.add(name);
101
+ }
102
+ }
103
+ }
104
+ const resolved = new Map(await Promise.all([...names].map(async (name) => [name, (await latest(name)).version])));
105
+ for (const { path, data } of manifests) {
106
+ for (const group of groups) {
107
+ for (const [name, range] of Object.entries(data[group] ?? {})) {
108
+ if (!range.startsWith("workspace:")) data[group][name] = compatible(name, path) ?? resolved.get(name);
109
+ }
110
+ }
111
+ if (data.peerDependencies?.react) {
112
+ data.peerDependencies.react = `^${compatibility.react ?? resolved.get("react")}`;
113
+ }
114
+ if (path === paths[0]) data.packageManager = `pnpm@${resolved.get("pnpm")}`;
115
+ await writeFile(path, JSON.stringify(data, null, 2) + "\n");
116
+ }
117
+ return { manager: `pnpm@${resolved.get("pnpm")}`, expo: expo?.version, react: compatibility.react };
118
+ }
package/package.json CHANGED
@@ -1,6 +1,25 @@
1
1
  {
2
2
  "name": "create-launchrail",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.1",
4
+ "description": "Create a Next.js and Expo workspace with your selected Launchrail tools.",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-launchrail": "./bin/create-launchrail.mjs"
8
+ },
9
+ "engines": {
10
+ "node": ">=24"
11
+ },
12
+ "files": [
13
+ "bin",
14
+ "template",
15
+ "presets",
16
+ "THIRD_PARTY_LICENSES"
17
+ ],
18
+ "scripts": {
19
+ "test": "node --test",
20
+ "site": "npm --prefix site run dev",
21
+ "pack:site": "npm pack --pack-destination site",
22
+ "site:build": "npm --prefix site run build && npm run pack:site && node site/copy-archive.mjs"
23
+ },
24
+ "license": "UNLICENSED"
25
+ }
@@ -0,0 +1,16 @@
1
+ import type { ComponentProps } from "react";
2
+
3
+ export function Button({
4
+ className = "",
5
+ type = "button",
6
+ ...props
7
+ }: ComponentProps<"button">) {
8
+ return (
9
+ <button
10
+ data-slot="button"
11
+ type={type}
12
+ className={`inline-flex h-9 items-center justify-center rounded-md bg-primary px-3 text-sm font-medium text-primary-foreground outline-offset-4 disabled:opacity-50 ${className}`}
13
+ {...props}
14
+ />
15
+ );
16
+ }
@@ -0,0 +1,25 @@
1
+ import type { ComponentProps } from "react";
2
+
3
+ export function Card({ className = "", ...props }: ComponentProps<"div">) {
4
+ return <div data-slot="card" className={`grid gap-4 rounded-md border bg-background p-6 ${className}`} {...props} />;
5
+ }
6
+
7
+ export function CardHeader({ className = "", ...props }: ComponentProps<"div">) {
8
+ return <div data-slot="card-header" className={`grid gap-1 ${className}`} {...props} />;
9
+ }
10
+
11
+ export function CardTitle({ className = "", ...props }: ComponentProps<"div">) {
12
+ return <div data-slot="card-title" className={`font-semibold ${className}`} {...props} />;
13
+ }
14
+
15
+ export function CardDescription({ className = "", ...props }: ComponentProps<"div">) {
16
+ return <div data-slot="card-description" className={`text-sm text-muted-foreground ${className}`} {...props} />;
17
+ }
18
+
19
+ export function CardContent(props: ComponentProps<"div">) {
20
+ return <div data-slot="card-content" {...props} />;
21
+ }
22
+
23
+ export function CardFooter(props: ComponentProps<"div">) {
24
+ return <div data-slot="card-footer" {...props} />;
25
+ }
@@ -0,0 +1,3 @@
1
+ # Launchrail template
2
+
3
+ The generator writes an app-specific package map.