@carlosbajo/roket-micro
Version:
framework para microservicios con google/pubsub
61 lines (59 loc) • 2.11 kB
JavaScript
const shell = require('shelljs');
const exec = require('child_process').exec;
const path = require('path');
const fs = require('fs');
const { addCheckMark, animateProgress, theBad } = require('./specialEfects');
const readline = require('readline');
process.stdin.resume();
process.stdin.setEncoding('utf8');
let interval = animateProgress('Apropieandote del repo');
process.stdout.write('Apropieandote del repo');
function cleanRepo(callback) {
shell.rm('-rf', '.git/');
setTimeout(() => addCheckMark(callback), 3000);
}
function initGit(callback) {
shell.sed('-i', 'roket-google', shell.env.MICROSERVICE, 'package.json');
exec('git init && git add . && git commit -m "Initial commit"', addCheckMark.bind(null, callback));
}
function installDepsCallback(error) {
clearInterval(interval);
process.stdout.write('\n\n');
if (error) {
theBad(error);
process.stdout.write('\n');
process.exit(1);
}
function deleteFileInCurrentDir(file, callback) {
fs.unlink(path.join(__dirname, file), callback);
}
deleteFileInCurrentDir('startup.js', () => {
interval = animateProgress('Creando "tu" nuevo repo');
process.stdout.write('Creando "tu" nuevo repo');
initGit(() => {
setTimeout(() => clearInterval(interval), 1000);
process.stdout.write('\n♦♦♦The End♦♦♦\n');
process.exit(0);
});
});
}
function installDeps() {
if (!shell.env.MICROSERVICE) installDepsCallback('\n Se necesita el nombre del microservicio... ejemplo: MICROSERVICE=@nombre@ npm run setup \n \n');
exec('node --version', (err, stdout) => {
const nodeVersion = stdout && parseFloat(stdout.substr(1, 4));
if (nodeVersion < 7.10 || err) {
installDepsCallback(err || 'Se necesita una version mas reciente que la 7.10');
} else {
exec('npm install', addCheckMark.bind(null, installDepsCallback));
}
});
}
cleanRepo(() => {
clearInterval(interval);
process.stdout.write('\ndependencies...');
setTimeout(() => {
readline.cursorTo(process.stdout, 0);
interval = animateProgress('dependencies...');
}, 500);
installDeps();
});