|
| 1 | +#!/usr/bin/env node |
| 2 | +const ch = require('child_process'); |
| 3 | +const gulp = require('gulp'); |
| 4 | +const runSequence = require('run-sequence'); |
| 5 | +const gutil = require('gulp-util'); |
| 6 | +const fileSave = require('file-save'); |
| 7 | +const path = require('path'); |
| 8 | +const exec = ch.exec; |
| 9 | + |
| 10 | +if (!process.argv[2]) { |
| 11 | + console.error('[组件名]必填.'); |
| 12 | + process.exit(1); |
| 13 | +} |
| 14 | + |
| 15 | +const name = process.argv[2]; |
| 16 | + |
| 17 | + |
| 18 | +// 项目规范文件拷贝 |
| 19 | +gulp.task('copy', function(callback) { |
| 20 | + gutil.log(gutil.colors.yellow('-------> 开始初始化')); |
| 21 | + |
| 22 | + exec('cd packages && git clone git@gitlab.qima-inc.com:fe/vue-seed.git ' + name, function(err, stdout, stderr) { |
| 23 | + gutil.log('-------> 拉取 vue-seed'); |
| 24 | + exec('rm -rf ./' + name + '/.git', function(err, stdout, stderr) { |
| 25 | + gutil.log('-------> ' + name + '组件初始化成功'); |
| 26 | + callback(); |
| 27 | + }); |
| 28 | + }); |
| 29 | +}); |
| 30 | + |
| 31 | + |
| 32 | +// 添加到 components.json |
| 33 | +gulp.task('addComponents', function(callback) { |
| 34 | + const componentsFile = require('../../components.json'); |
| 35 | + if (componentsFile[name]) { |
| 36 | + console.error(`${name} 已存在.`); |
| 37 | + process.exit(1); |
| 38 | + } |
| 39 | + componentsFile[name] = `./packages/${name}/index.js`; |
| 40 | + fileSave(path.join(__dirname, '../../components.json')) |
| 41 | + .write(JSON.stringify(componentsFile, null, ' '), 'utf8') |
| 42 | + .end('\n'); |
| 43 | + gutil.log('-------> components.json文件更新成功'); |
| 44 | + gutil.log(gutil.colors.yellow('-------> 请无视下面的make报错')); |
| 45 | +}); |
| 46 | + |
| 47 | +runSequence('copy', 'addComponents'); |
| 48 | + |
0 commit comments