Skip to content

Commit

Permalink
Fix things up 🚧
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 committed Mar 31, 2019
1 parent aa90d0f commit 4c39392
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 52 deletions.
8 changes: 2 additions & 6 deletions lib/commands/deploy/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ const { validateInstallation } = require('../../utils/validations');
exports.dockerize = () => {
showBanner();

setTimeout(() => {
setTimeout(async () => {
configFileExists();
await validateInstallation('docker');

if (!shell.which('docker')) {
shell.echo('Docker is currently not installed on your system');
validateInstallation('docker');
} else {
// currently works on linux only
if (os.type() === 'Linux') {
console.log('\n');
Expand All @@ -31,7 +28,6 @@ exports.dockerize = () => {
}
});
}
}

}, 100);
};
57 changes: 54 additions & 3 deletions lib/commands/deploy/herokuDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,37 @@ const os = require('os');
const shell = require('shelljs');

const { appData } = require('../../utils/projectConfig');
const { configFileExists } = require('../../utils/messages');
const { configFileExists, dependencyNotInstalled } = require('../../utils/messages');
const { showBanner } = require('../../external/banner');
const { validateInstallation } = require('../../utils/validations');

// Determining host OS
let isLinux = process.platform === 'linux';
let isWin = process.platform === 'win32';
let isMac = process.platform === 'darwin';

const validateInstallation = async () => {
if (!shell.which('heroku')) {
await inquirer.prompt([{
type: 'confirm',
name: 'installDependency',
message: `Sorry, heroku-cli is not installed on your system, Do you want to install it?`
}])
.then((choice) => {
if (choice.installDependency) {
installHerokuCLI();
} else {
dependencyNotInstalled('heroku-cli');
}
});
}
};

exports.deploy = () => {
showBanner();

setTimeout(async () => {
configFileExists();
validateInstallation('heroku');
await validateInstallation('heroku');

let templateIsNuxt;
await appData().
Expand Down Expand Up @@ -62,3 +83,33 @@ exports.deploy = () => {
}, 100);
;
};

const installHerokuCLI = async () => {
if (isWin) {
try{
await shell.echo('Installing heroku for Windows...');
await hell.echo('You need to manually download heroku-cli from: https://devcenter.heroku.com/articles/heroku-cli and try to deploy again');
await shell.exit(1);
}
catch (err) {
throw err;
}
} else if (isMac) {
try {
await shell.echo('Installing heroku for Mac...')
await shell.exec('brew tap heroku/brew && brew install heroku', {silent: true});
} catch (err) {
throw err;
}
} else if (isLinux) {
try {
await shell.echo('Installing heroku for Linux...');
await shell.exec('sudo apt get update', {silent: true});
await shell.exec('sudo apt-get install snap', {silent: true});
await shell.exec('sudo snap install --classic heroku', {silent: true});
await shell.echo('Heroku was installed successfully');
} catch (err) {
throw err;
}
}
};
54 changes: 11 additions & 43 deletions lib/utils/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,31 @@ const { executeCommands } = require('../commands/deploy/herokuDeploy');

// Determining host OS
let isLinux = process.platform === 'linux';
let isWindows = process.platform === 'win32';
let isWin = process.platform === 'win32';
let isMac = process.platform === 'darwin';

exports.validateInstallation = (dependency) => {
exports.validateInstallation = async (dependency) => {
if (!shell.which(dependency)) {
inquirer.prompt([{
await inquirer.prompt([{
type: 'confirm',
name: 'installDependency',
message: `Sorry, ${dependency} is not installed on your system, Do you want to install ${dependency}?`
message: `Sorry, ${dependency} is not installed on your system, Do you want to install it?`
}])
.then((choice) => {
if (choice.installDependency) {
if (dependency === 'git') {
validateGitInstallation();
} else if (dependency === 'docker') {
validateDockerInstallation();
} else {
validateHerokuCLIInstallation();
}
installGit();
} else {
installDocker();
}
} else {
dependencyNotInstalled(dependency);
}
});
}
};

const validateGitInstallation = async () => {
const installGit = async () => {
// install git for linux
if(isLinux){
shell.exec('sudo apt-get update', (err) => {
Expand Down Expand Up @@ -63,15 +61,15 @@ const validateGitInstallation = async () => {
}
};

const validateDockerInstallation = async () => {
const installDocker = async () => {
if (isMac) {
try{
await shell.echo('You need to install docker from the official downloads page: https://docs.docker.com/docker-for-mac/install/');
shell.exit(1);
} catch (err) {
throw err;
}
} else if (isWindows) {
} else if (isWin) {
try{
await shell.echo('You need to install docker from the official downloads page: https://hub.docker.com/editions/community/docker-ce-desktop-windows');
shell.exit(1);
Expand All @@ -93,33 +91,3 @@ const validateDockerInstallation = async () => {
}
}
};

const validateHerokuCLIInstallation = async () => {
if (isWindows) {
try{
await shell.echo('Installing heroku for Windows...');
await hell.echo('You need to manually download heroku-cli from: https://devcenter.heroku.com/articles/heroku-cli and try to deploy again');
await shell.exit(1);
}
catch (err) {
throw err;
}
} else if (isMac) {
try {
await shell.echo('Installing heroku for Mac...')
await shell.exec('brew tap heroku/brew && brew install heroku', {silent: true});
} catch (err) {
throw err;
}
} else if (isLinux) {
try {
await shell.echo('Installing heroku for Linux...');
await shell.exec('sudo apt get update', {silent: true});
await shell.exec('sudo apt-get install snap', {silent: true});
await shell.exec('sudo snap install --classic heroku', {silent: true});
await shell.echo('Heroku was installed successfully');
} catch (err) {
throw err;
}
}
};

0 comments on commit 4c39392

Please sign in to comment.