zents-cli
Version:
ZenTS is a Node.js & TypeScript MVC-Framework for building rich web applications, released as free and open-source software under the MIT License. It is designed for building web applications with modern tools and design patterns.
60 lines (59 loc) • 2.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../helper/log");
const AbstractCommand_1 = require("../classes/AbstractCommand");
const doesDirOrFileExists_1 = require("../helper/doesDirOrFileExists");
const command_1 = require("@oclif/command");
const isDirEmpty_1 = require("../helper/isDirEmpty");
const path_1 = require("path");
const removeDirOrFile_1 = require("../helper/removeDirOrFile");
const resolve_global_1 = require("resolve-global");
class Create extends AbstractCommand_1.AbstractCommand {
async run() {
this.welcome('Create a new ZenTS project!');
const { args, flags } = this.parse(Create);
const projectname = args.projectname;
const workingDir = path_1.join(process.cwd(), projectname);
if (flags.dev) {
this.log(log_1.debug('Running in dev mode...'));
if (!resolve_global_1.silent('yalc')) {
this.log(log_1.debug('Warning: Yalc is required to be installed globally when running in dev mode. Please install with npm i yalc -g. After installation you should publish a local copy of the ZenTS repository. If the create command fails in the tsc build phase you should execute cd myproject && yalc add zents && npm i && zen build after the command has failed.'));
}
}
if (await doesDirOrFileExists_1.doesDirOrFileExists(workingDir)) {
if (flags.clean) {
this.log(log_1.info('Cleaning destination directory...'));
await removeDirOrFile_1.removeDirOrFile(workingDir);
}
else if (!(await isDirEmpty_1.isDirEmpty(workingDir))) {
this.log(log_1.error(`Destination directory "${workingDir}" isn't empty! Use --clean or -c to clean destination.`));
process.exit(42);
}
}
await this.generate('Project', {
cwd: workingDir,
dev: flags.dev,
projectname,
});
this.log(log_1.success(`New ZenTS project created successfully under ${workingDir}`));
this.log(log_1.info(`Use cd ${projectname} && zen dev (or npm start) to start the ZenTS server.`));
}
}
exports.default = Create;
Create.aliases = ['create-project'];
Create.args = [
{
name: 'projectname',
required: true,
},
];
Create.description = 'create a new ZenTS project inside PROJECTNAME directory.';
Create.examples = [`$ zen create myproject`];
Create.flags = {
clean: command_1.flags.boolean({
char: 'c',
description: 'clean install directory before running installation',
}),
dev: command_1.flags.boolean({ char: 'd', hidden: true }),
help: command_1.flags.help({ char: 'h' }),
};