@beisen/bscpm
Version:
63 lines (49 loc) • 1.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _yeomanGenerator = require('yeoman-generator');
var _yeomanGenerator2 = _interopRequireDefault(_yeomanGenerator);
var _camelcase = require('camelcase');
var _camelcase2 = _interopRequireDefault(_camelcase);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = class extends _yeomanGenerator2.default {
prompting() {
this.promptes = {};
return this.prompt([{
'type': 'input',
'name': 'folderName',
'message': '组件示例名(目录名):',
'validate': function (value) {
if (!value.match(/^[a-z\-\d]+?$/)) {
return '格式错误, 只能包含小写英文、数字、中划线';
}
return true;
},
'default': 'default'
}, {
'type': 'input',
'name': 'cmpPath',
'message': '组件路径:',
'default': 'src'
}]).then(promptes => {
this.promptes.folderName = promptes.folderName;
this.promptes.cmpPath = `../../${promptes.cmpPath.replace(/^\s*?\.\//, '')}`;
this.promptes.cmpName = (0, _camelcase2.default)(this.promptes.folderName, { pascalCase: true });
});
}
writing() {
this._private_copies([['index.js', `examples/${this.promptes.folderName}/index.js`]]);
}
_private_copies(copyJobs = []) {
copyJobs.forEach(([tplFilePath, destFilePath]) => {
if (!destFilePath) {
destFilePath = tplFilePath;
}
if (!tplFilePath) throw new Error('tplFilePath is none');
if (!destFilePath) throw new Error('destFilePath is none');
this.fs.copyTpl(this.templatePath(tplFilePath), this.destinationPath(`${this.options.contextRoot}/${destFilePath}`), this.promptes);
});
}
};
module.exports = exports['default'];