UNPKG

config-ymal-react-angular

Version:

A CLI to help generate a YMAL for deploying React and Angular App

173 lines (167 loc) 5.24 kB
#! /usr/bin/env node const fs = require('fs'); const path = require('path'); const inquirer = require('inquirer'); const YAML = require('yaml'); const nowPath = path.join(process.cwd(), '*.yml'); const existingConfig = fs.existsSync(nowPath); const fef = require('./configs/fef'); async function buildConfig() { let config = { version: 2, }; const answers = await inquirer .prompt([ { type: 'text', name: 'name', message: 'What is the name of the project?', default: path.basename(process.cwd()), }, { type: 'list', name: 'type', message: 'What type of project?', choices: [ 'react', 'vue', 'angular' ], }, ]); config.name = answers.name; config.type = answers.type switch (answers.type) { case 'react': config = await fef(config, 'build', answers.type); config = { "trigger": [ "master" ], "pool": { "vmImage": "ubuntu-latest" }, "steps": [ { "task": "NodeTool@0", "inputs": { "versionSpec": "10.x" }, "displayName": "Install Node.js" }, { "script": "npm install\nnpm run build\n", "displayName": "npm install and build" } ] } break; case 'vue': config = await fef(config, 'dist', answers.type); config = { "trigger": [ "master" ], "pool": { "vmImage": "ubuntu-latest" }, "steps": [ { "task": "NodeTool@0", "inputs": { "versionSpec": "10.x" }, "displayName": "Install Node.js" }, { "script": "npm install\nnpm run build\n", "displayName": "npm install and build" } ] } break; case 'angular': config = await fef(config, 'dist', answers.type); config = { "trigger": [ "master" ], "pool": { "vmImage": "ubuntu-latest" }, "steps": [ { "task": "NodeTool@0", "inputs": { "versionSpec": "10.x" }, "displayName": "Install Node.js" }, { "script": "npm install -g @angular/cli\nnpm install\nng build --prod\n", "displayName": "npm install and build" } ] } break; default: break; } const devEnv = await inquirer .prompt([ { type: 'list', name: 'type', message: 'What type of project?', choices: [ 'Azure', 'AWS', 'others' ], }, ]); let file; switch (devEnv.type) { case 'Azure': file = path.join(process.cwd(), 'azure-pipelines.yml'); fs.writeFileSync(file, YAML.stringify(config), 'utf8'); console.log('All done! Type now to deploy!'); process.exit(0); break; case 'AWS': file = path.join(process.cwd(), 'appspec.yml'); fs.writeFileSync(file, YAML.stringify(config), 'utf8'); console.log('All done! Type now to deploy!'); process.exit(0); break; case 'others': file = path.join(process.cwd(), 'dev.yml'); fs.writeFileSync(file, YAML.stringify(config), 'utf8'); console.log('All done! Type now to deploy!'); process.exit(0); break; default: break; } } if (existingConfig) { inquirer.prompt([ { type: 'confirm', name: 'toChangeConfig', message: 'Do you want to change config?', default: false } ]) .then(answer => { if (answer.toChangeConfig) { buildConfig() } else { console.log('Goodbye!'); } }) } else { buildConfig() }