@orbclub/create-app 0.0.0 → 0.1.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/LICENSE +21 -0
- package/README.md +30 -0
- package/bin/create-orb-app.js +410 -0
- package/bin/node-version.js +6 -0
- package/bin/package-manager.js +87 -0
- package/bin/sdk-version.js +3 -0
- package/package.json +35 -1
- package/template/.env.local.example +10 -0
- package/template/AGENTS.md +105 -0
- package/template/README.md +56 -0
- package/template/eslint.config.mjs +11 -0
- package/template/gitignore +26 -0
- package/template/next.config.ts +25 -0
- package/template/package.json +29 -0
- package/template/pnpm-workspace.yaml +15 -0
- package/template/src/app/.well-known/orb-siwo.json/route.ts +23 -0
- package/template/src/app/api/local-sign-in/init/route.ts +12 -0
- package/template/src/app/api/local-sign-in/local-sign-in.ts +50 -0
- package/template/src/app/api/local-sign-in/status/route.ts +12 -0
- package/template/src/app/api/orb/route-validation.ts +123 -0
- package/template/src/app/api/orb/user/route.ts +44 -0
- package/template/src/app/api/route-security.ts +105 -0
- package/template/src/app/api/site-session/bind/route.ts +82 -0
- package/template/src/app/api/site-session/binding/route.ts +35 -0
- package/template/src/app/api/site-session/end/route.ts +30 -0
- package/template/src/app/api/site-session/renew/route.ts +71 -0
- package/template/src/app/api/site-session/site-session.ts +152 -0
- package/template/src/app/globals.css +196 -0
- package/template/src/app/home.tsx +115 -0
- package/template/src/app/layout.tsx +24 -0
- package/template/src/app/page.tsx +12 -0
- package/template/src/lib/orb-session.ts +703 -0
- package/template/src/lib/sign-in.ts +61 -0
- package/template/src/lib/site-origin.ts +35 -0
- package/template/src/lib/use-orb-session.ts +26 -0
- package/template/tsconfig.json +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Orb Club
|
|
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,30 @@
|
|
|
1
|
+
# @orbclub/create-app
|
|
2
|
+
|
|
3
|
+
Creates an Orb app: a Next.js project on
|
|
4
|
+
[`@orbclub/apps-sdk`](https://github.com/orb-club/orb-apps-sdk) with sign-in that
|
|
5
|
+
works inside Orb, on `http://localhost` and on your HTTPS origin.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm create @orbclub/app my-app # or: npx @orbclub/create-app my-app / bunx @orbclub/create-app my-app
|
|
9
|
+
cd my-app
|
|
10
|
+
pnpm dev # or the dev command it prints
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires Node.js 20.9.0 or newer. It installs dependencies, writes
|
|
14
|
+
`.env.local` with a fresh local sign-in secret, and makes a first git commit
|
|
15
|
+
(skipped if git isn't set up or the folder is already inside a repository). It
|
|
16
|
+
refuses a folder that isn't empty.
|
|
17
|
+
|
|
18
|
+
| Option | Effect |
|
|
19
|
+
| ---------------------------------------------------- | --------------------------------------------------------------------- |
|
|
20
|
+
| `--use-pnpm`, `--use-npm`, `--use-yarn`, `--use-bun` | Package manager (default: the one that ran the command) |
|
|
21
|
+
| `--no-install` | Skip installing dependencies |
|
|
22
|
+
| `--no-git` | Skip the git repository |
|
|
23
|
+
| `--sdk-path <path>` | Depend on a local `@orbclub/apps-sdk` checkout instead of the release |
|
|
24
|
+
|
|
25
|
+
The generated `README.md` and `AGENTS.md` cover the sign-in flows, settings
|
|
26
|
+
and deployment.
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
MIT
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
4
|
+
import { randomBytes } from "node:crypto";
|
|
5
|
+
import { constants } from "node:fs";
|
|
6
|
+
import {
|
|
7
|
+
access,
|
|
8
|
+
copyFile,
|
|
9
|
+
mkdir,
|
|
10
|
+
readdir,
|
|
11
|
+
readFile,
|
|
12
|
+
writeFile,
|
|
13
|
+
} from "node:fs/promises";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
|
|
17
|
+
import { MINIMUM_NODE_VERSION, supportsNodeVersion } from "./node-version.js";
|
|
18
|
+
import {
|
|
19
|
+
adaptManifest,
|
|
20
|
+
detectPackageManager,
|
|
21
|
+
PACKAGE_MANAGERS,
|
|
22
|
+
parsePnpmOverrides,
|
|
23
|
+
runScriptCommand,
|
|
24
|
+
} from "./package-manager.js";
|
|
25
|
+
import { SDK_VERSION } from "./sdk-version.js";
|
|
26
|
+
|
|
27
|
+
const HELP_TEXT = `Usage: create-orb-app <directory> [options]
|
|
28
|
+
|
|
29
|
+
Options:
|
|
30
|
+
--use-pnpm, --use-npm, --use-yarn, --use-bun
|
|
31
|
+
Package manager to install with (default: the one
|
|
32
|
+
running this command, otherwise npm)
|
|
33
|
+
--no-install Skip installing dependencies
|
|
34
|
+
--no-git Skip creating a git repository
|
|
35
|
+
--sdk-path <path> Depend on a local @orbclub/apps-sdk checkout instead of the
|
|
36
|
+
npm release
|
|
37
|
+
-h, --help Show this help
|
|
38
|
+
|
|
39
|
+
Example:
|
|
40
|
+
pnpm create @orbclub/app my-app`;
|
|
41
|
+
|
|
42
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
43
|
+
const __dirname = path.dirname(__filename);
|
|
44
|
+
const templateDir = path.resolve(__dirname, "../template");
|
|
45
|
+
|
|
46
|
+
// Only these files get template tokens replaced; everything else is copied
|
|
47
|
+
// byte for byte.
|
|
48
|
+
const TEXT_EXTENSIONS = new Set([
|
|
49
|
+
".cjs",
|
|
50
|
+
".css",
|
|
51
|
+
".example",
|
|
52
|
+
".js",
|
|
53
|
+
".json",
|
|
54
|
+
".jsx",
|
|
55
|
+
".md",
|
|
56
|
+
".mjs",
|
|
57
|
+
".mts",
|
|
58
|
+
".ts",
|
|
59
|
+
".tsx",
|
|
60
|
+
".txt",
|
|
61
|
+
".yaml",
|
|
62
|
+
".yml",
|
|
63
|
+
]);
|
|
64
|
+
const TEXT_FILE_NAMES = new Set(["gitignore", ".npmrc"]);
|
|
65
|
+
const RESERVED_PACKAGE_NAMES = new Set(["node_modules", "favicon.ico"]);
|
|
66
|
+
const LOCAL_SECRET_VARIABLE = "ORB_LOCAL_SIWO_SESSION_SECRET";
|
|
67
|
+
|
|
68
|
+
class UsageError extends Error {}
|
|
69
|
+
|
|
70
|
+
function toPackageName(name) {
|
|
71
|
+
return name
|
|
72
|
+
.trim()
|
|
73
|
+
.toLowerCase()
|
|
74
|
+
.replace(/\s+/g, "-")
|
|
75
|
+
.replace(/[^a-z0-9-_.~]/g, "-")
|
|
76
|
+
.replace(/-{2,}/g, "-")
|
|
77
|
+
.replace(/^[-_.]+|-+$/g, "");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function isValidPackageName(name) {
|
|
81
|
+
return (
|
|
82
|
+
name.length > 0 &&
|
|
83
|
+
name.length <= 214 &&
|
|
84
|
+
!RESERVED_PACKAGE_NAMES.has(name) &&
|
|
85
|
+
encodeURIComponent(name) === name
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function parseArgs(args) {
|
|
90
|
+
const options = {
|
|
91
|
+
help: false,
|
|
92
|
+
projectInput: undefined,
|
|
93
|
+
sdkPathInput: undefined,
|
|
94
|
+
packageManager: undefined,
|
|
95
|
+
install: true,
|
|
96
|
+
git: true,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
100
|
+
const arg = args[index];
|
|
101
|
+
|
|
102
|
+
if (arg === "-h" || arg === "--help") {
|
|
103
|
+
return { ...options, help: true };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (arg === "--no-install") {
|
|
107
|
+
options.install = false;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (arg === "--no-git") {
|
|
112
|
+
options.git = false;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const manager = /^--use-(\w+)$/.exec(arg)?.[1];
|
|
117
|
+
if (manager && PACKAGE_MANAGERS.includes(manager)) {
|
|
118
|
+
if (options.packageManager && options.packageManager !== manager) {
|
|
119
|
+
throw new UsageError("Choose one package manager.");
|
|
120
|
+
}
|
|
121
|
+
options.packageManager = manager;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (arg === "--sdk-path" || arg.startsWith("--sdk-path=")) {
|
|
126
|
+
const value =
|
|
127
|
+
arg === "--sdk-path" ? args[++index] : arg.slice("--sdk-path=".length);
|
|
128
|
+
if (!value || value.startsWith("-")) {
|
|
129
|
+
throw new UsageError("--sdk-path needs a path.");
|
|
130
|
+
}
|
|
131
|
+
options.sdkPathInput = value;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (arg.startsWith("-")) {
|
|
136
|
+
throw new UsageError(`Unknown option: ${arg}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (options.projectInput !== undefined) {
|
|
140
|
+
throw new UsageError(`Unexpected argument: ${arg}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
options.projectInput = arg;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return options;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function toFileDependency(targetDir, sdkDir) {
|
|
150
|
+
const relativePath = path.relative(targetDir, sdkDir) || ".";
|
|
151
|
+
const portablePath = relativePath.split(path.sep).join("/");
|
|
152
|
+
// On Windows a path on another drive has no relative form.
|
|
153
|
+
if (path.isAbsolute(relativePath)) return `file:${portablePath}`;
|
|
154
|
+
const dependencyPath = portablePath.startsWith(".")
|
|
155
|
+
? portablePath
|
|
156
|
+
: `./${portablePath}`;
|
|
157
|
+
|
|
158
|
+
return `file:${dependencyPath}`;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function pathExists(targetPath) {
|
|
162
|
+
try {
|
|
163
|
+
await access(targetPath, constants.F_OK);
|
|
164
|
+
return true;
|
|
165
|
+
} catch {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function isTextFile(fileName) {
|
|
171
|
+
return (
|
|
172
|
+
TEXT_FILE_NAMES.has(fileName) ||
|
|
173
|
+
TEXT_EXTENSIONS.has(path.extname(fileName).toLowerCase())
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function replaceTokens(source, replacements) {
|
|
178
|
+
const tokenPattern = new RegExp(
|
|
179
|
+
Object.keys(replacements)
|
|
180
|
+
.map((token) => token.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
|
181
|
+
.join("|"),
|
|
182
|
+
"g",
|
|
183
|
+
);
|
|
184
|
+
return source.replace(tokenPattern, (token) => replacements[token]);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async function copyTemplate(sourceDir, targetDir, { replacements, skip }) {
|
|
188
|
+
await mkdir(targetDir, { recursive: true });
|
|
189
|
+
const entries = await readdir(sourceDir, { withFileTypes: true });
|
|
190
|
+
|
|
191
|
+
for (const entry of entries) {
|
|
192
|
+
const sourcePath = path.join(sourceDir, entry.name);
|
|
193
|
+
if (skip.has(path.relative(templateDir, sourcePath))) continue;
|
|
194
|
+
|
|
195
|
+
// npm never publishes .gitignore files, so the template ships "gitignore".
|
|
196
|
+
const targetName = entry.name === "gitignore" ? ".gitignore" : entry.name;
|
|
197
|
+
const targetPath = path.join(targetDir, targetName);
|
|
198
|
+
|
|
199
|
+
if (entry.isDirectory()) {
|
|
200
|
+
await copyTemplate(sourcePath, targetPath, { replacements, skip });
|
|
201
|
+
} else if (isTextFile(entry.name)) {
|
|
202
|
+
const source = await readFile(sourcePath, "utf8");
|
|
203
|
+
await writeFile(targetPath, replaceTokens(source, replacements), "utf8");
|
|
204
|
+
} else {
|
|
205
|
+
await copyFile(sourcePath, targetPath);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async function scaffold({
|
|
211
|
+
targetDir,
|
|
212
|
+
displayName,
|
|
213
|
+
packageName,
|
|
214
|
+
sdkDependency,
|
|
215
|
+
packageManager,
|
|
216
|
+
}) {
|
|
217
|
+
const overrides = parsePnpmOverrides(
|
|
218
|
+
await readFile(path.join(templateDir, "pnpm-workspace.yaml"), "utf8"),
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
await copyTemplate(templateDir, targetDir, {
|
|
222
|
+
replacements: {
|
|
223
|
+
__APP_NAME__: packageName,
|
|
224
|
+
__DISPLAY_NAME_JSON__: JSON.stringify(displayName),
|
|
225
|
+
"{{DISPLAY_NAME}}": displayName,
|
|
226
|
+
"{{PM}}": packageManager,
|
|
227
|
+
__SDK_DEPENDENCY_JSON__: JSON.stringify(sdkDependency),
|
|
228
|
+
},
|
|
229
|
+
skip: new Set(packageManager === "pnpm" ? [] : ["pnpm-workspace.yaml"]),
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const manifestPath = path.join(targetDir, "package.json");
|
|
233
|
+
const manifest = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
234
|
+
await writeFile(
|
|
235
|
+
manifestPath,
|
|
236
|
+
`${JSON.stringify(adaptManifest(manifest, packageManager, overrides), null, 2)}\n`,
|
|
237
|
+
"utf8",
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
// .env.local is git-ignored; give it a fresh local sign-in secret so
|
|
241
|
+
// http://localhost development signs in without manual setup.
|
|
242
|
+
const envExample = await readFile(
|
|
243
|
+
path.join(targetDir, ".env.local.example"),
|
|
244
|
+
"utf8",
|
|
245
|
+
);
|
|
246
|
+
await writeFile(
|
|
247
|
+
path.join(targetDir, ".env.local"),
|
|
248
|
+
envExample.replace(
|
|
249
|
+
new RegExp(`^${LOCAL_SECRET_VARIABLE}=.*$`, "m"),
|
|
250
|
+
`${LOCAL_SECRET_VARIABLE}=${randomBytes(32).toString("base64url")}`,
|
|
251
|
+
),
|
|
252
|
+
{ encoding: "utf8", mode: 0o600 },
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function installDependencies(packageManager, cwd) {
|
|
257
|
+
return new Promise((resolve) => {
|
|
258
|
+
const child = spawn(packageManager, ["install"], {
|
|
259
|
+
cwd,
|
|
260
|
+
stdio: "inherit",
|
|
261
|
+
shell: process.platform === "win32",
|
|
262
|
+
});
|
|
263
|
+
child.on("error", () => resolve(false));
|
|
264
|
+
child.on("close", (code) => resolve(code === 0));
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function git(args, cwd) {
|
|
269
|
+
return execFileSync("git", args, { cwd, stdio: "pipe", encoding: "utf8" });
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function succeeds(run) {
|
|
273
|
+
try {
|
|
274
|
+
run();
|
|
275
|
+
return true;
|
|
276
|
+
} catch {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Creates a repository with an initial commit. Skipped without a message when
|
|
283
|
+
* git is missing or the app is inside an existing work tree.
|
|
284
|
+
*/
|
|
285
|
+
function initializeGit(cwd) {
|
|
286
|
+
if (!succeeds(() => git(["--version"], cwd))) return null;
|
|
287
|
+
if (succeeds(() => git(["rev-parse", "--is-inside-work-tree"], cwd))) {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (!succeeds(() => git(["init", "--quiet"], cwd))) return null;
|
|
292
|
+
|
|
293
|
+
const hasIdentity = ["user.name", "user.email"].every((key) =>
|
|
294
|
+
succeeds(() => {
|
|
295
|
+
if (!git(["config", key], cwd).trim()) throw new Error(key);
|
|
296
|
+
}),
|
|
297
|
+
);
|
|
298
|
+
if (!hasIdentity) {
|
|
299
|
+
return "Created a git repository. Set git user.name and user.email to commit.";
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const committed = succeeds(() => {
|
|
303
|
+
git(["add", "--all"], cwd);
|
|
304
|
+
git(["commit", "--quiet", "-m", "Initial commit from create-orb-app"], cwd);
|
|
305
|
+
});
|
|
306
|
+
return committed
|
|
307
|
+
? "Created a git repository with an initial commit."
|
|
308
|
+
: "Created a git repository. The initial commit failed; commit manually.";
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function shellQuote(value) {
|
|
312
|
+
return /^[\w@%+=:,./-]+$/.test(value)
|
|
313
|
+
? value
|
|
314
|
+
: `'${value.replace(/'/g, "'\\''")}'`;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function printNextSteps({ targetDir, packageManager, installed }) {
|
|
318
|
+
const relativeDir = path.relative(process.cwd(), targetDir);
|
|
319
|
+
const steps = [];
|
|
320
|
+
if (relativeDir) steps.push(`cd ${shellQuote(relativeDir)}`);
|
|
321
|
+
if (!installed) steps.push(`${packageManager} install`);
|
|
322
|
+
steps.push(runScriptCommand(packageManager, "dev"));
|
|
323
|
+
|
|
324
|
+
console.log("\nNext steps:\n");
|
|
325
|
+
for (const step of steps) console.log(` ${step}`);
|
|
326
|
+
console.log(
|
|
327
|
+
"\nThen open http://localhost:3000. README.md covers sign-in and deployment.",
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
async function main() {
|
|
332
|
+
if (!supportsNodeVersion(process.versions.node)) {
|
|
333
|
+
console.error(
|
|
334
|
+
`create-orb-app requires Node.js ${MINIMUM_NODE_VERSION} or newer. Current version: ${process.versions.node}.`,
|
|
335
|
+
);
|
|
336
|
+
process.exit(1);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const options = parseArgs(process.argv.slice(2));
|
|
340
|
+
|
|
341
|
+
if (options.help) {
|
|
342
|
+
console.log(HELP_TEXT);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const projectInput = options.projectInput?.trim();
|
|
347
|
+
if (!projectInput) {
|
|
348
|
+
throw new UsageError("Project directory is required.");
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const targetDir = path.resolve(process.cwd(), projectInput);
|
|
352
|
+
const displayName = path.basename(targetDir);
|
|
353
|
+
const packageName = toPackageName(displayName);
|
|
354
|
+
if (!isValidPackageName(packageName)) {
|
|
355
|
+
throw new Error(
|
|
356
|
+
`Cannot derive a package name from "${displayName}". Use letters, numbers, dashes, underscores, or periods.`,
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
let sdkDependency = `^${SDK_VERSION}`;
|
|
361
|
+
if (options.sdkPathInput) {
|
|
362
|
+
const sdkDir = path.resolve(process.cwd(), options.sdkPathInput);
|
|
363
|
+
if (!(await pathExists(path.join(sdkDir, "package.json")))) {
|
|
364
|
+
throw new Error(`SDK package not found: ${options.sdkPathInput}`);
|
|
365
|
+
}
|
|
366
|
+
sdkDependency = toFileDependency(targetDir, sdkDir);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if ((await pathExists(targetDir)) && (await readdir(targetDir)).length > 0) {
|
|
370
|
+
throw new Error(`Target directory is not empty: ${targetDir}`);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const packageManager =
|
|
374
|
+
options.packageManager ??
|
|
375
|
+
detectPackageManager(process.env.npm_config_user_agent);
|
|
376
|
+
|
|
377
|
+
console.log(`Creating ${displayName} in ${targetDir}`);
|
|
378
|
+
await scaffold({
|
|
379
|
+
targetDir,
|
|
380
|
+
displayName,
|
|
381
|
+
packageName,
|
|
382
|
+
sdkDependency,
|
|
383
|
+
packageManager,
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
let installed = false;
|
|
387
|
+
if (options.install) {
|
|
388
|
+
console.log(`\nInstalling dependencies with ${packageManager}...\n`);
|
|
389
|
+
installed = await installDependencies(packageManager, targetDir);
|
|
390
|
+
if (!installed) {
|
|
391
|
+
console.error(`\nCould not install dependencies with ${packageManager}.`);
|
|
392
|
+
process.exitCode = 1;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (options.git) {
|
|
397
|
+
const gitResult = initializeGit(targetDir);
|
|
398
|
+
if (gitResult) console.log(`\n${gitResult}`);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
printNextSteps({ targetDir, packageManager, installed });
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
main().catch((error) => {
|
|
405
|
+
console.error(
|
|
406
|
+
error instanceof Error ? error.message : "Failed to scaffold app.",
|
|
407
|
+
);
|
|
408
|
+
if (error instanceof UsageError) console.log(`\n${HELP_TEXT}`);
|
|
409
|
+
process.exit(1);
|
|
410
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export const PACKAGE_MANAGERS = ["pnpm", "npm", "yarn", "bun"];
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The package manager that launched the scaffolder, read from
|
|
5
|
+
* `npm_config_user_agent` (for example `pnpm/10.14.0 npm/? node/v22.0.0`).
|
|
6
|
+
* Falls back to npm, which ships with Node.js.
|
|
7
|
+
*/
|
|
8
|
+
export function detectPackageManager(userAgent) {
|
|
9
|
+
const name = userAgent?.trim().split(/[\s/]/, 1)[0];
|
|
10
|
+
return PACKAGE_MANAGERS.includes(name) ? name : "npm";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function runScriptCommand(packageManager, script) {
|
|
14
|
+
return packageManager === "npm" || packageManager === "bun"
|
|
15
|
+
? `${packageManager} run ${script}`
|
|
16
|
+
: `${packageManager} ${script}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Reads the `overrides` map from the template's pnpm-workspace.yaml. */
|
|
20
|
+
export function parsePnpmOverrides(source) {
|
|
21
|
+
const overrides = {};
|
|
22
|
+
let inOverrides = false;
|
|
23
|
+
|
|
24
|
+
for (const line of source.split(/\r?\n/)) {
|
|
25
|
+
if (!line.trim() || line.trim().startsWith("#")) continue;
|
|
26
|
+
|
|
27
|
+
if (!/^\s/.test(line)) {
|
|
28
|
+
inOverrides = line.trim() === "overrides:";
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const match = inOverrides && /^\s+("[^"]+"|\S+):\s*(.+?)\s*$/.exec(line);
|
|
33
|
+
if (match) {
|
|
34
|
+
overrides[match[1].replace(/^"|"$/g, "")] = match[2].replace(
|
|
35
|
+
/^"|"$/g,
|
|
36
|
+
"",
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return overrides;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function packageNameOf(selector) {
|
|
45
|
+
const versionAt = selector.indexOf("@", 1);
|
|
46
|
+
return versionAt === -1 ? selector : selector.slice(0, versionAt);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Yarn matches a version-qualified resolution key only against the exact
|
|
51
|
+
* range a dependent declares, so `postcss@^8` would not catch `8.4.31`. Pin
|
|
52
|
+
* by package name when the template overrides a single range of a package;
|
|
53
|
+
* drop packages overridden across several majors, which cannot be pinned by
|
|
54
|
+
* name and resolve to the newest release in each range on a fresh install.
|
|
55
|
+
*/
|
|
56
|
+
function toYarnResolutions(overrides) {
|
|
57
|
+
const byName = new Map();
|
|
58
|
+
for (const [selector, version] of Object.entries(overrides)) {
|
|
59
|
+
const name = packageNameOf(selector);
|
|
60
|
+
byName.set(name, [...(byName.get(name) ?? []), version]);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const resolutions = {};
|
|
64
|
+
for (const [name, versions] of byName) {
|
|
65
|
+
if (versions.length === 1) resolutions[name] = versions[0];
|
|
66
|
+
}
|
|
67
|
+
return resolutions;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Adapts the pnpm-flavored template manifest to another package manager.
|
|
72
|
+
* pnpm keeps `packageManager` and reads overrides from pnpm-workspace.yaml.
|
|
73
|
+
* npm and Bun take the same version-qualified keys in `overrides`; Yarn gets
|
|
74
|
+
* `resolutions`. pnpm's build-script policy (`ignoredBuiltDependencies`) has
|
|
75
|
+
* no counterpart and is dropped with pnpm-workspace.yaml.
|
|
76
|
+
*/
|
|
77
|
+
export function adaptManifest(manifest, packageManager, overrides) {
|
|
78
|
+
if (packageManager === "pnpm") return manifest;
|
|
79
|
+
|
|
80
|
+
const rest = { ...manifest };
|
|
81
|
+
delete rest.packageManager;
|
|
82
|
+
if (Object.keys(overrides).length === 0) return rest;
|
|
83
|
+
|
|
84
|
+
return packageManager === "yarn"
|
|
85
|
+
? { ...rest, resolutions: toYarnResolutions(overrides) }
|
|
86
|
+
: { ...rest, overrides: { ...overrides } };
|
|
87
|
+
}
|
package/package.json
CHANGED
|
@@ -1 +1,35 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@orbclub/create-app",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Create an Orb app with Next.js and @orbclub/apps-sdk",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"orb",
|
|
7
|
+
"orb-app",
|
|
8
|
+
"nextjs",
|
|
9
|
+
"create"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/orb-club/orb-apps-sdk.git",
|
|
14
|
+
"directory": "create-orb-app"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/orb-club/orb-apps-sdk/tree/main/create-orb-app#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/orb-club/orb-apps-sdk/issues"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"bin": {
|
|
22
|
+
"create-orb-app": "./bin/create-orb-app.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"bin",
|
|
26
|
+
"template"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20.9.0"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Deployed only: the exact HTTPS origin this app is served from (scheme,
|
|
2
|
+
# host, port; no path). It signs in with browser-site Sign in with Orb and
|
|
3
|
+
# serves /.well-known/orb-siwo.json. Leave it unset for local development.
|
|
4
|
+
# ORB_APP_ORIGIN=https://app.example.com
|
|
5
|
+
|
|
6
|
+
# Local development sign-in on http://localhost, 127.0.0.1 or [::1], any
|
|
7
|
+
# port: a random 32-byte key, base64url encoded. Server-only; leave it unset
|
|
8
|
+
# in production. create-orb-app writes one to .env.local. To generate another:
|
|
9
|
+
# node -e "console.log(require('node:crypto').randomBytes(32).toString('base64url'))"
|
|
10
|
+
ORB_LOCAL_SIWO_SESSION_SECRET=
|