update script

This commit is contained in:
Harvey Zack committed 2018-11-30 12:14:13 +08:00
1 parent d62405e8ff
commit 848c6ab131
8 files changed
+106 -69

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
const fs = require('fs');
const path = require('path');
const babel = require('rollup-plugin-babel');
const commonjs = require('rollup-plugin-commonjs');
const nodeResolve = require('rollup-plugin-node-resolve');
const postcss = require('rollup-plugin-postcss');
const { eslint } = require('rollup-plugin-eslint');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const replace = require('rollup-plugin-replace');
const svgo = require('rollup-plugin-svgo');
const { uglify } = require('rollup-plugin-uglify');
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';
const banner =
'/*!\n' +
` * ${name}.js v${version}\n` +
` * Github: ${homepage}\n` +
` * (c) 2017-${new Date().getFullYear()} Harvey Zack\n` +
' * Released under the MIT License.\n' +
' */\n';
return {
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`),
format: 'umd',
exports: 'named',
},
plugins: [
eslint({
exclude: ['node_modules/**', 'src/**/*.scss', 'src/**/*.svg'],
}),
postcss({
plugins: [autoprefixer, cssnano],
extract: isProd ? path.join(projectPath, `dist/${name}.css`) : path.join(process.cwd(), `docs/uncompiled/${name}.css`),
}),
nodeResolve(),
commonjs(),
babel({
runtimeHelpers: true,
exclude: 'node_modules/**',
presets: [['@babel/env', { modules: false }]],
plugins: ['@babel/plugin-external-helpers', '@babel/plugin-transform-runtime'],
}),
svgo({
raw: true,
}),
replace({
exclude: 'node_modules/**',
__ENV__: JSON.stringify(process.env.NODE_ENV || 'development'),
__VERSION__: version,
}),
isProd &&
uglify({
output: {
preamble: banner,
},
}),
],
};
};
module.exports = creatRollupConfig(process.env.TARGET);
View File
Whitespace-only changes.
+27
View File
@@ -0,0 +1,27 @@
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);
};