@platform/cell.tmpl
Version:
Template generator for the system
72 lines (71 loc) • 3.72 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 = tslib_1.__importStar(require("./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 = (0, common_1.defaultValue)(args.install, true);
tmplDir = common_1.PATHS.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("./".concat(name)),
name: name,
};
alerts$ = tmpl.events$.pipe((0, operators_1.filter)(function (e) { return e.type === 'TMPL/alert'; }), (0, operators_1.map)(function (e) { return e.payload; }));
task = {
title: common_1.log.gray("Create template: ".concat(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(" cd ".concat(common_1.log.green(common_1.fs.basename(variables.dir))));
common_1.log.info();
common_1.log.info.gray(variables.dir);
return [2];
}
});
});
}
exports.tmpl = tmpl;