@idevconn/create-icore 0.4.0 → 0.5.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/dist/cli.js +238 -2
- package/dist/index.cjs +238 -2
- package/dist/index.js +238 -2
- package/package.json +1 -1
- package/templates/.yarn/releases/yarn-4.15.0.cjs +940 -0
- package/templates/.yarnrc.yml +6 -1
- package/templates/apps/api/src/app/app.module.ts +5 -1
- package/templates/apps/api/src/main.ts +12 -6
- package/templates/apps/microservices/auth/project.json +2 -1
- package/templates/apps/microservices/auth/src/app/app.module.ts +47 -23
- package/templates/apps/microservices/jobs/project.json +2 -1
- package/templates/apps/microservices/notes/project.json +2 -1
- package/templates/apps/microservices/notes/src/app/app.module.ts +44 -25
- package/templates/apps/microservices/payment/project.json +2 -1
- package/templates/apps/microservices/payment/src/app/app.module.ts +35 -12
- package/templates/apps/microservices/upload/project.json +2 -1
- package/templates/apps/microservices/upload/src/app/app.module.ts +48 -28
- package/templates/apps/templates/client-antd/.env.example +7 -0
- package/templates/apps/templates/client-antd/vite.config.mts +4 -4
- package/templates/apps/templates/client-mui/.env.example +7 -0
- package/templates/apps/templates/client-mui/vite.config.mts +4 -4
- package/templates/apps/templates/client-shadcn/.env.example +6 -1
- package/templates/apps/templates/client-shadcn/vite.config.mts +4 -4
- package/templates/libs/auth-client/src/index.ts +1 -0
- package/templates/libs/auth-client/src/lib/auth-client.module.ts +1 -1
- package/templates/libs/auth-client/src/lib/auth-client.service.ts +1 -1
- package/templates/libs/auth-client/src/lib/auth-client.tokens.ts +4 -0
- package/templates/libs/jobs-client/src/index.ts +1 -0
- package/templates/libs/jobs-client/src/lib/jobs-client.module.ts +1 -1
- package/templates/libs/jobs-client/src/lib/jobs-client.service.ts +1 -1
- package/templates/libs/jobs-client/src/lib/jobs-client.tokens.ts +4 -0
- package/templates/libs/notes-client/src/index.ts +1 -0
- package/templates/libs/notes-client/src/lib/notes-client.module.ts +1 -1
- package/templates/libs/notes-client/src/lib/notes-client.service.ts +1 -1
- package/templates/libs/notes-client/src/lib/notes-client.tokens.ts +4 -0
- package/templates/libs/payment-client/src/index.ts +1 -0
- package/templates/libs/payment-client/src/lib/payment-client.module.ts +1 -1
- package/templates/libs/payment-client/src/lib/payment-client.service.ts +1 -1
- package/templates/libs/payment-client/src/lib/payment-client.tokens.ts +4 -0
- package/templates/libs/shared/src/env.ts +88 -0
- package/templates/libs/shared/src/index.ts +1 -0
- package/templates/libs/shared/src/transport.ts +37 -0
- package/templates/libs/upload-client/src/index.ts +1 -0
- package/templates/libs/upload-client/src/lib/upload-client.module.ts +1 -1
- package/templates/libs/upload-client/src/lib/upload-client.service.ts +1 -1
- package/templates/libs/upload-client/src/lib/upload-client.tokens.ts +4 -0
- package/templates/libs/vite-plugins/src/index.d.mts +6 -0
- package/templates/libs/vite-plugins/src/index.mjs +50 -0
- package/templates/package.json +1 -0
- package/templates/tools/create-icore/_template-shell/package.json +1 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/lib/scaffold.ts
|
|
2
2
|
import { copyFile, mkdir, readdir, readFile, stat, writeFile, rm } from "fs/promises";
|
|
3
|
+
import { readFileSync } from "fs";
|
|
3
4
|
import { join } from "path";
|
|
4
5
|
import { spawnSync } from "child_process";
|
|
5
6
|
var IGNORE_TOP = /* @__PURE__ */ new Set([
|
|
@@ -37,6 +38,22 @@ async function rewriteRootPackageJson(targetDir, opts) {
|
|
|
37
38
|
if (opts.packageManager !== "yarn") {
|
|
38
39
|
delete pkg.packageManager;
|
|
39
40
|
}
|
|
41
|
+
if (opts.packageManager === "pnpm") {
|
|
42
|
+
pkg["pnpm"] = {
|
|
43
|
+
onlyBuiltDependencies: [
|
|
44
|
+
"@firebase/util",
|
|
45
|
+
"@nestjs/core",
|
|
46
|
+
"@parcel/watcher",
|
|
47
|
+
"@scarf/scarf",
|
|
48
|
+
"@swc/core",
|
|
49
|
+
"less",
|
|
50
|
+
"msgpackr-extract",
|
|
51
|
+
"nx",
|
|
52
|
+
"protobufjs",
|
|
53
|
+
"unrs-resolver"
|
|
54
|
+
]
|
|
55
|
+
};
|
|
56
|
+
}
|
|
40
57
|
await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
41
58
|
}
|
|
42
59
|
async function writeAuthEnv(targetDir, opts) {
|
|
@@ -89,6 +106,14 @@ async function writeRootEnv(targetDir, opts) {
|
|
|
89
106
|
];
|
|
90
107
|
await writeFile(join(targetDir, ".env"), lines.join("\n"));
|
|
91
108
|
}
|
|
109
|
+
async function writeClientEnv(targetDir) {
|
|
110
|
+
const envExample = join(targetDir, "apps/client/.env.example");
|
|
111
|
+
try {
|
|
112
|
+
const env = await readFile(envExample, "utf8");
|
|
113
|
+
await writeFile(join(targetDir, "apps/client/.env"), env);
|
|
114
|
+
} catch {
|
|
115
|
+
}
|
|
116
|
+
}
|
|
92
117
|
async function writePaymentEnv(targetDir, opts) {
|
|
93
118
|
if (opts.payment === "none") return;
|
|
94
119
|
const envExample = join(targetDir, "apps/microservices/payment/.env.example");
|
|
@@ -437,9 +462,23 @@ function gitInit(cwd, projectName) {
|
|
|
437
462
|
{ cwd, stdio: "inherit" }
|
|
438
463
|
);
|
|
439
464
|
}
|
|
465
|
+
function resolveYarnBin(cwd) {
|
|
466
|
+
try {
|
|
467
|
+
const yarnrc = readFileSync(join(cwd, ".yarnrc.yml"), "utf8");
|
|
468
|
+
const match = yarnrc.match(/^yarnPath:\s*(.+)$/m);
|
|
469
|
+
if (match?.[1]) return join(cwd, match[1].trim());
|
|
470
|
+
} catch {
|
|
471
|
+
}
|
|
472
|
+
return join(cwd, ".yarn", "releases", "yarn-4.5.0.cjs");
|
|
473
|
+
}
|
|
440
474
|
function runInstall(cwd, pm) {
|
|
441
|
-
|
|
442
|
-
|
|
475
|
+
if (pm === "yarn") {
|
|
476
|
+
spawnSync("node", [resolveYarnBin(cwd), "install"], { cwd, stdio: "inherit" });
|
|
477
|
+
} else if (pm === "npm") {
|
|
478
|
+
spawnSync("npm", ["install"], { cwd, stdio: "inherit" });
|
|
479
|
+
} else {
|
|
480
|
+
spawnSync("pnpm", ["install"], { cwd, stdio: "inherit" });
|
|
481
|
+
}
|
|
443
482
|
}
|
|
444
483
|
async function scaffold(opts, templatesDir) {
|
|
445
484
|
await copyTree(templatesDir, opts.targetDir);
|
|
@@ -451,6 +490,7 @@ async function scaffold(opts, templatesDir) {
|
|
|
451
490
|
await writeGatewayEnv(opts.targetDir, opts);
|
|
452
491
|
await writeRootEnv(opts.targetDir, opts);
|
|
453
492
|
await selectClientTemplate(opts.targetDir, opts);
|
|
493
|
+
await writeClientEnv(opts.targetDir);
|
|
454
494
|
if (opts.upload === "none") await removeUploadStack(opts.targetDir);
|
|
455
495
|
if (opts.payment === "none") await removePaymentStack(opts.targetDir);
|
|
456
496
|
if (opts.jobs === "none") await removeJobsStack(opts.targetDir);
|
|
@@ -461,9 +501,199 @@ async function scaffold(opts, templatesDir) {
|
|
|
461
501
|
if (opts.packageManager === "yarn") {
|
|
462
502
|
await writeFile(join(opts.targetDir, "yarn.lock"), "");
|
|
463
503
|
}
|
|
504
|
+
await writeAiFiles(opts.targetDir, opts);
|
|
464
505
|
if (opts.install) runInstall(opts.targetDir, opts.packageManager);
|
|
465
506
|
if (opts.initGit) gitInit(opts.targetDir, opts.projectName);
|
|
466
507
|
}
|
|
508
|
+
async function writeAiFiles(targetDir, opts) {
|
|
509
|
+
const pm = opts.packageManager;
|
|
510
|
+
const nx = pm === "npm" ? "npx nx" : `${pm} nx`;
|
|
511
|
+
const devCmd = `${pm} dev`;
|
|
512
|
+
const activeMSes = ["auth (port 4001)"];
|
|
513
|
+
if (opts.upload !== "none") activeMSes.push(`upload (port 4002)`);
|
|
514
|
+
if (opts.payment !== "none") activeMSes.push(`payment (port 4003)`);
|
|
515
|
+
if (opts.example !== "none") activeMSes.push(`notes (port 4004)`);
|
|
516
|
+
if (opts.jobs !== "none") activeMSes.push(`jobs (standalone)`);
|
|
517
|
+
const usesSupabase = opts.authProvider === "supabase" || opts.dbProvider === "supabase" || opts.upload === "supabase";
|
|
518
|
+
const usesFirebase = opts.authProvider === "firebase" || opts.dbProvider === "firebase" || opts.upload === "firebase";
|
|
519
|
+
await writeFile(join(targetDir, "CLAUDE.md"), "@AGENTS.md\n");
|
|
520
|
+
const uiLabel = { shadcn: "shadcn/ui + Tailwind", antd: "Ant Design 6", mui: "MUI 6" }[opts.ui];
|
|
521
|
+
const readme = `# ${opts.projectName}
|
|
522
|
+
|
|
523
|
+
> Scaffolded with [iCore](https://github.com/iDEVconn/create-icore) \u2014 Nx + NestJS + React full-stack template.
|
|
524
|
+
|
|
525
|
+
## Stack
|
|
526
|
+
|
|
527
|
+
| Layer | Technology |
|
|
528
|
+
|-------|-----------|
|
|
529
|
+
| Monorepo | Nx + ${pm} |
|
|
530
|
+
| Gateway | NestJS 11 + Swagger |
|
|
531
|
+
| Auth | ${opts.authProvider} |
|
|
532
|
+
| Database | ${opts.dbProvider} |
|
|
533
|
+
| Upload | ${opts.upload === "none" ? "\u2014" : opts.upload} |
|
|
534
|
+
| UI | ${uiLabel} + TanStack Router + Query |
|
|
535
|
+
| i18n | i18next (en / ru / he) |
|
|
536
|
+
|
|
537
|
+
## Quick start
|
|
538
|
+
|
|
539
|
+
\`\`\`bash
|
|
540
|
+
# 1. Fill in provider credentials
|
|
541
|
+
# apps/microservices/auth/.env
|
|
542
|
+
# apps/microservices/upload/.env (if upload is enabled)
|
|
543
|
+
# apps/client/.env (VITE_API_URL \u2014 already defaults to /api)
|
|
544
|
+
|
|
545
|
+
# 2. Start everything
|
|
546
|
+
${devCmd}
|
|
547
|
+
# \u2192 http://localhost:4200 client
|
|
548
|
+
# \u2192 http://localhost:3001/api/docs Swagger
|
|
549
|
+
\`\`\`
|
|
550
|
+
|
|
551
|
+
## Commands
|
|
552
|
+
|
|
553
|
+
\`\`\`bash
|
|
554
|
+
${nx} run <project>:serve # start a single service
|
|
555
|
+
${nx} test <project> # unit tests
|
|
556
|
+
${nx} lint <project> # lint
|
|
557
|
+
${nx} build <project> # production build
|
|
558
|
+
${pm === "yarn" ? "yarn remove-notes" : pm === "pnpm" ? "pnpm remove-notes" : "npm run remove-notes"} # strip the notes sample feature
|
|
559
|
+
\`\`\`
|
|
560
|
+
|
|
561
|
+
## Scaffolded by
|
|
562
|
+
|
|
563
|
+
[iCore](https://github.com/iDEVconn/create-icore) \u2014 [@idevconn/create-icore](https://www.npmjs.com/package/@idevconn/create-icore)
|
|
564
|
+
|
|
565
|
+
## License
|
|
566
|
+
|
|
567
|
+
Apache-2.0
|
|
568
|
+
`;
|
|
569
|
+
await writeFile(join(targetDir, "README.md"), readme);
|
|
570
|
+
const agents = `# ${opts.projectName} \u2014 Agent Instructions
|
|
571
|
+
|
|
572
|
+
## Stack snapshot
|
|
573
|
+
|
|
574
|
+
| Dimension | Choice |
|
|
575
|
+
|------------|--------|
|
|
576
|
+
| Auth | ${opts.authProvider} |
|
|
577
|
+
| Database | ${opts.dbProvider} |
|
|
578
|
+
| Upload | ${opts.upload} |
|
|
579
|
+
| Payment | ${opts.payment} |
|
|
580
|
+
| Jobs | ${opts.jobs} |
|
|
581
|
+
| UI | ${opts.ui} |
|
|
582
|
+
| Transport | ${opts.transport} |
|
|
583
|
+
| PM | ${pm} |
|
|
584
|
+
|
|
585
|
+
## \u{1F680} Mandatory Workflow
|
|
586
|
+
|
|
587
|
+
- **Branch strategy**: \`dev\` is default. Cut \`feature/<name>\` or \`bug/<name>\` from dev. PRs only target dev. Never push directly to main.
|
|
588
|
+
- **No code without approval**: Propose changes first, wait for go-ahead.
|
|
589
|
+
- **\u0417\u0410\u041A\u041E\u041D \u2014 no crash on missing .env**: MS factories must catch config errors, print a boxed banner with ALL missing vars, and return a Fake strategy in dev. In prod (\`NODE_ENV=production\`) throw the same banner. The \`formatEnvBanner\` + \`missingEnv\` helpers from \`@icore/shared\` handle this.
|
|
590
|
+
- **Post-coding routine**: \`npx prettier --write <files>\` \u2192 \`${nx} lint <project>\` \u2192 \`${nx} build <project>\` \u2014 all green before committing.
|
|
591
|
+
- **Nx generators only**: never hand-write \`project.json\` / tsconfig stacks. Use \`${nx} g @nx/<plugin>:<schematic>\`.
|
|
592
|
+
|
|
593
|
+
## Architecture
|
|
594
|
+
|
|
595
|
+
\`\`\`
|
|
596
|
+
apps/
|
|
597
|
+
\u251C\u2500\u2500 api/ NestJS gateway \u2014 all client traffic enters here (:3001)
|
|
598
|
+
\u251C\u2500\u2500 microservices/
|
|
599
|
+
${activeMSes.map((s) => `\u2502 \u251C\u2500\u2500 ${s.split(" ")[0]}/`).join("\n")}
|
|
600
|
+
\u2514\u2500\u2500 client/ Vite + React 19 + ${opts.ui} (:4200)
|
|
601
|
+
libs/
|
|
602
|
+
\u251C\u2500\u2500 shared/ contracts, CASL, transport helpers, env banner utils
|
|
603
|
+
\u251C\u2500\u2500 auth-strategies/${opts.authProvider}/
|
|
604
|
+
${opts.upload !== "none" ? `\u251C\u2500\u2500 storage-strategies/${opts.upload}/
|
|
605
|
+
` : ""}\u251C\u2500\u2500 db-strategies/${opts.dbProvider === "firebase" ? "firestore" : opts.dbProvider}/
|
|
606
|
+
\u251C\u2500\u2500 auth-client/ gateway \u2192 auth MS (TCP/Redis/NATS)
|
|
607
|
+
${opts.upload !== "none" ? `\u251C\u2500\u2500 upload-client/ gateway \u2192 upload MS
|
|
608
|
+
` : ""}\u2514\u2500\u2500 template-shared/ browser-safe React foundation (stores, i18n, CASL)
|
|
609
|
+
\`\`\`
|
|
610
|
+
|
|
611
|
+
## Key patterns
|
|
612
|
+
|
|
613
|
+
**Strategy swap** \u2014 provider is chosen at runtime via env. Never import a concrete strategy in app code; always inject via the factory token (\`AuthStrategy\`, \`StorageStrategy\`, \`DBStrategy\`).
|
|
614
|
+
|
|
615
|
+
**Transport** \u2014 \`buildTransport(prefix)\` reads \`${opts.transport.toUpperCase()}*\` vars. Same helper on gateway client-modules and each MS \`main.ts\`. Supports tcp / redis / nats \u2014 change by flipping \`*_TRANSPORT\` in \`.env\`.
|
|
616
|
+
|
|
617
|
+
**Env layering**:
|
|
618
|
+
1. Root \`.env\` \u2014 \`DB_PROVIDER\`
|
|
619
|
+
2. \`apps/api/.env\` \u2014 gateway transport endpoints
|
|
620
|
+
3. \`apps/microservices/<name>/.env\` \u2014 each MS provider + transport
|
|
621
|
+
4. \`apps/client/.env\` \u2014 \`VITE_API_URL\`
|
|
622
|
+
|
|
623
|
+
## Commands
|
|
624
|
+
|
|
625
|
+
\`\`\`bash
|
|
626
|
+
${devCmd} # start all services
|
|
627
|
+
${nx} run api:serve # gateway only
|
|
628
|
+
${nx} run auth:serve # auth MS only
|
|
629
|
+
${nx} test <project> # run tests
|
|
630
|
+
${nx} lint <project> # lint
|
|
631
|
+
${nx} build <project> # build
|
|
632
|
+
${nx} g @nx/nest:resource # generate NestJS resource
|
|
633
|
+
\`\`\`
|
|
634
|
+
|
|
635
|
+
## .env files to configure
|
|
636
|
+
|
|
637
|
+
| File | Key vars |
|
|
638
|
+
|------|----------|
|
|
639
|
+
| \`apps/microservices/auth/.env\` | \`AUTH_PROVIDER=${opts.authProvider}\`, ${opts.authProvider === "supabase" ? "`SUPABASE_URL`, `SUPABASE_SERVICE_ROLE_KEY`" : "`FB_ADMIN_*`, `FIREBASE_WEB_API_KEY`"} |
|
|
640
|
+
${opts.upload !== "none" ? `| \`apps/microservices/upload/.env\` | \`STORAGE_PROVIDER=${opts.upload}\`, provider creds |
|
|
641
|
+
` : ""}| \`apps/microservices/notes/.env\` | \`DB_PROVIDER=${opts.dbProvider}\`, DB creds |
|
|
642
|
+
| \`apps/client/.env\` | \`VITE_API_URL=/api\` (proxied to :3001 in dev) |
|
|
643
|
+
|
|
644
|
+
## Testing
|
|
645
|
+
|
|
646
|
+
- Unit tests: Vitest, files named \`*.unit.test.ts(x)\` in \`__tests__/\` next to source.
|
|
647
|
+
- Test behaviour, not implementation. Fake strategies from \`@icore/shared\` (FakeAuthStrategy etc.) serve as test doubles.
|
|
648
|
+
- Run: \`${nx} test <project>\`
|
|
649
|
+
`;
|
|
650
|
+
await writeFile(join(targetDir, "AGENTS.md"), agents);
|
|
651
|
+
await mkdir(join(targetDir, ".claude"), { recursive: true });
|
|
652
|
+
const mcpServers = {
|
|
653
|
+
nx: {
|
|
654
|
+
command: "npx",
|
|
655
|
+
args: ["-y", "@nx/mcp@latest", "--directory", "."],
|
|
656
|
+
type: "stdio"
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
if (usesSupabase) {
|
|
660
|
+
mcpServers["supabase"] = {
|
|
661
|
+
command: "npx",
|
|
662
|
+
args: [
|
|
663
|
+
"-y",
|
|
664
|
+
"@supabase/mcp-server-supabase@latest",
|
|
665
|
+
"--access-token",
|
|
666
|
+
"<SUPABASE_PERSONAL_ACCESS_TOKEN>"
|
|
667
|
+
],
|
|
668
|
+
type: "stdio"
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
if (usesFirebase) {
|
|
672
|
+
mcpServers["firebase"] = {
|
|
673
|
+
command: "npx",
|
|
674
|
+
args: ["-y", "firebase-tools@latest", "experimental:mcp"],
|
|
675
|
+
type: "stdio"
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
const nxCmds = [`Bash(${nx} *)`, `Bash(${devCmd})`];
|
|
679
|
+
if (pm !== "npm") nxCmds.push(`Bash(npx nx *)`);
|
|
680
|
+
const settings = {
|
|
681
|
+
mcpServers,
|
|
682
|
+
permissions: {
|
|
683
|
+
allow: [
|
|
684
|
+
...nxCmds,
|
|
685
|
+
"Bash(npx prettier *)",
|
|
686
|
+
"Bash(git status)",
|
|
687
|
+
"Bash(git diff *)",
|
|
688
|
+
"Bash(git log *)"
|
|
689
|
+
]
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
await writeFile(
|
|
693
|
+
join(targetDir, ".claude", "settings.json"),
|
|
694
|
+
JSON.stringify(settings, null, 2) + "\n"
|
|
695
|
+
);
|
|
696
|
+
}
|
|
467
697
|
|
|
468
698
|
// src/lib/prompts.ts
|
|
469
699
|
import * as p from "@clack/prompts";
|
|
@@ -659,6 +889,12 @@ Re-run with @latest to refresh:
|
|
|
659
889
|
});
|
|
660
890
|
if (p.isCancel(transport)) throw new Error("cancelled");
|
|
661
891
|
const packageManager = flags.packageManager ?? detectPackageManager();
|
|
892
|
+
if (packageManager === "yarn") {
|
|
893
|
+
p.note(
|
|
894
|
+
"yarn 4.15+ enforces a 24h publish-age gate (npmMinimalAgeGate=1d), so a\n`yarn create @idevconn/icore@latest` run within 24h of a release resolves an\nolder version. If the banner above shows an unexpectedly old version, either:\n \u2022 wait \u2014 the version auto-unlocks 24h after publish, or\n \u2022 bypass once: yarn config set npmMinimalAgeGate 0 (then re-run), or\n \u2022 use npm/pnpm: npm init @idevconn/icore@latest <name> -- [flags]",
|
|
895
|
+
"\u26A0 yarn 24h age-gate"
|
|
896
|
+
);
|
|
897
|
+
}
|
|
662
898
|
const initGit = flags.initGit ?? !await p.confirm({ message: "Initialise git repo?", initialValue: true }) === false;
|
|
663
899
|
const install = flags.install ?? !await p.confirm({
|
|
664
900
|
message: `Run ${packageManager} install?`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idevconn/create-icore",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Bootstrap a new project from the iCore scaffold (Nx + NestJS + React + Vite + shadcn/Tailwind, swappable auth + storage providers).",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "iDEVconn",
|