@nexusts/cli 0.8.4 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/db-migrate.d.ts +1 -1
- package/dist/commands/init.d.ts +1 -1
- package/dist/core/config.d.ts +1 -1
- package/dist/index.js +65 -70
- package/dist/index.js.map +15 -15
- package/dist/templates/controller/nest.d.ts +3 -3
- package/dist/templates/crud/controller.d.ts +3 -2
- package/dist/templates/repository/repository.d.ts +6 -1
- package/dist/templates/service/service.d.ts +3 -1
- package/package.json +2 -2
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Implementation: spawns `bunx drizzle-kit migrate` if the
|
|
11
11
|
* drizzle-kit binary is on PATH; otherwise runs an in-process
|
|
12
|
-
* migration script that uses
|
|
12
|
+
* migration script that uses `@nexusts/drizzle`'s
|
|
13
13
|
* `db.migrate(folder)` directly.
|
|
14
14
|
*
|
|
15
15
|
* 2. **`--status`**: list applied migrations + pending count.
|
package/dist/commands/init.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Unlike `nx new <name>` — which requires a fresh, empty directory —
|
|
5
5
|
* `nx init` is non-destructive: it skips files that already exist,
|
|
6
6
|
* preserves the user's existing `package.json` (only adding the
|
|
7
|
-
*
|
|
7
|
+
* nexusts dependency if missing), and merges its `tsconfig.json`
|
|
8
8
|
* additions into the user's existing config.
|
|
9
9
|
*
|
|
10
10
|
* Typical use case: the user already ran `bun init` (or has an
|
package/dist/core/config.d.ts
CHANGED
|
@@ -131,6 +131,6 @@ export declare const DEFAULT_CONFIG: NxConfig;
|
|
|
131
131
|
*
|
|
132
132
|
* Missing / unloadable config files are not fatal — we log a debug
|
|
133
133
|
* message and use defaults so the CLI works in fresh projects where
|
|
134
|
-
* `
|
|
134
|
+
* `nexusts` hasn't been installed yet.
|
|
135
135
|
*/
|
|
136
136
|
export declare function loadConfig(cwd?: string): Promise<NxConfig>;
|
package/dist/index.js
CHANGED
|
@@ -578,45 +578,51 @@ export const {{ camel }}Routes = {
|
|
|
578
578
|
|
|
579
579
|
// packages/cli/src/templates/controller/nest.ts
|
|
580
580
|
var nest_default = `
|
|
581
|
-
import {
|
|
581
|
+
import { Controller, Delete, Get, Inject, Post, Put, inputValue } from '@nexusts/core';
|
|
582
|
+
import type { Context } from 'hono';
|
|
582
583
|
import { {{ service }} } from '../services/{{ kebab }}.service.js';
|
|
583
584
|
|
|
584
585
|
@Controller('/{{ kebab }}s')
|
|
585
586
|
export class {{ name }}Controller {
|
|
586
|
-
|
|
587
|
+
@Inject({{ service }}) declare {{ serviceCamel }}: {{ service }};
|
|
587
588
|
|
|
588
589
|
@Get('/')
|
|
589
|
-
async index() {
|
|
590
|
+
async index(ctx: Context) {
|
|
590
591
|
return this.{{ serviceCamel }}.findAll();
|
|
591
592
|
}
|
|
592
593
|
|
|
593
594
|
@Get('/:id')
|
|
594
|
-
async show(
|
|
595
|
-
|
|
595
|
+
async show(ctx: Context) {
|
|
596
|
+
const id = inputValue(ctx.req.param('id')).number().required().value();
|
|
597
|
+
return this.{{ serviceCamel }}.findOne(id);
|
|
596
598
|
}
|
|
597
599
|
|
|
598
600
|
@Post('/')
|
|
599
|
-
async create(
|
|
600
|
-
|
|
601
|
+
async create(ctx: Context) {
|
|
602
|
+
const body = await ctx.req.json();
|
|
603
|
+
return { status: 201, body: await this.{{ serviceCamel }}.create(body) };
|
|
601
604
|
}
|
|
602
605
|
|
|
603
606
|
@Put('/:id')
|
|
604
|
-
async update(
|
|
605
|
-
|
|
607
|
+
async update(ctx: Context) {
|
|
608
|
+
const id = inputValue(ctx.req.param('id')).number().required().value();
|
|
609
|
+
const body = await ctx.req.json();
|
|
610
|
+
return this.{{ serviceCamel }}.update(id, body);
|
|
606
611
|
}
|
|
607
612
|
|
|
608
613
|
@Delete('/:id')
|
|
609
|
-
async destroy(
|
|
610
|
-
|
|
614
|
+
async destroy(ctx: Context) {
|
|
615
|
+
const id = inputValue(ctx.req.param('id')).number().required().value();
|
|
616
|
+
return this.{{ serviceCamel }}.delete(id);
|
|
611
617
|
}
|
|
612
618
|
}
|
|
613
619
|
`.trimStart();
|
|
614
620
|
|
|
615
621
|
// packages/cli/src/templates/crud/controller.ts
|
|
616
622
|
var controller_default = `
|
|
617
|
-
import {
|
|
623
|
+
import { Controller, Delete, Get, Inject, Post, Put, inputValue } from '@nexusts/core';
|
|
618
624
|
import { z } from 'zod';
|
|
619
|
-
import {
|
|
625
|
+
import type { Context } from 'hono';
|
|
620
626
|
import { {{ service }} } from '../services/{{ kebab }}.service.js';
|
|
621
627
|
{{#hasInertia}}import { Inertia } from '@nexusts/view';{{/hasInertia}}
|
|
622
628
|
|
|
@@ -627,13 +633,11 @@ const Create{{ name }}Schema = z.object({
|
|
|
627
633
|
|
|
628
634
|
@Controller('/{{ kebab }}s')
|
|
629
635
|
export class {{ controller }} {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
{{#hasInertia}} @Inject(Inertia.TOKEN) private readonly inertia: Inertia,{{/hasInertia}}
|
|
633
|
-
) {}
|
|
636
|
+
@Inject({{ service }}) declare {{ camel }}Service: {{ service }};
|
|
637
|
+
{{#hasInertia}} @Inject(Inertia.TOKEN) declare inertia: Inertia;{{/hasInertia}}
|
|
634
638
|
|
|
635
639
|
@Get('/')
|
|
636
|
-
async index() {
|
|
640
|
+
async index(ctx: Context) {
|
|
637
641
|
const items = await this.{{ camel }}Service.findAll();
|
|
638
642
|
{{#hasInertia}}
|
|
639
643
|
return this.inertia.render('{{ viewComponent }}', { items });
|
|
@@ -644,8 +648,9 @@ export class {{ controller }} {
|
|
|
644
648
|
}
|
|
645
649
|
|
|
646
650
|
@Get('/:id')
|
|
647
|
-
async show(
|
|
648
|
-
const
|
|
651
|
+
async show(ctx: Context) {
|
|
652
|
+
const id = inputValue(ctx.req.param('id')).number().required().value();
|
|
653
|
+
const item = await this.{{ camel }}Service.findOne(id);
|
|
649
654
|
{{#hasInertia}}
|
|
650
655
|
return this.inertia.render('{{ viewShowComponent }}', { item });
|
|
651
656
|
{{/hasInertia}}
|
|
@@ -655,23 +660,22 @@ export class {{ controller }} {
|
|
|
655
660
|
}
|
|
656
661
|
|
|
657
662
|
@Post('/')
|
|
658
|
-
|
|
659
|
-
|
|
663
|
+
async create(ctx: Context) {
|
|
664
|
+
const body = Create{{ name }}Schema.parse(await ctx.req.json());
|
|
660
665
|
return { status: 201, body: await this.{{ camel }}Service.create(body) };
|
|
661
666
|
}
|
|
662
667
|
|
|
663
668
|
@Put('/:id')
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
) {
|
|
669
|
-
return await this.{{ camel }}Service.update(Number(id), body);
|
|
669
|
+
async update(ctx: Context) {
|
|
670
|
+
const id = inputValue(ctx.req.param('id')).number().required().value();
|
|
671
|
+
const body = Create{{ name }}Schema.partial().parse(await ctx.req.json());
|
|
672
|
+
return await this.{{ camel }}Service.update(id, body);
|
|
670
673
|
}
|
|
671
674
|
|
|
672
675
|
@Delete('/:id')
|
|
673
|
-
async destroy(
|
|
674
|
-
|
|
676
|
+
async destroy(ctx: Context) {
|
|
677
|
+
const id = inputValue(ctx.req.param('id')).number().required().value();
|
|
678
|
+
return await this.{{ camel }}Service.delete(id);
|
|
675
679
|
}
|
|
676
680
|
}
|
|
677
681
|
`.trimStart();
|
|
@@ -1008,26 +1012,21 @@ import type { {{ name }}, New{{ name }} } from '../models/{{ kebab }}.model.js';
|
|
|
1008
1012
|
|
|
1009
1013
|
@Injectable()
|
|
1010
1014
|
export class {{ repository }} extends DrizzleRepository<typeof {{ snake }}, {{ name }}> {
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
) {
|
|
1014
|
-
super(db, {{ snake }});
|
|
1015
|
-
}
|
|
1015
|
+
@Inject(DrizzleService.TOKEN) declare db: DrizzleService;
|
|
1016
|
+
protected readonly table = {{ snake }};
|
|
1016
1017
|
}
|
|
1017
1018
|
`.trimStart();
|
|
1018
1019
|
|
|
1019
1020
|
// packages/cli/src/templates/service/service.ts
|
|
1020
1021
|
var service_default = `
|
|
1021
|
-
import {
|
|
1022
|
+
import { Injectable, Inject } from '@nexusts/core';
|
|
1022
1023
|
{{#hasRepo}}import { eq } from '@nexusts/drizzle';
|
|
1023
1024
|
import { {{ repository }} } from '../repositories/{{ kebab }}.repository.js';
|
|
1024
1025
|
import { {{ snake }} } from '../models/{{ kebab }}.model.js';{{/hasRepo}}
|
|
1025
1026
|
|
|
1026
1027
|
@Injectable()
|
|
1027
1028
|
export class {{ name }}Service {
|
|
1028
|
-
|
|
1029
|
-
@Inject({{ repository }}) private readonly {{ repositoryCamel }}: {{ repository }},
|
|
1030
|
-
{{/hasRepo}}) {}
|
|
1029
|
+
{{#hasRepo}}@Inject({{ repository }}) declare {{ repositoryCamel }}: {{ repository }};{{/hasRepo}}
|
|
1031
1030
|
|
|
1032
1031
|
async findAll() {
|
|
1033
1032
|
{{#hasRepo}}return this.{{ repositoryCamel }}.findAll();{{/hasRepo}}
|
|
@@ -1124,7 +1123,6 @@ function ensureDirectories(target, view) {
|
|
|
1124
1123
|
function computeDeps(view, orm, db, frontend) {
|
|
1125
1124
|
const deps = {
|
|
1126
1125
|
"@nexusts/core": "*",
|
|
1127
|
-
"reflect-metadata": "^0.2.2",
|
|
1128
1126
|
hono: "^4.6.0",
|
|
1129
1127
|
zod: "^3.23.8"
|
|
1130
1128
|
};
|
|
@@ -1233,7 +1231,7 @@ function generateEnvFile() {
|
|
|
1233
1231
|
"# \u2500\u2500 Database: MySQL \u2500\u2500",
|
|
1234
1232
|
"# DATABASE_URL=mysql://user:password@localhost:3306/myapp",
|
|
1235
1233
|
"",
|
|
1236
|
-
"# \u2500\u2500 Better Auth (if using
|
|
1234
|
+
"# \u2500\u2500 Better Auth (if using @nexusts/auth) \u2500\u2500",
|
|
1237
1235
|
"# BETTER_AUTH_SECRET=",
|
|
1238
1236
|
"# BETTER_AUTH_URL=http://localhost:3000"
|
|
1239
1237
|
].join(`
|
|
@@ -1346,8 +1344,7 @@ const staticMiddleware = StaticModule.mount({ root: './public', prefix: '/static
|
|
|
1346
1344
|
` : "";
|
|
1347
1345
|
const staticOpt = hasView ? `
|
|
1348
1346
|
middleware: [staticMiddleware],` : "";
|
|
1349
|
-
write("app/main.ts", `import '
|
|
1350
|
-
import { Application } from '@nexusts/core';
|
|
1347
|
+
write("app/main.ts", `import { Application } from '@nexusts/core';
|
|
1351
1348
|
${staticMw}import { AppModule } from './app.module.js';
|
|
1352
1349
|
|
|
1353
1350
|
const app = new Application(AppModule, {
|
|
@@ -1393,7 +1390,7 @@ import { Inertia } from '@nexusts/view';
|
|
|
1393
1390
|
|
|
1394
1391
|
@Controller('/')
|
|
1395
1392
|
export class HomeController {
|
|
1396
|
-
|
|
1393
|
+
@Inject(Inertia.TOKEN) private inertia!: Inertia;
|
|
1397
1394
|
|
|
1398
1395
|
@Get('/')
|
|
1399
1396
|
index() {
|
|
@@ -1565,7 +1562,7 @@ var initCommand = {
|
|
|
1565
1562
|
async run(ctx) {
|
|
1566
1563
|
const interactive = flagBool(ctx.flags, "interaction", true);
|
|
1567
1564
|
const force = flagBool(ctx.flags, "force", false);
|
|
1568
|
-
const target = resolve6(ctx.cwd, ctx.flags
|
|
1565
|
+
const target = resolve6(ctx.cwd, ctx.flags.target ?? ".");
|
|
1569
1566
|
const routing = await resolveOpt(ctx.flags, "style", VALID_OPTIONS.style, "nest", interactive);
|
|
1570
1567
|
const view = await resolveOpt(ctx.flags, "view", VALID_OPTIONS.view, "rendu", interactive);
|
|
1571
1568
|
const orm = await resolveOpt(ctx.flags, "orm", VALID_OPTIONS.orm, "drizzle", interactive);
|
|
@@ -1606,7 +1603,7 @@ var initCommand = {
|
|
|
1606
1603
|
merged.push(entry.path);
|
|
1607
1604
|
} else {
|
|
1608
1605
|
const pkgJson = buildPackageJson(name, deps, devDeps, view, frontend);
|
|
1609
|
-
writeFileSync3(abs, JSON.stringify(pkgJson, null, 2)
|
|
1606
|
+
writeFileSync3(abs, `${JSON.stringify(pkgJson, null, 2)}
|
|
1610
1607
|
`);
|
|
1611
1608
|
created.push(entry.path);
|
|
1612
1609
|
}
|
|
@@ -1660,12 +1657,12 @@ function mergePackageJson(path, additions, devAdditions = {}, view, frontend) {
|
|
|
1660
1657
|
const raw = readFileSync4(path, "utf8");
|
|
1661
1658
|
const pkg = parseJsonLoose(raw);
|
|
1662
1659
|
let changed = false;
|
|
1663
|
-
if (!pkg
|
|
1664
|
-
pkg
|
|
1660
|
+
if (!pkg.type) {
|
|
1661
|
+
pkg.type = "module";
|
|
1665
1662
|
changed = true;
|
|
1666
1663
|
}
|
|
1667
|
-
if (!pkg
|
|
1668
|
-
pkg
|
|
1664
|
+
if (!pkg.private) {
|
|
1665
|
+
pkg.private = true;
|
|
1669
1666
|
changed = true;
|
|
1670
1667
|
}
|
|
1671
1668
|
const SCRIPTS = {
|
|
@@ -1678,9 +1675,9 @@ function mergePackageJson(path, additions, devAdditions = {}, view, frontend) {
|
|
|
1678
1675
|
if (view === "inertia") {
|
|
1679
1676
|
const ext = frontend === "vue" ? "ts" : "tsx";
|
|
1680
1677
|
SCRIPTS["build:frontend"] = `bun build ./resources/js/app.${ext} --outdir=./public --target=browser --format=esm --minify`;
|
|
1681
|
-
SCRIPTS
|
|
1678
|
+
SCRIPTS.dev = `bun run build:frontend && bun --hot app/main.ts`;
|
|
1682
1679
|
}
|
|
1683
|
-
const existingScripts = pkg
|
|
1680
|
+
const existingScripts = pkg.scripts ?? {};
|
|
1684
1681
|
for (const [k, v] of Object.entries(SCRIPTS)) {
|
|
1685
1682
|
if (!(k in existingScripts)) {
|
|
1686
1683
|
existingScripts[k] = v;
|
|
@@ -1688,27 +1685,27 @@ function mergePackageJson(path, additions, devAdditions = {}, view, frontend) {
|
|
|
1688
1685
|
}
|
|
1689
1686
|
}
|
|
1690
1687
|
if (Object.keys(existingScripts).length > 0)
|
|
1691
|
-
pkg
|
|
1692
|
-
const deps = pkg
|
|
1688
|
+
pkg.scripts = existingScripts;
|
|
1689
|
+
const deps = pkg.dependencies ?? {};
|
|
1693
1690
|
for (const [k, v] of Object.entries(additions)) {
|
|
1694
1691
|
if (!(k in deps)) {
|
|
1695
1692
|
deps[k] = v;
|
|
1696
1693
|
changed = true;
|
|
1697
1694
|
}
|
|
1698
1695
|
}
|
|
1699
|
-
pkg
|
|
1696
|
+
pkg.dependencies = deps;
|
|
1700
1697
|
if (Object.keys(devAdditions).length > 0) {
|
|
1701
|
-
const devDeps = pkg
|
|
1698
|
+
const devDeps = pkg.devDependencies ?? {};
|
|
1702
1699
|
for (const [k, v] of Object.entries(devAdditions)) {
|
|
1703
1700
|
if (!(k in devDeps)) {
|
|
1704
1701
|
devDeps[k] = v;
|
|
1705
1702
|
changed = true;
|
|
1706
1703
|
}
|
|
1707
1704
|
}
|
|
1708
|
-
pkg
|
|
1705
|
+
pkg.devDependencies = devDeps;
|
|
1709
1706
|
}
|
|
1710
1707
|
if (changed)
|
|
1711
|
-
writeFileSync3(path, JSON.stringify(pkg, null, 2)
|
|
1708
|
+
writeFileSync3(path, `${JSON.stringify(pkg, null, 2)}
|
|
1712
1709
|
`);
|
|
1713
1710
|
}
|
|
1714
1711
|
function mergeTsconfig(path, additions) {
|
|
@@ -1732,7 +1729,7 @@ function mergeTsconfig(path, additions) {
|
|
|
1732
1729
|
}
|
|
1733
1730
|
cfg.include = include;
|
|
1734
1731
|
if (changed)
|
|
1735
|
-
writeFileSync3(path, JSON.stringify(cfg, null, 2)
|
|
1732
|
+
writeFileSync3(path, `${JSON.stringify(cfg, null, 2)}
|
|
1736
1733
|
`);
|
|
1737
1734
|
}
|
|
1738
1735
|
function defaultTsconfig() {
|
|
@@ -1761,7 +1758,6 @@ var AUTH_INSTANCE_TEMPLATE = `/**
|
|
|
1761
1758
|
*
|
|
1762
1759
|
* Edit \`nx.config.ts\` (\`auth\` section) instead of this file when possible.
|
|
1763
1760
|
*/
|
|
1764
|
-
import 'reflect-metadata';
|
|
1765
1761
|
import { createAuth } from '@nexusts/auth';
|
|
1766
1762
|
|
|
1767
1763
|
export const auth = createAuth({
|
|
@@ -2015,10 +2011,10 @@ var DIALECT_SPECS = {
|
|
|
2015
2011
|
tableFn: "sqliteTable",
|
|
2016
2012
|
idHelper: "integer",
|
|
2017
2013
|
idOpts: "{ autoIncrement: true }",
|
|
2018
|
-
tsTimestamp: "
|
|
2019
|
-
tsDateMode: "",
|
|
2020
|
-
defaultTs: ".$defaultFn(() =>
|
|
2021
|
-
defaultTsUpdate: ""
|
|
2014
|
+
tsTimestamp: "integer",
|
|
2015
|
+
tsDateMode: ", { mode: 'timestamp' }",
|
|
2016
|
+
defaultTs: ".$defaultFn(() => Date.now())",
|
|
2017
|
+
defaultTsUpdate: ".$defaultFn(() => Date.now())"
|
|
2022
2018
|
},
|
|
2023
2019
|
sqlite: {
|
|
2024
2020
|
imports: ["sqliteTable", "integer", "text", "real"],
|
|
@@ -3222,7 +3218,6 @@ async function runStatus(cwd, folder, dialect, configUrl = "") {
|
|
|
3222
3218
|
return 1;
|
|
3223
3219
|
}
|
|
3224
3220
|
const script = `
|
|
3225
|
-
import 'reflect-metadata';
|
|
3226
3221
|
import { DrizzleService } from '@nexusts/drizzle';
|
|
3227
3222
|
|
|
3228
3223
|
const url = ${JSON.stringify(url)};
|
|
@@ -3439,7 +3434,6 @@ var dbSeedCommand = {
|
|
|
3439
3434
|
const seedCalls = target.map((_, i) => ` await seed_${i}({ db, logger, dialect, truncate: (t) => db.truncate(t) });`).join(`
|
|
3440
3435
|
`);
|
|
3441
3436
|
const script = `
|
|
3442
|
-
import 'reflect-metadata';
|
|
3443
3437
|
import { DrizzleService } from '@nexusts/drizzle';
|
|
3444
3438
|
import { Logger } from '@nexusts/logger';
|
|
3445
3439
|
|
|
@@ -3610,7 +3604,7 @@ var newCommand = {
|
|
|
3610
3604
|
`);
|
|
3611
3605
|
const { deps, devDeps } = computeDeps(view, orm, db, frontend);
|
|
3612
3606
|
const pkgJson = buildPackageJson(name, deps, devDeps, view, frontend);
|
|
3613
|
-
writeFileSync4(resolve24(target, "package.json"), JSON.stringify(pkgJson, null, 2)
|
|
3607
|
+
writeFileSync4(resolve24(target, "package.json"), `${JSON.stringify(pkgJson, null, 2)}
|
|
3614
3608
|
`);
|
|
3615
3609
|
const opts = { target, name, routing, view, orm, db, frontend, ssr, dbUrl };
|
|
3616
3610
|
const files = generateProjectFiles(target, opts);
|
|
@@ -4262,6 +4256,7 @@ var repl_default = replCommand;
|
|
|
4262
4256
|
// packages/cli/src/commands/route-list.ts
|
|
4263
4257
|
import { readdirSync, statSync as statSync2 } from "fs";
|
|
4264
4258
|
import { resolve as resolve27 } from "path";
|
|
4259
|
+
import { safeGetMeta } from "@nexusts/core/di/safe-reflect";
|
|
4265
4260
|
var routeListCommand = {
|
|
4266
4261
|
name: "route:list",
|
|
4267
4262
|
aliases: ["routes", "route-list"],
|
|
@@ -4292,9 +4287,9 @@ var routeListCommand = {
|
|
|
4292
4287
|
const cls = mod[exportName];
|
|
4293
4288
|
if (typeof cls !== "function")
|
|
4294
4289
|
continue;
|
|
4295
|
-
const controllerMeta =
|
|
4290
|
+
const controllerMeta = safeGetMeta("nexus:controller", cls);
|
|
4296
4291
|
const prefix = controllerMeta?.prefix ?? "";
|
|
4297
|
-
const routeList =
|
|
4292
|
+
const routeList = safeGetMeta("nexus:routes", cls) ?? [];
|
|
4298
4293
|
for (const r of routeList) {
|
|
4299
4294
|
routes.push({
|
|
4300
4295
|
method: String(r.method).toUpperCase(),
|
|
@@ -4487,5 +4482,5 @@ main().then((code) => process.exit(code)).catch((err) => {
|
|
|
4487
4482
|
process.exit(1);
|
|
4488
4483
|
});
|
|
4489
4484
|
|
|
4490
|
-
//# debugId=
|
|
4485
|
+
//# debugId=CD81895BB61DC37964756E2164756E21
|
|
4491
4486
|
//# sourceMappingURL=index.js.map
|