Dev: Use prettier to format code

This commit is contained in:
redhoodsu
2018-06-12 22:19:56 +08:00
parent 70b5aedc36
commit 1e5a6560fa
68 changed files with 5051 additions and 5884 deletions

View File

@@ -7,31 +7,36 @@ var collector = new istanbul.Collector(),
var remappedJson = require('../coverage/coverage-remapped.json');
var coverage = util.reduce(util.keys(remappedJson), function (result, source)
{
if (isSrc())
{
var correctPath = source.replace(path.resolve(__dirname, '../src'), path.resolve(__dirname, '../'));
var coverage = util.reduce(
util.keys(remappedJson),
function(result, source) {
if (isSrc()) {
var correctPath = source.replace(
path.resolve(__dirname, '../src'),
path.resolve(__dirname, '../')
);
var val = remappedJson[source];
val.path = correctPath;
result[correctPath] = val;
}
var val = remappedJson[source];
val.path = correctPath;
result[correctPath] = val;
}
function isSrc(src)
{
return source.match(/src.*\.js$/) &&
source.indexOf('node_modules') < 0 &&
source.indexOf('util') < 0;
}
function isSrc(src) {
return (
source.match(/src.*\.js$/) &&
source.indexOf('node_modules') < 0 &&
source.indexOf('util') < 0
);
}
return result;
}, {});
return result;
},
{}
);
collector.add(coverage);
reporter.addAll(['html', 'lcov']);
reporter.write(collector, true, function ()
{
reporter.write(collector, true, function() {
console.log('open coverage/index.html to see the coverage report.');
});
});

View File

@@ -2,46 +2,49 @@ var copy = require('copy'),
path = require('path'),
util = require('./util');
util.mkdir(path.resolve(__dirname, '../test/lib'), function (err)
{
util.mkdir(path.resolve(__dirname, '../test/lib'), function(err) {
if (err) return console.log(err);
cpTestFiles();
});
function cpTestFiles()
{
util.parallel([
genCpCb('/jasmine-core/lib/jasmine-core/{jasmine.css,jasmine.js,jasmine-html.js,boot.js}', '/lib', {
srcBase: '/jasmine-core/lib/jasmine-core/'
}),
genCpCb('/jasmine-jquery/lib/jasmine-jquery.js', '/lib', {
srcBase: '/jasmine-jquery/lib/'
}),
genCpCb('/jquery/dist/jquery.js', '/lib', {
srcBase: '/jquery/dist/'
})
], function (err)
{
if (err) return console.log(err);
function cpTestFiles() {
util.parallel(
[
genCpCb(
'/jasmine-core/lib/jasmine-core/{jasmine.css,jasmine.js,jasmine-html.js,boot.js}',
'/lib',
{
srcBase: '/jasmine-core/lib/jasmine-core/'
}
),
genCpCb('/jasmine-jquery/lib/jasmine-jquery.js', '/lib', {
srcBase: '/jasmine-jquery/lib/'
}),
genCpCb('/jquery/dist/jquery.js', '/lib', {
srcBase: '/jquery/dist/'
})
],
function(err) {
if (err) return console.log(err);
console.log('Copy test lib successfully!');
});
console.log('Copy test lib successfully!');
}
);
}
function genCpCb(src, dest, options)
{
function genCpCb(src, dest, options) {
options = options || {};
if (options.srcBase) options.srcBase = path.resolve(__dirname, '../node_modules/') + options.srcBase;
if (options.srcBase)
options.srcBase =
path.resolve(__dirname, '../node_modules/') + options.srcBase;
src = path.resolve(__dirname, '../node_modules/') + src;
dest = path.resolve(__dirname, '../test/') + dest;
return function (cb)
{
return function(cb) {
console.log('Copy %s to %s', src, dest);
copy(src, dest, options, function (err)
{
copy(src, dest, options, function(err) {
if (err) return cb(err);
cb();

View File

@@ -3,36 +3,50 @@
var fs = require('fs'),
path = require('path');
fs.readFile(path.resolve(__dirname, 'icomoon/fonts/icomoon.woff'), function (err, data)
{
fs.readFile(path.resolve(__dirname, 'icomoon/fonts/icomoon.woff'), function(
err,
data
) {
if (err) return console.log(err);
genCssFile(data.toString('base64'));
});
function genCssFile(fontData)
{
fs.readFile(path.resolve(__dirname, 'icomoon/style.css'), 'utf-8', function (err, data)
{
function genCssFile(fontData) {
fs.readFile(path.resolve(__dirname, 'icomoon/style.css'), 'utf-8', function(
err,
data
) {
if (err) return console.log(err);
data = data.split('\n');
data.splice(2, 5, ' src: url(\'data:application/x-font-woff;charset=utf-8;base64,' +
fontData + '\') format(\'woff\');');
data.splice(
2,
5,
" src: url('data:application/x-font-woff;charset=utf-8;base64," +
fontData +
"') format('woff');"
);
data = data.join('\n');
data = data.replace(/icon-"/g, 'eruda-icon-"');
data = data.replace(/font-family: 'icomoon'/g, 'font-family: \'eruda-icon\'');
data = data.replace(
/font-family: 'icomoon'/g,
"font-family: 'eruda-icon'"
);
writeCssFile(data);
});
}
function writeCssFile(data)
{
fs.writeFile(path.resolve(__dirname, '../src/style/icon.css'), data, 'utf-8', function (err, data)
{
if (err) return console.log(err);
function writeCssFile(data) {
fs.writeFile(
path.resolve(__dirname, '../src/style/icon.css'),
data,
'utf-8',
function(err, data) {
if (err) return console.log(err);
console.log('icon.css generated!');
})
}
console.log('icon.css generated!');
}
);
}

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,7 @@ var autoprefixer = require('autoprefixer'),
pkg = require('../package.json'),
path = require('path');
process.traceDeprecation = true;
process.traceDeprecation = true;
var nodeModDir = path.resolve('./node_modules/') + '/',
banner = pkg.name + ' v' + pkg.version + ' ' + pkg.homepage;
@@ -12,9 +12,9 @@ var nodeModDir = path.resolve('./node_modules/') + '/',
var postcssLoader = {
loader: 'postcss-loader',
options: {
plugins: [classPrefix('eruda-'), autoprefixer]
plugins: [classPrefix('eruda-'), autoprefixer]
}
};
};
module.exports = {
entry: './src/index',
@@ -24,7 +24,7 @@ module.exports = {
},
output: {
path: path.resolve(__dirname, '../'),
publicPath: "/assets/",
publicPath: '/assets/',
library: ['eruda'],
libraryTarget: 'umd'
},
@@ -68,7 +68,8 @@ module.exports = {
test: /\.hbs$/,
loader: nodeModDir + 'handlebars-loader/index.js',
options: {
runtime: nodeModDir + 'handlebars/dist/handlebars.runtime.js'
runtime:
nodeModDir + 'handlebars/dist/handlebars.runtime.js'
}
},
{
@@ -83,4 +84,4 @@ module.exports = {
VERSION: '"' + pkg.version + '"'
})
]
};
};

View File

@@ -6,8 +6,8 @@ exports.output.filename = 'eruda.js';
exports.devtool = 'source-map';
exports.plugins = exports.plugins.concat([
new webpack.DefinePlugin({
ENV: '"development"',
ENV: '"development"'
})
]);
module.exports = exports;
module.exports = exports;

View File

@@ -12,8 +12,8 @@ exports.plugins = exports.plugins.concat([
comments: /eruda/
}),
new webpack.DefinePlugin({
ENV: '"production"',
ENV: '"production"'
})
]);
module.exports = exports;
module.exports = exports;