saasaloy 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/index.js +222 -79
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/schemas/registry-item.schema.json +5 -2
- package/templates/base/AGENTS.md +80 -470
- package/templates/base/_agents/skills/saasaloy-design/SKILL.md +33 -22
- package/templates/base/_agents/skills/saasaloy-landing-copy/SKILL.md +17 -2
- package/templates/base/_agents/skills/saasaloy-setup/SKILL.md +38 -7
- package/templates/base/_saasaloy-base.json +1 -0
- package/templates/base/apps/web/DESIGN.md +4 -4
- package/templates/base/apps/web/astro.config.mjs +2 -1
- package/templates/base/apps/web/src/layouts/Layout.astro +2 -2
- package/templates/base/oxlint.config.mjs +14 -10
- package/templates/base/package.json +1 -0
- package/templates/base/packages/env/src/define.test.ts +33 -0
- package/templates/base/packages/ui/AGENTS.md +159 -0
- package/templates/base/packages/ui/CLAUDE.md +1 -0
- package/templates/base/packages/ui/components.json +1 -1
- package/templates/base/packages/ui/src/containers/README.md +4 -4
- package/templates/base/packages/ui/src/styles/brand.css +145 -0
- package/templates/base/packages/ui/src/styles/globals.css +6 -7
- package/templates/base/packages/ui/src/styles/web.css +7 -139
- package/templates/base/turbo.json +1 -0
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<!-- Generated by scripts/build-cli-readme.ts from the repo root README.md. Edit that file. -->
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
|
|
3
5
|
# Saasaloy
|
|
4
6
|
|
|
5
7
|
**Open source, composable SaaS starter kit for Cloudflare.** A CLI plus a module registry, not a boilerplate. You scaffold a small base, then copy in the API, database, auth, billing and product features one command at a time, as source files you own. Think shadcn/ui for a full-stack SaaS.
|
|
@@ -79,7 +81,7 @@ Full walkthrough: [Getting started](https://github.com/mimukit/saasaloy/blob/mai
|
|
|
79
81
|
| Stage | What you need | What you add |
|
|
80
82
|
|---|---|---|
|
|
81
83
|
| Validate the idea | a landing page and a waitlist | `init`, then `waitlist` |
|
|
82
|
-
| Build the MVP | sign-in, an admin app, transactional email | `auth`, `admin`, `email` + a provider |
|
|
84
|
+
| Build the MVP | sign-in, a customer app, an admin app, transactional email | `auth`, `app`, `admin`, `email` + a provider |
|
|
83
85
|
| Onboard teams | organizations, tenant isolation, roles | `teams`, `multitenant` |
|
|
84
86
|
| Charge money | subscriptions, plan limits, webhooks | `billing`, `billing-stripe` |
|
|
85
87
|
| Scale the backend | jobs, caching, files, rate limits, API access | `queue`, `kv`, `storage`, `ratelimit`, `api-keys` |
|
|
@@ -109,7 +111,7 @@ Modules come in tiers. A **capability** scaffolds a workspace and sets conventio
|
|
|
109
111
|
| Tier | Modules |
|
|
110
112
|
|---|---|
|
|
111
113
|
| Capability | `api`, `database`, `validators`, `logger`, `auth`, `admin`, `email`, `sms`, `queue`, `kv`, `storage`, `billing`, `payment` |
|
|
112
|
-
| Feature | `waitlist`, `teams`, `multitenant`, `api-keys`, `email-react`, `ratelimit`, `feature-flags` |
|
|
114
|
+
| Feature | `waitlist`, `teams`, `multitenant`, `api-keys`, `email-react`, `ratelimit`, `feature-flags`, `command` |
|
|
113
115
|
| Provider | `email-console`, `email-cloudflare`, `email-plunk`, `logger-console`, `sms-console`, `sms-khudebarta`, `queue-cloudflare`, `queue-memory`, `kv-cloudflare`, `kv-upstash`, `kv-memory`, `storage-cloudflare`, `storage-memory`, `billing-console`, `billing-stripe`, `payment-console`, `payment-manual` |
|
|
114
116
|
| Driver | `database-d1`, `database-postgres`, `api-keys-organization`, `api-keys-user` |
|
|
115
117
|
|
package/dist/index.js
CHANGED
|
@@ -346,8 +346,8 @@ async function createDirLink(linkAbs, targetAbs) {
|
|
|
346
346
|
// src/lib/env-example.ts
|
|
347
347
|
var ENV_EXAMPLE = "packages/env/.env.example";
|
|
348
348
|
var PUBLIC_PREFIX = "PUBLIC_";
|
|
349
|
-
var SERVICE_NAMES = ["api", "web", "admin", "deploy"];
|
|
350
|
-
var CLIENT_SERVICES = ["web", "admin"];
|
|
349
|
+
var SERVICE_NAMES = ["api", "web", "admin", "app", "deploy"];
|
|
350
|
+
var CLIENT_SERVICES = ["web", "admin", "app"];
|
|
351
351
|
function isPublicVar(name) {
|
|
352
352
|
return name.startsWith(PUBLIC_PREFIX);
|
|
353
353
|
}
|
|
@@ -2226,6 +2226,31 @@ function isPatchTracked(manifest, module, op, siblings) {
|
|
|
2226
2226
|
);
|
|
2227
2227
|
}
|
|
2228
2228
|
|
|
2229
|
+
// src/lib/requested.ts
|
|
2230
|
+
function toRequested(input) {
|
|
2231
|
+
return typeof input === "string" ? { names: [input], rootOf: /* @__PURE__ */ new Map() } : input;
|
|
2232
|
+
}
|
|
2233
|
+
function listLabel(items) {
|
|
2234
|
+
if (items.length <= 1) {
|
|
2235
|
+
return items[0] ?? "";
|
|
2236
|
+
}
|
|
2237
|
+
return `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
|
|
2238
|
+
}
|
|
2239
|
+
function requestedLabel(input) {
|
|
2240
|
+
return listLabel(toRequested(input).names);
|
|
2241
|
+
}
|
|
2242
|
+
function requestedArgv(input) {
|
|
2243
|
+
return toRequested(input).names.join(" ");
|
|
2244
|
+
}
|
|
2245
|
+
function subjectOf(name, input) {
|
|
2246
|
+
const requested = toRequested(input);
|
|
2247
|
+
if (requested.names.includes(name)) {
|
|
2248
|
+
return name;
|
|
2249
|
+
}
|
|
2250
|
+
const root = requested.rootOf.get(name) ?? requested.names[0];
|
|
2251
|
+
return `${name} (required by ${root})`;
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2229
2254
|
// src/lib/applier.ts
|
|
2230
2255
|
var SAFE = /* @__PURE__ */ new Set([
|
|
2231
2256
|
"create",
|
|
@@ -2421,16 +2446,8 @@ async function planModuleFile(module, ref, root, manifest) {
|
|
|
2421
2446
|
};
|
|
2422
2447
|
}
|
|
2423
2448
|
async function buildPlan(args) {
|
|
2424
|
-
const {
|
|
2425
|
-
|
|
2426
|
-
install,
|
|
2427
|
-
alreadyInstalled,
|
|
2428
|
-
modules,
|
|
2429
|
-
config,
|
|
2430
|
-
manifest,
|
|
2431
|
-
requested,
|
|
2432
|
-
select: select2
|
|
2433
|
-
} = args;
|
|
2449
|
+
const { root, install, alreadyInstalled, modules, config, manifest, select: select2 } = args;
|
|
2450
|
+
const requested = args.requested === void 0 ? void 0 : requestedLabel(args.requested);
|
|
2434
2451
|
const testingMode = args.testingMode ?? readTestingMode(config);
|
|
2435
2452
|
const gate = gateFor(manifest, testingMode);
|
|
2436
2453
|
const byTarget = /* @__PURE__ */ new Map();
|
|
@@ -2443,7 +2460,8 @@ async function buildPlan(args) {
|
|
|
2443
2460
|
const devVars = {};
|
|
2444
2461
|
const envServices = {};
|
|
2445
2462
|
const envServicesGuessed = /* @__PURE__ */ new Set();
|
|
2446
|
-
const
|
|
2463
|
+
const envDeclaredBy = /* @__PURE__ */ new Map();
|
|
2464
|
+
const envOptionalBy = /* @__PURE__ */ new Map();
|
|
2447
2465
|
const removeWarnings = {};
|
|
2448
2466
|
const aliases = {};
|
|
2449
2467
|
for (const name of install) {
|
|
@@ -2603,10 +2621,11 @@ async function buildPlan(args) {
|
|
|
2603
2621
|
devVars[key] = value;
|
|
2604
2622
|
}
|
|
2605
2623
|
for (const key of item.envOptional ?? []) {
|
|
2606
|
-
|
|
2624
|
+
envOptionalBy.set(key, (envOptionalBy.get(key) ?? /* @__PURE__ */ new Set()).add(name));
|
|
2607
2625
|
}
|
|
2608
2626
|
for (const [key, value] of Object.entries(item.envVars ?? {})) {
|
|
2609
2627
|
envVars[key] = value;
|
|
2628
|
+
envDeclaredBy.set(key, (envDeclaredBy.get(key) ?? /* @__PURE__ */ new Set()).add(name));
|
|
2610
2629
|
if (!item.envServices) {
|
|
2611
2630
|
envServicesGuessed.add(name);
|
|
2612
2631
|
}
|
|
@@ -2669,7 +2688,12 @@ async function buildPlan(args) {
|
|
|
2669
2688
|
dependencies,
|
|
2670
2689
|
devDependencies,
|
|
2671
2690
|
devVars,
|
|
2672
|
-
|
|
2691
|
+
// A key may stay blank only when every module declaring it in this run says so. kv
|
|
2692
|
+
// calls `KV_KEY_PREFIX` optional and kv-upstash requires it, and `add kv-upstash` on a
|
|
2693
|
+
// fresh project installs both, so a union would mark a required key blank (#249).
|
|
2694
|
+
envOptional: [...envDeclaredBy].filter(
|
|
2695
|
+
([key, declaredBy]) => [...declaredBy].every((module) => envOptionalBy.get(key)?.has(module))
|
|
2696
|
+
).map(([key]) => key).toSorted(),
|
|
2673
2697
|
envServices,
|
|
2674
2698
|
envServicesGuessed: [...envServicesGuessed].toSorted(),
|
|
2675
2699
|
envVars,
|
|
@@ -3120,7 +3144,7 @@ function detectCliMismatches(args) {
|
|
|
3120
3144
|
}
|
|
3121
3145
|
function describe3(mismatch, requested, cliVersion) {
|
|
3122
3146
|
const { declaredBy, range, reason } = mismatch;
|
|
3123
|
-
const subject = declaredBy
|
|
3147
|
+
const subject = subjectOf(declaredBy, requested);
|
|
3124
3148
|
if (reason === "unparseable") {
|
|
3125
3149
|
return `${subject} declares requires.saasaloy "${range}", which isn't a semver range \u2014 the module's author has to fix it.`;
|
|
3126
3150
|
}
|
|
@@ -3130,7 +3154,7 @@ function describe3(mismatch, requested, cliVersion) {
|
|
|
3130
3154
|
return `${subject} needs saasaloy ${range}, and ${cliVersion} is installed. Upgrade with \`${UPGRADE_COMMAND}\`.`;
|
|
3131
3155
|
}
|
|
3132
3156
|
function formatCliMismatches(mismatches, requested, cliVersion) {
|
|
3133
|
-
const heading = `Cannot apply ${requested} \u2014 this CLI is too old for ${mismatches.length > 1 ? "these modules" : "it"}:`;
|
|
3157
|
+
const heading = `Cannot apply ${requestedLabel(requested)} \u2014 this CLI is too old for ${mismatches.length > 1 ? "these modules" : "it"}:`;
|
|
3134
3158
|
return [
|
|
3135
3159
|
heading,
|
|
3136
3160
|
...mismatches.map((m) => ` ${describe3(m, requested, cliVersion)}`),
|
|
@@ -3228,16 +3252,16 @@ var GERUND = {
|
|
|
3228
3252
|
function describe4(conflict, requested, action) {
|
|
3229
3253
|
const { declaredBy, conflictsWith, installed } = conflict;
|
|
3230
3254
|
if (!installed) {
|
|
3231
|
-
const first = declaredBy
|
|
3232
|
-
return `${first} declares a conflict with ${conflictsWith}, and ${GERUND[action]} ${requested} installs both. Add only one of them.`;
|
|
3255
|
+
const first = subjectOf(declaredBy, requested);
|
|
3256
|
+
return `${first} declares a conflict with ${conflictsWith}, and ${GERUND[action]} ${requestedLabel(requested)} installs both. Add only one of them.`;
|
|
3233
3257
|
}
|
|
3234
3258
|
const incoming = installed === declaredBy ? conflictsWith : declaredBy;
|
|
3235
|
-
const phrase = incoming
|
|
3259
|
+
const phrase = subjectOf(incoming, requested);
|
|
3236
3260
|
const sentence = installed === declaredBy ? `${installed} is already installed and declares a conflict with ${phrase}` : `${phrase} declares a conflict with ${installed}, which is already installed`;
|
|
3237
3261
|
return `${sentence}. Run \`saasaloy remove ${installed}\` first.`;
|
|
3238
3262
|
}
|
|
3239
3263
|
function formatConflicts(conflicts, requested, action = "add") {
|
|
3240
|
-
const heading = `Cannot ${action} ${requested} \u2014 module conflict${conflicts.length > 1 ? "s" : ""}:`;
|
|
3264
|
+
const heading = `Cannot ${action} ${requestedLabel(requested)} \u2014 module conflict${conflicts.length > 1 ? "s" : ""}:`;
|
|
3241
3265
|
return [
|
|
3242
3266
|
heading,
|
|
3243
3267
|
...conflicts.map((c) => ` ${describe4(c, requested, action)}`)
|
|
@@ -3300,18 +3324,21 @@ function wrapForNote(text2) {
|
|
|
3300
3324
|
|
|
3301
3325
|
// src/lib/json-output.ts
|
|
3302
3326
|
var JSON_SCHEMA_VERSION = 1;
|
|
3303
|
-
function printJson(document) {
|
|
3327
|
+
function printJson(document, schemaVersion = JSON_SCHEMA_VERSION) {
|
|
3304
3328
|
process.stdout.write(
|
|
3305
|
-
`${JSON.stringify({ schemaVersion
|
|
3329
|
+
`${JSON.stringify({ schemaVersion, ...document }, null, 2)}
|
|
3306
3330
|
`
|
|
3307
3331
|
);
|
|
3308
3332
|
}
|
|
3309
|
-
function createOutput(json) {
|
|
3333
|
+
function createOutput(json, schemaVersion = JSON_SCHEMA_VERSION) {
|
|
3310
3334
|
const tui = json ? TUI_ON_STDERR : {};
|
|
3311
3335
|
const refuse2 = (message, code) => {
|
|
3312
3336
|
cancel(message, tui);
|
|
3313
3337
|
if (json) {
|
|
3314
|
-
printJson(
|
|
3338
|
+
printJson(
|
|
3339
|
+
{ error: { exitCode: code, message: stripAnsi(message) } },
|
|
3340
|
+
schemaVersion
|
|
3341
|
+
);
|
|
3315
3342
|
}
|
|
3316
3343
|
return code;
|
|
3317
3344
|
};
|
|
@@ -3607,11 +3634,20 @@ function createRegistrySource(coord) {
|
|
|
3607
3634
|
coord.ref
|
|
3608
3635
|
);
|
|
3609
3636
|
}
|
|
3637
|
+
var UnknownModuleError = class extends RefusalError {
|
|
3638
|
+
constructor(module, message) {
|
|
3639
|
+
super(message);
|
|
3640
|
+
this.module = module;
|
|
3641
|
+
}
|
|
3642
|
+
module;
|
|
3643
|
+
name = "UnknownModuleError";
|
|
3644
|
+
};
|
|
3610
3645
|
async function loadModuleFolder(dir, name, requiredBy) {
|
|
3611
3646
|
const file = join8(dir, "registry-item.json");
|
|
3612
3647
|
if (!await pathExists(file)) {
|
|
3613
3648
|
const because = requiredBy ? ` (required by ${requiredBy})` : "";
|
|
3614
|
-
throw new
|
|
3649
|
+
throw new UnknownModuleError(
|
|
3650
|
+
name,
|
|
3615
3651
|
`Unknown module "${name}"${because} \u2014 no ${name}/registry-item.json in the registry.`
|
|
3616
3652
|
);
|
|
3617
3653
|
}
|
|
@@ -3709,7 +3745,7 @@ var OFFLINE_HINT = `Set ${REGISTRY_ENV} to a local \`modules/\` checkout to work
|
|
|
3709
3745
|
function authToken() {
|
|
3710
3746
|
return process.env.GITHUB_TOKEN ?? process.env.GIGET_AUTH;
|
|
3711
3747
|
}
|
|
3712
|
-
function
|
|
3748
|
+
function subjectOf2(message) {
|
|
3713
3749
|
return message.split("\n", 1)[0]?.trim() ?? "";
|
|
3714
3750
|
}
|
|
3715
3751
|
var RemoteRegistrySource = class {
|
|
@@ -3801,7 +3837,7 @@ var RemoteRegistrySource = class {
|
|
|
3801
3837
|
`/repos/${this.owner}/${this.repo}/commits?sha=${headSha}&path=${encodeURIComponent(modulePath)}&per_page=100`
|
|
3802
3838
|
);
|
|
3803
3839
|
const touchingShas = new Set(touching.map((c) => c.sha));
|
|
3804
|
-
return (between.commits ?? []).filter((c) => touchingShas.has(c.sha)).map((c) =>
|
|
3840
|
+
return (between.commits ?? []).filter((c) => touchingShas.has(c.sha)).map((c) => subjectOf2(c.commit.message)).filter((subject) => subject.length > 0);
|
|
3805
3841
|
} catch {
|
|
3806
3842
|
return [];
|
|
3807
3843
|
}
|
|
@@ -4096,6 +4132,7 @@ async function writeDeps(root, pkg, added, devAdded = []) {
|
|
|
4096
4132
|
// src/lib/prompts.ts
|
|
4097
4133
|
import {
|
|
4098
4134
|
confirm as clackConfirm,
|
|
4135
|
+
multiselect as clackMultiselect,
|
|
4099
4136
|
select as clackSelect,
|
|
4100
4137
|
text as clackText
|
|
4101
4138
|
} from "@clack/prompts";
|
|
@@ -4121,6 +4158,13 @@ function select(opts) {
|
|
|
4121
4158
|
}
|
|
4122
4159
|
return clackSelect(rest);
|
|
4123
4160
|
}
|
|
4161
|
+
function multiselect(opts) {
|
|
4162
|
+
const { answeredBy, ...rest } = opts;
|
|
4163
|
+
if (!canAsk(rest.output)) {
|
|
4164
|
+
refuse(rest.message, answeredBy);
|
|
4165
|
+
}
|
|
4166
|
+
return clackMultiselect(rest);
|
|
4167
|
+
}
|
|
4124
4168
|
function confirm(opts) {
|
|
4125
4169
|
const { answeredBy, ...rest } = opts;
|
|
4126
4170
|
if (!canAsk(rest.output)) {
|
|
@@ -4176,13 +4220,13 @@ function detectMissingRequirements(args) {
|
|
|
4176
4220
|
}
|
|
4177
4221
|
function describe5(missing, requested) {
|
|
4178
4222
|
const { declaredBy, options } = missing;
|
|
4179
|
-
const subject = declaredBy
|
|
4223
|
+
const subject = subjectOf(declaredBy, requested);
|
|
4180
4224
|
const first = options[0];
|
|
4181
|
-
const suggestion = first ? ` Re-run as \`saasaloy add ${requested} --with ${first}\`, or pick another from that list.` : "";
|
|
4225
|
+
const suggestion = first ? ` Re-run as \`saasaloy add ${requestedArgv(requested)} --with ${first}\`, or pick another from that list.` : "";
|
|
4182
4226
|
return `${subject} needs one of: ${options.join(", ")}, and none is installed.${suggestion}`;
|
|
4183
4227
|
}
|
|
4184
4228
|
function formatMissingRequirements(missing, requested) {
|
|
4185
|
-
const heading = `Cannot add ${requested} \u2014 unmet requirement${missing.length > 1 ? "s" : ""}:`;
|
|
4229
|
+
const heading = `Cannot add ${requestedLabel(requested)} \u2014 unmet requirement${missing.length > 1 ? "s" : ""}:`;
|
|
4186
4230
|
return [heading, ...missing.map((m) => ` ${describe5(m, requested)}`)].join(
|
|
4187
4231
|
"\n"
|
|
4188
4232
|
);
|
|
@@ -4203,17 +4247,22 @@ function formatUpdateRequirements(missing) {
|
|
|
4203
4247
|
function formatUnansweredWith(names, requested) {
|
|
4204
4248
|
const flags = names.map((name) => `--with ${name}`).join(", ");
|
|
4205
4249
|
const verb = names.length === 1 ? "answers" : "answer";
|
|
4206
|
-
return `Cannot add ${requested} \u2014 ${flags} ${verb} no unmet requirement. \`--with\` picks one option of a \`requiresOneOf\` list; add any other module with its own \`saasaloy add\`.`;
|
|
4250
|
+
return `Cannot add ${requestedLabel(requested)} \u2014 ${flags} ${verb} no unmet requirement. \`--with\` picks one option of a \`requiresOneOf\` list; add any other module with its own \`saasaloy add\`.`;
|
|
4207
4251
|
}
|
|
4208
4252
|
|
|
4209
4253
|
// src/lib/resolve.ts
|
|
4210
4254
|
async function resolveGraph(source, requested) {
|
|
4255
|
+
const { modules, order } = await resolveGraphs(source, [requested]);
|
|
4256
|
+
return { modules, order };
|
|
4257
|
+
}
|
|
4258
|
+
async function resolveGraphs(source, roots) {
|
|
4211
4259
|
const modules = /* @__PURE__ */ new Map();
|
|
4212
4260
|
const order = [];
|
|
4261
|
+
const rootOf = /* @__PURE__ */ new Map();
|
|
4213
4262
|
const done = /* @__PURE__ */ new Set();
|
|
4214
4263
|
const onPath = /* @__PURE__ */ new Set();
|
|
4215
4264
|
const stack = [];
|
|
4216
|
-
async function visit(name, requiredBy) {
|
|
4265
|
+
async function visit(name, root, requiredBy) {
|
|
4217
4266
|
if (done.has(name)) {
|
|
4218
4267
|
return;
|
|
4219
4268
|
}
|
|
@@ -4221,20 +4270,42 @@ async function resolveGraph(source, requested) {
|
|
|
4221
4270
|
const cycle = [...stack.slice(stack.indexOf(name)), name].join(" \u2192 ");
|
|
4222
4271
|
throw new Error(`Dependency cycle detected: ${cycle}.`);
|
|
4223
4272
|
}
|
|
4273
|
+
const mod = await source.readModule(name, requiredBy);
|
|
4224
4274
|
onPath.add(name);
|
|
4225
4275
|
stack.push(name);
|
|
4226
|
-
const mod = await source.readModule(name, requiredBy);
|
|
4227
4276
|
modules.set(name, mod);
|
|
4277
|
+
rootOf.set(name, root);
|
|
4228
4278
|
for (const dep of mod.item.dependsOn ?? []) {
|
|
4229
|
-
await visit(dep, name);
|
|
4279
|
+
await visit(dep, root, name);
|
|
4230
4280
|
}
|
|
4231
4281
|
onPath.delete(name);
|
|
4232
4282
|
stack.pop();
|
|
4233
4283
|
done.add(name);
|
|
4234
4284
|
order.push(name);
|
|
4235
4285
|
}
|
|
4236
|
-
|
|
4237
|
-
|
|
4286
|
+
const unknown = [];
|
|
4287
|
+
for (const root of roots) {
|
|
4288
|
+
try {
|
|
4289
|
+
await visit(root, root);
|
|
4290
|
+
} catch (error) {
|
|
4291
|
+
if (error instanceof UnknownModuleError && error.module === root) {
|
|
4292
|
+
unknown.push(error);
|
|
4293
|
+
continue;
|
|
4294
|
+
}
|
|
4295
|
+
throw error;
|
|
4296
|
+
}
|
|
4297
|
+
}
|
|
4298
|
+
const [first] = unknown;
|
|
4299
|
+
if (first && unknown.length === 1) {
|
|
4300
|
+
throw first;
|
|
4301
|
+
}
|
|
4302
|
+
if (unknown.length > 1) {
|
|
4303
|
+
const names = unknown.map((error) => `"${error.module}"`).join(", ");
|
|
4304
|
+
throw new RefusalError(
|
|
4305
|
+
`Unknown modules ${names} \u2014 the registry has no descriptor for any of them. Nothing was written.`
|
|
4306
|
+
);
|
|
4307
|
+
}
|
|
4308
|
+
return { modules, order, rootOf };
|
|
4238
4309
|
}
|
|
4239
4310
|
function mergeGraph(base, extra) {
|
|
4240
4311
|
const modules = new Map(base.modules);
|
|
@@ -4448,7 +4519,7 @@ import { fileURLToPath as fileURLToPath3 } from "url";
|
|
|
4448
4519
|
// package.json
|
|
4449
4520
|
var package_default = {
|
|
4450
4521
|
name: "saasaloy",
|
|
4451
|
-
version: "0.
|
|
4522
|
+
version: "0.8.0",
|
|
4452
4523
|
description: "Composable SaaS accelerator kit.",
|
|
4453
4524
|
keywords: [
|
|
4454
4525
|
"saas",
|
|
@@ -4986,7 +5057,7 @@ var KNOWN_FLAGS2 = /* @__PURE__ */ new Set([
|
|
|
4986
5057
|
"--help",
|
|
4987
5058
|
"-h"
|
|
4988
5059
|
]);
|
|
4989
|
-
var USAGE2 = "saasaloy add [<module
|
|
5060
|
+
var USAGE2 = "saasaloy add [<module>...|<owner/repo[@ref]/module>...|<owner/repo>] [--with <module>]... [--dry-run [--json]] [--diff] [--yes] [--force]";
|
|
4990
5061
|
var HELP2 = {
|
|
4991
5062
|
name: "add",
|
|
4992
5063
|
describe: DESCRIPTIONS.add,
|
|
@@ -4995,7 +5066,7 @@ var HELP2 = {
|
|
|
4995
5066
|
"--dry-run": "show the plan and write nothing",
|
|
4996
5067
|
"--diff": "show a per-file diff and write nothing",
|
|
4997
5068
|
"-y, --yes": "skip the confirmation prompt",
|
|
4998
|
-
"--force": "re-apply
|
|
5069
|
+
"--force": "re-apply the named modules that are already installed",
|
|
4999
5070
|
"--with <module>": "answer a `requiresOneOf` choice, e.g. `--with database-d1` (repeatable)",
|
|
5000
5071
|
"--json": "with --dry-run, print the plan as one JSON document on stdout"
|
|
5001
5072
|
}
|
|
@@ -5027,28 +5098,67 @@ function parseArgs2(argv) {
|
|
|
5027
5098
|
unknown.push(arg);
|
|
5028
5099
|
}
|
|
5029
5100
|
}
|
|
5030
|
-
unknown.push(...positional.slice(1));
|
|
5031
5101
|
return {
|
|
5032
5102
|
diff: argv.includes("--diff"),
|
|
5033
5103
|
dryRun: argv.includes("--dry-run"),
|
|
5034
5104
|
force: argv.includes("--force"),
|
|
5035
5105
|
json: argv.includes("--json"),
|
|
5036
|
-
|
|
5106
|
+
names: positional,
|
|
5037
5107
|
unknown,
|
|
5038
5108
|
with: withModules,
|
|
5039
5109
|
yes: argv.includes("--yes") || argv.includes("-y")
|
|
5040
5110
|
};
|
|
5041
5111
|
}
|
|
5042
|
-
function
|
|
5043
|
-
|
|
5112
|
+
function sourceLabel(coord) {
|
|
5113
|
+
const slug = `${coord.owner ?? DEFAULT_OWNER}/${coord.repo ?? DEFAULT_REPO}`;
|
|
5114
|
+
return coord.ref ? `${slug}@${coord.ref}` : slug;
|
|
5115
|
+
}
|
|
5116
|
+
function requestedModules(inputs) {
|
|
5117
|
+
const coords = inputs.map((input) => parseCoordinate(input));
|
|
5118
|
+
const [first] = coords;
|
|
5119
|
+
if (!first) {
|
|
5120
|
+
return { names: [], source: {} };
|
|
5121
|
+
}
|
|
5122
|
+
if (coords.length === 1) {
|
|
5123
|
+
return { names: first.module ? [first.module] : [], source: first };
|
|
5124
|
+
}
|
|
5125
|
+
const bare = inputs.find((_, i) => !coords[i]?.module);
|
|
5126
|
+
if (bare !== void 0) {
|
|
5127
|
+
throw new RefusalError(
|
|
5128
|
+
`"${bare}" names a registry and no module, and it cannot be mixed with other names \u2014 usage: \`${USAGE2}\`.`
|
|
5129
|
+
);
|
|
5130
|
+
}
|
|
5131
|
+
const firstLabel = sourceLabel(first);
|
|
5132
|
+
const other = coords.findIndex((coord) => sourceLabel(coord) !== firstLabel);
|
|
5133
|
+
const otherCoord = coords[other];
|
|
5134
|
+
if (otherCoord) {
|
|
5135
|
+
throw new RefusalError(
|
|
5136
|
+
`Cannot add modules from two sources in one run \u2014 "${inputs[0]}" reads ${firstLabel} and "${inputs[other]}" reads ${sourceLabel(otherCoord)}. Add them in separate runs.`
|
|
5137
|
+
);
|
|
5138
|
+
}
|
|
5139
|
+
const names = [
|
|
5140
|
+
...new Set(coords.map((coord) => coord.module ?? "").filter(Boolean))
|
|
5141
|
+
];
|
|
5142
|
+
const spelled = coords.find((coord) => coord.owner) ?? first;
|
|
5143
|
+
return { names, source: { ...spelled, module: names[0] } };
|
|
5144
|
+
}
|
|
5145
|
+
function pinToLock(coord, lock, modules = coord.module ? [coord.module] : []) {
|
|
5146
|
+
if (process.env[REGISTRY_ENV] || coord.ref) {
|
|
5044
5147
|
return coord;
|
|
5045
5148
|
}
|
|
5046
5149
|
const slug = `${coord.owner ?? DEFAULT_OWNER}/${coord.repo ?? DEFAULT_REPO}`;
|
|
5047
|
-
const
|
|
5048
|
-
|
|
5049
|
-
return
|
|
5150
|
+
const pins = modules.flatMap((name) => {
|
|
5151
|
+
const pinned = lock.modules[name];
|
|
5152
|
+
return pinned && pinned.source === slug && pinned.resolved !== "local" ? [{ name, sha: pinned.resolved }] : [];
|
|
5153
|
+
});
|
|
5154
|
+
if (new Set(pins.map((pin2) => pin2.sha)).size > 1) {
|
|
5155
|
+
const named = pins.map((pin2) => `${pin2.name} (${pin2.sha.slice(0, 7)})`);
|
|
5156
|
+
throw new RefusalError(
|
|
5157
|
+
`Cannot re-apply ${listLabel(named)} together, they are pinned to different commits. Re-apply them in separate runs, or pass @<ref>.`
|
|
5158
|
+
);
|
|
5050
5159
|
}
|
|
5051
|
-
|
|
5160
|
+
const [pin] = pins;
|
|
5161
|
+
return pin ? { ...coord, ref: pin.sha } : coord;
|
|
5052
5162
|
}
|
|
5053
5163
|
var ACTION_LABEL = {
|
|
5054
5164
|
conflict: pc4.yellow("conflict \u2192 merge"),
|
|
@@ -5057,6 +5167,7 @@ var ACTION_LABEL = {
|
|
|
5057
5167
|
overwrite: pc4.cyan("overwrite"),
|
|
5058
5168
|
unchanged: pc4.dim("unchanged")
|
|
5059
5169
|
};
|
|
5170
|
+
var ADD_JSON_SCHEMA_VERSION = 2;
|
|
5060
5171
|
var MAX_DIFF_LINES = 60;
|
|
5061
5172
|
var MAX_REQUIREMENT_PROMPTS = 8;
|
|
5062
5173
|
var DIFF_LINE_STYLE = {
|
|
@@ -5076,14 +5187,14 @@ function fileLabel(file) {
|
|
|
5076
5187
|
return file.onlyWith === void 0 ? file.target : `${file.target} ${pc4.dim(`(${file.from})`)}`;
|
|
5077
5188
|
}
|
|
5078
5189
|
function summarizePlan(plan, requested, prereqs, tui = {}) {
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
`${pc4.bold(requested)} requires: ${prereqs.map((p) => pc4.cyan(p)).join(", ")}`
|
|
5083
|
-
),
|
|
5084
|
-
"Dependencies",
|
|
5085
|
-
tui
|
|
5190
|
+
const dependencyLines = requested.names.flatMap((root) => {
|
|
5191
|
+
const own = prereqs.filter(
|
|
5192
|
+
(p) => (requested.rootOf.get(p) ?? requested.names[0]) === root
|
|
5086
5193
|
);
|
|
5194
|
+
return own.length === 0 ? [] : [`${pc4.bold(root)} requires: ${own.map((p) => pc4.cyan(p)).join(", ")}`];
|
|
5195
|
+
});
|
|
5196
|
+
if (dependencyLines.length > 0) {
|
|
5197
|
+
note2(wrapForNote(dependencyLines.join("\n")), "Dependencies", tui);
|
|
5087
5198
|
}
|
|
5088
5199
|
const willInstall = plan.install.map((m) => pc4.cyan(m)).join(pc4.dim(" \u2192 "));
|
|
5089
5200
|
const lines = [`will install: ${willInstall}`];
|
|
@@ -5186,7 +5297,7 @@ ${pc4.dim("Symlinked for Claude Code \u2014 the skill files live in `.agents/ski
|
|
|
5186
5297
|
}
|
|
5187
5298
|
function planDocument(requested, prereqs, plan, alreadyInstalled = plan?.alreadyInstalled ?? []) {
|
|
5188
5299
|
return {
|
|
5189
|
-
requested,
|
|
5300
|
+
requested: [...requested],
|
|
5190
5301
|
prerequisites: prereqs,
|
|
5191
5302
|
install: plan?.install ?? [],
|
|
5192
5303
|
alreadyInstalled,
|
|
@@ -5275,10 +5386,10 @@ function formatIncomplete(incomplete, requested) {
|
|
|
5275
5386
|
const names = incomplete.map((name) => pc4.cyan(name)).join(", ");
|
|
5276
5387
|
const verb = incomplete.length === 1 ? "is" : "are";
|
|
5277
5388
|
const object = incomplete.length === 1 ? "it" : "them";
|
|
5278
|
-
return `${names} ${verb} not installed \u2014 files changed while the plan was open. Re-run ${pc4.cyan(`saasaloy add ${requested}`)} to complete ${object}.`;
|
|
5389
|
+
return `${names} ${verb} not installed \u2014 files changed while the plan was open. Re-run ${pc4.cyan(`saasaloy add ${requestedArgv(requested)}`)} to complete ${object}.`;
|
|
5279
5390
|
}
|
|
5280
5391
|
function formatRecovery(requested) {
|
|
5281
|
-
return `Partial apply \u2014 the manifest, config and lock describe what landed. Re-run ${pc4.cyan(`saasaloy add ${requested}`)} to complete it.`;
|
|
5392
|
+
return `Partial apply \u2014 the manifest, config and lock describe what landed. Re-run ${pc4.cyan(`saasaloy add ${requestedArgv(requested)}`)} to complete it.`;
|
|
5282
5393
|
}
|
|
5283
5394
|
async function persistState(input) {
|
|
5284
5395
|
const failures = [];
|
|
@@ -5372,7 +5483,7 @@ async function runAdd(argv) {
|
|
|
5372
5483
|
printCommandHelp(HELP2);
|
|
5373
5484
|
return EXIT_OK;
|
|
5374
5485
|
}
|
|
5375
|
-
const out = createOutput(opts.json);
|
|
5486
|
+
const out = createOutput(opts.json, ADD_JSON_SCHEMA_VERSION);
|
|
5376
5487
|
const { tui } = out;
|
|
5377
5488
|
intro2(pc4.bgCyan(pc4.black(" saasaloy add ")), tui);
|
|
5378
5489
|
if (opts.unknown.length > 0) {
|
|
@@ -5388,12 +5499,13 @@ async function runAdd(argv) {
|
|
|
5388
5499
|
);
|
|
5389
5500
|
}
|
|
5390
5501
|
let coord;
|
|
5502
|
+
let names;
|
|
5391
5503
|
try {
|
|
5392
|
-
coord =
|
|
5504
|
+
({ names, source: coord } = requestedModules(opts.names));
|
|
5393
5505
|
} catch (error) {
|
|
5394
5506
|
return out.fail(error);
|
|
5395
5507
|
}
|
|
5396
|
-
const cannotConfirm =
|
|
5508
|
+
const cannotConfirm = names.length > 0 && !opts.yes && !opts.dryRun && !opts.diff && !process.stdin.isTTY;
|
|
5397
5509
|
let root;
|
|
5398
5510
|
let config;
|
|
5399
5511
|
try {
|
|
@@ -5408,7 +5520,11 @@ async function runAdd(argv) {
|
|
|
5408
5520
|
let partial;
|
|
5409
5521
|
try {
|
|
5410
5522
|
const lock = await loadLock(root);
|
|
5411
|
-
coord = pinToLock(
|
|
5523
|
+
coord = pinToLock(
|
|
5524
|
+
coord,
|
|
5525
|
+
lock,
|
|
5526
|
+
names.length === 1 ? names : names.filter((n) => opts.force && config.installed.includes(n))
|
|
5527
|
+
);
|
|
5412
5528
|
source = createRegistrySource(coord);
|
|
5413
5529
|
if (process.env[REGISTRY_ENV] && (coord.owner || coord.repo)) {
|
|
5414
5530
|
log4.warn(
|
|
@@ -5416,8 +5532,7 @@ async function runAdd(argv) {
|
|
|
5416
5532
|
tui
|
|
5417
5533
|
);
|
|
5418
5534
|
}
|
|
5419
|
-
|
|
5420
|
-
if (!requested) {
|
|
5535
|
+
if (names.length === 0) {
|
|
5421
5536
|
if (!isInteractive() || opts.json) {
|
|
5422
5537
|
return out.refuse(
|
|
5423
5538
|
`No module named and no terminal to pick one in \u2014 usage: \`${USAGE2}\`.`,
|
|
@@ -5439,18 +5554,32 @@ async function runAdd(argv) {
|
|
|
5439
5554
|
outro2(pc4.dim("use `saasaloy add <module> --force` to re-apply one"));
|
|
5440
5555
|
return EXIT_OK;
|
|
5441
5556
|
}
|
|
5442
|
-
const picked = await
|
|
5443
|
-
answeredBy: "
|
|
5444
|
-
message: `Pick
|
|
5445
|
-
options: available.map((n) => ({ label: n, value: n }))
|
|
5557
|
+
const picked = await multiselect({
|
|
5558
|
+
answeredBy: "one or more module names",
|
|
5559
|
+
message: `Pick modules to add ${pc4.dim(`(from ${source.label}, ${installed.size} already installed)`)}`,
|
|
5560
|
+
options: available.map((n) => ({ label: n, value: n })),
|
|
5561
|
+
required: true
|
|
5446
5562
|
});
|
|
5447
5563
|
if (isCancel(picked)) {
|
|
5448
5564
|
cancel3("add cancelled");
|
|
5449
5565
|
return EXIT_FAILURE;
|
|
5450
5566
|
}
|
|
5451
|
-
|
|
5452
|
-
}
|
|
5453
|
-
|
|
5567
|
+
names = picked;
|
|
5568
|
+
}
|
|
5569
|
+
const rooted = await resolveGraphs(source, names);
|
|
5570
|
+
let graph = rooted;
|
|
5571
|
+
const requested = { names, rootOf: rooted.rootOf };
|
|
5572
|
+
const registry = source;
|
|
5573
|
+
const mergePicked = async (name, declaredBy) => {
|
|
5574
|
+
const picked = await resolveGraph(registry, name);
|
|
5575
|
+
const owner = rooted.rootOf.get(declaredBy) ?? names[0] ?? name;
|
|
5576
|
+
for (const module of picked.order) {
|
|
5577
|
+
if (!rooted.rootOf.has(module)) {
|
|
5578
|
+
rooted.rootOf.set(module, owner);
|
|
5579
|
+
}
|
|
5580
|
+
}
|
|
5581
|
+
graph = mergeGraph(graph, picked);
|
|
5582
|
+
};
|
|
5454
5583
|
const cliVersion = await readVersion();
|
|
5455
5584
|
const cliCheckFails = () => {
|
|
5456
5585
|
const mismatches = detectCliMismatches({ cliVersion, graph });
|
|
@@ -5471,10 +5600,13 @@ async function runAdd(argv) {
|
|
|
5471
5600
|
for (let progressed = true; pending.size > 0 && progressed; ) {
|
|
5472
5601
|
progressed = false;
|
|
5473
5602
|
for (const name of pending) {
|
|
5474
|
-
|
|
5603
|
+
const answered = unmet.find(
|
|
5604
|
+
(requirement) => requirement.options.includes(name)
|
|
5605
|
+
);
|
|
5606
|
+
if (!answered) {
|
|
5475
5607
|
continue;
|
|
5476
5608
|
}
|
|
5477
|
-
|
|
5609
|
+
await mergePicked(name, answered.declaredBy);
|
|
5478
5610
|
pending.delete(name);
|
|
5479
5611
|
unmet = detectMissingRequirements({ config, graph });
|
|
5480
5612
|
progressed = true;
|
|
@@ -5506,7 +5638,7 @@ async function runAdd(argv) {
|
|
|
5506
5638
|
cancel3("add cancelled");
|
|
5507
5639
|
return EXIT_FAILURE;
|
|
5508
5640
|
}
|
|
5509
|
-
|
|
5641
|
+
await mergePicked(picked, requirement.declaredBy);
|
|
5510
5642
|
unmet = detectMissingRequirements({ config, graph });
|
|
5511
5643
|
}
|
|
5512
5644
|
if (unmet.length > 0) {
|
|
@@ -5524,7 +5656,7 @@ async function runAdd(argv) {
|
|
|
5524
5656
|
if (cliCheckFails()) {
|
|
5525
5657
|
return EXIT_REFUSED;
|
|
5526
5658
|
}
|
|
5527
|
-
prereqs = graph.order.filter((n) => n
|
|
5659
|
+
prereqs = graph.order.filter((n) => !names.includes(n));
|
|
5528
5660
|
const manifest = await loadManifest(root);
|
|
5529
5661
|
const conflicts = detectConflicts({ graph, config, lock });
|
|
5530
5662
|
if (conflicts.missingLockEntries.length > 0) {
|
|
@@ -5540,7 +5672,7 @@ async function runAdd(argv) {
|
|
|
5540
5672
|
);
|
|
5541
5673
|
}
|
|
5542
5674
|
const install = graph.order.filter(
|
|
5543
|
-
(n) => !config.installed.includes(n) || opts.force && n
|
|
5675
|
+
(n) => !config.installed.includes(n) || opts.force && names.includes(n)
|
|
5544
5676
|
);
|
|
5545
5677
|
const alreadyInstalled = graph.order.filter(
|
|
5546
5678
|
(n) => config.installed.includes(n) && !install.includes(n)
|
|
@@ -5548,11 +5680,12 @@ async function runAdd(argv) {
|
|
|
5548
5680
|
if (install.length === 0) {
|
|
5549
5681
|
if (opts.json) {
|
|
5550
5682
|
printJson(
|
|
5551
|
-
planDocument(
|
|
5683
|
+
planDocument(names, prereqs, void 0, alreadyInstalled),
|
|
5684
|
+
ADD_JSON_SCHEMA_VERSION
|
|
5552
5685
|
);
|
|
5553
5686
|
}
|
|
5554
5687
|
note2(
|
|
5555
|
-
`${pc4.cyan(
|
|
5688
|
+
`${listLabel(names.map((n) => pc4.cyan(n)))} and ${names.length === 1 ? "its" : "their"} dependencies are already installed.`,
|
|
5556
5689
|
"Nothing to do",
|
|
5557
5690
|
tui
|
|
5558
5691
|
);
|
|
@@ -5570,6 +5703,16 @@ async function runAdd(argv) {
|
|
|
5570
5703
|
root,
|
|
5571
5704
|
...enabler === void 0 ? {} : { testingMode: ENABLED_MODE }
|
|
5572
5705
|
});
|
|
5706
|
+
if (names.length > 1) {
|
|
5707
|
+
for (const name of names) {
|
|
5708
|
+
if (config.installed.includes(name) && !install.includes(name)) {
|
|
5709
|
+
log4.info(
|
|
5710
|
+
`${pc4.cyan(name)} is already installed \u2014 skipped ${pc4.dim("(pass --force to re-apply it)")}.`,
|
|
5711
|
+
tui
|
|
5712
|
+
);
|
|
5713
|
+
}
|
|
5714
|
+
}
|
|
5715
|
+
}
|
|
5573
5716
|
summarizePlan(plan, requested, prereqs, tui);
|
|
5574
5717
|
if (enabler !== void 0 && (opts.dryRun || opts.diff)) {
|
|
5575
5718
|
log4.info(
|
|
@@ -5602,7 +5745,7 @@ async function runAdd(argv) {
|
|
|
5602
5745
|
}
|
|
5603
5746
|
if (opts.dryRun || opts.diff) {
|
|
5604
5747
|
if (opts.json) {
|
|
5605
|
-
printJson(planDocument(
|
|
5748
|
+
printJson(planDocument(names, prereqs, plan), ADD_JSON_SCHEMA_VERSION);
|
|
5606
5749
|
}
|
|
5607
5750
|
outro2(
|
|
5608
5751
|
pc4.dim(
|