@botmock-api/export-cli
Advanced tools
Comparing version 1.0.0 to 1.0.1
54
index.js
@@ -1,52 +0,2 @@ | ||
#! /usr/bin/env node | ||
import prompts from 'prompts'; | ||
import chalk from 'chalk'; | ||
import fs from 'fs'; | ||
import { exec } from 'child_process'; | ||
import { promisify } from 'util'; | ||
import * as literals from './templates'; | ||
try { | ||
const { platform, nodeVersion } = await prompts([ | ||
{ | ||
type: 'text', | ||
name: 'platform', | ||
message: `What's the name of the platform?`, | ||
format: str => str.toLowerCase().replace(/\s/g, '-'), | ||
validate: str => (str.length < 1 ? 'must be nonempty' : true) | ||
}, | ||
{ | ||
type: 'text', | ||
name: 'nodeVersion', | ||
message: `What's the node.js version it requires?`, | ||
validate: str => (isNaN(parseInt(str)) ? `${str} must be a number` : true) | ||
} | ||
]); | ||
const NEW_PROJECT_DIRECTORY = `${process.cwd()}/botmock-${platform}-export`; | ||
// Create this directory if it does not exist yet | ||
try { | ||
await fs.promises.access(NEW_PROJECT_DIRECTORY, fs.constants.R_OK); | ||
} catch (_) { | ||
await fs.promises.mkdir(NEW_PROJECT_DIRECTORY); | ||
} | ||
// Write the files | ||
await Promise.all( | ||
Object.keys(literals).map(async k => { | ||
const { filename, content } = literals[k]; | ||
await fs.promises.writeFile( | ||
`${NEW_PROJECT_DIRECTORY}/${filename}`, | ||
content | ||
.replace(/@PLATFORM/g, platform) | ||
.replace(/@NODE-VERSION/g, nodeVersion) | ||
); | ||
}) | ||
); | ||
process.chdir(NEW_PROJECT_DIRECTORY); | ||
await promisify(exec)('npm install'); | ||
console.log(chalk.dim(`installing dependencies in ${NEW_PROJECT_DIRECTORY}`)); | ||
process.chdir('../'); | ||
console.log(chalk.dim(`created ${__dirname}`)); | ||
} catch (err) { | ||
console.error(err.message); | ||
process.exit(1); | ||
} | ||
require = require('esm')(module); | ||
module.exports = require('./main.js'); |
{ | ||
"name": "@botmock-api/export-cli", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Scaffold Botmock export scripts", | ||
"bin": "index.js", | ||
"scripts": { | ||
"start": "node --no-warnings -r esm index.js" | ||
}, | ||
"bin": "./index.js", | ||
"esm": { | ||
@@ -10,0 +7,0 @@ "await": true |
11967
7
144