diff --git a/packages/cli-core/src/services/CliService.ts b/packages/cli-core/src/services/CliService.ts index 820dbb1cd..ebe900d69 100644 --- a/packages/cli-core/src/services/CliService.ts +++ b/packages/cli-core/src/services/CliService.ts @@ -16,7 +16,7 @@ import {ProjectPackageJson} from "./ProjectPackageJson"; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore import inquirer_autocomplete_prompt from "inquirer-autocomplete-prompt"; -import {mapCommanderOptions} from "@tsed/cli-core"; +import {mapCommanderOptions} from "../utils/mapCommanderOptions"; Inquirer.registerPrompt("autocomplete", inquirer_autocomplete_prompt); diff --git a/packages/cli-plugin-oidc-provider/test/init/__snapshots__/init.integration.spec.ts.snap b/packages/cli-plugin-oidc-provider/test/init/__snapshots__/init.integration.spec.ts.snap index ff8a8959c..3d3f85003 100644 --- a/packages/cli-plugin-oidc-provider/test/init/__snapshots__/init.integration.spec.ts.snap +++ b/packages/cli-plugin-oidc-provider/test/init/__snapshots__/init.integration.spec.ts.snap @@ -75,7 +75,7 @@ import {InteractionsController} from \\"./controllers/oidc/InteractionsControlle acceptMimes: [\\"application/json\\"], httpPort: process.env.PORT || 8083, httpsPort: false, // CHANGE - componentsScan: false, + disableComponentsScan: true mount: { \\"/rest\\": [ ...Object.values(rest) @@ -186,7 +186,7 @@ import {InteractionsController} from \\"./controllers/oidc/InteractionsControlle acceptMimes: [\\"application/json\\"], httpPort: process.env.PORT || 8083, httpsPort: false, // CHANGE - componentsScan: false, + disableComponentsScan: true mount: { \\"/rest\\": [ ...Object.values(rest) diff --git a/packages/cli-plugin-typegraphql/test/init/__snapshots__/init.integration.spec.ts.snap b/packages/cli-plugin-typegraphql/test/init/__snapshots__/init.integration.spec.ts.snap index 1a928923a..08f3d2528 100644 --- a/packages/cli-plugin-typegraphql/test/init/__snapshots__/init.integration.spec.ts.snap +++ b/packages/cli-plugin-typegraphql/test/init/__snapshots__/init.integration.spec.ts.snap @@ -17,7 +17,7 @@ import * as rest from \\"./controllers/rest/index\\"; acceptMimes: [\\"application/json\\"], httpPort: process.env.PORT || 8083, httpsPort: false, // CHANGE - componentsScan: false, + disableComponentsScan: true mount: { \\"/rest\\": [ ...Object.values(rest) diff --git a/packages/cli-plugin-typeorm/test/integrations/init/__snapshots__/init.integration.spec.ts.snap b/packages/cli-plugin-typeorm/test/integrations/init/__snapshots__/init.integration.spec.ts.snap index f2854a8b1..ced700dc5 100644 --- a/packages/cli-plugin-typeorm/test/integrations/init/__snapshots__/init.integration.spec.ts.snap +++ b/packages/cli-plugin-typeorm/test/integrations/init/__snapshots__/init.integration.spec.ts.snap @@ -14,7 +14,7 @@ import * as rest from \\"./controllers/rest/index\\"; acceptMimes: [\\"application/json\\"], httpPort: process.env.PORT || 8083, httpsPort: false, // CHANGE - componentsScan: false, + disableComponentsScan: true mount: { \\"/rest\\": [ ...Object.values(rest) diff --git a/packages/cli/templates/generate/server.hbs b/packages/cli/templates/generate/server.hbs index 23c0cc50b..0df297876 100644 --- a/packages/cli/templates/generate/server.hbs +++ b/packages/cli/templates/generate/server.hbs @@ -11,7 +11,7 @@ import {PlatformApplication} from "@tsed/common"; acceptMimes: ["application/json"], httpPort: process.env.PORT || 8083, httpsPort: false, // CHANGE - componentsScan: false, + disableComponentsScan: true mount: { "{{route}}": [ ...Object.values(rest) diff --git a/packages/cli/test/integrations/init/__snapshots__/init.integration.spec.ts.snap b/packages/cli/test/integrations/init/__snapshots__/init.integration.spec.ts.snap new file mode 100644 index 000000000..bce297014 --- /dev/null +++ b/packages/cli/test/integrations/init/__snapshots__/init.integration.spec.ts.snap @@ -0,0 +1,261 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Init cmd Express.js should generate a project with Convention ANGULAR 1`] = ` +"import {join} from \\"path\\"; +import {Configuration, Inject} from \\"@tsed/di\\"; +import {PlatformApplication} from \\"@tsed/common\\"; +import \\"@tsed/platform-express\\"; // /!\\\\ keep this import +import \\"@tsed/ajv\\"; +import \\"@tsed/swagger\\"; +import {config} from \\"./config/index\\"; +import * as rest from \\"./controllers/rest/index\\"; +import * as pages from \\"./controllers/pages/index\\"; + +@Configuration({ + ...config, + acceptMimes: [\\"application/json\\"], + httpPort: process.env.PORT || 8083, + httpsPort: false, // CHANGE + disableComponentsScan: true + mount: { + \\"/rest\\": [ + ...Object.values(rest) + ], + \\"/\\": [ + ...Object.values(pages) + ] + }, + swagger: [ + { + path: \\"/doc\\", + specVersion: \\"3.0.1\\" + } + ], + middlewares: [ + \\"cors\\", + \\"cookie-parser\\", + \\"compression\\", + \\"method-override\\", + \\"json-parser\\", + { use: \\"urlencoded-parser\\", options: { extended: true }} + ], + views: { + root: join(process.cwd(), \\"../views\\"), + extensions: { + ejs: \\"ejs\\" + } + }, + exclude: [ + \\"**/*.spec.ts\\" + ] +}) +export class Server { + @Inject() + protected app: PlatformApplication; + + @Configuration() + protected settings: Configuration; +} +" +`; + +exports[`Init cmd Express.js should generate a project with NPM 1`] = ` +"import {join} from \\"path\\"; +import {Configuration, Inject} from \\"@tsed/di\\"; +import {PlatformApplication} from \\"@tsed/common\\"; +import \\"@tsed/platform-express\\"; // /!\\\\ keep this import +import \\"@tsed/ajv\\"; +import {config} from \\"./config/index\\"; +import * as rest from \\"./controllers/rest/index\\"; + +@Configuration({ + ...config, + acceptMimes: [\\"application/json\\"], + httpPort: process.env.PORT || 8083, + httpsPort: false, // CHANGE + disableComponentsScan: true + mount: { + \\"/rest\\": [ + ...Object.values(rest) + ] + }, + middlewares: [ + \\"cors\\", + \\"cookie-parser\\", + \\"compression\\", + \\"method-override\\", + \\"json-parser\\", + { use: \\"urlencoded-parser\\", options: { extended: true }} + ], + views: { + root: join(process.cwd(), \\"../views\\"), + extensions: { + ejs: \\"ejs\\" + } + }, + exclude: [ + \\"**/*.spec.ts\\" + ] +}) +export class Server { + @Inject() + protected app: PlatformApplication; + + @Configuration() + protected settings: Configuration; +} +" +`; + +exports[`Init cmd Express.js should generate a project with swagger 1`] = ` +"import {join} from \\"path\\"; +import {Configuration, Inject} from \\"@tsed/di\\"; +import {PlatformApplication} from \\"@tsed/common\\"; +import \\"@tsed/platform-express\\"; // /!\\\\ keep this import +import \\"@tsed/ajv\\"; +import \\"@tsed/swagger\\"; +import {config} from \\"./config/index\\"; +import * as rest from \\"./controllers/rest/index\\"; +import * as pages from \\"./controllers/pages/index\\"; + +@Configuration({ + ...config, + acceptMimes: [\\"application/json\\"], + httpPort: process.env.PORT || 8083, + httpsPort: false, // CHANGE + disableComponentsScan: true + mount: { + \\"/rest\\": [ + ...Object.values(rest) + ], + \\"/\\": [ + ...Object.values(pages) + ] + }, + swagger: [ + { + path: \\"/doc\\", + specVersion: \\"3.0.1\\" + } + ], + middlewares: [ + \\"cors\\", + \\"cookie-parser\\", + \\"compression\\", + \\"method-override\\", + \\"json-parser\\", + { use: \\"urlencoded-parser\\", options: { extended: true }} + ], + views: { + root: join(process.cwd(), \\"../views\\"), + extensions: { + ejs: \\"ejs\\" + } + }, + exclude: [ + \\"**/*.spec.ts\\" + ] +}) +export class Server { + @Inject() + protected app: PlatformApplication; + + @Configuration() + protected settings: Configuration; +} +" +`; + +exports[`Init cmd Express.js should generate a project with the right options 1`] = ` +"import {join} from \\"path\\"; +import {Configuration, Inject} from \\"@tsed/di\\"; +import {PlatformApplication} from \\"@tsed/common\\"; +import \\"@tsed/platform-express\\"; // /!\\\\ keep this import +import \\"@tsed/ajv\\"; +import {config} from \\"./config/index\\"; +import * as rest from \\"./controllers/rest/index\\"; + +@Configuration({ + ...config, + acceptMimes: [\\"application/json\\"], + httpPort: process.env.PORT || 8083, + httpsPort: false, // CHANGE + disableComponentsScan: true + mount: { + \\"/rest\\": [ + ...Object.values(rest) + ] + }, + middlewares: [ + \\"cors\\", + \\"cookie-parser\\", + \\"compression\\", + \\"method-override\\", + \\"json-parser\\", + { use: \\"urlencoded-parser\\", options: { extended: true }} + ], + views: { + root: join(process.cwd(), \\"../views\\"), + extensions: { + ejs: \\"ejs\\" + } + }, + exclude: [ + \\"**/*.spec.ts\\" + ] +}) +export class Server { + @Inject() + protected app: PlatformApplication; + + @Configuration() + protected settings: Configuration; +} +" +`; + +exports[`Init cmd Koa.js should generate a project with the right options 1`] = ` +"import {join} from \\"path\\"; +import {Configuration, Inject} from \\"@tsed/di\\"; +import {PlatformApplication} from \\"@tsed/common\\"; +import \\"@tsed/platform-koa\\"; // /!\\\\ keep this import +import \\"@tsed/ajv\\"; +import {config} from \\"./config/index\\"; +import * as rest from \\"./controllers/rest/index\\"; + +@Configuration({ + ...config, + acceptMimes: [\\"application/json\\"], + httpPort: process.env.PORT || 8083, + httpsPort: false, // CHANGE + disableComponentsScan: true + mount: { + \\"/rest\\": [ + ...Object.values(rest) + ] + }, + middlewares: [ + \\"@koa/cors\\", + \\"koa-compress\\", + \\"koa-override\\", + \\"koa-bodyparser\\" + ], + views: { + root: join(process.cwd(), \\"../views\\"), + extensions: { + ejs: \\"ejs\\" + } + }, + exclude: [ + \\"**/*.spec.ts\\" + ] +}) +export class Server { + @Inject() + protected app: PlatformApplication; + + @Configuration() + protected settings: Configuration; +} +" +`; diff --git a/packages/cli/test/integrations/init/data/Server.express.swagger.ts.txt b/packages/cli/test/integrations/init/data/Server.express.swagger.ts.txt deleted file mode 100644 index 80c92a481..000000000 --- a/packages/cli/test/integrations/init/data/Server.express.swagger.ts.txt +++ /dev/null @@ -1,55 +0,0 @@ -import {join} from "path"; -import {Configuration, Inject} from "@tsed/di"; -import {PlatformApplication} from "@tsed/common"; -import "@tsed/platform-express"; // /!\ keep this import -import "@tsed/ajv"; -import "@tsed/swagger"; -import {config} from "./config/index"; -import * as rest from "./controllers/rest/index"; -import * as pages from "./controllers/pages/index"; - -@Configuration({ - ...config, - acceptMimes: ["application/json"], - httpPort: process.env.PORT || 8083, - httpsPort: false, // CHANGE - componentsScan: false, - mount: { - "/rest": [ - ...Object.values(rest) - ], - "/": [ - ...Object.values(pages) - ] - }, - swagger: [ - { - path: "/doc", - specVersion: "3.0.1" - } - ], - middlewares: [ - "cors", - "cookie-parser", - "compression", - "method-override", - "json-parser", - { use: "urlencoded-parser", options: { extended: true }} - ], - views: { - root: join(process.cwd(), "../views"), - extensions: { - ejs: "ejs" - } - }, - exclude: [ - "**/*.spec.ts" - ] -}) -export class Server { - @Inject() - protected app: PlatformApplication; - - @Configuration() - protected settings: Configuration; -} diff --git a/packages/cli/test/integrations/init/data/Server.express.ts.txt b/packages/cli/test/integrations/init/data/Server.express.ts.txt deleted file mode 100644 index 80c92a481..000000000 --- a/packages/cli/test/integrations/init/data/Server.express.ts.txt +++ /dev/null @@ -1,55 +0,0 @@ -import {join} from "path"; -import {Configuration, Inject} from "@tsed/di"; -import {PlatformApplication} from "@tsed/common"; -import "@tsed/platform-express"; // /!\ keep this import -import "@tsed/ajv"; -import "@tsed/swagger"; -import {config} from "./config/index"; -import * as rest from "./controllers/rest/index"; -import * as pages from "./controllers/pages/index"; - -@Configuration({ - ...config, - acceptMimes: ["application/json"], - httpPort: process.env.PORT || 8083, - httpsPort: false, // CHANGE - componentsScan: false, - mount: { - "/rest": [ - ...Object.values(rest) - ], - "/": [ - ...Object.values(pages) - ] - }, - swagger: [ - { - path: "/doc", - specVersion: "3.0.1" - } - ], - middlewares: [ - "cors", - "cookie-parser", - "compression", - "method-override", - "json-parser", - { use: "urlencoded-parser", options: { extended: true }} - ], - views: { - root: join(process.cwd(), "../views"), - extensions: { - ejs: "ejs" - } - }, - exclude: [ - "**/*.spec.ts" - ] -}) -export class Server { - @Inject() - protected app: PlatformApplication; - - @Configuration() - protected settings: Configuration; -} diff --git a/packages/cli/test/integrations/init/data/Server.koa.ts.txt b/packages/cli/test/integrations/init/data/Server.koa.ts.txt deleted file mode 100644 index f25221280..000000000 --- a/packages/cli/test/integrations/init/data/Server.koa.ts.txt +++ /dev/null @@ -1,42 +0,0 @@ -import {join} from "path"; -import {Configuration, Inject} from "@tsed/di"; -import {PlatformApplication} from "@tsed/common"; -import "@tsed/platform-koa"; // /!\ keep this import -import "@tsed/ajv"; -import {config} from "./config/index"; -import * as rest from "./controllers/rest/index"; - -@Configuration({ - ...config, - acceptMimes: ["application/json"], - httpPort: process.env.PORT || 8083, - httpsPort: false, // CHANGE - componentsScan: false, - mount: { - "/rest": [ - ...Object.values(rest) - ] - }, - middlewares: [ - "@koa/cors", - "koa-compress", - "koa-override", - "koa-bodyparser" - ], - views: { - root: join(process.cwd(), "../views"), - extensions: { - ejs: "ejs" - } - }, - exclude: [ - "**/*.spec.ts" - ] -}) -export class Server { - @Inject() - protected app: PlatformApplication; - - @Configuration() - protected settings: Configuration; -} diff --git a/packages/cli/test/integrations/init/init.integration.spec.ts b/packages/cli/test/integrations/init/init.integration.spec.ts index 30c603005..829bd9fcf 100644 --- a/packages/cli/test/integrations/init/init.integration.spec.ts +++ b/packages/cli/test/integrations/init/init.integration.spec.ts @@ -7,18 +7,6 @@ import filedirname from "filedirname"; const [, dir] = filedirname(); -function readFile(file: string, content: string, rewrite = true) { - const path = `${dir}/${file}` - - ensureDirSync(dirname(path)) - - if (!existsSync(path) || rewrite) { - writeFileSync(path, content, {encoding: "utf8"}); - } - - return readFileSync(path, {encoding: "utf8"}); -} - describe("Init cmd", () => { beforeEach(() => { return CliPlatformTest.bootstrap({ @@ -86,7 +74,7 @@ describe("Init cmd", () => { expect(content).toContain("import {Configuration, Inject} from \"@tsed/di\""); expect(content).toContain("import \"@tsed/platform-express\""); expect(content).toContain("import \"@tsed/ajv\""); - expect(content).toEqual(readFile("data/Server.express.ts.txt", content)); + expect(content).toMatchSnapshot(); const pkg = JSON.parse(FakeCliFs.entries.get("project-name/package.json")!); expect(pkg).toEqual({ @@ -186,7 +174,7 @@ describe("Init cmd", () => { expect(content).toContain("import \"@tsed/platform-express\""); expect(content).toContain("import \"@tsed/ajv\""); expect(content).toContain("import * as pages from \"./controllers/pages/index\""); - expect(content).toEqual(readFile("data/Server.express.swagger.ts.txt", content)); + expect(content).toMatchSnapshot(); const pkg = JSON.parse(FakeCliFs.entries.get("project-name/package.json")!); expect(pkg).toEqual({ @@ -280,7 +268,7 @@ describe("Init cmd", () => { expect(content).toContain("import {Configuration, Inject} from \"@tsed/di\""); expect(content).toContain("import \"@tsed/platform-express\""); expect(content).toContain("import \"@tsed/ajv\""); - expect(content).toEqual(readFile("data/Server.express.ts.txt", content)); + expect(content).toMatchSnapshot(); const pkg = JSON.parse(FakeCliFs.entries.get("project-name/package.json")!); expect(pkg).toEqual({ @@ -385,7 +373,7 @@ describe("Init cmd", () => { expect(content).toContain("import {Configuration, Inject} from \"@tsed/di\""); expect(content).toContain("import \"@tsed/platform-express\""); expect(content).toContain("import \"@tsed/ajv\""); - expect(content).toEqual(readFile("data/Server.express.ts.txt", content)); + expect(content).toMatchSnapshot(); expect(content).toContain("import * as pages from \"./controllers/pages/index\""); expect(content).toContain("export class Server {"); }); @@ -449,7 +437,7 @@ describe("Init cmd", () => { expect(content).toContain("import {Configuration, Inject} from \"@tsed/di\""); expect(content).toContain("import \"@tsed/platform-koa\""); expect(content).toContain("import \"@tsed/ajv\""); - expect(content).toEqual(readFile("data/Server.koa.ts.txt", content)); + expect(content).toMatchSnapshot(); const pkg = JSON.parse(FakeCliFs.entries.get("project-name/package.json")!); expect(pkg).toEqual({