mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
refactor: clean up logging
This commit is contained in:
@ -1,8 +1,7 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import dedent from 'ts-dedent';
|
|
||||||
import * as lib from '../index';
|
import * as lib from '../index';
|
||||||
import { error, info } from './log';
|
import { error, info, warn } from './log';
|
||||||
import { getAllDependencies, getDependencyPath } from './dependencies';
|
import { getAllDependencies, getDependencyPath } from './dependencies';
|
||||||
|
|
||||||
export function applyExternalConfigs() {
|
export function applyExternalConfigs() {
|
||||||
@ -17,17 +16,22 @@ export function applyExternalConfigs() {
|
|||||||
const externalConfig = require(configPath);
|
const externalConfig = require(configPath);
|
||||||
|
|
||||||
if (typeof externalConfig === 'function') {
|
if (typeof externalConfig === 'function') {
|
||||||
|
info('Applying external config...');
|
||||||
externalConfig(lib);
|
externalConfig(lib);
|
||||||
|
} else if (externalConfig) {
|
||||||
|
info('Merging external config...');
|
||||||
|
lib.mergeWebpack(externalConfig);
|
||||||
} else {
|
} else {
|
||||||
// todo: warn user
|
warn(
|
||||||
// todo: perhaps support exported objects to merge into config?
|
'Unsupported external config. The config must export a function or an object.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error(
|
error(
|
||||||
dedent`
|
`
|
||||||
Unable to apply config: ${configPath}.
|
Unable to apply config: ${configPath}.
|
||||||
Error is:
|
Error is:
|
||||||
`,
|
`,
|
||||||
err
|
err
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { defaultConfigs } from '@nativescript/webpack';
|
import { defaultConfigs } from '@nativescript/webpack';
|
||||||
import { getAllDependencies } from './dependencies';
|
import { getAllDependencies } from './dependencies';
|
||||||
import { error } from './log';
|
import { error } from './log';
|
||||||
import dedent from 'ts-dedent';
|
|
||||||
|
|
||||||
export function determineProjectFlavor(): keyof typeof defaultConfigs | false {
|
export function determineProjectFlavor(): keyof typeof defaultConfigs | false {
|
||||||
const dependencies = getAllDependencies();
|
const dependencies = getAllDependencies();
|
||||||
@ -35,7 +34,7 @@ export function determineProjectFlavor(): keyof typeof defaultConfigs | false {
|
|||||||
return 'javascript';
|
return 'javascript';
|
||||||
}
|
}
|
||||||
|
|
||||||
error(dedent`
|
error(`
|
||||||
Could not determine project flavor.
|
Could not determine project flavor.
|
||||||
Please use webpack.useConfig('<flavor>') to explicitly set the base config.
|
Please use webpack.useConfig('<flavor>') to explicitly set the base config.
|
||||||
`);
|
`);
|
||||||
|
@ -1,3 +1,34 @@
|
|||||||
|
import dedent from 'ts-dedent';
|
||||||
|
|
||||||
|
// de-indents strings so multi-line string literals can be used
|
||||||
|
function cleanup(data: any[]) {
|
||||||
|
return data.map((d) => {
|
||||||
|
if (typeof d === 'string') {
|
||||||
|
return dedent(d);
|
||||||
|
}
|
||||||
|
return d;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function error(...data: any): Error {
|
||||||
|
console.error(`[@nativescript/webpack]`, ...cleanup(data));
|
||||||
|
|
||||||
|
// we return the error - the caller can throw or ignore
|
||||||
|
if (typeof data[0] === 'string') {
|
||||||
|
return new Error(data[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Error('@nativescript/webpack ran into a problem...');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function warn(...data: any): void {
|
||||||
|
console.warn(`[@nativescript/webpack]`, ...cleanup(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function info(...data: any): void {
|
||||||
|
console.info(`[@nativescript/webpack]`, ...cleanup(data));
|
||||||
|
}
|
||||||
|
|
||||||
// todo: refine
|
// todo: refine
|
||||||
// export function error(message: string, info?: { possibleCauses?: string[] }) {
|
// export function error(message: string, info?: { possibleCauses?: string[] }) {
|
||||||
// console.error(`
|
// console.error(`
|
||||||
@ -9,15 +40,3 @@
|
|||||||
// ${info?.possibleCauses?.map((cause) => `- ${cause}`).join('\n')}
|
// ${info?.possibleCauses?.map((cause) => `- ${cause}`).join('\n')}
|
||||||
// `);
|
// `);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
export function error(...data: any) {
|
|
||||||
console.error(`[@nativescript/webpack]`, ...data);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function warn(...data: any) {
|
|
||||||
console.warn(`[@nativescript/webpack]`, ...data);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function info(...data: any) {
|
|
||||||
console.info(`[@nativescript/webpack]`, ...data);
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user