初始化组件脚本update

This commit is contained in:
niunai
2017-01-15 16:15:53 +08:00
parent 900b5d7063
commit 61415a16b6
18 changed files with 159 additions and 294 deletions
-9
View File
@@ -8,21 +8,12 @@ var OUTPUT_PATH = path.join(__dirname, '../../src/index.js');
var IMPORT_TEMPLATE = 'import {{name}} from \'../packages/{{package}}/index.js\';';
var ISNTALL_COMPONENT_TEMPLATE = ' Vue.component({{name}}.name, {{name}});';
var MAIN_TEMPLATE = `{{include}}
import '../src/assets/font/iconfont.css';
const install = function(Vue) {
if (install.installed) return;
{{install}}
Vue.use(InfiniteScroll);
Vue.use(Lazyload, {
loading: require('./assets/loading-spin.svg'),
try: 3
});
Vue.$messagebox = Vue.prototype.$messagebox = MessageBox;
Vue.$toast = Vue.prototype.$toast = Toast;
Vue.$indicator = Vue.prototype.$indicator = Indicator;
};
// auto install
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env node
const ch = require('child_process');
const gulp = require('gulp');
const runSequence = require('run-sequence');
const gutil = require('gulp-util');
const fileSave = require('file-save');
const path = require('path');
const exec = ch.exec;
if (!process.argv[2]) {
console.error('[组件名]必填.');
process.exit(1);
}
const name = process.argv[2];
// 项目规范文件拷贝
gulp.task('copy', function(callback) {
gutil.log(gutil.colors.yellow('-------> 开始初始化'));
exec('cd packages && git clone git@gitlab.qima-inc.com:fe/vue-seed.git ' + name, function(err, stdout, stderr) {
gutil.log('-------> 拉取 vue-seed');
exec('rm -rf ./' + name + '/.git', function(err, stdout, stderr) {
gutil.log('-------> ' + name + '组件初始化成功');
callback();
});
});
});
// 添加到 components.json
gulp.task('addComponents', function(callback) {
const componentsFile = require('../../components.json');
if (componentsFile[name]) {
console.error(`${name} 已存在.`);
process.exit(1);
}
componentsFile[name] = `./packages/${name}/index.js`;
fileSave(path.join(__dirname, '../../components.json'))
.write(JSON.stringify(componentsFile, null, ' '), 'utf8')
.end('\n');
gutil.log('-------> components.json文件更新成功');
gutil.log(gutil.colors.yellow('-------> 请无视下面的make报错'));
});
runSequence('copy', 'addComponents');