Skip to content

Commit

Permalink
fix(cli): update server template
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Nov 16, 2022
1 parent 8928cd7 commit 58e19d0
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ exports[`Init OIDC Provider project should generate a project with oidc 2`] = `
import {Configuration, Inject} from \\"@tsed/di\\";
import {PlatformApplication} from \\"@tsed/common\\";
import \\"@tsed/platform-express\\"; // /!\\\\ keep this import
import bodyParser from \\"body-parser\\";
import compress from \\"compression\\";
import cookieParser from \\"cookie-parser\\";
import methodOverride from \\"method-override\\";
import cors from \\"cors\\";
import \\"@tsed/ajv\\";
import \\"@tsed/oidc-provider\\";
import {config} from \\"./config/index\\";
Expand All @@ -90,14 +85,12 @@ import {InteractionsController} from \\"./controllers/oidc/InteractionsControlle
]
},
middlewares: [
cors(),
cookieParser(),
compress({}),
methodOverride(),
bodyParser.json(),
bodyParser.urlencoded({
extended: true
})
\\"cors\\",
\\"cookie-parser\\",
\\"compression\\",
\\"method-override\\",
\\"json-parser\\",
{ use: \\"urlencoded-parser\\", options: { extended: true }}
],
views: {
root: join(process.cwd(), \\"../views\\"),
Expand Down Expand Up @@ -180,11 +173,6 @@ exports[`Init OIDC Provider project should generate a project with oidc and swag
import {Configuration, Inject} from \\"@tsed/di\\";
import {PlatformApplication} from \\"@tsed/common\\";
import \\"@tsed/platform-express\\"; // /!\\\\ keep this import
import bodyParser from \\"body-parser\\";
import compress from \\"compression\\";
import cookieParser from \\"cookie-parser\\";
import methodOverride from \\"method-override\\";
import cors from \\"cors\\";
import \\"@tsed/ajv\\";
import \\"@tsed/swagger\\";
import \\"@tsed/oidc-provider\\";
Expand Down Expand Up @@ -215,14 +203,12 @@ import {InteractionsController} from \\"./controllers/oidc/InteractionsControlle
}
],
middlewares: [
cors(),
cookieParser(),
compress({}),
methodOverride(),
bodyParser.json(),
bodyParser.urlencoded({
extended: true
})
\\"cors\\",
\\"cookie-parser\\",
\\"compression\\",
\\"method-override\\",
\\"json-parser\\",
{ use: \\"urlencoded-parser\\", options: { extended: true }}
],
views: {
root: join(process.cwd(), \\"../views\\"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ exports[`Init TypeGraphQL project should generate a project with typegraphql 1`]
import {Configuration, Inject} from \\"@tsed/di\\";
import {PlatformApplication} from \\"@tsed/common\\";
import \\"@tsed/platform-express\\"; // /!\\\\ keep this import
import bodyParser from \\"body-parser\\";
import compress from \\"compression\\";
import cookieParser from \\"cookie-parser\\";
import methodOverride from \\"method-override\\";
import cors from \\"cors\\";
import \\"@tsed/ajv\\";
import \\"@tsed/typegraphql\\";
import \\"./datasources/index\\";
Expand All @@ -29,14 +24,12 @@ import * as rest from \\"./controllers/rest/index\\";
]
},
middlewares: [
cors(),
cookieParser(),
compress({}),
methodOverride(),
bodyParser.json(),
bodyParser.urlencoded({
extended: true
})
\\"cors\\",
\\"cookie-parser\\",
\\"compression\\",
\\"method-override\\",
\\"json-parser\\",
{ use: \\"urlencoded-parser\\", options: { extended: true }}
],
views: {
root: join(process.cwd(), \\"../views\\"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TypeORM: Init cmd 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
componentsScan: false,
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;
}
"
`;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe("TypeORM: Init cmd", () => {
]);

const content = FakeCliFs.entries.get("project-name/src/Server.ts")!;
expect(content).toEqual(readFile("data/Server.express.ts.txt", content, false));
expect(content).toMatchSnapshot();

const datasource = FakeCliFs.entries.get("project-name/src/datasources/MysqlDatasource.ts")!;
expect(datasource).toEqual(readFile("data/MysqlDatasource.ts.txt", datasource, false));
Expand Down
9 changes: 0 additions & 9 deletions packages/cli/src/utils/fillImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,7 @@ export function fillImports(ctx: any) {

ctx.imports = [
ctx.express && {from: "@tsed/platform-express", comment: " // /!\\ keep this import"},
ctx.express && {symbols: "bodyParser", from: "body-parser"},
ctx.express && {symbols: "compress", from: "compression"},
ctx.express && {symbols: "cookieParser", from: "cookie-parser"},
ctx.express && {symbols: "methodOverride", from: "method-override"},
ctx.express && {symbols: "cors", from: "cors"},
ctx.koa && {from: "@tsed/platform-koa", comment: " // /!\\ keep this import"},
ctx.koa && {symbols: "bodyParser", from: "koa-bodyparser"},
ctx.koa && {symbols: "compress", from: "koa-compress"},
ctx.koa && {symbols: "cors", from: "@koa/cors"},
ctx.koa && {symbols: "methodOverride", from: "koa-override", tsIgnore: true},
{from: "@tsed/ajv"},
ctx.swagger && {from: "@tsed/swagger"},
ctx.mongoose && {from: "@tsed/mongoose"},
Expand Down
22 changes: 10 additions & 12 deletions packages/cli/templates/generate/server.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,16 @@ import {PlatformApplication} from "@tsed/common";
}
],{{/if}}
middlewares: [{{#if express}}
cors(),
cookieParser(),
compress({}),
methodOverride(),
bodyParser.json(),
bodyParser.urlencoded({
extended: true
}){{/if}}{{#if koa}}
cors(),
compress({}),
methodOverride(),
bodyParser(){{/if}}
"cors",
"cookie-parser",
"compression",
"method-override",
"json-parser",
{ use: "urlencoded-parser", options: { extended: true }}{{/if}}{{#if koa}}
"@koa/cors",
"koa-compress",
"koa-override",
"koa-bodyparser"{{/if}}
],
views: {
root: join(process.cwd(), "../views"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import {join} from "path";
import {Configuration, Inject} from "@tsed/di";
import {PlatformApplication} from "@tsed/common";
import "@tsed/platform-express"; // /!\ keep this import
import bodyParser from "body-parser";
import compress from "compression";
import cookieParser from "cookie-parser";
import methodOverride from "method-override";
import cors from "cors";
import "@tsed/ajv";
import "@tsed/swagger";
import {config} from "./config/index";
Expand Down Expand Up @@ -34,14 +29,12 @@ import * as pages from "./controllers/pages/index";
}
],
middlewares: [
cors(),
cookieParser(),
compress({}),
methodOverride(),
bodyParser.json(),
bodyParser.urlencoded({
extended: true
})
"cors",
"cookie-parser",
"compression",
"method-override",
"json-parser",
{ use: "urlencoded-parser", options: { extended: true }}
],
views: {
root: join(process.cwd(), "../views"),
Expand Down
19 changes: 6 additions & 13 deletions packages/cli/test/integrations/init/data/Server.express.ts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import {join} from "path";
import {Configuration, Inject} from "@tsed/di";
import {PlatformApplication} from "@tsed/common";
import "@tsed/platform-express"; // /!\ keep this import
import bodyParser from "body-parser";
import compress from "compression";
import cookieParser from "cookie-parser";
import methodOverride from "method-override";
import cors from "cors";
import "@tsed/ajv";
import "@tsed/swagger";
import {config} from "./config/index";
Expand Down Expand Up @@ -34,14 +29,12 @@ import * as pages from "./controllers/pages/index";
}
],
middlewares: [
cors(),
cookieParser(),
compress({}),
methodOverride(),
bodyParser.json(),
bodyParser.urlencoded({
extended: true
})
"cors",
"cookie-parser",
"compression",
"method-override",
"json-parser",
{ use: "urlencoded-parser", options: { extended: true }}
],
views: {
root: join(process.cwd(), "../views"),
Expand Down
12 changes: 4 additions & 8 deletions packages/cli/test/integrations/init/data/Server.koa.ts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import {join} from "path";
import {Configuration, Inject} from "@tsed/di";
import {PlatformApplication} from "@tsed/common";
import "@tsed/platform-koa"; // /!\ keep this import
import bodyParser from "koa-bodyparser";
import compress from "koa-compress";
import cors from "@koa/cors";
import methodOverride from "koa-override";
import "@tsed/ajv";
import {config} from "./config/index";
import * as rest from "./controllers/rest/index";
Expand All @@ -22,10 +18,10 @@ import * as rest from "./controllers/rest/index";
]
},
middlewares: [
cors(),
compress({}),
methodOverride(),
bodyParser()
"@koa/cors",
"koa-compress",
"koa-override",
"koa-bodyparser"
],
views: {
root: join(process.cwd(), "../views"),
Expand Down

0 comments on commit 58e19d0

Please sign in to comment.