完成ci优化

This commit is contained in:
Harvey Zack committed 2018-11-30 17:25:48 +08:00
1 parent 848c6ab131
commit 00ea9c4ca4
23 files changed
+94 -306

No files matched your search

+14 -6
View File
@@ -10,10 +10,10 @@ const cssnano = require('cssnano');
const replace = require('rollup-plugin-replace');
const svgo = require('rollup-plugin-svgo');
const { uglify } = require('rollup-plugin-uglify');
const copyAfterBuild = require('./copyAfterBuild');
function creatRollupConfig(target) {
const projectPath = path.join(process.cwd(), 'packages', target);
console.log(projectPath);
const packageJson = JSON.parse(fs.readFileSync(path.join(projectPath, 'package.json'), 'utf-8'));
const { version, homepage, name } = packageJson;
const isProd = process.env.NODE_ENV === 'production';
@@ -29,17 +29,21 @@ function creatRollupConfig(target) {
input: path.join(projectPath, 'src/index.js'),
output: {
name,
file: isProd ? path.join(projectPath, `dist/${name}.js`) : path.join(process.cwd(), `docs/uncompiled/${name}.js`),
file: isProd
? path.join(projectPath, `dist/${name}.js`)
: path.join(process.cwd(), `docs/uncompiled/${name}.js`),
format: 'umd',
exports: 'named',
},
plugins: [
eslint({
exclude: ['node_modules/**', 'src/**/*.scss', 'src/**/*.svg'],
exclude: ['node_modules/**', 'packages/*/src/**/*.scss', 'packages/*/src/**/*.svg'],
}),
postcss({
plugins: [autoprefixer, cssnano],
extract: isProd ? path.join(projectPath, `dist/${name}.css`) : path.join(process.cwd(), `docs/uncompiled/${name}.css`),
extract: isProd
? path.join(projectPath, `dist/${name}.css`)
: path.join(process.cwd(), `docs/uncompiled/${name}.css`),
}),
nodeResolve(),
commonjs(),
@@ -63,8 +67,12 @@ function creatRollupConfig(target) {
preamble: banner,
},
}),
isProd && copyAfterBuild({
from: path.join(projectPath, 'dist/*'),
to: path.join(process.cwd(), 'docs/compiled'),
}),
],
};
};
}
module.exports = creatRollupConfig(process.env.TARGET);
module.exports = creatRollupConfig(process.env.TARGET);
+18
View File
@@ -0,0 +1,18 @@
const cpy = require('cpy');
module.exports = (opts = {}) => ({
name: 'copyAfterBuild',
generateBundle(outputOptions, bundle, isWrite) {
if (!isWrite) {
throw new Error('copyAfterBuild currently only works with bundles that are written to disk');
}
if (opts.from && opts.to) {
cpy(opts.from, opts.to).then(() => {
console.log('File copy succeeded!');
}).catch(() => {
throw new Error('File copy failed!');
});
}
},
});
-27
View File
@@ -1,27 +0,0 @@
const chalk = require('chalk');
const { format } = require('util');
const prefix = 'artplayer-cli';
const sep = chalk.gray('·');
exports.log = function log(...args) {
const msg = format.apply(format, args);
console.log(chalk.white(prefix), sep, msg);
};
exports.fatal = function fatal(...args) {
if (args[0] instanceof Error) args[0] = args[0].message.trim();
const msg = format.apply(format, args);
console.error(chalk.red(prefix), sep, msg);
process.exit(1);
};
exports.success = function success(...args) {
const msg = format.apply(format, args);
console.log(chalk.green(prefix), sep, msg);
};
exports.warn = function warn(...args) {
const msg = format.apply(format, args);
console.log(chalk.yellow(prefix), sep, msg);
};