Skip to content
Permalink
Browse files

Add backup command.

  • Loading branch information
charlietango committed Nov 28, 2019
1 parent 6dca22c commit d43aba926e90b8d370a9cbcdc7a0d55eb4c8e0d5
Showing with 105 additions and 10 deletions.
  1. +6 −1 index.js
  2. +6 −6 package-lock.json
  3. +20 −2 utils/commands.js
  4. +67 −1 utils/helpers.js
  5. +6 −0 utils/inquirer-questions.js
@@ -1,7 +1,7 @@
const program = require('commander');
const Configstore = require('configstore');

const { clean, build, deploy, serve, updateFramework, create } = require('./utils/commands');
const { clean, build, deploy, backup, updateFramework, create } = require('./utils/commands');
const { version, name } = require('./package.json');

log = console.log;
@@ -40,6 +40,11 @@ program
.description('Wipe the local Remake environment including caches and build assets')
.action(() => clean());

program
.command('backup')
.description('Backup the deployed version of your app')
.action(() => backup());

module.exports = async () => {
program.parse(process.argv)
}

Some generated files are not rendered by default. Learn more.

@@ -10,7 +10,15 @@ const ora = require('ora');
const process = require('process');

const { readDotRemake, writeDotRemake, generateDotRemakeContent } = require('./dot-remake');
const { registerUser, checkSubdomain, registerSubdomain, createDeploymentZip, removeDeploymentZip, pushZipToServer } = require('./helpers');
const {
registerUser,
checkSubdomain,
registerSubdomain,
createDeploymentZip,
removeDeploymentZip,
pushZipToServer,
getAppsList,
backupApp } = require('./helpers');
const { questions } = require('./inquirer-questions');
const { getSuccessMessage } = require('./get-success-message');

@@ -196,4 +204,14 @@ const updateFramework = async () => {
log(chalk.greenBright('Framework successfully updated.'))
}

module.exports = { create, deploy, clean, build, updateFramework }
const backup = async () => {
await registerUser();
let appsList = await getAppsList();
const question = questions.APP_BACKUP;
question.choices = appsList.map((app) => ({ name: app.name, value: app.id }));
const backupAnswer = await inquirer.prompt([question]);
await backupApp(backupAnswer.appId);
process.exit();
}

module.exports = { create, deploy, clean, build, updateFramework, backup }
@@ -165,4 +165,70 @@ const pushZipToServer = async (projectName) => {
}
}

module.exports = { checkSubdomain, registerSubdomain, registerUser, createDeploymentZip, removeDeploymentZip, pushZipToServer }
const getAppsList = async () => {
const spinner = ora('Getting your apps list.').start();
try {
const appListResponse = await axios({
method: 'get',
url: `${remakeServiceHost}/service/apps`,
headers: {
'Authorization': `Bearer ${remakeCliConfig.get('user.authToken')}`
},
});
if (appListResponse.status === 200) {
spinner.succeed();
return appListResponse.data;
} else {
spinner.fail();
return null;
}
} catch (err) {
console.log(err)
spinner.fail();
return null;
}
}

const backupApp = async (appId) => {
const spinner = ora('Generating and downlading zip.').start();
try {
const backupResponse = await axios({
method: 'get',
url: `${remakeServiceHost}/service/backup`,
responseType: 'stream',
headers: {
'Authorization': `Bearer ${remakeCliConfig.get('user.authToken')}`
},
params: {
appId,
}
})
if (backupResponse.status === 200) {
const fileName = backupResponse.headers['content-disposition'].split('=')[1].replace(/\"/g, '');
const writer = fs.createWriteStream(fileName);
backupResponse.data.pipe(writer);
return new Promise((resolve, reject) => {
writer.on('finish', () => { spinner.succeed(); resolve(); });
writer.on('error', () => { spinner.fail(); reject(); });
});
} else {
spinner.fail();
return null;
}
} catch (err) {
console.log(err)
spinner.fail();
return null;
}
}

module.exports = {
checkSubdomain,
registerSubdomain,
registerUser,
createDeploymentZip,
removeDeploymentZip,
pushZipToServer,
getAppsList,
backupApp,
}
@@ -55,6 +55,12 @@ Your app will be accessible at <subdomain>.remakeapps.com
name: 'deployOk',
message: 'Subdomain is available. Do you want to proceed?',
type: 'confirm'
},
APP_BACKUP: {
message: 'Which app do you want to back up?',
name: 'appId',
type: 'list',
choices: []
}
}

0 comments on commit d43aba9

Please sign in to comment.
You can’t perform that action at this time.