@sb-codex/create-sb-app 0.0.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.
- package/LICENSE +21 -0
- package/README.md +48 -0
- package/dist/index.js +256 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Slim Bouchoucha
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @sb-codex/create-sb-app
|
|
2
|
+
|
|
3
|
+
Scaffold a new multi-tenant SaaS project from the [sb-codex starter](https://github.com/SB-SLIM/react-app-starter). Downloads the full monorepo (apps + packages in `workspace:^`, self-contained) and replaces project-specific values for you.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm create @sb-codex/sb-app my-saas
|
|
9
|
+
# or: npm create @sb-codex/sb-app my-saas
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Prompts:
|
|
13
|
+
|
|
14
|
+
- **Project directory** — where to create the project
|
|
15
|
+
- **Project name** — root `package.json` name
|
|
16
|
+
- **Production domain** — replaces the reference domain across docs, compose and Traefik config
|
|
17
|
+
- **git init** — start with fresh git history
|
|
18
|
+
|
|
19
|
+
Then:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
cd my-saas
|
|
23
|
+
pnpm install
|
|
24
|
+
pnpm dev
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## What it replaces
|
|
28
|
+
|
|
29
|
+
| Token | Replaced with |
|
|
30
|
+
| ----------------------------------- | ---------------------------- |
|
|
31
|
+
| `slimbouchoucha.tn` | your domain |
|
|
32
|
+
| `ghcr.io/sb-slim/react-app-starter` | `ghcr.io/your-gh-org/<name>` |
|
|
33
|
+
| `SB-SLIM/react-app-starter` | `your-gh-org/<name>` |
|
|
34
|
+
| `152.53.187.54` | `YOUR_VPS_IP` |
|
|
35
|
+
| Notion page id | `YOUR_NOTION_PAGE_ID` |
|
|
36
|
+
|
|
37
|
+
It also drops its own `packages/create-sb-app` from the generated project and copies `.env.example` → `.env`.
|
|
38
|
+
|
|
39
|
+
## Local usage (from the monorepo)
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pnpm --filter @sb-codex/create-sb-app build
|
|
43
|
+
node packages/create-sb-app/dist/index.js ../my-saas
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
Part of the [sb-codex SaaS starter](https://github.com/SB-SLIM/react-app-starter). See [docs/plugins](../../docs/plugins/README.md).
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import {
|
|
5
|
+
existsSync,
|
|
6
|
+
readdirSync,
|
|
7
|
+
readFileSync,
|
|
8
|
+
writeFileSync,
|
|
9
|
+
rmSync,
|
|
10
|
+
copyFileSync
|
|
11
|
+
} from "fs";
|
|
12
|
+
import { join, extname, basename } from "path";
|
|
13
|
+
import { execSync } from "child_process";
|
|
14
|
+
import {
|
|
15
|
+
intro,
|
|
16
|
+
outro,
|
|
17
|
+
text,
|
|
18
|
+
confirm,
|
|
19
|
+
spinner,
|
|
20
|
+
isCancel,
|
|
21
|
+
cancel,
|
|
22
|
+
note
|
|
23
|
+
} from "@clack/prompts";
|
|
24
|
+
import { downloadTemplate } from "giget";
|
|
25
|
+
import pc from "picocolors";
|
|
26
|
+
|
|
27
|
+
// src/replacements.ts
|
|
28
|
+
var NOTION_PAGE_ID_DASHED = /3741c921-e61d-815f-8b78-e896fe1b65f3/g;
|
|
29
|
+
var NOTION_PAGE_ID_COMPACT = /3741c921e61d815f8b78e896fe1b65f3/g;
|
|
30
|
+
function buildReplacements(answers) {
|
|
31
|
+
const { name, domain } = answers;
|
|
32
|
+
return [
|
|
33
|
+
// Production domain (hub.<domain>, hub-dev.<domain>, …)
|
|
34
|
+
{ find: /slimbouchoucha\.tn/g, replace: domain },
|
|
35
|
+
// GHCR image prefix — owner unknown at scaffold time, leave a placeholder
|
|
36
|
+
{
|
|
37
|
+
find: /ghcr\.io\/sb-slim\/react-app-starter/gi,
|
|
38
|
+
replace: `ghcr.io/your-gh-org/${name}`
|
|
39
|
+
},
|
|
40
|
+
// GitHub repo references
|
|
41
|
+
{
|
|
42
|
+
find: /SB-SLIM\/react-app-starter/g,
|
|
43
|
+
replace: `your-gh-org/${name}`
|
|
44
|
+
},
|
|
45
|
+
// Remaining bare repo name (URLs, image names)
|
|
46
|
+
{ find: /react-app-starter/g, replace: name },
|
|
47
|
+
// VPS IP
|
|
48
|
+
{ find: /152\.53\.187\.54/g, replace: "YOUR_VPS_IP" },
|
|
49
|
+
// Notion page id (mirror of architecture docs — project specific)
|
|
50
|
+
{ find: NOTION_PAGE_ID_DASHED, replace: "YOUR_NOTION_PAGE_ID" },
|
|
51
|
+
{ find: NOTION_PAGE_ID_COMPACT, replace: "YOUR_NOTION_PAGE_ID" }
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
var TEXT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
55
|
+
".ts",
|
|
56
|
+
".tsx",
|
|
57
|
+
".js",
|
|
58
|
+
".jsx",
|
|
59
|
+
".mjs",
|
|
60
|
+
".cjs",
|
|
61
|
+
".json",
|
|
62
|
+
".md",
|
|
63
|
+
".yml",
|
|
64
|
+
".yaml",
|
|
65
|
+
".css",
|
|
66
|
+
".html",
|
|
67
|
+
".example",
|
|
68
|
+
".env"
|
|
69
|
+
]);
|
|
70
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
71
|
+
"node_modules",
|
|
72
|
+
".git",
|
|
73
|
+
"dist",
|
|
74
|
+
".turbo",
|
|
75
|
+
".next",
|
|
76
|
+
"build"
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
// src/index.ts
|
|
80
|
+
var TEMPLATE = "github:SB-SLIM/react-app-starter";
|
|
81
|
+
function bail(message) {
|
|
82
|
+
cancel(message);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
function slugify(input) {
|
|
86
|
+
return input.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
87
|
+
}
|
|
88
|
+
function parseFlags(argv) {
|
|
89
|
+
const flags = {};
|
|
90
|
+
for (let i = 0; i < argv.length; i++) {
|
|
91
|
+
const arg = argv[i];
|
|
92
|
+
if (!arg || !arg.startsWith("--")) continue;
|
|
93
|
+
const eq = arg.indexOf("=");
|
|
94
|
+
if (eq !== -1) {
|
|
95
|
+
flags[arg.slice(2, eq)] = arg.slice(eq + 1);
|
|
96
|
+
} else {
|
|
97
|
+
const key = arg.slice(2);
|
|
98
|
+
const next = argv[i + 1];
|
|
99
|
+
if (next && !next.startsWith("--")) {
|
|
100
|
+
flags[key] = next;
|
|
101
|
+
i++;
|
|
102
|
+
} else {
|
|
103
|
+
flags[key] = true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return flags;
|
|
108
|
+
}
|
|
109
|
+
function collectTextFiles(dir, acc = []) {
|
|
110
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
111
|
+
if (entry.isDirectory()) {
|
|
112
|
+
if (SKIP_DIRS.has(entry.name)) continue;
|
|
113
|
+
collectTextFiles(join(dir, entry.name), acc);
|
|
114
|
+
} else if (entry.isFile()) {
|
|
115
|
+
const name = entry.name;
|
|
116
|
+
if (TEXT_EXTENSIONS.has(extname(name)) || name.startsWith(".env")) {
|
|
117
|
+
acc.push(join(dir, name));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return acc;
|
|
122
|
+
}
|
|
123
|
+
async function main() {
|
|
124
|
+
console.log();
|
|
125
|
+
intro(pc.bgCyan(pc.black(" create-sb-app ")));
|
|
126
|
+
const flags = parseFlags(process.argv.slice(2));
|
|
127
|
+
const positional = process.argv.slice(2).find((a) => !a.startsWith("--"));
|
|
128
|
+
let target = positional ?? (typeof flags.dir === "string" ? flags.dir : void 0);
|
|
129
|
+
if (!target) {
|
|
130
|
+
const answer = await text({
|
|
131
|
+
message: "Project directory?",
|
|
132
|
+
placeholder: "my-saas",
|
|
133
|
+
validate: (v) => v.length === 0 ? "Required" : void 0
|
|
134
|
+
});
|
|
135
|
+
if (isCancel(answer)) bail("Cancelled.");
|
|
136
|
+
target = answer;
|
|
137
|
+
}
|
|
138
|
+
const targetDir = join(process.cwd(), target);
|
|
139
|
+
if (existsSync(targetDir) && readdirSync(targetDir).length > 0) {
|
|
140
|
+
bail(`Directory "${target}" already exists and is not empty.`);
|
|
141
|
+
}
|
|
142
|
+
let name;
|
|
143
|
+
if (typeof flags.name === "string") {
|
|
144
|
+
name = flags.name;
|
|
145
|
+
} else {
|
|
146
|
+
const nameAnswer = await text({
|
|
147
|
+
message: "Project name (package name)?",
|
|
148
|
+
initialValue: slugify(basename(target)),
|
|
149
|
+
validate: (v) => slugify(v).length === 0 ? "Invalid name" : void 0
|
|
150
|
+
});
|
|
151
|
+
if (isCancel(nameAnswer)) bail("Cancelled.");
|
|
152
|
+
name = nameAnswer;
|
|
153
|
+
}
|
|
154
|
+
let domain;
|
|
155
|
+
if (typeof flags.domain === "string") {
|
|
156
|
+
domain = flags.domain;
|
|
157
|
+
} else {
|
|
158
|
+
const domainAnswer = await text({
|
|
159
|
+
message: "Production domain?",
|
|
160
|
+
placeholder: "myapp.com",
|
|
161
|
+
defaultValue: "example.com"
|
|
162
|
+
});
|
|
163
|
+
if (isCancel(domainAnswer)) bail("Cancelled.");
|
|
164
|
+
domain = domainAnswer || "example.com";
|
|
165
|
+
}
|
|
166
|
+
let doGit;
|
|
167
|
+
if (flags.git === true || flags["no-git"] === true) {
|
|
168
|
+
doGit = flags.git === true;
|
|
169
|
+
} else {
|
|
170
|
+
const gitAnswer = await confirm({ message: "Initialize a fresh git repo?" });
|
|
171
|
+
if (isCancel(gitAnswer)) bail("Cancelled.");
|
|
172
|
+
doGit = gitAnswer;
|
|
173
|
+
}
|
|
174
|
+
const answers = {
|
|
175
|
+
name: slugify(name),
|
|
176
|
+
domain: domain.trim()
|
|
177
|
+
};
|
|
178
|
+
const s = spinner();
|
|
179
|
+
s.start("Downloading template");
|
|
180
|
+
try {
|
|
181
|
+
await downloadTemplate(TEMPLATE, { dir: targetDir, forceClean: true });
|
|
182
|
+
} catch (err) {
|
|
183
|
+
s.stop("Download failed");
|
|
184
|
+
bail(err instanceof Error ? err.message : String(err));
|
|
185
|
+
}
|
|
186
|
+
s.stop("Template downloaded");
|
|
187
|
+
const selfDir = join(targetDir, "packages", "create-sb-app");
|
|
188
|
+
if (existsSync(selfDir)) rmSync(selfDir, { recursive: true, force: true });
|
|
189
|
+
const gitDir = join(targetDir, ".git");
|
|
190
|
+
if (existsSync(gitDir)) rmSync(gitDir, { recursive: true, force: true });
|
|
191
|
+
const lockfile = join(targetDir, "pnpm-lock.yaml");
|
|
192
|
+
if (existsSync(lockfile)) rmSync(lockfile, { force: true });
|
|
193
|
+
s.start("Personalizing project");
|
|
194
|
+
const replacements = buildReplacements(answers);
|
|
195
|
+
for (const file of collectTextFiles(targetDir)) {
|
|
196
|
+
let content = readFileSync(file, "utf8");
|
|
197
|
+
let changed = false;
|
|
198
|
+
for (const { find, replace } of replacements) {
|
|
199
|
+
if (find.test(content)) {
|
|
200
|
+
content = content.replace(find, replace);
|
|
201
|
+
changed = true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (changed) writeFileSync(file, content);
|
|
205
|
+
}
|
|
206
|
+
const rootPkgPath = join(targetDir, "package.json");
|
|
207
|
+
if (existsSync(rootPkgPath)) {
|
|
208
|
+
const pkg = JSON.parse(readFileSync(rootPkgPath, "utf8"));
|
|
209
|
+
pkg.name = answers.name;
|
|
210
|
+
writeFileSync(rootPkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
211
|
+
}
|
|
212
|
+
const envExample = join(targetDir, ".env.example");
|
|
213
|
+
const envFile = join(targetDir, ".env");
|
|
214
|
+
if (existsSync(envExample) && !existsSync(envFile)) {
|
|
215
|
+
copyFileSync(envExample, envFile);
|
|
216
|
+
}
|
|
217
|
+
s.stop("Project personalized");
|
|
218
|
+
if (doGit) {
|
|
219
|
+
try {
|
|
220
|
+
execSync("git init", { cwd: targetDir, stdio: "ignore" });
|
|
221
|
+
execSync("git add -A", { cwd: targetDir, stdio: "ignore" });
|
|
222
|
+
} catch {
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
note(
|
|
226
|
+
[
|
|
227
|
+
pc.bold("apps/"),
|
|
228
|
+
" admin React 19 + Vite + Tailwind v4 + TanStack Router/Query",
|
|
229
|
+
" server Fastify 5 + tRPC v11 + Pino (stateless API)",
|
|
230
|
+
" web Next.js 15 marketing site",
|
|
231
|
+
" e2e Playwright",
|
|
232
|
+
pc.bold("packages/ (@sb-codex/* plugins, workspace:^)"),
|
|
233
|
+
" core \xB7 config \xB7 db \xB7 auth \xB7 api-contracts \xB7 jobs \xB7 ui-components",
|
|
234
|
+
pc.bold("infra/"),
|
|
235
|
+
" docker \xB7 compose \xB7 traefik",
|
|
236
|
+
"",
|
|
237
|
+
pc.dim("Multi-tenant: Postgres + RLS, x-workspace-slug header."),
|
|
238
|
+
pc.dim("Docs: docs/architecture.md \xB7 docs/roadmap.md \xB7 docs/plugins/")
|
|
239
|
+
].join("\n"),
|
|
240
|
+
"Architecture"
|
|
241
|
+
);
|
|
242
|
+
note(
|
|
243
|
+
[
|
|
244
|
+
`cd ${target}`,
|
|
245
|
+
"pnpm install",
|
|
246
|
+
"# .env already created from .env.example \u2014 fill the secrets",
|
|
247
|
+
"pnpm dev"
|
|
248
|
+
].join("\n"),
|
|
249
|
+
"Next steps"
|
|
250
|
+
);
|
|
251
|
+
outro(pc.green(`Created ${pc.bold(answers.name)} \u{1F389}`));
|
|
252
|
+
}
|
|
253
|
+
main().catch((err) => {
|
|
254
|
+
console.error(err);
|
|
255
|
+
process.exit(1);
|
|
256
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
+
"name": "@sb-codex/create-sb-app",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "Scaffold a new multi-tenant SaaS project from the sb-codex starter.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "Slim Bouchoucha",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"sb-codex",
|
|
11
|
+
"saas-starter",
|
|
12
|
+
"create",
|
|
13
|
+
"scaffold",
|
|
14
|
+
"cli",
|
|
15
|
+
"template"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://github.com/SB-SLIM/react-app-starter/tree/main/packages/create-sb-app#readme",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/SB-SLIM/react-app-starter.git",
|
|
21
|
+
"directory": "packages/create-sb-app"
|
|
22
|
+
},
|
|
23
|
+
"bugs": "https://github.com/SB-SLIM/react-app-starter/issues",
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"bin": {
|
|
28
|
+
"create-sb-app": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@clack/prompts": "^0.7.0",
|
|
35
|
+
"giget": "^1.2.1",
|
|
36
|
+
"picocolors": "^1.1.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^24.0.0",
|
|
40
|
+
"tsup": "^8.5.0"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"clean": "premove ./dist",
|
|
44
|
+
"build": "tsup",
|
|
45
|
+
"dev": "tsup --watch"
|
|
46
|
+
}
|
|
47
|
+
}
|