UNPKG

@lenne.tech/cli

Version:

lenne.Tech CLI: lt

120 lines (119 loc) 5.34 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); /** * Create a new TypeScript project */ const NewCommand = { alias: ['ce'], description: 'Creates a new Chrome extension', hidden: false, name: 'chrome-extension', run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () { // Retrieve the tools we need const { filesystem, git, helper, meta, parameters, patching, print: { error, info, spin, success }, strings: { kebabCase }, system, } = toolbox; // Start timer const timer = system.startTimer(); // Info info('Create a new Chrome extension project'); // Check git if (!(yield git.gitInstalled())) { return; } // Get name const name = yield helper.getInput(parameters.first, { name: 'Project name', showError: true, }); if (!name) { return; } // Set project directory const projectDir = kebabCase(name); // Check if directory already exists if (filesystem.exists(projectDir)) { info(''); error(`There's already a folder named "${projectDir}" here.`); return; } // Clone git repository const cloneSpinner = spin('Clone https://github.com/lenneTech/chrome-extension-angular-starter.git'); yield system.run(`git clone https://github.com/lenneTech/chrome-extension-angular-starter.git ${projectDir}`); if (filesystem.isDirectory(`./${projectDir}`)) { filesystem.remove(`./${projectDir}/.git`); cloneSpinner.succeed('Repository cloned from https://github.com/lenneTech/chrome-extension-angular-starter.git'); } // Check directory if (!filesystem.isDirectory(`./${projectDir}`)) { error(`The directory "${projectDir}" could not be created.`); return; } // Get author const author = yield helper.getInput(parameters.second, { name: 'Author', showError: false, }); const prepareSpinner = spin('Prepare files'); // Set up initial props (to pass into templates) const nameKebab = kebabCase(name); // Patch readme yield patching.replace(`./${projectDir}/README.md`, '# Starter for Chrome Extension via Angular', `# ${name}`); yield patching.replace(`./${projectDir}/README.md`, 'This is the lenne.Tech starter for new Chrome Extension via Angular.', ''); // Set package.json yield patching.update(`./${projectDir}/package.json`, (config) => { config.author = author; config.bugs = { url: '', }; config.description = name; config.homepage = ''; config.name = nameKebab; config.repository = { type: 'git', url: '', }; config.version = '0.0.1'; return config; }); // Set package.json yield patching.update(`./${projectDir}/package-lock.json`, (config) => { config.name = nameKebab; config.version = '0.0.1'; return config; }); // Set manifest.json yield patching.update(`./${projectDir}/angular/src/manifest.json`, (config) => { config.name = name; config.short_name = name; config.description = ''; return config; }); // Patch app component yield patching.replace(`./${projectDir}/angular/src/app/app.component.html`, 'Chrome Extension Starter', name); yield patching.replace(`./${projectDir}/angular/src/app/app.component.html`, 'Chrome Extension starter', name); prepareSpinner.succeed('Files prepared'); // Install packages const installSpinner = spin('Install packages'); yield system.run(`cd ${projectDir} && ${toolbox.pm.install(toolbox.pm.detect(projectDir))}`); installSpinner.succeed('Packages installed'); // Init git const initGitSpinner = spin('Initialize git'); yield system.run(`cd ${projectDir} && git init && git add . && git commit -am "Init via lenne.Tech CLI ${meta.version()}"`); initGitSpinner.succeed('Git initialized'); // We're done, so show what to do next info(''); success(`Generated ${name} with lenne.Tech CLI ${meta.version()} in ${helper.msToMinutesAndSeconds(timer())}m.`); info(''); // For tests return `project ${name} created`; }), }; exports.default = NewCommand;