create-cliz
Version:
Cliz Multiple Commands CLI Template
93 lines (92 loc) • 2.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generate = exports.Generator = void 0;
const cli_1 = require("@cliz/cli");
// 1. clone
// 2. change config
// 3. install
// 4.
class Generator {
constructor(config) {
this.config = config;
//
}
async clone() {
const { config } = this;
// await api.$.runShell(`git clone --progress ${config.templateURL} ${config.projectPath}`);
await cli_1.api.$ `git clone ${config.templateURL} ${config.projectPath} --depth=1`;
// clean git history and regenerate
await cli_1.api.fs.rmdir(`${config.projectPath}/.git`);
await cli_1.api.$.cd(config.projectPath);
await cli_1.api.$ `git init`;
}
async changeConfig() {
var _a, _b;
const { config } = this;
const pkg = await cli_1.api.fs.json.read(`${config.projectPath}/package.json`);
pkg.version = '0.0.0';
pkg.name = config.packageName;
pkg.description = config.description;
pkg.author = config.author;
pkg.homepage = (_a = config.homepage) !== null && _a !== void 0 ? _a : '';
pkg.repository = (_b = config.repository) !== null && _b !== void 0 ? _b : '';
pkg.bin = {
[config.name]: 'lib/cli.js',
};
pkg.cliz = {
name: config.name,
};
if (pkg.repository) {
pkg.bugs = {
url: `${pkg.repository}/issues`,
};
}
else {
delete pkg.bugs;
}
await cli_1.api.fs.writeFile(`${config.projectPath}/package.json`, JSON.stringify(pkg, null, 2));
}
async install() {
const { config } = this;
await cli_1.api.$.cd(config.projectPath);
// await api.$.runShell(`yarn`);
await cli_1.api.$ `yarn`;
}
async copyProjectPath() {
const { config } = this;
await cli_1.api.clipboard.copy(config.projectPath);
}
}
exports.Generator = Generator;
async function generate(options) {
const generator = new Generator(options);
cli_1.api.task.add({
title: 'Load template ...',
task: async () => {
await cli_1.doreamon.delay(1000);
await generator.clone();
},
}, {
title: 'Apply config ...',
task: async () => {
await cli_1.doreamon.delay(1000);
await generator.changeConfig();
},
},
// {
// title: 'Install dependencies',
// task: async () => {
// await doreamon.delay(1000);
// await generator.install();
// },
// },
{
title: 'Copy project path ...',
task: async () => {
await cli_1.doreamon.delay(1000);
await generator.copyProjectPath();
},
});
await cli_1.api.task.run();
}
exports.generate = generate;