@lark-apaas/fullstack-nestjs-core 1.0.3-alpha.8 → 1.0.3-alpha.9
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/index.cjs +92 -8
- package/dist/index.js +92 -8
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -367,12 +367,12 @@ var import_path = require("path");
|
|
|
367
367
|
var import_hbs = require("hbs");
|
|
368
368
|
var import_cookie_parser = __toESM(require("cookie-parser"), 1);
|
|
369
369
|
|
|
370
|
-
// src/modules/devtool/index.ts
|
|
370
|
+
// src/modules/devtool-v2/index.ts
|
|
371
371
|
var import_swagger = require("@nestjs/swagger");
|
|
372
372
|
var import_node_fs3 = require("fs");
|
|
373
373
|
var import_node_path3 = require("path");
|
|
374
374
|
|
|
375
|
-
// src/modules/devtool/helper.ts
|
|
375
|
+
// src/modules/devtool-v2/helper.ts
|
|
376
376
|
var import_node_path = require("path");
|
|
377
377
|
var import_node_fs = require("fs");
|
|
378
378
|
function normalizeBasePath(rawBasePath) {
|
|
@@ -409,14 +409,14 @@ function ensureDirAndWrite(filePath, content) {
|
|
|
409
409
|
}
|
|
410
410
|
__name(ensureDirAndWrite, "ensureDirAndWrite");
|
|
411
411
|
|
|
412
|
-
// src/modules/devtool/plugins/client-config-generator.ts
|
|
412
|
+
// src/modules/devtool-v2/plugins/client-config-generator.ts
|
|
413
413
|
var import_node_fs2 = require("fs");
|
|
414
414
|
var import_node_path2 = require("path");
|
|
415
415
|
function generateClientConfig(options) {
|
|
416
416
|
const configFilePath = (0, import_node_path2.resolve)(options.outputPath, "client.config.ts");
|
|
417
417
|
const configContent = `// This file is auto-generated by @hey-api/openapi-ts
|
|
418
418
|
import axios from 'axios';
|
|
419
|
-
import type { CreateClientConfig } from './client
|
|
419
|
+
import type { CreateClientConfig } from './client';
|
|
420
420
|
export const createClientConfig: CreateClientConfig = (config) => ({
|
|
421
421
|
axios
|
|
422
422
|
});
|
|
@@ -426,10 +426,10 @@ export const createClientConfig: CreateClientConfig = (config) => ({
|
|
|
426
426
|
}
|
|
427
427
|
__name(generateClientConfig, "generateClientConfig");
|
|
428
428
|
|
|
429
|
-
// src/modules/devtool/index.ts
|
|
430
|
-
var
|
|
429
|
+
// src/modules/devtool-v2/index.ts
|
|
430
|
+
var DevToolsV2Module = class {
|
|
431
431
|
static {
|
|
432
|
-
__name(this, "
|
|
432
|
+
__name(this, "DevToolsV2Module");
|
|
433
433
|
}
|
|
434
434
|
static async mount(app, opts = {}) {
|
|
435
435
|
const options = resolveOptsWithDefaultValue(opts);
|
|
@@ -488,7 +488,7 @@ async function configureApp(app, options) {
|
|
|
488
488
|
app.setViewEngine("html");
|
|
489
489
|
app.engine("html", import_hbs.__express);
|
|
490
490
|
if (process.env.NODE_ENV !== "production") {
|
|
491
|
-
await
|
|
491
|
+
await DevToolsV2Module.mount(app, {
|
|
492
492
|
basePath: process.env.CLIENT_BASE_PATH,
|
|
493
493
|
docsPath: "/api_docs"
|
|
494
494
|
});
|
|
@@ -496,6 +496,90 @@ async function configureApp(app, options) {
|
|
|
496
496
|
}
|
|
497
497
|
__name(configureApp, "configureApp");
|
|
498
498
|
|
|
499
|
+
// src/modules/devtool/index.ts
|
|
500
|
+
var import_swagger2 = require("@nestjs/swagger");
|
|
501
|
+
var import_node_fs5 = require("fs");
|
|
502
|
+
var import_node_path5 = require("path");
|
|
503
|
+
|
|
504
|
+
// src/modules/devtool/helper.ts
|
|
505
|
+
var import_node_path4 = require("path");
|
|
506
|
+
var import_node_fs4 = require("fs");
|
|
507
|
+
function normalizeBasePath2(rawBasePath) {
|
|
508
|
+
const normalizedBasePath = rawBasePath.startsWith("/") ? rawBasePath : `/${rawBasePath}`;
|
|
509
|
+
return normalizedBasePath.endsWith("/") ? normalizedBasePath.slice(0, -1) : normalizedBasePath;
|
|
510
|
+
}
|
|
511
|
+
__name(normalizeBasePath2, "normalizeBasePath");
|
|
512
|
+
function resolveOptsWithDefaultValue2(options) {
|
|
513
|
+
const basePath = normalizeBasePath2(options.basePath || "/");
|
|
514
|
+
const docsPath = normalizeBasePath2(options.docsPath || `api/docs`);
|
|
515
|
+
return {
|
|
516
|
+
...options,
|
|
517
|
+
needSetupServer: options.needSetupServer ?? false,
|
|
518
|
+
basePath,
|
|
519
|
+
docsPath: `${basePath}${docsPath}`,
|
|
520
|
+
openapiOut: options.openapiOut || "./client/src/api/gen/openapi.json",
|
|
521
|
+
clientSdkOut: options.clientSdkOut || "./client/src/api/gen",
|
|
522
|
+
needGenerateClientSdk: options.needGenerateClientSdk ?? true,
|
|
523
|
+
swaggerOptions: {
|
|
524
|
+
title: options.swaggerOptions?.title ?? "NestJS Fullstack API",
|
|
525
|
+
version: options.swaggerOptions?.version ?? "1.0.0",
|
|
526
|
+
customSiteTitle: options.swaggerOptions?.customSiteTitle ?? "API Documentation",
|
|
527
|
+
customCss: options.swaggerOptions?.customCss ?? ".swagger-ui .topbar { display: none }"
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
__name(resolveOptsWithDefaultValue2, "resolveOptsWithDefaultValue");
|
|
532
|
+
function ensureDirAndWrite2(filePath, content) {
|
|
533
|
+
const dir = (0, import_node_path4.dirname)(filePath);
|
|
534
|
+
(0, import_node_fs4.mkdirSync)(dir, {
|
|
535
|
+
recursive: true
|
|
536
|
+
});
|
|
537
|
+
(0, import_node_fs4.writeFileSync)(filePath, content);
|
|
538
|
+
}
|
|
539
|
+
__name(ensureDirAndWrite2, "ensureDirAndWrite");
|
|
540
|
+
|
|
541
|
+
// src/modules/devtool/index.ts
|
|
542
|
+
var DevToolsModule = class {
|
|
543
|
+
static {
|
|
544
|
+
__name(this, "DevToolsModule");
|
|
545
|
+
}
|
|
546
|
+
static async mount(app, opts = {}) {
|
|
547
|
+
const options = resolveOptsWithDefaultValue2(opts);
|
|
548
|
+
const baseDirname = process.cwd();
|
|
549
|
+
const builder = new import_swagger2.DocumentBuilder().setTitle(options.swaggerOptions.title).setVersion(options.swaggerOptions.version);
|
|
550
|
+
const document = import_swagger2.SwaggerModule.createDocument(app, builder.build(), {
|
|
551
|
+
operationIdFactory: /* @__PURE__ */ __name((_c, m) => m, "operationIdFactory")
|
|
552
|
+
});
|
|
553
|
+
if (options.needSetupServer) {
|
|
554
|
+
import_swagger2.SwaggerModule.setup(options.docsPath, app, document, {
|
|
555
|
+
customSiteTitle: options.swaggerOptions.customSiteTitle,
|
|
556
|
+
customCss: options.swaggerOptions.customCss,
|
|
557
|
+
swaggerOptions: {
|
|
558
|
+
persistAuthorization: true
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
console.log(`[OpenAPI] Swagger UI \u5DF2\u6302\u8F7D\u81F3 ${options.docsPath}`);
|
|
562
|
+
}
|
|
563
|
+
const openapiPath = (0, import_node_path5.resolve)(baseDirname, options.openapiOut);
|
|
564
|
+
ensureDirAndWrite2(openapiPath, JSON.stringify(document, null, 2));
|
|
565
|
+
if (options.needGenerateClientSdk) {
|
|
566
|
+
const clientSdkOutPath = (0, import_node_path5.resolve)(baseDirname, options.clientSdkOut);
|
|
567
|
+
(0, import_node_fs5.mkdirSync)(clientSdkOutPath, {
|
|
568
|
+
recursive: true
|
|
569
|
+
});
|
|
570
|
+
const { generate } = await import("openapi-typescript-codegen");
|
|
571
|
+
await generate({
|
|
572
|
+
input: openapiPath,
|
|
573
|
+
output: clientSdkOutPath,
|
|
574
|
+
httpClient: "axios",
|
|
575
|
+
useOptions: false,
|
|
576
|
+
exportServices: true
|
|
577
|
+
});
|
|
578
|
+
console.log("[OpenAPI] \u5BFC\u51FA openapi.json \u5E76\u751F\u6210 axios SDK \u2705");
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
|
|
499
583
|
// src/index.ts
|
|
500
584
|
__reExport(index_exports, require("@lark-apaas/nestjs-authnpaas"), module.exports);
|
|
501
585
|
__reExport(index_exports, require("@lark-apaas/nestjs-datapaas"), module.exports);
|
package/dist/index.js
CHANGED
|
@@ -326,12 +326,12 @@ import { join as join2 } from "path";
|
|
|
326
326
|
import { __express as hbsExpressEngine } from "hbs";
|
|
327
327
|
import cookieParser from "cookie-parser";
|
|
328
328
|
|
|
329
|
-
// src/modules/devtool/index.ts
|
|
329
|
+
// src/modules/devtool-v2/index.ts
|
|
330
330
|
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
|
|
331
331
|
import { mkdirSync as mkdirSync2 } from "fs";
|
|
332
332
|
import { resolve as resolve2, join } from "path";
|
|
333
333
|
|
|
334
|
-
// src/modules/devtool/helper.ts
|
|
334
|
+
// src/modules/devtool-v2/helper.ts
|
|
335
335
|
import { dirname } from "path";
|
|
336
336
|
import { writeFileSync, mkdirSync } from "fs";
|
|
337
337
|
function normalizeBasePath(rawBasePath) {
|
|
@@ -368,14 +368,14 @@ function ensureDirAndWrite(filePath, content) {
|
|
|
368
368
|
}
|
|
369
369
|
__name(ensureDirAndWrite, "ensureDirAndWrite");
|
|
370
370
|
|
|
371
|
-
// src/modules/devtool/plugins/client-config-generator.ts
|
|
371
|
+
// src/modules/devtool-v2/plugins/client-config-generator.ts
|
|
372
372
|
import { writeFileSync as writeFileSync2 } from "fs";
|
|
373
373
|
import { resolve } from "path";
|
|
374
374
|
function generateClientConfig(options) {
|
|
375
375
|
const configFilePath = resolve(options.outputPath, "client.config.ts");
|
|
376
376
|
const configContent = `// This file is auto-generated by @hey-api/openapi-ts
|
|
377
377
|
import axios from 'axios';
|
|
378
|
-
import type { CreateClientConfig } from './client
|
|
378
|
+
import type { CreateClientConfig } from './client';
|
|
379
379
|
export const createClientConfig: CreateClientConfig = (config) => ({
|
|
380
380
|
axios
|
|
381
381
|
});
|
|
@@ -385,10 +385,10 @@ export const createClientConfig: CreateClientConfig = (config) => ({
|
|
|
385
385
|
}
|
|
386
386
|
__name(generateClientConfig, "generateClientConfig");
|
|
387
387
|
|
|
388
|
-
// src/modules/devtool/index.ts
|
|
389
|
-
var
|
|
388
|
+
// src/modules/devtool-v2/index.ts
|
|
389
|
+
var DevToolsV2Module = class {
|
|
390
390
|
static {
|
|
391
|
-
__name(this, "
|
|
391
|
+
__name(this, "DevToolsV2Module");
|
|
392
392
|
}
|
|
393
393
|
static async mount(app, opts = {}) {
|
|
394
394
|
const options = resolveOptsWithDefaultValue(opts);
|
|
@@ -447,7 +447,7 @@ async function configureApp(app, options) {
|
|
|
447
447
|
app.setViewEngine("html");
|
|
448
448
|
app.engine("html", hbsExpressEngine);
|
|
449
449
|
if (process.env.NODE_ENV !== "production") {
|
|
450
|
-
await
|
|
450
|
+
await DevToolsV2Module.mount(app, {
|
|
451
451
|
basePath: process.env.CLIENT_BASE_PATH,
|
|
452
452
|
docsPath: "/api_docs"
|
|
453
453
|
});
|
|
@@ -455,6 +455,90 @@ async function configureApp(app, options) {
|
|
|
455
455
|
}
|
|
456
456
|
__name(configureApp, "configureApp");
|
|
457
457
|
|
|
458
|
+
// src/modules/devtool/index.ts
|
|
459
|
+
import { SwaggerModule as SwaggerModule2, DocumentBuilder as DocumentBuilder2 } from "@nestjs/swagger";
|
|
460
|
+
import { mkdirSync as mkdirSync4 } from "fs";
|
|
461
|
+
import { resolve as resolve3 } from "path";
|
|
462
|
+
|
|
463
|
+
// src/modules/devtool/helper.ts
|
|
464
|
+
import { dirname as dirname2 } from "path";
|
|
465
|
+
import { writeFileSync as writeFileSync3, mkdirSync as mkdirSync3 } from "fs";
|
|
466
|
+
function normalizeBasePath2(rawBasePath) {
|
|
467
|
+
const normalizedBasePath = rawBasePath.startsWith("/") ? rawBasePath : `/${rawBasePath}`;
|
|
468
|
+
return normalizedBasePath.endsWith("/") ? normalizedBasePath.slice(0, -1) : normalizedBasePath;
|
|
469
|
+
}
|
|
470
|
+
__name(normalizeBasePath2, "normalizeBasePath");
|
|
471
|
+
function resolveOptsWithDefaultValue2(options) {
|
|
472
|
+
const basePath = normalizeBasePath2(options.basePath || "/");
|
|
473
|
+
const docsPath = normalizeBasePath2(options.docsPath || `api/docs`);
|
|
474
|
+
return {
|
|
475
|
+
...options,
|
|
476
|
+
needSetupServer: options.needSetupServer ?? false,
|
|
477
|
+
basePath,
|
|
478
|
+
docsPath: `${basePath}${docsPath}`,
|
|
479
|
+
openapiOut: options.openapiOut || "./client/src/api/gen/openapi.json",
|
|
480
|
+
clientSdkOut: options.clientSdkOut || "./client/src/api/gen",
|
|
481
|
+
needGenerateClientSdk: options.needGenerateClientSdk ?? true,
|
|
482
|
+
swaggerOptions: {
|
|
483
|
+
title: options.swaggerOptions?.title ?? "NestJS Fullstack API",
|
|
484
|
+
version: options.swaggerOptions?.version ?? "1.0.0",
|
|
485
|
+
customSiteTitle: options.swaggerOptions?.customSiteTitle ?? "API Documentation",
|
|
486
|
+
customCss: options.swaggerOptions?.customCss ?? ".swagger-ui .topbar { display: none }"
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
__name(resolveOptsWithDefaultValue2, "resolveOptsWithDefaultValue");
|
|
491
|
+
function ensureDirAndWrite2(filePath, content) {
|
|
492
|
+
const dir = dirname2(filePath);
|
|
493
|
+
mkdirSync3(dir, {
|
|
494
|
+
recursive: true
|
|
495
|
+
});
|
|
496
|
+
writeFileSync3(filePath, content);
|
|
497
|
+
}
|
|
498
|
+
__name(ensureDirAndWrite2, "ensureDirAndWrite");
|
|
499
|
+
|
|
500
|
+
// src/modules/devtool/index.ts
|
|
501
|
+
var DevToolsModule = class {
|
|
502
|
+
static {
|
|
503
|
+
__name(this, "DevToolsModule");
|
|
504
|
+
}
|
|
505
|
+
static async mount(app, opts = {}) {
|
|
506
|
+
const options = resolveOptsWithDefaultValue2(opts);
|
|
507
|
+
const baseDirname = process.cwd();
|
|
508
|
+
const builder = new DocumentBuilder2().setTitle(options.swaggerOptions.title).setVersion(options.swaggerOptions.version);
|
|
509
|
+
const document = SwaggerModule2.createDocument(app, builder.build(), {
|
|
510
|
+
operationIdFactory: /* @__PURE__ */ __name((_c, m) => m, "operationIdFactory")
|
|
511
|
+
});
|
|
512
|
+
if (options.needSetupServer) {
|
|
513
|
+
SwaggerModule2.setup(options.docsPath, app, document, {
|
|
514
|
+
customSiteTitle: options.swaggerOptions.customSiteTitle,
|
|
515
|
+
customCss: options.swaggerOptions.customCss,
|
|
516
|
+
swaggerOptions: {
|
|
517
|
+
persistAuthorization: true
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
console.log(`[OpenAPI] Swagger UI \u5DF2\u6302\u8F7D\u81F3 ${options.docsPath}`);
|
|
521
|
+
}
|
|
522
|
+
const openapiPath = resolve3(baseDirname, options.openapiOut);
|
|
523
|
+
ensureDirAndWrite2(openapiPath, JSON.stringify(document, null, 2));
|
|
524
|
+
if (options.needGenerateClientSdk) {
|
|
525
|
+
const clientSdkOutPath = resolve3(baseDirname, options.clientSdkOut);
|
|
526
|
+
mkdirSync4(clientSdkOutPath, {
|
|
527
|
+
recursive: true
|
|
528
|
+
});
|
|
529
|
+
const { generate } = await import("openapi-typescript-codegen");
|
|
530
|
+
await generate({
|
|
531
|
+
input: openapiPath,
|
|
532
|
+
output: clientSdkOutPath,
|
|
533
|
+
httpClient: "axios",
|
|
534
|
+
useOptions: false,
|
|
535
|
+
exportServices: true
|
|
536
|
+
});
|
|
537
|
+
console.log("[OpenAPI] \u5BFC\u51FA openapi.json \u5E76\u751F\u6210 axios SDK \u2705");
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
|
|
458
542
|
// src/index.ts
|
|
459
543
|
export * from "@lark-apaas/nestjs-authnpaas";
|
|
460
544
|
export * from "@lark-apaas/nestjs-datapaas";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-nestjs-core",
|
|
3
|
-
"version": "1.0.3-alpha.
|
|
3
|
+
"version": "1.0.3-alpha.9",
|
|
4
4
|
"description": "FullStack Nestjs Core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@hey-api/openapi-ts": "^0.86.11",
|
|
44
|
+
"openapi-typescript-codegen": "^0.29.0",
|
|
44
45
|
"@lark-apaas/nestjs-authnpaas": "^1.0.0",
|
|
45
46
|
"@lark-apaas/nestjs-datapaas": "^1.0.1",
|
|
46
47
|
"@lark-apaas/nestjs-logger": "^1.0.0",
|