UNPKG

@getditto/project-cli

Version:
60 lines 2.6 kB
#!/usr/bin/env node var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const program = require("commander"); const path = require("path"); const shell = require("shelljs"); const fs = require("fs-extra"); const colors = require("colors"); const version = require('../package.json').version; program .version(version) .command('init [name]') .description('Create a project with a name. If the template option is not specified') .action((projectName) => __awaiter(this, void 0, void 0, function* () { if (!projectName) { console.error('You need to specify a project name.'); console.log(`Example usage: "$ project-cli init MY_PROJECT"`); } let projectPath = path.join(process.cwd(), projectName); const exists = fs.existsSync(projectPath); if (exists) { console.error(`Oh no... "${projectName}" is already taken`); return; } shell.exec(`git clone https://github.com/getditto/node-typescript-starter ${projectName}`); shell.exec(`rm -rf ${projectName}/.git/`); let rawData = fs.readFileSync(path.join(projectPath, 'package.json'), 'utf8'); let packageJson = JSON.parse(rawData); packageJson.name = projectName; packageJson.repository = ""; packageJson.description = ""; fs.writeFileSync(path.join(projectPath, 'package.json'), JSON.stringify(packageJson, null, 2), 'utf8'); if (shell.which('yarn')) { const currentPwd = process.cwd(); shell.exec(`cd ${projectPath}; yarn; cd ${currentPwd}`); } else if (shell.which('npm')) { shell.exec(`npm install --prefix ${projectPath}`); } else { console.log(colors.red('Sorry you will need either yarn or npm.')); return; } console.log(colors.green(`Congrats! Your new project "${projectName}" is ready!`)); })) .on('--help', () => { console.log(` Examples: project-cli init MY_PROJECT `); }); program.parse(process.argv); //# sourceMappingURL=index.js.map