mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-05-20 00:06:24 +08:00
Use winston
This commit is contained in:
@@ -2,6 +2,7 @@ import * as ts from 'typescript';
|
||||
import * as fs from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
import { camelCase, clone } from 'lodash';
|
||||
import { Logger } from '../logger';
|
||||
|
||||
export const ROOT = path.resolve(__dirname, '../../');
|
||||
export const TS_CONFIG = clone(require(path.resolve(ROOT, 'tsconfig.json')));
|
||||
@@ -57,7 +58,7 @@ export function getDecoratorArgs(decorator: any) {
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log(prop.initializer);
|
||||
Logger.error('Unexpected property value type: ', prop.initializer.kind);
|
||||
throw 'Unexpected property value type << helpers.ts >>';
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as ts from 'typescript';
|
||||
import { Logger } from '../../logger';
|
||||
import { convertValueToLiteral, getDecorator, getDecoratorArgs, getDecoratorName, getMethodsForDecorator } from '../helpers';
|
||||
|
||||
export function transformMethod(method: ts.MethodDeclaration) {
|
||||
@@ -15,8 +16,8 @@ export function transformMethod(method: ts.MethodDeclaration) {
|
||||
)
|
||||
]));
|
||||
} catch (e) {
|
||||
console.log('Error transforming method: ', (method.name as any).text);
|
||||
console.log(e.message);
|
||||
Logger.error('Error transforming method: ' + (method.name as any).text);
|
||||
Logger.error(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import * as ts from 'typescript';
|
||||
import { Logger } from '../../logger';
|
||||
import { convertValueToLiteral, getDecorator, getDecoratorArgs, getDecoratorName } from '../helpers';
|
||||
import { transformMembers } from './members';
|
||||
|
||||
function transformClass(cls: any, ngcBuild?: boolean) {
|
||||
|
||||
console.time('~ transformClass: ' + cls.name.text);
|
||||
Logger.profile((ngcBuild ? '[ngc]' : '[esm]') + 'transformClass: ' + cls.name.text);
|
||||
|
||||
const pluginStatics = [];
|
||||
const dec: any = getDecorator(cls);
|
||||
@@ -37,7 +38,7 @@ function transformClass(cls: any, ngcBuild?: boolean) {
|
||||
]
|
||||
);
|
||||
|
||||
console.timeEnd('~ transformClass: ' + cls.name.text);
|
||||
Logger.profile((ngcBuild ? '[ngc]' : '[esm]') + 'transformClass' + cls.name.text);
|
||||
return cls;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import * as winston from 'winston';
|
||||
import { isEmpty } from 'lodash';
|
||||
|
||||
const LOG_LEVEL = 'debug';
|
||||
|
||||
export const Logger = new winston.Logger({
|
||||
level: LOG_LEVEL,
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
level: 'debug',
|
||||
formatter: (opts: any) => {
|
||||
if (opts.meta) {
|
||||
if (typeof opts.meta['durationMs'] === 'number') {
|
||||
opts.message += ' ' + opts.meta['durationMs'] + 'ms';
|
||||
delete opts.meta['durationMs'];
|
||||
}
|
||||
if (!isEmpty(opts.meta)) console.log(opts.meta);
|
||||
}
|
||||
return winston.config.colorize(opts.level, opts.level.toUpperCase()) + ' ' + opts.message;
|
||||
}
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import * as uglifyJsPlugin from 'uglifyjs-webpack-plugin';
|
||||
import * as unminifiedPlugin from 'unminified-webpack-plugin';
|
||||
import { cleanEmittedData, EMIT_PATH, InjectableClassEntry } from '../build/transformers/extract-injectables';
|
||||
import { ROOT } from '../build/helpers';
|
||||
import { Logger } from '../logger';
|
||||
|
||||
const DIST = path.resolve(ROOT, 'dist');
|
||||
const INDEX_PATH = path.resolve(DIST, 'index.js');
|
||||
@@ -45,7 +46,7 @@ const webpackConfig: webpack.Configuration = {
|
||||
new uglifyJsPlugin({
|
||||
sourceMap: true
|
||||
}),
|
||||
|
||||
new unminifiedPlugin()
|
||||
]
|
||||
};
|
||||
|
||||
@@ -66,9 +67,14 @@ function createIndexFile() {
|
||||
}
|
||||
|
||||
function compile() {
|
||||
Logger.profile('build-es5');
|
||||
webpack(webpackConfig, (err, stats) => {
|
||||
if (err) console.log(err);
|
||||
else console.log(stats);
|
||||
Logger.profile('build-es5');
|
||||
if (err) Logger.error('Error occurred while compiling with Webpack', err);
|
||||
else {
|
||||
Logger.info('Compiled ES5 file with Webpack successfully.');
|
||||
// Logger.verbose('Webpack complete', stats, () => {});
|
||||
}
|
||||
cleanEmittedData();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { exec } from 'child_process';
|
||||
import { PLUGIN_PATHS, ROOT } from '../build/helpers';
|
||||
import { cpus } from 'os';
|
||||
import * as Queue from 'async-promise-queue';
|
||||
import { Logger } from '../logger';
|
||||
|
||||
const MAIN_PACKAGE_JSON = require('../../package.json');
|
||||
const VERSION = MAIN_PACKAGE_JSON.version;
|
||||
@@ -66,18 +67,19 @@ function prepare() {
|
||||
}
|
||||
|
||||
async function publish(ignoreErrors: boolean = false) {
|
||||
Logger.profile('Publishing');
|
||||
// upload 1 package per CPU thread at a time
|
||||
const worker = Queue.async.asyncify((pkg: any) => {
|
||||
new Promise<any>((resolve, reject) => {
|
||||
exec(`npm publish ${ pkg } ${ FLAGS }`, (err, stdout) => {
|
||||
if (stdout) {
|
||||
console.log(stdout);
|
||||
Logger.log(stdout.trim());
|
||||
resolve(stdout);
|
||||
}
|
||||
if (err) {
|
||||
if (!ignoreErrors) {
|
||||
if (err.message.includes('You cannot publish over the previously published version')) {
|
||||
console.log('Ignoring duplicate version error.');
|
||||
Logger.verbose('Ignoring duplicate version error.');
|
||||
return resolve();
|
||||
}
|
||||
reject(err);
|
||||
@@ -89,10 +91,12 @@ async function publish(ignoreErrors: boolean = false) {
|
||||
|
||||
try {
|
||||
await Queue(worker, PACKAGES, cpus().length);
|
||||
console.log('Done publishing!');
|
||||
Logger.log('Done publishing!');
|
||||
} catch (e) {
|
||||
console.log('Error publishing!');
|
||||
console.log(e);
|
||||
Logger.error('Error publishing!');
|
||||
Logger.error(e);
|
||||
} finally {
|
||||
Logger.profile('Publishing');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user