express-file-cluster 0.9.0 → 0.9.2
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/dist/auth/index.cjs +8 -2
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +13 -2
- package/dist/auth/index.d.ts +13 -2
- package/dist/auth/index.js +9 -3
- package/dist/{chunk-2J3HHQKP.cjs → chunk-ANUSWEAP.cjs} +55 -2
- package/dist/chunk-ANUSWEAP.cjs.map +1 -0
- package/dist/{chunk-RSZB7VAO.js → chunk-ATL4GYFU.js} +54 -1
- package/dist/chunk-ATL4GYFU.js.map +1 -0
- package/dist/{chunk-2PBMLMO4.js → chunk-QKQZF573.js} +26 -4
- package/dist/chunk-QKQZF573.js.map +1 -0
- package/dist/{chunk-6QNLN6AI.js → chunk-RRQ2RK5M.js} +353 -3
- package/dist/chunk-RRQ2RK5M.js.map +1 -0
- package/dist/{chunk-RGTENTDN.cjs → chunk-RTF7PHS2.cjs} +432 -82
- package/dist/chunk-RTF7PHS2.cjs.map +1 -0
- package/dist/{chunk-66R7S7J3.cjs → chunk-X2US4RAM.cjs} +26 -4
- package/dist/chunk-X2US4RAM.cjs.map +1 -0
- package/dist/cli/db-runner.cjs +17 -17
- package/dist/cli/db-runner.js +2 -2
- package/dist/cli/index.cjs +315 -26
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +295 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/docs/api-reference/auth.md +35 -0
- package/dist/docs/api-reference/collection.md +155 -0
- package/dist/docs/cli/add.md +36 -7
- package/dist/docs/guides/authentication.md +80 -4
- package/dist/docs/guides/coming-from-mongoose.md +60 -0
- package/dist/docs/guides/which-api.md +21 -12
- package/dist/docs/index.md +4 -2
- package/dist/docs/skills/SKILL.md +3 -3
- package/dist/docs/skills/api-surface.md +16 -0
- package/dist/docs/skills/what-not-to-invent.md +3 -2
- package/dist/index.cjs +18 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +193 -3
- package/dist/index.d.ts +193 -3
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/registry/index.json +1 -1
- package/dist/registry/js-mongo/admin-users.json +1 -1
- package/dist/registry/js-mongo/auth.json +1 -1
- package/dist/registry/js-mongo/auth@apple.json +1 -1
- package/dist/registry/js-mongo/auth@google.json +1 -1
- package/dist/registry/js-mongo/email-client.json +1 -1
- package/dist/registry/js-mongo/forgot-password.json +1 -1
- package/dist/registry/js-pg-model/admin-users.json +1 -1
- package/dist/registry/js-pg-model/auth.json +1 -1
- package/dist/registry/js-pg-model/auth@apple.json +1 -1
- package/dist/registry/js-pg-model/auth@google.json +1 -1
- package/dist/registry/js-pg-model/email-client.json +1 -1
- package/dist/registry/js-pg-model/forgot-password.json +1 -1
- package/dist/registry/js-pg-table/admin-users.json +1 -1
- package/dist/registry/js-pg-table/auth.json +1 -1
- package/dist/registry/js-pg-table/auth@apple.json +1 -1
- package/dist/registry/js-pg-table/auth@google.json +1 -1
- package/dist/registry/js-pg-table/email-client.json +1 -1
- package/dist/registry/js-pg-table/forgot-password.json +1 -1
- package/dist/registry/ts-mongo/admin-users.json +1 -1
- package/dist/registry/ts-mongo/auth.json +1 -1
- package/dist/registry/ts-mongo/auth@apple.json +1 -1
- package/dist/registry/ts-mongo/auth@google.json +1 -1
- package/dist/registry/ts-mongo/email-client.json +1 -1
- package/dist/registry/ts-mongo/forgot-password.json +1 -1
- package/dist/registry/ts-pg-model/admin-users.json +1 -1
- package/dist/registry/ts-pg-model/auth.json +1 -1
- package/dist/registry/ts-pg-model/auth@apple.json +1 -1
- package/dist/registry/ts-pg-model/auth@google.json +1 -1
- package/dist/registry/ts-pg-model/email-client.json +1 -1
- package/dist/registry/ts-pg-model/forgot-password.json +1 -1
- package/dist/registry/ts-pg-table/admin-users.json +1 -1
- package/dist/registry/ts-pg-table/auth.json +1 -1
- package/dist/registry/ts-pg-table/auth@apple.json +1 -1
- package/dist/registry/ts-pg-table/auth@google.json +1 -1
- package/dist/registry/ts-pg-table/email-client.json +1 -1
- package/dist/registry/ts-pg-table/forgot-password.json +1 -1
- package/dist/tasks/index.d.cts +1 -1
- package/dist/tasks/index.d.ts +1 -1
- package/dist/{types-gyvA7BtO.d.ts → types-BY-ObnZH.d.cts} +36 -7
- package/dist/{types-gyvA7BtO.d.cts → types-BY-ObnZH.d.ts} +36 -7
- package/package.json +3 -3
- package/dist/chunk-2J3HHQKP.cjs.map +0 -1
- package/dist/chunk-2PBMLMO4.js.map +0 -1
- package/dist/chunk-66R7S7J3.cjs.map +0 -1
- package/dist/chunk-6QNLN6AI.js.map +0 -1
- package/dist/chunk-RGTENTDN.cjs.map +0 -1
- package/dist/chunk-RSZB7VAO.js.map +0 -1
package/dist/cli/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "../chunk-BBSZLGZW.js";
|
|
11
11
|
import {
|
|
12
12
|
tableNameFor
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-QKQZF573.js";
|
|
14
14
|
import "../chunk-HXV543HZ.js";
|
|
15
15
|
import "../chunk-LJNSJFOL.js";
|
|
16
16
|
import "../chunk-HBYSKULC.js";
|
|
@@ -879,6 +879,9 @@ var Registry = class {
|
|
|
879
879
|
}
|
|
880
880
|
dir;
|
|
881
881
|
index;
|
|
882
|
+
has(name) {
|
|
883
|
+
return this.index.items.some((i) => i.name === name || i.aliases?.includes(name));
|
|
884
|
+
}
|
|
882
885
|
meta(name) {
|
|
883
886
|
const item = this.index.items.find((i) => i.name === name || i.aliases?.includes(name));
|
|
884
887
|
if (!item) {
|
|
@@ -1264,6 +1267,200 @@ function lineDiff(a, b) {
|
|
|
1264
1267
|
});
|
|
1265
1268
|
return shown;
|
|
1266
1269
|
}
|
|
1270
|
+
var RESERVED_ENTITIES = /* @__PURE__ */ new Set(["user", "admin"]);
|
|
1271
|
+
function toPascal(s) {
|
|
1272
|
+
const parts = s.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").trim().split(/\s+/);
|
|
1273
|
+
return parts.map((p) => p.charAt(0).toUpperCase() + p.slice(1).toLowerCase()).join("");
|
|
1274
|
+
}
|
|
1275
|
+
function toCamel(s) {
|
|
1276
|
+
const p = toPascal(s);
|
|
1277
|
+
return p.charAt(0).toLowerCase() + p.slice(1);
|
|
1278
|
+
}
|
|
1279
|
+
function toSlug(s) {
|
|
1280
|
+
return s.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[-_\s]+/g, "-").toLowerCase();
|
|
1281
|
+
}
|
|
1282
|
+
function validateEntityName(name) {
|
|
1283
|
+
const raw = name.trim();
|
|
1284
|
+
if (!raw) return { error: "Entity name cannot be empty" };
|
|
1285
|
+
if (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(raw))
|
|
1286
|
+
return { error: `Entity name must be alphanumeric and start with a letter: "${raw}"` };
|
|
1287
|
+
const pascal = toPascal(raw);
|
|
1288
|
+
const camel = toCamel(raw);
|
|
1289
|
+
const slug = toSlug(raw);
|
|
1290
|
+
if (RESERVED_ENTITIES.has(slug) || RESERVED_ENTITIES.has(pascal.toLowerCase()))
|
|
1291
|
+
return { error: `"${pascal}" is a built-in entity \u2014 use \`efc add auth\` for User/Admin` };
|
|
1292
|
+
return { pascal, camel, slug };
|
|
1293
|
+
}
|
|
1294
|
+
function entityUsesTables(cfg) {
|
|
1295
|
+
return cfg.database === "postgresql" && cfg.modelApi === "defineTable";
|
|
1296
|
+
}
|
|
1297
|
+
function entityOrm(cfg) {
|
|
1298
|
+
const t = entityUsesTables(cfg);
|
|
1299
|
+
return {
|
|
1300
|
+
findOne: (model, filter) => t ? `${model}.findFirst({ where: ${filter} })` : `${model}.findOne(${filter})`,
|
|
1301
|
+
create: (model, data) => t ? `${model}.create({ data: ${data} })` : `${model}.create(${data})`
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
function entityModelContent(pascal, slug, cfg) {
|
|
1305
|
+
const api = entityUsesTables(cfg) ? "defineTable" : "defineModel";
|
|
1306
|
+
return `import { ${api} } from 'express-file-cluster';
|
|
1307
|
+
|
|
1308
|
+
export const ${pascal} = ${api}('${pascal}', {
|
|
1309
|
+
name: { type: 'string', required: true },
|
|
1310
|
+
email: { type: 'string', required: true, unique: true },
|
|
1311
|
+
password: { type: 'string', required: true },
|
|
1312
|
+
role: { type: 'string', required: true, default: '${slug}' },
|
|
1313
|
+
avatar: { type: 'string' },
|
|
1314
|
+
isVerified: { type: 'boolean', default: false },
|
|
1315
|
+
isActive: { type: 'boolean', default: true },
|
|
1316
|
+
verifyToken: { type: 'string' },
|
|
1317
|
+
resetToken: { type: 'string' },
|
|
1318
|
+
resetTokenExpiry: { type: 'date' },
|
|
1319
|
+
refreshToken: { type: 'string' },
|
|
1320
|
+
refreshTokenExpiry: { type: 'date' },
|
|
1321
|
+
});
|
|
1322
|
+
`;
|
|
1323
|
+
}
|
|
1324
|
+
function entityRegisterContent(pascal, camel, cfg) {
|
|
1325
|
+
const ts = cfg.language === "typescript";
|
|
1326
|
+
const db = entityOrm(cfg);
|
|
1327
|
+
const typedArgs = ts ? "(req: Request, res: Response)" : "(req, res)";
|
|
1328
|
+
const typeImport = ts ? "import type { Request, Response } from 'express';\n" : "";
|
|
1329
|
+
return `${typeImport}import { hashPassword } from 'express-file-cluster/auth';
|
|
1330
|
+
import { ${pascal} } from '../../../model/${pascal}.js';
|
|
1331
|
+
|
|
1332
|
+
export const POST = async ${typedArgs} => {
|
|
1333
|
+
const { name, email, password } = req.body;
|
|
1334
|
+
if (!name || !email || !password) {
|
|
1335
|
+
return res.status(400).json({ error: 'name, email and password are required' });
|
|
1336
|
+
}
|
|
1337
|
+
const existing = await ${db.findOne(pascal, "{ email }")};
|
|
1338
|
+
if (existing) return res.status(409).json({ error: 'Email already in use' });
|
|
1339
|
+
const hashed = await hashPassword(password);
|
|
1340
|
+
const record = await ${db.create(pascal, "{ name, email, password: hashed }")};
|
|
1341
|
+
const { password: _, ...safe } = record;
|
|
1342
|
+
res.status(201).json({ message: '${pascal} account created', ${camel}: safe });
|
|
1343
|
+
};
|
|
1344
|
+
`;
|
|
1345
|
+
}
|
|
1346
|
+
function entityLoginContent(pascal, slug, cfg) {
|
|
1347
|
+
const ts = cfg.language === "typescript";
|
|
1348
|
+
const db = entityOrm(cfg);
|
|
1349
|
+
const typedArgs = ts ? "(req: Request, res: Response)" : "(req, res)";
|
|
1350
|
+
const typeImport = ts ? "import type { Request, Response } from 'express';\n" : "";
|
|
1351
|
+
return `${typeImport}import { issueToken, verifyPassword } from 'express-file-cluster/auth';
|
|
1352
|
+
import { ${pascal} } from '../../../model/${pascal}.js';
|
|
1353
|
+
|
|
1354
|
+
export const POST = async ${typedArgs} => {
|
|
1355
|
+
const { email, password } = req.body;
|
|
1356
|
+
if (!email || !password) return res.status(400).json({ error: 'email and password are required' });
|
|
1357
|
+
|
|
1358
|
+
const record = await ${db.findOne(pascal, "{ email }")};
|
|
1359
|
+
if (!record) return res.status(401).json({ error: 'Invalid credentials' });
|
|
1360
|
+
const match = await verifyPassword(password, record.password);
|
|
1361
|
+
if (!match) return res.status(401).json({ error: 'Invalid credentials' });
|
|
1362
|
+
if (!record.isActive) return res.status(403).json({ error: 'Account suspended' });
|
|
1363
|
+
await issueToken(res, { id: record.id, role: record.role, email: record.email });
|
|
1364
|
+
res.json({ message: 'Logged in as ${slug}' });
|
|
1365
|
+
};
|
|
1366
|
+
`;
|
|
1367
|
+
}
|
|
1368
|
+
function entityLogoutContent(cfg) {
|
|
1369
|
+
const ts = cfg.language === "typescript";
|
|
1370
|
+
const typedArgs = ts ? "(req: Request, res: Response)" : "(req, res)";
|
|
1371
|
+
const typeImport = ts ? "import type { Request, Response } from 'express';\n" : "";
|
|
1372
|
+
return `${typeImport}import { requireAuth, revokeSession } from 'express-file-cluster/auth';
|
|
1373
|
+
|
|
1374
|
+
export const middlewares = [requireAuth];
|
|
1375
|
+
|
|
1376
|
+
export const POST = async ${typedArgs} => {
|
|
1377
|
+
try {
|
|
1378
|
+
await revokeSession(req, res);
|
|
1379
|
+
} catch {
|
|
1380
|
+
res.clearCookie('efc_token');
|
|
1381
|
+
}
|
|
1382
|
+
res.json({ message: 'Logged out successfully' });
|
|
1383
|
+
};
|
|
1384
|
+
`;
|
|
1385
|
+
}
|
|
1386
|
+
function entityMeContent(slug, cfg) {
|
|
1387
|
+
const ts = cfg.language === "typescript";
|
|
1388
|
+
const typedArgs = ts ? "(req: Request, res: Response)" : "(req, res)";
|
|
1389
|
+
const typeImport = ts ? "import type { Request, Response } from 'express';\n" : "";
|
|
1390
|
+
return `${typeImport}import { requireAuth } from 'express-file-cluster/auth';
|
|
1391
|
+
|
|
1392
|
+
export const middlewares = [requireAuth('${slug}')];
|
|
1393
|
+
|
|
1394
|
+
export const GET = async ${typedArgs} => {
|
|
1395
|
+
res.json((req${ts ? " as any" : ""}).user);
|
|
1396
|
+
};
|
|
1397
|
+
`;
|
|
1398
|
+
}
|
|
1399
|
+
function generateEntityAuth(cwd, entityName, cfg, options) {
|
|
1400
|
+
const validated = validateEntityName(entityName);
|
|
1401
|
+
if ("error" in validated) throw new Error(`[EFC] ${validated.error}`);
|
|
1402
|
+
const { pascal, camel, slug } = validated;
|
|
1403
|
+
const ext = cfg.language === "typescript" ? "ts" : "js";
|
|
1404
|
+
const result = { written: [], manual: [], conflicts: [] };
|
|
1405
|
+
const files = [
|
|
1406
|
+
{ rel: `src/model/${pascal}.${ext}`, content: entityModelContent(pascal, slug, cfg) },
|
|
1407
|
+
{
|
|
1408
|
+
rel: `src/api/auth/${slug}/register.${ext}`,
|
|
1409
|
+
content: entityRegisterContent(pascal, camel, cfg)
|
|
1410
|
+
},
|
|
1411
|
+
{
|
|
1412
|
+
rel: `src/api/auth/${slug}/login.${ext}`,
|
|
1413
|
+
content: entityLoginContent(pascal, slug, cfg)
|
|
1414
|
+
},
|
|
1415
|
+
{
|
|
1416
|
+
rel: `src/api/auth/${slug}/logout.${ext}`,
|
|
1417
|
+
content: entityLogoutContent(cfg)
|
|
1418
|
+
},
|
|
1419
|
+
{
|
|
1420
|
+
rel: `src/api/auth/${slug}/me.${ext}`,
|
|
1421
|
+
content: entityMeContent(slug, cfg)
|
|
1422
|
+
}
|
|
1423
|
+
];
|
|
1424
|
+
for (const f of files) {
|
|
1425
|
+
const abs = path7.join(cwd, f.rel);
|
|
1426
|
+
const exists = fs7.existsSync(abs);
|
|
1427
|
+
if (exists && !options?.overwrite) {
|
|
1428
|
+
result.conflicts.push(f.rel);
|
|
1429
|
+
result.manual.push(`${f.rel} already exists \u2014 skipped (pass --overwrite to replace)`);
|
|
1430
|
+
continue;
|
|
1431
|
+
}
|
|
1432
|
+
result.written.push(f.rel);
|
|
1433
|
+
if (!options?.dryRun) {
|
|
1434
|
+
fs7.mkdirSync(path7.dirname(abs), { recursive: true });
|
|
1435
|
+
fs7.writeFileSync(abs, f.content);
|
|
1436
|
+
cfg.files[f.rel] = sha256(f.content);
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
if (entityUsesTables(cfg) && !options?.dryRun) {
|
|
1440
|
+
result.manual.push(...registerModels(cwd, cfg.language, [pascal]));
|
|
1441
|
+
}
|
|
1442
|
+
const envFile = path7.join(cwd, ".env");
|
|
1443
|
+
if (fs7.existsSync(envFile)) {
|
|
1444
|
+
const envKeys = readEnvKeys(envFile);
|
|
1445
|
+
if (!envKeys.includes("JWT_SECRET")) {
|
|
1446
|
+
const secret = crypto.randomBytes(64).toString("hex");
|
|
1447
|
+
if (!options?.dryRun) {
|
|
1448
|
+
appendEnv(envFile, [`JWT_SECRET=${secret}`]);
|
|
1449
|
+
const exampleFile = path7.join(cwd, ".env.example");
|
|
1450
|
+
if (fs7.existsSync(exampleFile) && !readEnvKeys(exampleFile).includes("JWT_SECRET")) {
|
|
1451
|
+
appendEnv(exampleFile, ["JWT_SECRET=<generate with: openssl rand -hex 64>"]);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
result.manual.push("Added JWT_SECRET to .env");
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
const itemName = `auth:${slug}`;
|
|
1458
|
+
if (!cfg.items.includes(itemName)) cfg.items.push(itemName);
|
|
1459
|
+
if (!options?.dryRun) {
|
|
1460
|
+
writeEfcJson(cwd, cfg);
|
|
1461
|
+
}
|
|
1462
|
+
return result;
|
|
1463
|
+
}
|
|
1267
1464
|
|
|
1268
1465
|
// src/cli/commands/registry.ts
|
|
1269
1466
|
function registryCommands() {
|
|
@@ -1442,16 +1639,85 @@ function packageManager(cwd) {
|
|
|
1442
1639
|
}
|
|
1443
1640
|
function addCommand() {
|
|
1444
1641
|
return new Command8("add").description("Add features to the app from the registry (copies their source into src/)").argument(
|
|
1445
|
-
"
|
|
1446
|
-
"registry items
|
|
1447
|
-
).option("-y, --yes", "skip the confirmation").option("--overwrite", "replace files that were changed in this app").option("--dry-run", "show what would change without writing anything").option("--no-install", "don't run the package manager afterwards").option("--no-prompt", "don't ask for credentials \u2014 write placeholders to .env instead").action(
|
|
1642
|
+
"[items...]",
|
|
1643
|
+
"registry items (auth forgot-password admin-users) or custom auth entities (auth:merchant, auth --entity merchant)"
|
|
1644
|
+
).option("-y, --yes", "skip the confirmation").option("--overwrite", "replace files that were changed in this app").option("--dry-run", "show what would change without writing anything").option("--no-install", "don't run the package manager afterwards").option("--no-prompt", "don't ask for credentials \u2014 write placeholders to .env instead").option("--entity <name>", "scaffold a custom auth entity (model + auth routes)").action(
|
|
1448
1645
|
async (names, opts) => {
|
|
1449
1646
|
try {
|
|
1647
|
+
const rawNames = names ?? [];
|
|
1648
|
+
const entityNames = [];
|
|
1649
|
+
const registryNames = [];
|
|
1650
|
+
let i = 0;
|
|
1651
|
+
if (rawNames[0] === "auth" && rawNames[1] === "new" && rawNames.length >= 3) {
|
|
1652
|
+
for (let j = 2; j < rawNames.length; j++) {
|
|
1653
|
+
entityNames.push(rawNames[j]);
|
|
1654
|
+
}
|
|
1655
|
+
i = rawNames.length;
|
|
1656
|
+
}
|
|
1657
|
+
for (; i < rawNames.length; i++) {
|
|
1658
|
+
const n = rawNames[i];
|
|
1659
|
+
const colonMatch = /^auth:([A-Za-z][A-Za-z0-9_-]*)$/.exec(n);
|
|
1660
|
+
if (colonMatch) {
|
|
1661
|
+
entityNames.push(colonMatch[1]);
|
|
1662
|
+
} else if (opts.entity && n === "auth") {
|
|
1663
|
+
continue;
|
|
1664
|
+
} else {
|
|
1665
|
+
registryNames.push(n);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
if (opts.entity && !entityNames.includes(opts.entity)) {
|
|
1669
|
+
entityNames.push(opts.entity);
|
|
1670
|
+
}
|
|
1671
|
+
if (entityNames.length === 0 && registryNames.length === 0) {
|
|
1672
|
+
fail(
|
|
1673
|
+
"Specify at least one item or entity to add \u2014 e.g. `efc add auth` or `efc add auth:merchant`. Run `efc list` to see available features."
|
|
1674
|
+
);
|
|
1675
|
+
}
|
|
1676
|
+
if (entityNames.length > 0) {
|
|
1677
|
+
const { cwd: cwd2, cfg: cfg2, detected: detected2 } = load();
|
|
1678
|
+
if (detected2) {
|
|
1679
|
+
console.log(
|
|
1680
|
+
pc8.dim(`
|
|
1681
|
+
No ${EFC_JSON} yet \u2014 detected ${describe(cfg2)}; it'll be created.`)
|
|
1682
|
+
);
|
|
1683
|
+
}
|
|
1684
|
+
for (const eName of entityNames) {
|
|
1685
|
+
const validated = validateEntityName(eName);
|
|
1686
|
+
if ("error" in validated) fail(validated.error);
|
|
1687
|
+
const { pascal, slug } = validated;
|
|
1688
|
+
console.log(pc8.bold(`
|
|
1689
|
+
Adding auth entity: ${pascal}
|
|
1690
|
+
`));
|
|
1691
|
+
const result2 = generateEntityAuth(cwd2, eName, cfg2, {
|
|
1692
|
+
dryRun: opts.dryRun,
|
|
1693
|
+
overwrite: opts.overwrite
|
|
1694
|
+
});
|
|
1695
|
+
if (result2.written.length) {
|
|
1696
|
+
for (const f of result2.written) console.log(` ${pc8.green("create ")} ${f}`);
|
|
1697
|
+
const actionVerb = opts.dryRun ? "would be written (dry run)" : "written";
|
|
1698
|
+
console.log(pc8.green(`
|
|
1699
|
+
\u2713 ${result2.written.length} file(s) ${actionVerb}`));
|
|
1700
|
+
}
|
|
1701
|
+
for (const m of result2.manual) console.log(pc8.yellow(` ! ${m}`));
|
|
1702
|
+
console.log(
|
|
1703
|
+
pc8.dim(
|
|
1704
|
+
`
|
|
1705
|
+
Routes: POST /auth/${slug}/register, /login, /logout; GET /me`
|
|
1706
|
+
)
|
|
1707
|
+
);
|
|
1708
|
+
console.log(
|
|
1709
|
+
pc8.dim(` Protect routes with: requireAuth('${slug}')`)
|
|
1710
|
+
);
|
|
1711
|
+
}
|
|
1712
|
+
console.log();
|
|
1713
|
+
if (registryNames.length === 0) return;
|
|
1714
|
+
}
|
|
1450
1715
|
const { cwd, registry, cfg, detected } = load();
|
|
1451
|
-
const
|
|
1716
|
+
const itemsToAdd = registryNames;
|
|
1717
|
+
const plan = planAdd(cwd, registry, itemsToAdd, { overwrite: !!opts.overwrite }, cfg);
|
|
1452
1718
|
if (plan.problems.length) fail(plan.problems.join("\n"));
|
|
1453
1719
|
if (plan.items.length === 0) {
|
|
1454
|
-
console.log(pc8.dim(`Already installed: ${
|
|
1720
|
+
console.log(pc8.dim(`Already installed: ${itemsToAdd.join(", ")}`));
|
|
1455
1721
|
return;
|
|
1456
1722
|
}
|
|
1457
1723
|
if (detected) {
|
|
@@ -1541,6 +1807,13 @@ function listCommand() {
|
|
|
1541
1807
|
console.log(` ${mark} ${pc8.cyan(item.name.padEnd(20))} ${item.description}${deps}`);
|
|
1542
1808
|
}
|
|
1543
1809
|
}
|
|
1810
|
+
const entities = (readEfcJson(cwd)?.items ?? []).filter((i) => i.startsWith("auth:")).map((i) => i.slice(5));
|
|
1811
|
+
if (entities.length > 0) {
|
|
1812
|
+
console.log(pc8.bold("\n custom auth entities"));
|
|
1813
|
+
for (const e of entities) {
|
|
1814
|
+
console.log(` ${pc8.green("\u2713")} ${pc8.cyan(e.padEnd(20))} model + auth routes for ${e}`);
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1544
1817
|
console.log(pc8.dim("\n efc add <item...> \xB7 efc view <item>\n"));
|
|
1545
1818
|
} catch (err) {
|
|
1546
1819
|
fail(err);
|
|
@@ -1585,6 +1858,22 @@ function diffCommand() {
|
|
|
1585
1858
|
const names = name ? [name] : cfg.items;
|
|
1586
1859
|
let clean = true;
|
|
1587
1860
|
for (const n of names) {
|
|
1861
|
+
if (!registry.has(n)) {
|
|
1862
|
+
if (n.startsWith("auth:")) {
|
|
1863
|
+
if (name) {
|
|
1864
|
+
console.log(
|
|
1865
|
+
pc8.dim(
|
|
1866
|
+
`
|
|
1867
|
+
${n} is a custom auth entity (files are owned by your project, no upstream registry item to diff).`
|
|
1868
|
+
)
|
|
1869
|
+
);
|
|
1870
|
+
}
|
|
1871
|
+
} else {
|
|
1872
|
+
console.log(pc8.dim(`
|
|
1873
|
+
${n} is not a registry item.`));
|
|
1874
|
+
}
|
|
1875
|
+
continue;
|
|
1876
|
+
}
|
|
1588
1877
|
for (const f of itemStatus(cwd, registry, cfg, n)) {
|
|
1589
1878
|
if (f.status === "unchanged") continue;
|
|
1590
1879
|
clean = false;
|