Skip to content

Commit

Permalink
CLI: Added Way to Update Backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
tks18 committed Nov 28, 2020
1 parent 20b562f commit 9a079f1
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 2 deletions.
1 change: 1 addition & 0 deletions cli-tool/commands/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
exports.init = require('./init');
exports.deploy = require('./deploy');
exports.update = require('./update');
123 changes: 123 additions & 0 deletions cli-tool/commands/update/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
const checkHerokuLogin = require('../deploy/checkHerokuLogin');
const gitCheckoutHApp = require('../deploy/gitCheckoutHApp');
const createTMP = require('../deploy/createTMP');
const downloadUnzip = require('../deploy/downloadUnzip');
const initBackendnCommit = require('../deploy/initBackendnCommit');
const inputPrompts = require('../deploy/inputPrompts');
const pushBackend = require('./pushBackend');
const herokuNotAuthMess = require('../init/post-init');
const spinner = require('../../helpers/spinner');

const chalk = require('chalk');

module.exports = async () => {
spinner(true, 'Check for Heroku Login Status', 0, false, async(herokuSpin) => {
const checkHeroku = await checkHerokuLogin();
herokuSpin.stop();
if(checkHeroku.res){
console.log(
'\n'+
chalk.bold.green("Heroku Login Successfull")+'\n\n'+
chalk.white(checkHeroku.output)+
'\n'
);
const appname = await inputPrompts.appName();
if(appname.length > 1){
createTMP(async (tempPath, resPath) => {
spinner(true, 'Downloading latest Backend Repo and Unzipping Now', 0, false, async(downSpin) => {
const downloadUnzipBackend = downloadUnzip(tempPath, async () => {
downSpin.stop();
console.log(
'\n'+
chalk.bold.green("Download and Unzip of Backend Successfull")+'\n\n'+
chalk.white("Backend downloaded and Unzipped in "+tempPath+". Don\'t Worry this will be Autocleaned after this Process.")+
'\n'
);
spinner(true, 'Initializing Repo for Deploying to Heroku', 0, false, async(initSpin) => {
const gitInitBack = await initBackendnCommit(resPath);
initSpin.stop();
if(gitInitBack.res){
console.log(
'\n'+
chalk.bold.green("Initialized Backend and Ready to Deploy to Heroku")+'\n\n'+
chalk.white(gitInitBack.output)+
'\n'
);
spinner(true, 'Checking Heroku App for Deployment', 0, false, async(checkSpin) => {
const checkOutHeroku = await gitCheckoutHApp(appname, resPath);
checkSpin.stop();
if(checkOutHeroku.res){
console.log(
'\n'+
chalk.bold.green("Sucessfully Initialized the Heroku app for Backend Deployment")+'\n\n'+
chalk.white(checkOutHeroku.output)+
'\n'
);
spinner(true, 'Pushing the Latest Backend to Heroku App', 0, false, async(pushSpin) => {
const pushHeroku = await pushBackend(resPath);
pushSpin.stop();
if(pushHeroku.res){
console.log(
'\n'+
chalk.bold.green("Pushing to Backend Successfull. Here is the Build Process.")+'\n\n'+
chalk.white(pushHeroku.output)+
'\n'
);
console.log(
'\n'+
chalk.yellow.bold(`You can Access the backend in the following Address for Creating the Super User\n>> https://${appname}.herokuapp.com`)+
'\n'
);
process.exit();
} else {
console.log(
'\n'+
chalk.bold.red("Pushing to Backend Failed with the Following Error")+'\n\n'+
chalk.white(pushHeroku.output)+
'\n'
);
process.exit();
}
})
} else {
console.log(
'\n'+
chalk.bold.red("Initializing Heroku App Failed with the Following Error")+'\n\n'+
chalk.white(checkOutHeroku.output)+
'\n'
);
process.exit();
}
})
} else {
console.log(
'\n'+
chalk.bold.red("Initializing Backend Zip Failed with the Following Error")+'\n\n'+
chalk.white(gitInitBack.output)+
'\n'
);
process.exit();
}
})
})
})
})
} else {
console.log(
'\n'+
chalk.bold.red("Appname Should be More than Atleast 1 Chars")+'\n'
);
process.exit();
}
} else {
console.log(
'\n'+
chalk.bold.red("It Looks like You are not Logged in to Heroku")+'\n\n'+
chalk.white(checkHeroku.output)+
'\n'+
herokuNotAuthMess
);
process.exit();
}
})
}
31 changes: 31 additions & 0 deletions cli-tool/commands/update/pushBackend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const execa = require('execa');
const path = require('path');

module.exports = async (cwdPath) => {
const backPath = path.resolve(cwdPath);
try {
const result = await execa('git', ['push','heroku', 'master', '--force'], { cwd: backPath });
if(!result.failed && !result.killed && !result.timedOut && !result.isCancelled){
return {
res: true,
output: result.stdout+'\n'+result.stderr,
cmd: result.command,
exitCode: result.exitCode
};
} else {
return {
res: false,
output: result.stdout+'\n'+result.stderr,
cmd: result.command,
exitCode: result.exitCode
};
}
} catch(e) {
return {
res: false,
output: e.stdout+'\n'+e.stderr,
cmd: e.command,
exitCode: e.exitCode
};
}
}
7 changes: 6 additions & 1 deletion cli-tool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const spinner = require('./helpers/spinner');
const yargs = require('yargs')
const { hideBin } = require('yargs/helpers')
const initialRender = require('./displays/initial-render');
const { init, deploy } = require('./commands');
const { init, deploy, update } = require('./commands');

console.log(
initialRender()
Expand All @@ -19,6 +19,11 @@ yargs(hideBin(process.argv))
deploy();
});
})
.command('update', 'Update Your Backend to latest Version', {}, (argv) => {
spinner(false, `Initializing Now`, 2, false, function(){
update();
});
})
.argv

if(yargs.argv._.length < 1){
Expand Down
2 changes: 1 addition & 1 deletion cli-tool/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gindex-cli-tool",
"version": "1.0.0",
"version": "1.1.0",
"description": "A Cli Tool to Publish Google Drive Index's Frontend and Backend all in One Tool",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 9a079f1

Please sign in to comment.