Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 990df10

Browse files
adamdbradleydanbucholtz
authored andcommitted
chore(logger): improve build error logging
1 parent 892cf4a commit 990df10

File tree

13 files changed

+131
-58
lines changed

13 files changed

+131
-58
lines changed

bin/ion-dev.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@
157157
color: #969896;
158158
}
159159

160-
#ion-diagnostics .ion-diagnostics-system-info {
160+
#ion-diagnostics-system-info {
161+
padding-bottom: 20px;
161162
font-size: 10px;
162163
color: #999;
163164
}

bin/ion-dev.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
window.IonicDevServerConfig = window.IonicDevServerConfig || {};
12
window.IonicDevServer = {
23
start: function() {
34
this.msgQueue = [];
@@ -6,19 +7,30 @@ window.IonicDevServer = {
67
this.consoleError = console.error;
78
this.consoleWarn = console.warn;
89

9-
if (IonicDevServerConfig && IonicDevServerConfig.sendConsoleLogs) {
10+
IonicDevServerConfig.systemInfo.push('Navigator Platform: ' + window.navigator.platform);
11+
IonicDevServerConfig.systemInfo.push('User Agent: ' + window.navigator.userAgent);
12+
13+
if (IonicDevServerConfig.sendConsoleLogs) {
1014
this.patchConsole();
1115
}
1216

13-
console.log('dev server enabled');
14-
1517
this.openConnection();
1618

1719
this.bindKeyboardEvents();
1820

1921
document.addEventListener("DOMContentLoaded", IonicDevServer.domReady);
2022
},
2123

24+
domReady: function() {
25+
document.removeEventListener("DOMContentLoaded", IonicDevServer.domReady);
26+
var diagnosticsEle = document.getElementById('ion-diagnostics');
27+
if (diagnosticsEle) {
28+
IonicDevServer.buildStatus('error');
29+
} else {
30+
IonicDevServer.buildStatus('success');
31+
}
32+
},
33+
2234
handleError: function(err) {
2335
var self = this;
2436

@@ -291,15 +303,18 @@ window.IonicDevServer = {
291303
iconLink.type = 'image/png';
292304
iconLink.href = IonicDevServer[status + 'Icon'];
293305
document.head.appendChild(iconLink);
294-
},
295306

296-
domReady: function() {
297-
document.removeEventListener("DOMContentLoaded", IonicDevServer.domReady);
298-
var diagnosticsEle = document.getElementById('ion-diagnostics');
299-
if (diagnosticsEle) {
300-
IonicDevServer.buildStatus('error');
301-
} else {
302-
IonicDevServer.buildStatus('success');
307+
if (status === 'error') {
308+
var diagnosticsEle = document.getElementById('ion-diagnostics');
309+
if (diagnosticsEle) {
310+
var systemInfoEle = diagnosticsEle.querySelector('#ion-diagnostics-system-info');
311+
if (!systemInfoEle) {
312+
systemInfoEle = document.createElement('pre');
313+
systemInfoEle.id = 'ion-diagnostics-system-info';
314+
systemInfoEle.innerHTML = IonicDevServerConfig.systemInfo.join('\n');
315+
diagnosticsEle.appendChild(systemInfoEle);
316+
}
317+
}
303318
}
304319
},
305320

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"fs-extra": "0.30.0",
4141
"json-loader": "^0.5.4",
4242
"node-sass": "3.10.1",
43+
"os-name": "^2.0.1",
4344
"postcss": "5.2.0",
4445
"proxy-middleware": "^0.15.0",
4546
"rollup": "0.36.3",

src/build.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function buildDev(context: BuildContext) {
118118

119119
export function buildUpdate(event: string, filePath: string, context: BuildContext) {
120120
return new Promise(resolve => {
121-
const logger = new Logger('build update');
121+
const logger = new Logger('build');
122122

123123
buildUpdateId++;
124124
emit(EventType.BuildUpdateStarted, buildUpdateId);
@@ -150,8 +150,7 @@ export function buildUpdate(event: string, filePath: string, context: BuildConte
150150
lintUpdate(event, filePath, context);
151151
}
152152

153-
Logger.newLine();
154-
logger.ready('green', true);
153+
logger.finish('green', true);
155154
Logger.newLine();
156155

157156
// we did it!

src/declarations.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
declare module 'autoprefixer';
22
declare module 'mime-types';
3+
declare module 'os-name';
34
declare module 'proxy-middleware';
45
declare module 'rollup-pluginutils';
56
declare module 'rollup';

src/dev-server/http-server.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ function serveIndex(req: express.Request, res: express.Response) {
6464
indexHtml = injectLiveReloadScript(indexHtml, config.host, config.liveReloadPort);
6565
}
6666

67-
if (config.useNotifier) {
68-
indexHtml = injectNotificationScript(indexHtml, config.notifyOnConsoleLog, config.notificationPort);
69-
}
67+
indexHtml = injectNotificationScript(config.rootDir, indexHtml, config.notifyOnConsoleLog, config.notificationPort);
7068

7169
indexHtml = injectDiagnosticsHtml(config.buildDir, indexHtml);
7270

src/dev-server/injector.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { getAppScriptsVersion } from '../util/logger';
1+
import { getAppScriptsVersion, getSystemInfo } from '../util/helpers';
22
import { LOGGER_DIR } from './serve-config';
33

44

55
const LOGGER_HEADER = '<!-- Ionic Dev Server: Injected Logger Script -->';
66

7-
export function injectNotificationScript(content: any, notifyOnConsoleLog: boolean, notificationPort: Number): any {
7+
export function injectNotificationScript(rootDir: string, content: any, notifyOnConsoleLog: boolean, notificationPort: Number): any {
88
let contentStr = content.toString();
9-
const consoleLogScript = getConsoleLoggerScript(notifyOnConsoleLog, notificationPort);
9+
const consoleLogScript = getDevLoggerScript(rootDir, notifyOnConsoleLog, notificationPort);
1010

1111
if (contentStr.indexOf(LOGGER_HEADER) > -1) {
1212
// already added script somehow
@@ -26,12 +26,13 @@ export function injectNotificationScript(content: any, notifyOnConsoleLog: boole
2626
return contentStr;
2727
}
2828

29-
function getConsoleLoggerScript(notifyOnConsoleLog: boolean, notificationPort: Number) {
29+
function getDevLoggerScript(rootDir: string, notifyOnConsoleLog: boolean, notificationPort: Number) {
3030
const appScriptsVersion = getAppScriptsVersion();
3131
const ionDevServer = JSON.stringify({
3232
sendConsoleLogs: notifyOnConsoleLog,
3333
wsPort: notificationPort,
34-
appScriptsVersion: appScriptsVersion
34+
appScriptsVersion: appScriptsVersion,
35+
systemInfo: getSystemInfo(rootDir)
3536
});
3637

3738
return `

src/dev-server/serve-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export interface ServeConfig {
22
httpPort: number;
33
host: string;
4+
rootDir: string;
45
wwwDir: string;
56
buildDir: string;
67
launchBrowser: boolean;
@@ -9,7 +10,6 @@ export interface ServeConfig {
910
useLiveReload: boolean;
1011
liveReloadPort: Number;
1112
notificationPort: Number;
12-
useNotifier: boolean;
1313
useServerLogs: boolean;
1414
notifyOnConsoleLog: boolean;
1515
useProxy: boolean;

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export * from './util/config';
1414
export * from './util/helpers';
1515
export * from './util/interfaces';
1616

17-
import { Logger, getAppScriptsVersion } from './util/logger';
18-
import * as chalk from 'chalk';
17+
import { getAppScriptsVersion } from './util/helpers';
18+
import { Logger } from './util/logger';
1919

2020

2121
export function run(task: string) {
2222
try {
23-
Logger.info(chalk.cyan(`ionic-app-scripts ${getAppScriptsVersion()}`));
23+
Logger.info(`ionic-app-scripts ${getAppScriptsVersion()}`, 'cyan');
2424
} catch (e) {}
2525

2626
try {

src/serve.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { BuildContext } from './util/interfaces';
22
import { generateContext, getConfigValue, hasConfigValue } from './util/config';
33
import { Logger } from './util/logger';
44
import { watch } from './watch';
5-
import * as chalk from 'chalk';
65
import open from './util/open';
76
import { createNotificationServer } from './dev-server/notification-server';
87
import { createHttpServer } from './dev-server/http-server';
@@ -21,6 +20,7 @@ export function serve(context?: BuildContext) {
2120
const config: ServeConfig = {
2221
httpPort: getHttpServerPort(context),
2322
host: getHttpServerHost(context),
23+
rootDir: context.rootDir,
2424
wwwDir: context.wwwDir,
2525
buildDir: context.buildDir,
2626
launchBrowser: launchBrowser(context),
@@ -30,7 +30,6 @@ export function serve(context?: BuildContext) {
3030
liveReloadPort: getLiveReloadServerPort(context),
3131
notificationPort: getNotificationPort(context),
3232
useServerLogs: useServerLogs(context),
33-
useNotifier: true,
3433
useProxy: useProxy(context),
3534
notifyOnConsoleLog: sendClientConsoleLogs(context)
3635
};
@@ -59,7 +58,8 @@ function onReady(config: ServeConfig, context: BuildContext) {
5958

6059
open(openOptions.join(''), browserToLaunch(context));
6160
}
62-
Logger.info(chalk.green(`dev server running: http://${config.host}:${config.httpPort}/`));
61+
Logger.info(`dev server running: http://${config.host}:${config.httpPort}/`, 'green', true);
62+
Logger.newLine();
6363
}
6464

6565
function getHttpServerPort(context: BuildContext) {

0 commit comments

Comments
 (0)