From 24a2d407c8aa158a0bd702db79ecbfcc96acbf12 Mon Sep 17 00:00:00 2001 From: redhoodsu Date: Sat, 31 Aug 2019 23:29:16 +0800 Subject: [PATCH] chore: remove script util --- .eustia.js | 5 - eustia/evalCss.js | 2 +- eustia/isErudaEl.js | 2 +- package.json | 3 +- script/coverage.js | 7 +- script/cpTestLib.js | 7 +- script/genIcon.js | 4 +- script/util.js | 709 -------------------------------------------- src/lib/logger.js | 4 +- 9 files changed, 16 insertions(+), 727 deletions(-) delete mode 100644 script/util.js diff --git a/.eustia.js b/.eustia.js index d76bbdf..e5559f5 100644 --- a/.eustia.js +++ b/.eustia.js @@ -1,9 +1,4 @@ module.exports = { - script: { - files: 'script/*.js', - output: 'script/util.js', - format: 'commonjs' - }, eruda: { library: 'https://raw.githubusercontent.com/liriliri/fione/master/', files: 'src/**/*.js', diff --git a/eustia/evalCss.js b/eustia/evalCss.js index 4dafbad..483780b 100644 --- a/eustia/evalCss.js +++ b/eustia/evalCss.js @@ -6,7 +6,7 @@ _('toStr each filter') let styleList = [] let scale = 1 -exports = function (css, container) { +exports = function(css, container) { css = toStr(css) for (let i = 0, len = styleList.length; i < len; i++) { diff --git a/eustia/isErudaEl.js b/eustia/isErudaEl.js index a757bb8..4e239a5 100644 --- a/eustia/isErudaEl.js +++ b/eustia/isErudaEl.js @@ -1,7 +1,7 @@ /* See if an element is within eruda. */ -exports = function (el) { +exports = function(el) { let parentNode = el.parentNode if (!parentNode) return false diff --git a/package.json b/package.json index ed51d9c..64f0b6e 100644 --- a/package.json +++ b/package.json @@ -66,10 +66,11 @@ "karma-sourcemap-loader": "^0.3.7", "karma-sourcemap-writer": "^0.1.2", "karma-webpack": "^2.0.6", + "licia": "^1.6.1", "node-sass": "^4.7.2", "postcss-class-prefix": "^0.3.0", "postcss-loader": "^2.0.9", - "prettier": "^1.13.5", + "prettier": "^1.18.2", "remap-istanbul": "^0.9.5", "sass-loader": "^6.0.6", "webpack": "^3.12.0", diff --git a/script/coverage.js b/script/coverage.js index d1d2929..5a42edf 100644 --- a/script/coverage.js +++ b/script/coverage.js @@ -1,14 +1,15 @@ const path = require('path') -const util = require('./util') const istanbul = require('istanbul') +const reduce = require('licia/reduce') +const keys = require('licia/keys') let collector = new istanbul.Collector() let reporter = new istanbul.Reporter() let remappedJson = require('../coverage/coverage-remapped.json') -let coverage = util.reduce( - util.keys(remappedJson), +let coverage = reduce( + keys(remappedJson), function(result, source) { if (isSrc()) { let correctPath = source.replace( diff --git a/script/cpTestLib.js b/script/cpTestLib.js index e243817..00d8697 100644 --- a/script/cpTestLib.js +++ b/script/cpTestLib.js @@ -1,15 +1,16 @@ const copy = require('copy') const path = require('path') -const util = require('./util') +const mkdir = require('licia/mkdir') +const parallel = require('licia/parallel') -util.mkdir(path.resolve(__dirname, '../test/lib'), function(err) { +mkdir(path.resolve(__dirname, '../test/lib'), function(err) { if (err) return console.log(err) cpTestFiles() }) function cpTestFiles() { - util.parallel( + parallel( [ genCpCb( '/jasmine-core/lib/jasmine-core/{jasmine.css,jasmine.js,jasmine-html.js,boot.js}', diff --git a/script/genIcon.js b/script/genIcon.js index 2e7fa6e..9ab17d2 100644 --- a/script/genIcon.js +++ b/script/genIcon.js @@ -1,6 +1,6 @@ const fs = require('fs') const path = require('path') -const util = require('./util') +const each = require('licia/each') const nameMap = { Clearsearch: 'clear', @@ -36,7 +36,7 @@ function genCssFile(fontData) { "[class^='eruda-icon-'],\n[class*=' eruda-icon-']" ) - util.each(nameMap, (val, key) => { + each(nameMap, (val, key) => { data = data.replace('icon-' + key + ':', 'icon-' + val + ':') }) diff --git a/script/util.js b/script/util.js deleted file mode 100644 index f0956c5..0000000 --- a/script/util.js +++ /dev/null @@ -1,709 +0,0 @@ -// Built by eustia. -/* eslint-disable */ -"use strict"; - -var _ = {}; - -/* ------------------------------ types ------------------------------ */ - -var types = _.types = (function (exports) { - /* Used for typescript definitions only. - */ - - /* typescript - * export declare namespace types { - * interface Collection {} - * interface List extends Collection { - * [index: number]: T; - * length: number; - * } - * interface ListIterator { - * (value: T, index: number, list: List): TResult; - * } - * interface Dictionary extends Collection { - * [index: string]: T; - * } - * interface ObjectIterator { - * (element: T, key: string, list: Dictionary): TResult; - * } - * interface MemoIterator { - * (prev: TResult, curr: T, index: number, list: List): TResult; - * } - * interface MemoObjectIterator { - * (prev: TResult, curr: T, key: string, list: Dictionary): TResult; - * } - * } - * export declare const types: {} - */ - exports = {}; - - return exports; -})({}); - -/* ------------------------------ has ------------------------------ */ - -var has = _.has = (function (exports) { - /* Checks if key is a direct property. - * - * |Name |Type |Desc | - * |------|-------|--------------------------------| - * |obj |object |Object to query | - * |key |string |Path to check | - * |return|boolean|True if key is a direct property| - */ - - /* example - * has({one: 1}, 'one'); // -> true - */ - - /* typescript - * export declare function has(obj: {}, key: string): boolean; - */ - var hasOwnProp = Object.prototype.hasOwnProperty; - - exports = function(obj, key) { - return hasOwnProp.call(obj, key); - }; - - return exports; -})({}); - -/* ------------------------------ isBrowser ------------------------------ */ - -var isBrowser = _.isBrowser = (function (exports) { - /* Check if running in a browser. - */ - - /* example - * console.log(isBrowser); // -> true if running in a browser - */ - - /* typescript - * export declare const isBrowser: boolean; - */ - exports = - typeof window === 'object' && - typeof document === 'object' && - document.nodeType === 9; - - return exports; -})({}); - -/* ------------------------------ root ------------------------------ */ - -var root = _.root = (function (exports) { - /* Root object reference, `global` in nodeJs, `window` in browser. */ - - /* typescript - * export declare const root: any; - */ - - /* dependencies - * isBrowser - */ - - exports = isBrowser ? window : global; - - return exports; -})({}); - -/* ------------------------------ detectMocha ------------------------------ */ - -var detectMocha = _.detectMocha = (function (exports) { - /* Detect if mocha is running. - */ - - /* example - * detectMocha(); // -> True if mocha is running. - */ - - /* typescript - * export declare function detectMocha(): boolean; - */ - - /* dependencies - * root - */ - - exports = function() { - for (var i = 0, len = methods.length; i < len; i++) { - var method = methods[i]; - if (typeof root[method] !== 'function') return false; - } - - return true; - }; - - var methods = ['afterEach', 'after', 'beforeEach', 'before', 'describe', 'it']; - - return exports; -})({}); - -/* ------------------------------ keys ------------------------------ */ - -var keys = _.keys = (function (exports) { - /* Create an array of the own enumerable property names of object. - * - * |Name |Type |Desc | - * |------|------|-----------------------| - * |obj |object|Object to query | - * |return|array |Array of property names| - */ - - /* example - * keys({a: 1}); // -> ['a'] - */ - - /* typescript - * export declare function keys(obj: any): string[]; - */ - - /* dependencies - * has detectMocha - */ - - if (Object.keys && !detectMocha()) { - exports = Object.keys; - } else { - exports = function(obj) { - var ret = []; - - for (var key in obj) { - if (has(obj, key)) ret.push(key); - } - - return ret; - }; - } - - return exports; -})({}); - -/* ------------------------------ objToStr ------------------------------ */ - -var objToStr = _.objToStr = (function (exports) { - /* Alias of Object.prototype.toString. - * - * |Name |Type |Desc | - * |------|------|------------------------------------| - * |val |* |Source value | - * |return|string|String representation of given value| - */ - - /* example - * objToStr(5); // -> '[object Number]' - */ - - /* typescript - * export declare function objToStr(val: any): string; - */ - var ObjToStr = Object.prototype.toString; - - exports = function(val) { - return ObjToStr.call(val); - }; - - return exports; -})({}); - -/* ------------------------------ isFn ------------------------------ */ - -var isFn = _.isFn = (function (exports) { - /* Check if value is a function. - * - * |Name |Type |Desc | - * |------|-------|---------------------------| - * |val |* |Value to check | - * |return|boolean|True if value is a function| - * - * Generator function is also classified as true. - */ - - /* example - * isFn(function() {}); // -> true - * isFn(function*() {}); // -> true - * isFn(async function() {}); // -> true - */ - - /* typescript - * export declare function isFn(val: any): boolean; - */ - - /* dependencies - * objToStr - */ - - exports = function(val) { - var objStr = objToStr(val); - return ( - objStr === '[object Function]' || - objStr === '[object GeneratorFunction]' || - objStr === '[object AsyncFunction]' - ); - }; - - return exports; -})({}); - -/* ------------------------------ isNum ------------------------------ */ - -var isNum = _.isNum = (function (exports) { - /* Check if value is classified as a Number primitive or object. - * - * |Name |Type |Desc | - * |------|-------|-------------------------------------| - * |val |* |Value to check | - * |return|boolean|True if value is correctly classified| - */ - - /* example - * isNum(5); // -> true - * isNum(5.1); // -> true - * isNum({}); // -> false - */ - - /* typescript - * export declare function isNum(val: any): boolean; - */ - - /* dependencies - * objToStr - */ - - exports = function(val) { - return objToStr(val) === '[object Number]'; - }; - - return exports; -})({}); - -/* ------------------------------ isArrLike ------------------------------ */ - -var isArrLike = _.isArrLike = (function (exports) { - /* Check if value is array-like. - * - * |Name |Type |Desc | - * |------|-------|---------------------------| - * |val |* |Value to check | - * |return|boolean|True if value is array like| - * - * Function returns false. - */ - - /* example - * isArrLike('test'); // -> true - * isArrLike(document.body.children); // -> true; - * isArrLike([1, 2, 3]); // -> true - */ - - /* typescript - * export declare function isArrLike(val: any): boolean; - */ - - /* dependencies - * isNum isFn - */ - - var MAX_ARR_IDX = Math.pow(2, 53) - 1; - - exports = function(val) { - if (!val) return false; - var len = val.length; - return isNum(len) && len >= 0 && len <= MAX_ARR_IDX && !isFn(val); - }; - - return exports; -})({}); - -/* ------------------------------ isUndef ------------------------------ */ - -var isUndef = _.isUndef = (function (exports) { - /* Check if value is undefined. - * - * |Name |Type |Desc | - * |------|-------|--------------------------| - * |val |* |Value to check | - * |return|boolean|True if value is undefined| - */ - - /* example - * isUndef(void 0); // -> true - * isUndef(null); // -> false - */ - - /* typescript - * export declare function isUndef(val: any): boolean; - */ - exports = function(val) { - return val === void 0; - }; - - return exports; -})({}); - -/* ------------------------------ optimizeCb ------------------------------ */ - -var optimizeCb = _.optimizeCb = (function (exports) { - /* Used for function context binding. - */ - - /* typescript - * export declare function optimizeCb(fn: Function, ctx: any, argCount?: number): Function; - */ - - /* dependencies - * isUndef - */ - - exports = function(fn, ctx, argCount) { - if (isUndef(ctx)) return fn; - - switch (argCount == null ? 3 : argCount) { - case 1: - return function(val) { - return fn.call(ctx, val); - }; - - case 3: - return function(val, idx, collection) { - return fn.call(ctx, val, idx, collection); - }; - - case 4: - return function(accumulator, val, idx, collection) { - return fn.call(ctx, accumulator, val, idx, collection); - }; - } - - return function() { - return fn.apply(ctx, arguments); - }; - }; - - return exports; -})({}); - -/* ------------------------------ each ------------------------------ */ - -var each = _.each = (function (exports) { - /* Iterate over elements of collection and invokes iterator for each element. - * - * |Name |Type |Desc | - * |--------|------------|------------------------------| - * |obj |object array|Collection to iterate over | - * |iterator|function |Function invoked per iteration| - * |[ctx] |* |Function context | - */ - - /* example - * each({'a': 1, 'b': 2}, function (val, key) {}); - */ - - /* typescript - * export declare function each( - * list: types.List, - * iterator: types.ListIterator, - * ctx?: any - * ): types.List; - * export declare function each( - * object: types.Dictionary, - * iterator: types.ObjectIterator, - * ctx?: any - * ): types.Collection; - */ - - /* eslint-disable no-unused-vars */ - - /* dependencies - * isArrLike keys optimizeCb types - */ - - exports = function(obj, iterator, ctx) { - iterator = optimizeCb(iterator, ctx); - var i, len; - - if (isArrLike(obj)) { - for (i = 0, len = obj.length; i < len; i++) { - iterator(obj[i], i, obj); - } - } else { - var _keys = keys(obj); - - for (i = 0, len = _keys.length; i < len; i++) { - iterator(obj[_keys[i]], _keys[i], obj); - } - } - - return obj; - }; - - return exports; -})({}); - -/* ------------------------------ noop ------------------------------ */ - -var noop = _.noop = (function (exports) { - /* A no-operation function. - */ - - /* example - * noop(); // Does nothing - */ - - /* typescript - * export declare function noop(): void; - */ - exports = function() {}; - - return exports; -})({}); - -/* ------------------------------ mkdir ------------------------------ */ -_.mkdir = (function (exports) { - /* Recursively create directories. - * - * |Name |Type |Desc | - * |----------|--------|-------------------| - * |dir |string |Directory to create| - * |mode=0777 |number |Directory mode | - * |[callback]|function|Callback | - */ - - /* example - * mkdir('/tmp/foo/bar/baz', function (err) { - * if (err) console.log(err); - * else console.log('Done'); - * }); - */ - - /* typescript - * export declare function mkdir(dir: string, mode?: number, cb?: Function): void; - * export declare function mkdir(dir: string, cb?: Function): void; - */ - - /* dependencies - * isFn noop - */ - - const fs = require('fs'); - const path = require('path'); - - const _0777 = parseInt('0777', 8); - - exports = function(p, mode, cb) { - if (isFn(mode)) { - cb = mode; - mode = _0777; - } - cb = cb || noop; - p = path.resolve(p); - - fs.mkdir(p, mode, function(err) { - if (!err) return cb(); - - switch (err.code) { - case 'ENOENT': - exports(path.dirname(p), mode, function(err) { - if (err) return cb(err); - - exports(p, mode, cb); - }); - break; - default: - fs.stat(p, function(errStat, stat) { - if (errStat || !stat.isDirectory()) return cb(errStat); - - cb(); - }); - } - }); - }; - - return exports; -})({}); - -/* ------------------------------ nextTick ------------------------------ */ - -var nextTick = _.nextTick = (function (exports) { - /* Next tick for both node and browser. - * - * |Name|Type |Desc | - * |----|--------|----------------| - * |cb |function|Function to call| - * - * Use process.nextTick if available. - * - * Otherwise setImmediate or setTimeout is used as fallback. - */ - - /* example - * nextTick(function () { - * // Do something... - * }); - */ - - /* typescript - * export declare function nextTick(cb: Function): void; - */ - if (typeof process === 'object' && process.nextTick) { - exports = process.nextTick; - } else if (typeof setImmediate === 'function') { - exports = function(cb) { - setImmediate(ensureCallable(cb)); - }; - } else { - exports = function(cb) { - setTimeout(ensureCallable(cb), 0); - }; - } - - function ensureCallable(fn) { - if (typeof fn !== 'function') - throw new TypeError(fn + ' is not a function'); - return fn; - } - - return exports; -})({}); - -/* ------------------------------ parallel ------------------------------ */ -_.parallel = (function (exports) { - /* Run an array of functions in parallel. - * - * |Name |Type |Desc | - * |-----|--------|-----------------------| - * |tasks|array |Array of functions | - * |[cb] |function|Callback once completed| - */ - - /* example - * parallel([ - * function(cb) { - * setTimeout(function () { cb(null, 'one') }, 200); - * }, - * function(cb) { - * setTimeout(function () { cb(null, 'two') }, 100); - * } - * ], function (err, results) { - * // results -> ['one', 'two'] - * }); - */ - - /* typescript - * export declare function parallel(tasks: Function[], cb?: Function): void; - */ - - /* dependencies - * noop each nextTick - */ - - exports = function(tasks, cb) { - cb = cb || noop; - var results = []; - var pending = tasks.length; - if (!pending) return done(null); - each(tasks, function(task, i) { - task(function(err, result) { - taskCb(i, err, result); - }); - }); - - function taskCb(i, err, result) { - results[i] = result; - if (--pending === 0 || err) done(err); - } - - function done(err) { - nextTick(function() { - cb(err, results); - cb = noop; - }); - } - }; - - return exports; -})({}); - -/* ------------------------------ reduce ------------------------------ */ -_.reduce = (function (exports) { - /* Turn a list of values into a single value. - * - * |Name |Type |Desc | - * |-----------------|------------|------------------------------| - * |obj |object array|Collection to iterate over | - * |iterator=identity|function |Function invoked per iteration| - * |[initial] |* |Initial value | - * |[ctx] |* |Function context | - * |return |* |Accumulated value | - */ - - /* example - * reduce([1, 2, 3], function (sum, n) { return sum + n }, 0); // -> 6 - */ - - /* typescript - * export declare function reduce( - * list: types.List, - * iterator: types.MemoIterator, - * memo?: TResult, - * context?: any - * ): TResult; - * export declare function reduce( - * list: types.Dictionary, - * iterator: types.MemoObjectIterator, - * memo?: TResult, - * context?: any - * ): TResult; - */ - - /* eslint-disable no-unused-vars */ - - /* dependencies - * optimizeCb isArrLike isUndef keys types - */ - - exports = createReduce(1); - exports.create = createReduce; - - function createReduce(dir) { - return function(obj, iterator, initial, ctx) { - iterator = optimizeCb(iterator, ctx); - var i, len, key; - - if (isArrLike(obj)) { - len = obj.length; - i = dir > 0 ? 0 : len - 1; - - if (isUndef(initial)) { - initial = obj[i]; - i += dir; - } - - for (; i < len && i >= 0; i += dir) { - initial = iterator(initial, obj[i], i, obj); - } - } else { - var _keys = keys(obj); - - len = _keys.length; - i = dir > 0 ? 0 : len - 1; - - if (isUndef(initial)) { - initial = obj[_keys[i]]; - i += dir; - } - - for (; i < len && i >= 0; i += dir) { - key = _keys[i]; - initial = iterator(initial, obj[key], key, obj); - } - } - - return initial; - }; - } - - return exports; -})({}); - -module.exports = _; \ No newline at end of file diff --git a/src/lib/logger.js b/src/lib/logger.js index 7e00b92..faa17a4 100644 --- a/src/lib/logger.js +++ b/src/lib/logger.js @@ -2,10 +2,10 @@ import { Logger } from './util' let logger -export default (logger = new Logger( +export default logger = new Logger( '[Eruda]', ENV === 'production' ? 'warn' : 'debug' -)) +) logger.formatter = function(type, argList) { argList.unshift(this.name)