UNPKG

create-ext-app

Version:

## Installation This is a [Node.js](https://nodejs.org/en/) module available through the [npm registry](https://www.npmjs.com/).

93 lines 4.77 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.cli = void 0; const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const figlet = require("figlet"); const inquirer_1 = __importDefault(require("inquirer")); const fs = require('fs-extra'); const path = require('path'); const utils_1 = require("./utils"); function cli(argv) { return __awaiter(this, void 0, void 0, function* () { const program = new commander_1.Command(); program .version("1.0.0") .arguments('[app-name]') .description('Create a new project') .option('-h, --help', 'Display help', () => { console.log(`Usage: create-ext-app ${chalk_1.default.green('<project-directory>')} [options]`); console.log('\nOptions:'); console.log(` -V, --version output the version number`); console.log(` --template <typescript | javascript> Will create ext project with selected template`); console.log(` -h, --help output usage information`); process.exit(0); }) .option('--template <template-name>', 'Specify the project template') .action((appName, options) => __awaiter(this, void 0, void 0, function* () { if (!appName) { console.log('Please specify the project directory:'); console.log(` ${chalk_1.default.cyan('create-ext-app')} ${chalk_1.default.green('<project-directory>')}`); console.log('\nFor example:'); console.log(` ${chalk_1.default.cyan('create-ext-app')} ${chalk_1.default.green('my-ext-app')}`); console.log(`\nRun ${chalk_1.default.cyan('create-ext-app --help')} to see all options.`); process.exit(1); } const templateName = options.template; const answers = yield inquirer_1.default.prompt([ { type: 'checkbox', name: 'modules', message: 'Select ext modules to include:', choices: ['console', 'timers', 'websessions'], }, ]); let git_repo = "https://github.com/donalawa/ext-typescript-template.git"; if (templateName) { if (templateName == 'javascript') { git_repo = "https://github.com/donalawa/ext-javascript-template.git"; } } const currentPath = process.cwd(); const projectPath = path.join(currentPath, appName); console.log(`✨ Crating ext project in ${chalk_1.default.green(`${projectPath}`)}`); try { fs.mkdirSync(projectPath); if (templateName && templateName == 'javascript') { (0, utils_1.loadJavascriptTemplate)(git_repo, projectPath); } else { (0, utils_1.loadTypeScriptTemplate)(git_repo, projectPath, answers.modules, appName); (0, utils_1.modifyTsConfig)(projectPath, answers.modules); } (0, utils_1.modifyManifest)(projectPath, answers.modules, appName, templateName); } catch (err) { if (err.code === 'EEXIST') { console.log(`${chalk_1.default.red(`The file ${appName} already exist in the current directory, please give it another name.`)}`); } else { console.log(err); } process.exit(1); } console.log(chalk_1.default.green('\nProject created successfully!')); console.log(chalk_1.default.cyan('Happy Porting!')); })); program.parse(argv); }); } exports.cli = cli; //# sourceMappingURL=cli.js.map