From b45baeeb6ad4ef1def3dc82e742f26cc9b1e1cf8 Mon Sep 17 00:00:00 2001 From: Harminder virk Date: Sun, 15 Sep 2019 08:51:42 +0530 Subject: [PATCH] feat(server): accept nodeArgs to be passed to the node command line --- src/Commands/Build.ts | 2 +- src/Commands/Serve.ts | 10 +++++++++- src/Services/Compiler.ts | 5 +++-- src/Services/HttpServer.ts | 2 ++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Commands/Build.ts b/src/Commands/Build.ts index d91be3b..66b7877 100644 --- a/src/Commands/Build.ts +++ b/src/Commands/Build.ts @@ -42,7 +42,7 @@ export default class Build extends BaseCommand { return } - const compiler = new Compiler(this, this.projectRoot, rcContents) + const compiler = new Compiler(this, this.projectRoot, rcContents, []) /** * Pushing `package.json` and lock file to `copyToBuild` array, so that later we can run `npm install` diff --git a/src/Commands/Serve.ts b/src/Commands/Serve.ts index ff4ec63..281c29e 100644 --- a/src/Commands/Serve.ts +++ b/src/Commands/Serve.ts @@ -23,6 +23,9 @@ export default class Serve extends BaseCommand { @flags.boolean({ description: 'Watch for file changes' }) public dev: boolean + @flags.array({ description: 'Pass arguments to the node command' }) + public nodeArgs: string[] + /** * Reference to the project root. It always have to be * the current working directory @@ -39,7 +42,12 @@ export default class Serve extends BaseCommand { return } - const compiler = new Compiler(this, this.projectRoot, rcContents) + const compiler = new Compiler( + this, + this.projectRoot, + rcContents, + this.nodeArgs, + ) /** * Watch or compile project diff --git a/src/Services/Compiler.ts b/src/Services/Compiler.ts index 9b9cacd..6241bd4 100644 --- a/src/Services/Compiler.ts +++ b/src/Services/Compiler.ts @@ -53,6 +53,7 @@ export class Compiler { private _command: BaseCommand, private _projectRoot: string, private _rcFile: RcFile, + private _nodeArgs: string[], ) { const compilerPath = require.resolve('typescript/lib/typescript', { paths: [this._projectRoot] }) @@ -266,7 +267,7 @@ export class Compiler { */ if (startServer && !hasError) { console.log(this._command.colors.bgGreen().black(' Starting server ')) - new HttpServer(`${config.options.outDir}/server.js`, this._projectRoot).start() + new HttpServer(`${config.options.outDir}/server.js`, this._projectRoot, this._nodeArgs).start() } }) @@ -318,7 +319,7 @@ export class Compiler { /** * Reference to HTTP server */ - const httpServer = new HttpServer(`${config.options.outDir}/server.js`, this._projectRoot) + const httpServer = new HttpServer(`${config.options.outDir}/server.js`, this._projectRoot, this._nodeArgs) /** * Step 1: Cleanup build directory diff --git a/src/Services/HttpServer.ts b/src/Services/HttpServer.ts index 71f0052..a6deed7 100644 --- a/src/Services/HttpServer.ts +++ b/src/Services/HttpServer.ts @@ -21,6 +21,7 @@ export class HttpServer { constructor ( private _sourceFile: string, private _projectRoot: string, + private _nodeArgs: string[] = [], ) {} get isConnected () { @@ -39,6 +40,7 @@ export class HttpServer { buffer: false, cwd: this._projectRoot, env: getChildProcessEnvVariables(this._projectRoot), + nodeOptions: this._nodeArgs, }) /**