diff --git a/README.md b/README.md index a9540ea..7e40bd9 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,10 @@ npm i https://github.com/ElementUI/theme-chalk -D et --init [file path] # watch then build -et --watch [--config variable file path] [--out theme path] +et --watch [--config variable file path] [--out theme path] [-s --source filePath] # build -et [--config variable file path] [--out theme path] [--minimize] +et [--config variable file path] [--out theme path] [--minimize] [-s --source filePath] ``` ## Node API @@ -40,12 +40,14 @@ var et = require('element-theme') // watch mode et.watch({ config: 'variables/path', + source: 'source/path' out: 'output/path' }) // build et.run({ config: 'variables/path', + source: 'source/path' out: 'output/path', minimize: true }) @@ -55,6 +57,9 @@ et.run({ ### config Variable file path, default `./element-variables.css`. +### source +Theme source files path, default `element-theme-default module folder`. + ### out Theme output path, default `./theme`. @@ -76,6 +81,7 @@ You can configure some options in `element-theme` by putting it in package.json: { "element-theme": { "browsers": ["ie > 9", "last 2 versions"], + "source": "theme source files", "out": "./theme", "config": "./element-variables.css", "theme": "element-theme-chalk", diff --git a/bin/element-theme b/bin/element-theme index 7987874..d6aca9a 100755 --- a/bin/element-theme +++ b/bin/element-theme @@ -1,28 +1,39 @@ #!/usr/bin/env node -var program = require('commander') -var main = require('../index.js') -var check = require('../lib/gen-vars').check -var config = {} +var program = require('commander'); +var main = require('../index.js'); +var check = require('../lib/gen-vars').check; +var config = {}; -console.log() +console.log(); process.on('exit', function () { - console.log() -}) + console.log(); +}); program - .version(require('../package.json').version) - .option('-i --init [filePath]', 'init variables file') - .option('-w --watch', 'watch variable changes then build') - .option('-o --out [outPath]', 'output path', function (out) {config.out = out}) - .option('-m --minimize', 'compressed file', function (minimize) {config.minimize = minimize !== false}) - .option('-c --config [filePath]', 'variables file', function (c) {config.config = c}) - .option('-b --browsers ', 'set browsers', function (browsers) {config.browsers = browsers.split(',')}) - .parse(process.argv) + .version(require('../package.json').version) + .option('-i --init [filePath]', 'init variables file') + .option('-w --watch', 'watch variable changes then build') + .option('-o --out [outPath]', 'output path', function (out) { + config.out = out; + }) + .option('-m --minimize', 'compressed file', function (minimize) { + config.minimize = minimize !== false; + }) + .option('-c --config [filePath]', 'variables file', function (c) { + config.config = c; + }) + .option('-s --source [filePath]', 'Source path', function (s) { + config.themePath = s; + }) + .option('-b --browsers ', 'set browsers', function (browsers) { + config.browsers = browsers.split(','); + }) + .parse(process.argv); -check() +check(); if (program.init) { - return main.init(program.init) + return main.init(program.init); } -program.watch ? main.watch(config) : main.run(config) +program.watch ? main.watch(config) : main.run(config); diff --git a/index.js b/index.js index f7edda1..dac0bae 100644 --- a/index.js +++ b/index.js @@ -1,37 +1,37 @@ -var gulp = require('gulp') -var series = require('run-sequence').use(gulp) -var task = require('./lib/task') -var vars = require('./lib/gen-vars') -var config = require('./lib/config') +var gulp = require('gulp'); +var series = require('run-sequence').use(gulp); +var task = require('./lib/task'); +var vars = require('./lib/gen-vars'); +var config = require('./lib/config'); var build = function (opts) { - return function () { - return task.build(Object.assign(opts, {message: 'build element theme'})) - } -} + return function () { + return task.build(Object.assign(opts, {message: 'build element theme'})); + }; +}; var fonts = function (opts) { - return function () { - return task.fonts(Object.assign(opts, {message: 'build theme font'})) - } -} + return function () { + return task.fonts(Object.assign(opts, {message: 'build theme font'})); + }; +}; exports.init = function (filePath) { - filePath = {}.toString.call(filePath) === '[object String]' ? filePath : '' - vars.init(filePath) -} + filePath = {}.toString.call(filePath) === '[object String]' ? filePath : ''; + vars.init(filePath); +}; exports.watch = function (opts) { - gulp.task('build', build(opts)) - exports.run(opts) - gulp.watch(opts.config || config.config, ['build']) -} + gulp.task('build', build(opts)); + exports.run(opts); + gulp.watch(opts.config || config.config, ['build']); +}; exports.run = function (opts, cb) { - gulp.task('build', build(opts)) - gulp.task('fonts', fonts(opts)) - if (typeof cb === 'function') { - return series('build', 'fonts', cb); - } - return series('build', 'fonts'); -} + gulp.task('build', build(opts)); + gulp.task('fonts', fonts(opts)); + if (typeof cb === 'function') { + return series('build', 'fonts', cb); + } + return series('build', 'fonts'); +}; diff --git a/lib/config.js b/lib/config.js index caa8b08..9118484 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,23 +1,24 @@ -var path = require('path') +var path = require('path'); -var pkg = {} +var pkg = {}; try { - pkg = require(path.resolve(process.cwd(), 'package.json')) -} catch (err) {} + pkg = require(path.resolve(process.cwd(), 'package.json')); +} catch (err) { +} var config = Object.assign({ - browsers: ['ie > 9', 'last 2 versions'], - out: './theme', - config: './element-variables.scss', - theme: 'element-theme-chalk', - minimize: false -}, pkg['element-theme']) + browsers: ['ie > 9', 'last 2 versions'], + out: './theme', + config: './element-variables.scss', + theme: 'element-theme-chalk', + minimize: false +}, pkg['element-theme']); -exports.themePath = path.resolve(process.cwd(), './node_modules/' + config.theme) -exports.out = config.out -exports.config = config.config -exports.minimize = config.minimize -exports.browsers = config.browsers -exports.components = config.components -exports.themeName = config.theme +exports.themePath = path.resolve(process.cwd(), './node_modules/' + config.theme); +exports.out = config.out; +exports.config = config.config; +exports.minimize = config.minimize; +exports.browsers = config.browsers; +exports.components = config.components; +exports.themeName = config.theme; diff --git a/lib/gen-vars.js b/lib/gen-vars.js index 4b4ef10..e869cb4 100644 --- a/lib/gen-vars.js +++ b/lib/gen-vars.js @@ -1,27 +1,27 @@ -var path = require('path') -var fs = require('fs') -var ora = require('ora') -var config = require('./config') +var path = require('path'); +var fs = require('fs'); +var ora = require('ora'); +var config = require('./config'); -var varsPath = path.resolve(config.themePath, './src/common/var.scss') -var filePath = path.resolve(process.cwd(), config.config) +var varsPath = path.resolve(config.themePath, './src/common/var.scss'); +var filePath = path.resolve(process.cwd(), config.config); exports.check = function () { - if (!fs.existsSync(varsPath)) { - ora('please install `' + config.themeName + '`').fail() - process.exit(1) - } -} + if (!fs.existsSync(varsPath)) { + ora('please install `' + config.themeName + '`').fail(); + process.exit(1); + } +}; exports.init = function (_file) { - var spinner = ora('Generator variables file').start() + var spinner = ora('Generator variables file').start(); - filePath = path.resolve(process.cwd(), _file ? _file : config.config) - if (fs.existsSync(filePath)) { - spinner.text = 'Variables file already exists.' - spinner.fail() - } else { - fs.writeFileSync(filePath, fs.readFileSync(varsPath), 'utf-8') - spinner.succeed() - } -} + filePath = path.resolve(process.cwd(), _file ? _file : config.config); + if (fs.existsSync(filePath)) { + spinner.text = 'Variables file already exists.'; + spinner.fail(); + } else { + fs.writeFileSync(filePath, fs.readFileSync(varsPath), 'utf-8'); + spinner.succeed(); + } +}; diff --git a/lib/task.js b/lib/task.js index 557e233..b09a9b3 100644 --- a/lib/task.js +++ b/lib/task.js @@ -1,49 +1,49 @@ -var path = require('path') -var fs = require('fs') -var gulp = require('gulp') -var ora = require('ora') -var nop = require('gulp-nop') -var sass = require('gulp-sass') -var autoprefixer = require('gulp-autoprefixer') -var cssmin = require('gulp-cssmin') -var config = require('./config') +var path = require('path'); +var fs = require('fs'); +var gulp = require('gulp'); +var ora = require('ora'); +var nop = require('gulp-nop'); +var sass = require('gulp-sass'); +var autoprefixer = require('gulp-autoprefixer'); +var cssmin = require('gulp-cssmin'); +var config = require('./config'); exports.fonts = function (opts) { - var spin = ora(opts.message).start() - var stream = gulp.src(path.resolve(config.themePath, './src/fonts/**')) - .pipe((opts.minimize || config.minimize) ? cssmin({showLog: false}) : nop()) - .pipe(gulp.dest(path.resolve(opts.out || config.out, './fonts'))) - .on('end', function () { - spin.succeed() - }) + var spin = ora(opts.message).start(); + var stream = gulp.src(path.resolve(opts.themePath || config.themePath, './src/fonts/**')) + .pipe((opts.minimize || config.minimize) ? cssmin({showLog: false}) : nop()) + .pipe(gulp.dest(path.resolve(opts.out || config.out, './fonts'))) + .on('end', function () { + spin.succeed(); + }); - return stream -} + return stream; +}; exports.build = function (opts) { - var spin = ora(opts.message).start() - var stream - var components - var cssFiles = '*' + var spin = ora(opts.message).start(); + var stream; + var components; + var cssFiles = '*'; - if (config.components) { - components = config.components.concat(['base']) - cssFiles = '{' + components.join(',') + '}' - } - var varsPath = path.resolve(config.themePath, './src/common/var.scss') - fs.writeFileSync(varsPath, fs.readFileSync(path.resolve(process.cwd(), opts.config || config.config)), 'utf-8') + if (config.components) { + components = config.components.concat(['base']); + cssFiles = '{' + components.join(',') + '}'; + } + var varsPath = path.resolve(opts.themePath || config.themePath, './src/common/var.scss'); + fs.writeFileSync(varsPath, fs.readFileSync(path.resolve(process.cwd(), opts.config || config.config)), 'utf-8'); - stream = gulp.src([opts.config || config.config, path.resolve(config.themePath, './src/' + cssFiles + '.scss')]) - .pipe(sass.sync()) - .pipe(autoprefixer({ - browsers: config.browsers, - cascade: false - })) - .pipe((opts.minimize || config.minimize) ? cssmin({showLog: false}) : nop()) - .pipe(gulp.dest(opts.out || config.out)) - .on('end', function () { - spin.succeed() - }) + stream = gulp.src([opts.config || config.config, path.resolve(opts.themePath || config.themePath, './src/' + cssFiles + '.scss')]) + .pipe(sass.sync()) + .pipe(autoprefixer({ + browsers: config.browsers, + cascade: false + })) + .pipe((opts.minimize || config.minimize) ? cssmin({showLog: false}) : nop()) + .pipe(gulp.dest(opts.out || config.out)) + .on('end', function () { + spin.succeed(); + }); - return stream -} + return stream; +}; diff --git a/package.json b/package.json index a6b467b..55f5f24 100644 --- a/package.json +++ b/package.json @@ -15,9 +15,9 @@ "test": "xo" }, "xo": { - "space": true, + "space": false, "rule": { - "semi": 0, + "semi": 1, "unicorn/no-process-exit": 0, "import/no-dynamic-require": 0 }