@beisen/bscpm
Version:
74 lines (56 loc) • 2.64 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);
var _requestPromise = require('request-promise');
var _requestPromise2 = _interopRequireDefault(_requestPromise);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
exports.default = class extends _yeomanGenerator2.default {
prompting() {
var _this = this;
return _asyncToGenerator(function* () {
const { CMP_SERVER_HOST, GITLAB_HOST } = process.env;
_this.promptes = {};
_this.groupNames = [];
_this.groupNameCNMaps = {};
try {
let groups = yield (0, _requestPromise2.default)({ 'uri': `${CMP_SERVER_HOST}/api/v2/groups`, 'json': true });
groups.forEach(function (group) {
let shownNameCN = `${group.nameCN} (${group.name})`;
_this.groupNames.push(shownNameCN);
_this.groupNameCNMaps[shownNameCN] = group.name;
});
} catch (e) {
console.log(e);
// throw new Error('应用信息获取失败,请检查网络连接是否正确')
}
return _this.prompt([{
'type': 'list',
'name': 'group',
'message': '所属项目组:',
'choices': _this.groupNames
}]).then(function (promptes) {
_this.promptes.group = _this.groupNameCNMaps[promptes.group]; // 获取真正的APP_NAME
});
})();
}
writing() {
this._private_copies([['bscpmrc.json', `.bscpmrc`]]);
}
_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'];