From 5b1fbb9f3dd2e227c2f904bed024df97fcb715be Mon Sep 17 00:00:00 2001 From: ZimGil Date: Sun, 2 Dec 2018 01:38:18 +0200 Subject: [PATCH 01/13] config file added ready to be implemented --- config/config.interface.ts | 16 ++++++++++++++++ config/config.json | 8 ++++++++ config/config.manager.ts | 37 +++++++++++++++++++++++++++++++++++++ config/tsconfig.json | 21 +++++++++++++++++++++ package.json | 4 ++-- tsconfig.json | 2 +- 6 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 config/config.interface.ts create mode 100644 config/config.json create mode 100644 config/config.manager.ts create mode 100644 config/tsconfig.json diff --git a/config/config.interface.ts b/config/config.interface.ts new file mode 100644 index 0000000..3cb856d --- /dev/null +++ b/config/config.interface.ts @@ -0,0 +1,16 @@ +export interface ConfigInterface { + // The port ngWiz server is listening to. + port?: number; + + // The URL ngWiz will be accessible from. + url?: string; + + // Launch ngWiz browser window when ngWiz starts. + launchBrowser?: boolean; + + // Directory to output log files. + logDirectory?: string; + + // Date format for logging. + logDateFormat?: string; +} diff --git a/config/config.json b/config/config.json new file mode 100644 index 0000000..0bbc8af --- /dev/null +++ b/config/config.json @@ -0,0 +1,8 @@ +{ + "port": "3000", + "url": "http://localhost", + "launchBrowser": "true", + "_COMMENT_logDirectory": "LEAVE EMPTY FOR DEFAULT %APPDATA%/npm/ngWiz/logs", + "logDirectory": "", + "logDateFormat": "DDMMYYTHHmmZZ" +} diff --git a/config/config.manager.ts b/config/config.manager.ts new file mode 100644 index 0000000..fdfea4f --- /dev/null +++ b/config/config.manager.ts @@ -0,0 +1,37 @@ +import fs = require('fs'); +import path = require('path'); +// +import { ConfigInterface } from './config.interface'; +import getAppDataPath from 'appdata-path'; + +export function configMaker(): ConfigInterface { + return handleJSONFile(fs.readFileSync('./config/config.json')); +} + +function handleJSONFile(data): ConfigInterface { + const config: ConfigInterface = {}; + const configFile = JSON.parse(data); + + // The port ngWiz server is listening to. + configFile.port ? config.port = configFile.port : config.port = null; + + // The URL ngWiz will be accessible from. + configFile.url ? config.url = configFile.url : config.url = null; + + // Launch ngWiz browser window when ngWiz starts. + configFile.launchBrowser ? config.launchBrowser = configFile.launchBrowser : config.launchBrowser = null; + + // Directory to output log files. + configFile.logDateFormat ? config.logDateFormat = configFile.logDateFormat : config.logDateFormat = null; + + // Date format for logging. + if (configFile.logDirectory !== null && configFile.logDirectory !== undefined) { + if (configFile.logDirectory === '') { + config.logDirectory = getAppDataPath(`npm${path.sep}ngWiz${path.sep}logs`); + } else { + config.logDirectory = configFile.logDirectory; + } + } + + return config; +} diff --git a/config/tsconfig.json b/config/tsconfig.json new file mode 100644 index 0000000..94c6e30 --- /dev/null +++ b/config/tsconfig.json @@ -0,0 +1,21 @@ + +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "noLib": false, + "allowSyntheticDefaultImports": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "target": "es6", + "sourceMap": true, + "outDir": "../dist/config", + }, + "include": [ + "**/*.ts" + ], + "exclude": [ + "node_modules", + "**/*.spec.ts" + ] +} diff --git a/package.json b/package.json index c536df1..897d8d6 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,11 @@ "version": "0.0.0", "scripts": { "ng": "ng", - "start": "npm run build && node ./bin/ng-wiz.js -o", + "start": "npm run build && node ./bin/ng-wiz.js", "start:client": "ng serve", "start:client-no-progress": "ng serve --progress=false", "start:server": "ts-node server/server.ts", - "build": "ng build && tsc -p ./server/", + "build": "ng build && tsc -p ./", "install": "npm run build", "test": "ng test", "lint": "ng lint", diff --git a/tsconfig.json b/tsconfig.json index ef44e28..7cfab5c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compileOnSave": false, "compilerOptions": { "baseUrl": "./", - "outDir": "./dist/out-tsc", + "outDir": "./dist", "sourceMap": true, "declaration": false, "moduleResolution": "node", From 7590806704792730e156700e300418369aafd730 Mon Sep 17 00:00:00 2001 From: ZimGil Date: Mon, 3 Dec 2018 18:26:04 +0200 Subject: [PATCH 02/13] better names and implementation --- config/config.interface.ts | 16 ----------- config/config.manager.ts | 37 ------------------------ config/ng-wiz-config.interface.ts | 16 +++++++++++ config/ng-wiz-config.ts | 48 +++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 53 deletions(-) delete mode 100644 config/config.interface.ts delete mode 100644 config/config.manager.ts create mode 100644 config/ng-wiz-config.interface.ts create mode 100644 config/ng-wiz-config.ts diff --git a/config/config.interface.ts b/config/config.interface.ts deleted file mode 100644 index 3cb856d..0000000 --- a/config/config.interface.ts +++ /dev/null @@ -1,16 +0,0 @@ -export interface ConfigInterface { - // The port ngWiz server is listening to. - port?: number; - - // The URL ngWiz will be accessible from. - url?: string; - - // Launch ngWiz browser window when ngWiz starts. - launchBrowser?: boolean; - - // Directory to output log files. - logDirectory?: string; - - // Date format for logging. - logDateFormat?: string; -} diff --git a/config/config.manager.ts b/config/config.manager.ts deleted file mode 100644 index fdfea4f..0000000 --- a/config/config.manager.ts +++ /dev/null @@ -1,37 +0,0 @@ -import fs = require('fs'); -import path = require('path'); -// -import { ConfigInterface } from './config.interface'; -import getAppDataPath from 'appdata-path'; - -export function configMaker(): ConfigInterface { - return handleJSONFile(fs.readFileSync('./config/config.json')); -} - -function handleJSONFile(data): ConfigInterface { - const config: ConfigInterface = {}; - const configFile = JSON.parse(data); - - // The port ngWiz server is listening to. - configFile.port ? config.port = configFile.port : config.port = null; - - // The URL ngWiz will be accessible from. - configFile.url ? config.url = configFile.url : config.url = null; - - // Launch ngWiz browser window when ngWiz starts. - configFile.launchBrowser ? config.launchBrowser = configFile.launchBrowser : config.launchBrowser = null; - - // Directory to output log files. - configFile.logDateFormat ? config.logDateFormat = configFile.logDateFormat : config.logDateFormat = null; - - // Date format for logging. - if (configFile.logDirectory !== null && configFile.logDirectory !== undefined) { - if (configFile.logDirectory === '') { - config.logDirectory = getAppDataPath(`npm${path.sep}ngWiz${path.sep}logs`); - } else { - config.logDirectory = configFile.logDirectory; - } - } - - return config; -} diff --git a/config/ng-wiz-config.interface.ts b/config/ng-wiz-config.interface.ts new file mode 100644 index 0000000..8d12da2 --- /dev/null +++ b/config/ng-wiz-config.interface.ts @@ -0,0 +1,16 @@ +export interface NgWizConfig { + // The port ngWiz server is listening to. +port: number; + +// The URL ngWiz will be accessible from. +url: string; + +// Launch ngWiz browser window when ngWiz starts. +launchBrowser: boolean; + +// Directory to output log files. +logDirectory: string; + +// Date format for logging. +logDateFormat: string; +} diff --git a/config/ng-wiz-config.ts b/config/ng-wiz-config.ts new file mode 100644 index 0000000..c40848f --- /dev/null +++ b/config/ng-wiz-config.ts @@ -0,0 +1,48 @@ +import fs = require('fs'); +import path = require('path'); +// +import getAppDataPath from 'appdata-path'; +// +import { NgWizConfig } from './ng-wiz-config.interface'; + +export function ngWizConfig(): NgWizConfig { + try { + return handleJSONFile(fs.readFileSync('./config/config.json')); + } catch { + return defaultConfig; + } +} + +const defaultConfig = { + port: 3000, + url: 'http://localhost', + launchBrowser: true, + logDirectory: getAppDataPath(`npm${path.sep}ngWiz${path.sep}logs`), + logDateFormat: 'DDMMYYTHHmmZZ' +}; + +function handleJSONFile(data): NgWizConfig { + const config: NgWizConfig = defaultConfig; + const configFile = JSON.parse(data); + + // The port ngWiz server is listening to. + configFile.port ? config.port = configFile.port : config.port = defaultConfig.port; + + // The URL ngWiz will be accessible from. + configFile.url ? config.url = configFile.url : config.url = defaultConfig.url; + + // Launch ngWiz browser window when ngWiz starts. + configFile.launchBrowser ? config.launchBrowser = configFile.launchBrowser : config.launchBrowser = defaultConfig.launchBrowser; + + // Directory to output log files. + configFile.logDateFormat ? config.logDateFormat = configFile.logDateFormat : config.logDateFormat = defaultConfig.logDateFormat; + + // Date format for logging. + if (configFile.logDirectory !== null && configFile.logDirectory !== undefined && configFile.logDirectory !== '') { + config.logDirectory = configFile.logDirectory; + } else { + config.logDirectory = defaultConfig.logDirectory; + } + + return config; +} From 05ca266a2c669b6560193c025dc1859f0131b12a Mon Sep 17 00:00:00 2001 From: ZimGil Date: Mon, 3 Dec 2018 19:24:35 +0200 Subject: [PATCH 03/13] removed URL from config --- config/config.json | 1 - config/ng-wiz-config.interface.ts | 3 --- config/ng-wiz-config.ts | 4 ---- 3 files changed, 8 deletions(-) diff --git a/config/config.json b/config/config.json index 0bbc8af..3f3b015 100644 --- a/config/config.json +++ b/config/config.json @@ -1,6 +1,5 @@ { "port": "3000", - "url": "http://localhost", "launchBrowser": "true", "_COMMENT_logDirectory": "LEAVE EMPTY FOR DEFAULT %APPDATA%/npm/ngWiz/logs", "logDirectory": "", diff --git a/config/ng-wiz-config.interface.ts b/config/ng-wiz-config.interface.ts index 8d12da2..bccbc10 100644 --- a/config/ng-wiz-config.interface.ts +++ b/config/ng-wiz-config.interface.ts @@ -2,9 +2,6 @@ export interface NgWizConfig { // The port ngWiz server is listening to. port: number; -// The URL ngWiz will be accessible from. -url: string; - // Launch ngWiz browser window when ngWiz starts. launchBrowser: boolean; diff --git a/config/ng-wiz-config.ts b/config/ng-wiz-config.ts index c40848f..8150fa0 100644 --- a/config/ng-wiz-config.ts +++ b/config/ng-wiz-config.ts @@ -15,7 +15,6 @@ export function ngWizConfig(): NgWizConfig { const defaultConfig = { port: 3000, - url: 'http://localhost', launchBrowser: true, logDirectory: getAppDataPath(`npm${path.sep}ngWiz${path.sep}logs`), logDateFormat: 'DDMMYYTHHmmZZ' @@ -28,9 +27,6 @@ function handleJSONFile(data): NgWizConfig { // The port ngWiz server is listening to. configFile.port ? config.port = configFile.port : config.port = defaultConfig.port; - // The URL ngWiz will be accessible from. - configFile.url ? config.url = configFile.url : config.url = defaultConfig.url; - // Launch ngWiz browser window when ngWiz starts. configFile.launchBrowser ? config.launchBrowser = configFile.launchBrowser : config.launchBrowser = defaultConfig.launchBrowser; From ccf7cac089c0d77355292a3dd834507e768bb981 Mon Sep 17 00:00:00 2001 From: ZimGil Date: Mon, 3 Dec 2018 19:51:27 +0200 Subject: [PATCH 04/13] bin/ng-wiz to typescript config included --- bin/ng-wiz.js | 22 ---------------------- bin/ng-wiz.ts | 27 +++++++++++++++++++++++++++ bin/tsconfig.json | 21 +++++++++++++++++++++ package.json | 2 +- server/server.ts | 4 +--- 5 files changed, 50 insertions(+), 26 deletions(-) delete mode 100755 bin/ng-wiz.js create mode 100644 bin/ng-wiz.ts create mode 100644 bin/tsconfig.json diff --git a/bin/ng-wiz.js b/bin/ng-wiz.js deleted file mode 100755 index 7148fb9..0000000 --- a/bin/ng-wiz.js +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env node -const path = require('path'); -const opn = require('opn'); -const ngWiz = require('../dist/server/server'); - -const PORT = 3000; -const STATIC_FILES_LOCATION = path.join(__dirname, '../dist/ngWiz'); - -let isOpenBrowser; - -process.argv.forEach((val, index, array) => { - if (val === '-o') { - isOpenBrowser = true; - } -}); - - -// run the app -ngWiz(PORT, STATIC_FILES_LOCATION) -// Opens the url in the default browser -.then(() => isOpenBrowser ? opn(`http://localhost:${ PORT }`) : null) -.catch((error) => console.error(error)); diff --git a/bin/ng-wiz.ts b/bin/ng-wiz.ts new file mode 100644 index 0000000..bd546e0 --- /dev/null +++ b/bin/ng-wiz.ts @@ -0,0 +1,27 @@ +#!/usr/bin/env node +import path = require('path'); +import opn = require('opn'); +// +import { runServer as ngWiz } from '../server/server'; +import { ngWizConfig } from '../config/ng-wiz-config'; + +const STATIC_FILES_LOCATION = path.join(__dirname, '../ngWiz'); + +const config = ngWizConfig(); +let launchBrowser = config.launchBrowser; + +process.argv.forEach((val, index, array) => { + if (val === '-l') { + launchBrowser = true; + } + if (val === '-dl') { + launchBrowser = false; + } +}); + + +// run the app +ngWiz(config.port, STATIC_FILES_LOCATION) +// Opens the url in the default browser +.then(() => launchBrowser ? opn(`http://localhost:${ config.port }`) : null) +.catch((error) => console.error(error)); diff --git a/bin/tsconfig.json b/bin/tsconfig.json new file mode 100644 index 0000000..b232920 --- /dev/null +++ b/bin/tsconfig.json @@ -0,0 +1,21 @@ + +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "noLib": false, + "allowSyntheticDefaultImports": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "target": "es6", + "sourceMap": true, + "outDir": "../bin", + }, + "include": [ + "**/*.ts" + ], + "exclude": [ + "node_modules", + "**/*.spec.ts" + ] +} diff --git a/package.json b/package.json index 897d8d6..6a1d958 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "e2e": "ng e2e" }, "bin": { - "ng-wiz": "bin/ng-wiz.js" + "ng-wiz": "dist/bin/ng-wiz.js" }, "private": true, "dependencies": { diff --git a/server/server.ts b/server/server.ts index f5af12e..2feab01 100644 --- a/server/server.ts +++ b/server/server.ts @@ -13,9 +13,7 @@ import { CommandStatusResponse } from './models/command-status-response.interfac import { IsAngularProjectResponse } from 'server/models/is-angular-project-response.interface'; import { GetProjectsResponse } from './models/get-projects-response.interface'; -module.exports = runServer; - -function runServer(PORT: number, STATIC_FILES_LOCATION: string): Promise { +export function runServer(PORT: number, STATIC_FILES_LOCATION: string): Promise { const app: express.Application = express(); const logger = new NgWizLogger('debug'); From 5933a045ef0ff3fa3c0a2e1a7053d404402c0d12 Mon Sep 17 00:00:00 2001 From: ZimGil Date: Mon, 3 Dec 2018 19:58:32 +0200 Subject: [PATCH 05/13] logger adjusted --- config/config.json | 1 + server/ngWizLogger.ts | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/config/config.json b/config/config.json index 3f3b015..b8f5a8b 100644 --- a/config/config.json +++ b/config/config.json @@ -3,5 +3,6 @@ "launchBrowser": "true", "_COMMENT_logDirectory": "LEAVE EMPTY FOR DEFAULT %APPDATA%/npm/ngWiz/logs", "logDirectory": "", + "_COMMENT_logDateFormat": "formatting: https://devhints.io/moment#formatting-1", "logDateFormat": "DDMMYYTHHmmZZ" } diff --git a/server/ngWizLogger.ts b/server/ngWizLogger.ts index be53ef4..645abdd 100644 --- a/server/ngWizLogger.ts +++ b/server/ngWizLogger.ts @@ -1,13 +1,14 @@ import { configure, getLogger, Logger } from 'log4js'; -import { getAppDataPath } from 'appdata-path'; -// import moment = require('moment'); import fs = require('fs'); import path = require('path'); +// +import { ngWizConfig } from '../config/ng-wiz-config'; + +const config = ngWizConfig(); -const LOG_FILES_DIR = getAppDataPath(`ngWiz${path.sep}logs`); -const dateInFormat = moment().format('DDMMYYTHHmmZZ'); // [171118T1510+0200] -const logFileName = `${LOG_FILES_DIR}/[${dateInFormat}].debug.log`; +const dateInFormat = moment().format(config.logDateFormat); +const logFileName = `${config.logDirectory}/[${dateInFormat}].debug.log`; export class NgWizLogger { @@ -33,11 +34,11 @@ export class NgWizLogger { } private deleteOldLogs(log: Logger): void { - fs.readdir(LOG_FILES_DIR, (err, files) => { + fs.readdir(config.logDirectory, (err, files) => { files.forEach(file => { if (path.extname(file) === '.log') { - const filePath = LOG_FILES_DIR + path.sep + file; + const filePath = config.logDirectory + path.sep + file; fs.stat(filePath, (statsErr, stats) => { const lastModify = moment(stats.mtime); From cdf4419a2b967cf610383b6b283df53e5b933a3a Mon Sep 17 00:00:00 2001 From: ZimGil Date: Mon, 3 Dec 2018 20:06:40 +0200 Subject: [PATCH 06/13] correct default log directory --- .gitignore | 3 +++ IDEA.md | 14 -------------- config/ng-wiz-config.ts | 2 +- 3 files changed, 4 insertions(+), 15 deletions(-) delete mode 100644 IDEA.md diff --git a/.gitignore b/.gitignore index 41f5447..0954500 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ testem.log # System Files .DS_Store Thumbs.db + +# Production logs +/logs diff --git a/IDEA.md b/IDEA.md deleted file mode 100644 index 520bb67..0000000 --- a/IDEA.md +++ /dev/null @@ -1,14 +0,0 @@ -##Serve -* port - int -* host - string -* isOpen - bool - -##Generate -* type - string (component/service) -* name - string - -##New -* name - string - -##Directory -* path - string \ No newline at end of file diff --git a/config/ng-wiz-config.ts b/config/ng-wiz-config.ts index 8150fa0..2a1f2d6 100644 --- a/config/ng-wiz-config.ts +++ b/config/ng-wiz-config.ts @@ -16,7 +16,7 @@ export function ngWizConfig(): NgWizConfig { const defaultConfig = { port: 3000, launchBrowser: true, - logDirectory: getAppDataPath(`npm${path.sep}ngWiz${path.sep}logs`), + logDirectory: getAppDataPath(`npm${path.sep}node_modules${path.sep}ngWiz${path.sep}logs`), logDateFormat: 'DDMMYYTHHmmZZ' }; From 443ced6924c01df75cde86cba3325032eba15d0b Mon Sep 17 00:00:00 2001 From: ZimGil Date: Mon, 3 Dec 2018 20:15:44 +0200 Subject: [PATCH 07/13] avoiding bugs --- server/server.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/server.ts b/server/server.ts index 2feab01..29adc0a 100644 --- a/server/server.ts +++ b/server/server.ts @@ -50,10 +50,10 @@ export function runServer(PORT: number, STATIC_FILES_LOCATION: string): Promise< app.get('/stopServing', (req, res) => { logger.log.debug(`Request to stop "ng serve" command`); if (processRunner.runningProcesses[ngServeCommandId]) { - const port = processRunner.runningProcesses[ngServeCommandId].command.match(/\s([0-9]{4,5})\s?/g)[0].replace(/\s/g, ''); + const commandPort = processRunner.runningProcesses[ngServeCommandId].command.match(/\s([0-9]{4,5})\s?/g)[0].replace(/\s/g, ''); const killProcess = { id: 'killer', - params: `for /f "tokens=5" %a in ('netstat -ano ^| find "${port}" ^| find "LISTENING"') do taskkill /f /pid %a` + params: `for /f "tokens=5" %a in ('netstat -ano ^| find "${commandPort}" ^| find "LISTENING"') do taskkill /f /pid %a` }; const ngServeStopper = timer(0, 500).subscribe(() => { if (processRunner.runningProcesses[ngServeCommandId].status === AngularCliProcessStatus.done) { From f7402841248f770d504c7060df3059298ff240e3 Mon Sep 17 00:00:00 2001 From: ZimGil Date: Mon, 3 Dec 2018 20:41:22 +0200 Subject: [PATCH 08/13] redundant lines --- bin/ng-wiz.ts | 2 -- bin/tsconfig.json | 1 - config/tsconfig.json | 1 - server/ngWizLogger.ts | 1 - 4 files changed, 5 deletions(-) diff --git a/bin/ng-wiz.ts b/bin/ng-wiz.ts index bd546e0..254ae58 100644 --- a/bin/ng-wiz.ts +++ b/bin/ng-wiz.ts @@ -6,7 +6,6 @@ import { runServer as ngWiz } from '../server/server'; import { ngWizConfig } from '../config/ng-wiz-config'; const STATIC_FILES_LOCATION = path.join(__dirname, '../ngWiz'); - const config = ngWizConfig(); let launchBrowser = config.launchBrowser; @@ -19,7 +18,6 @@ process.argv.forEach((val, index, array) => { } }); - // run the app ngWiz(config.port, STATIC_FILES_LOCATION) // Opens the url in the default browser diff --git a/bin/tsconfig.json b/bin/tsconfig.json index b232920..53fac2c 100644 --- a/bin/tsconfig.json +++ b/bin/tsconfig.json @@ -1,4 +1,3 @@ - { "extends": "../tsconfig.json", "compilerOptions": { diff --git a/config/tsconfig.json b/config/tsconfig.json index 94c6e30..065c266 100644 --- a/config/tsconfig.json +++ b/config/tsconfig.json @@ -1,4 +1,3 @@ - { "extends": "../tsconfig.json", "compilerOptions": { diff --git a/server/ngWizLogger.ts b/server/ngWizLogger.ts index 645abdd..f63ee8c 100644 --- a/server/ngWizLogger.ts +++ b/server/ngWizLogger.ts @@ -6,7 +6,6 @@ import path = require('path'); import { ngWizConfig } from '../config/ng-wiz-config'; const config = ngWizConfig(); - const dateInFormat = moment().format(config.logDateFormat); const logFileName = `${config.logDirectory}/[${dateInFormat}].debug.log`; From 16c2ac9ccf20a2fdc2a53daf6373b62444a12d65 Mon Sep 17 00:00:00 2001 From: ZimGil Date: Tue, 4 Dec 2018 15:58:56 +0200 Subject: [PATCH 09/13] Config moved into server Added client configurations --- bin/ng-wiz.ts | 2 +- config/tsconfig.json | 20 ------------------- {config => server/config}/config.json | 4 +++- .../config}/ng-wiz-config.interface.ts | 6 ++++++ {config => server/config}/ng-wiz-config.ts | 14 ++++++++++++- 5 files changed, 23 insertions(+), 23 deletions(-) delete mode 100644 config/tsconfig.json rename {config => server/config}/config.json (71%) rename {config => server/config}/ng-wiz-config.interface.ts (62%) rename {config => server/config}/ng-wiz-config.ts (72%) diff --git a/bin/ng-wiz.ts b/bin/ng-wiz.ts index 254ae58..58868dc 100644 --- a/bin/ng-wiz.ts +++ b/bin/ng-wiz.ts @@ -3,7 +3,7 @@ import path = require('path'); import opn = require('opn'); // import { runServer as ngWiz } from '../server/server'; -import { ngWizConfig } from '../config/ng-wiz-config'; +import { ngWizConfig } from '../server/config/ng-wiz-config'; const STATIC_FILES_LOCATION = path.join(__dirname, '../ngWiz'); const config = ngWizConfig(); diff --git a/config/tsconfig.json b/config/tsconfig.json deleted file mode 100644 index 065c266..0000000 --- a/config/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "module": "commonjs", - "noLib": false, - "allowSyntheticDefaultImports": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "target": "es6", - "sourceMap": true, - "outDir": "../dist/config", - }, - "include": [ - "**/*.ts" - ], - "exclude": [ - "node_modules", - "**/*.spec.ts" - ] -} diff --git a/config/config.json b/server/config/config.json similarity index 71% rename from config/config.json rename to server/config/config.json index b8f5a8b..911f885 100644 --- a/config/config.json +++ b/server/config/config.json @@ -4,5 +4,7 @@ "_COMMENT_logDirectory": "LEAVE EMPTY FOR DEFAULT %APPDATA%/npm/ngWiz/logs", "logDirectory": "", "_COMMENT_logDateFormat": "formatting: https://devhints.io/moment#formatting-1", - "logDateFormat": "DDMMYYTHHmmZZ" + "logDateFormat": "DDMMYYTHHmmZZ", + "ngServeLaunchBrowser": "true", + "ngServeProt": "4200" } diff --git a/config/ng-wiz-config.interface.ts b/server/config/ng-wiz-config.interface.ts similarity index 62% rename from config/ng-wiz-config.interface.ts rename to server/config/ng-wiz-config.interface.ts index bccbc10..ae2a297 100644 --- a/config/ng-wiz-config.interface.ts +++ b/server/config/ng-wiz-config.interface.ts @@ -10,4 +10,10 @@ logDirectory: string; // Date format for logging. logDateFormat: string; + +// Launch browser when running development server with "ng serve -o" +ngServeLaunchBrowser: boolean; + +// The port the development server run at +ngServePort: number; } diff --git a/config/ng-wiz-config.ts b/server/config/ng-wiz-config.ts similarity index 72% rename from config/ng-wiz-config.ts rename to server/config/ng-wiz-config.ts index 2a1f2d6..e5bea08 100644 --- a/config/ng-wiz-config.ts +++ b/server/config/ng-wiz-config.ts @@ -17,7 +17,9 @@ const defaultConfig = { port: 3000, launchBrowser: true, logDirectory: getAppDataPath(`npm${path.sep}node_modules${path.sep}ngWiz${path.sep}logs`), - logDateFormat: 'DDMMYYTHHmmZZ' + logDateFormat: 'DDMMYYTHHmmZZ', + ngServeLaunchBrowser: true, + ngServePort: 4200 }; function handleJSONFile(data): NgWizConfig { @@ -40,5 +42,15 @@ function handleJSONFile(data): NgWizConfig { config.logDirectory = defaultConfig.logDirectory; } + // Launch browser when running development server with "ng serve -o" + if (configFile.ngServeLaunchBrowser) { + config.ngServeLaunchBrowser = configFile.ngServeLaunchBrowser; + } else { + config.ngServeLaunchBrowser = defaultConfig.ngServeLaunchBrowser; + } + + // The port the development server run at + configFile.ngservePort ? config.ngServePort = configFile.ngServePort : config.ngServePort = defaultConfig.ngServePort; + return config; } From 36f02381ef009ebec14f67bb6726741df8a49946 Mon Sep 17 00:00:00 2001 From: ZimGil Date: Tue, 4 Dec 2018 16:00:08 +0200 Subject: [PATCH 10/13] Adjustment to config file location --- server/ngWizLogger.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/ngWizLogger.ts b/server/ngWizLogger.ts index f63ee8c..08f982d 100644 --- a/server/ngWizLogger.ts +++ b/server/ngWizLogger.ts @@ -3,7 +3,7 @@ import moment = require('moment'); import fs = require('fs'); import path = require('path'); // -import { ngWizConfig } from '../config/ng-wiz-config'; +import { ngWizConfig } from './config/ng-wiz-config'; const config = ngWizConfig(); const dateInFormat = moment().format(config.logDateFormat); From 2e16117572c2bcb16e7e74ee24078b3f9d01c422 Mon Sep 17 00:00:00 2001 From: ZimGil Date: Tue, 4 Dec 2018 16:01:00 +0200 Subject: [PATCH 11/13] Getting config from server --- server/server.ts | 7 +++++++ src/app/home/services/command/command.service.ts | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/server/server.ts b/server/server.ts index 29adc0a..c047383 100644 --- a/server/server.ts +++ b/server/server.ts @@ -12,10 +12,12 @@ import { NgWizLogger } from './ngWizLogger'; import { CommandStatusResponse } from './models/command-status-response.interface'; import { IsAngularProjectResponse } from 'server/models/is-angular-project-response.interface'; import { GetProjectsResponse } from './models/get-projects-response.interface'; +import { ngWizConfig } from './config/ng-wiz-config'; export function runServer(PORT: number, STATIC_FILES_LOCATION: string): Promise { const app: express.Application = express(); const logger = new NgWizLogger('debug'); + const config = ngWizConfig(); let ngServeCommandId = null; @@ -31,6 +33,11 @@ export function runServer(PORT: number, STATIC_FILES_LOCATION: string): Promise< next(); }); + app.get('/config', (req, res) => { + logger.log.debug('Client request for config', config); + res.send(config); + }); + app.get('/isServing', (req, res) => { logger.log.debug(`Client ask if currently running "ng serve", answering ${!!ngServeCommandId}`); res.send(!!ngServeCommandId); diff --git a/src/app/home/services/command/command.service.ts b/src/app/home/services/command/command.service.ts index aca6fc8..8ddfdd4 100644 --- a/src/app/home/services/command/command.service.ts +++ b/src/app/home/services/command/command.service.ts @@ -5,6 +5,7 @@ import { Observable } from 'rxjs'; // import { CommandRequest } from '../../models/angular-command-request'; import { CommandStatusResponse } from '../../models/command-status-response.interface'; +import { NgWizConfig } from '../../../../../server/config/ng-wiz-config.interface'; @Injectable({ @@ -17,6 +18,10 @@ export class CommandService { constructor(private http: HttpClient) { } + getConfig(): Observable { + return this.http.get(`${this.BASE_URL}:${this.PORT}/config`); + } + isAngularProject() { return this.http.get(`${this.BASE_URL}:${this.PORT}/isAngularProject`); } From 30b6fe18a1e8650064a1c4ea2f4b8f33c169184f Mon Sep 17 00:00:00 2001 From: ZimGil Date: Tue, 4 Dec 2018 16:01:36 +0200 Subject: [PATCH 12/13] Putting config to use in ngServe --- src/app/home/components/serve/serve.component.ts | 16 ++++++++-------- src/app/home/home.component.html | 3 ++- src/app/home/home.component.ts | 10 ++++++++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/app/home/components/serve/serve.component.ts b/src/app/home/components/serve/serve.component.ts index bcac2b4..6af54d5 100644 --- a/src/app/home/components/serve/serve.component.ts +++ b/src/app/home/components/serve/serve.component.ts @@ -1,18 +1,17 @@ -import { Component, Output, EventEmitter, Input } from '@angular/core'; +import { Component, Output, EventEmitter, Input, OnInit } from '@angular/core'; // import * as _ from 'lodash'; // import { AngularCliCommand } from '../../models/angular-cli-command.interface'; import { NgserveOptions } from '../../default-values/ng-serve-options'; -import { CommandService } from './../../services/command/command.service'; -import { ErrorService } from './../../services/error/error.service'; +import { NgWizConfig } from '../../../../../server/config/ng-wiz-config.interface'; @Component({ selector: 'app-serve', templateUrl: './serve.component.html', styleUrls: ['./serve.component.css'] }) -export class ServeComponent { +export class ServeComponent implements OnInit { private readonly MINIMUM_PORT = 1000; private readonly MAXIMUM_PORT = 99999; @@ -21,13 +20,14 @@ export class ServeComponent { @Output() serveStopper = new EventEmitter(); @Input() isServing: boolean; @Input() isStoppingServeCommand: boolean; + @Input() config: NgWizConfig; command: AngularCliCommand; options = new NgserveOptions(); - constructor( - private commandService: CommandService, - private errorService: ErrorService - ) {} + ngOnInit() { + this.options.optionalFlags.port.value = this.config.ngServePort; + this.options.optionalFlags.open.isActive = this.config.ngServeLaunchBrowser; + } startServing(): void { this.sendCommand.emit(this.options.createCommandString()); diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 8262ec4..9552ccd 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -18,7 +18,8 @@

{{ currentWorkingDir }}

(sendCommand)="sendServeCommand($event)" (serveStopper)="stopServing($event)" [isStoppingServeCommand]="isStoppingServeCommand" - [isServing]="isServing"> + [isServing]="isServing" + [config]="config">