@platform/cell.tmpl
Version:
Template generator for CellOS.
76 lines (75 loc) • 3.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.tmpl = void 0;
var tslib_1 = require("tslib");
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
var common_1 = require("../common");
var middleware = require("./cmd.tmpl.middleware");
function tmpl(args) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var install, tmplDir, fsPrompt, dir, name, rename, tmpl, variables, alerts$, task;
var _this = this;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
install = common_1.defaultValue(args.install, true);
tmplDir = common_1.fs.resolve(common_1.fs.join(__dirname, '../../templates'));
fsPrompt = common_1.cli.prompt.fs.paths(tmplDir, { pageSize: 10, all: false });
return [4, fsPrompt.radio('create from:')];
case 1:
dir = (_a.sent())[0];
return [4, common_1.cli.prompt.text({ message: 'module name' })];
case 2:
name = _a.sent();
rename = [{ from: 'pkg.json', to: 'package.json' }];
tmpl = common_1.Template
.create(dir)
.use(middleware.processPackage({ filename: 'pkg.json' }))
.use(middleware.replaceText())
.use(middleware.saveFile({ rename: rename, done: install ? 'NEXT' : 'COMPLETE' }));
if (install) {
tmpl = tmpl.use(middleware.npmInstall({ done: 'COMPLETE' }));
}
variables = {
dir: common_1.fs.resolve("./" + name),
name: name,
};
alerts$ = tmpl.events$.pipe(operators_1.filter(function (e) { return e.type === 'TMPL/alert'; }), operators_1.map(function (e) { return e.payload; }));
task = {
title: common_1.log.gray("Create template: " + common_1.log.white(common_1.fs.basename(dir))),
task: function () {
return new rxjs_1.Observable(function (observer) {
alerts$.subscribe(function (e) { return observer.next(e.message); });
(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, tmpl.execute({ variables: variables })];
case 1:
_a.sent();
observer.complete();
return [2];
}
});
}); })();
});
},
};
common_1.log.info();
return [4, common_1.cli.exec.tasks.run(task)];
case 3:
_a.sent();
common_1.log.info();
common_1.log.info.cyan(" cd " + common_1.fs.basename(variables.dir));
if (!install) {
common_1.log.info.cyan(" yarn install");
}
common_1.log.info.cyan(" yarn " + common_1.log.green('start'));
common_1.log.info();
common_1.log.info.gray(variables.dir);
return [2];
}
});
});
}
exports.tmpl = tmpl;