UNPKG

atomic-reactor-cli

Version:

A CLI for creating Atomic Reactor Awesomeness

67 lines (54 loc) 2.08 kB
const path = require('path'); const fs = require('fs-extra'); const op = require('object-path'); const request = require('request'); const decompress = require('@atomic-reactor/decompress'); module.exports = spinner => { const message = text => { if (spinner) { spinner.text = text; } }; return { download: ({ params, props, action }) => { const { config, cwd } = props; message('downloading payload, this may take awhile...'); // Create the tmp directory. fs.ensureDirSync(path.normalize(`${cwd}/tmp`)); // Download the most recent version of actinium return new Promise((resolve, reject) => { request(config.actinium.repo) .pipe( fs.createWriteStream( path.normalize(`${cwd}/tmp/actinium.zip`), ), ) .on('error', error => reject(error)) .on('close', () => resolve({ action, status: 200 })); }); }, unzip: ({ params, props, action }) => { const { config, cwd } = props; message('unpacking...'); const zipFile = path.normalize(`${cwd}/tmp/actinium.zip`); return new Promise((resolve, reject) => { decompress(zipFile, cwd, { strip: 1 }) .then(() => resolve({ action, status: 200 })) .catch(error => reject(error)); }); }, cleanup: ({ params, props, action }) => { const { config, cwd } = props; message('removing temp files...'); return new Promise((resolve, reject) => { fs.remove(path.normalize(`${cwd}/tmp`), error => { if (error) { reject(error); } else { resolve({ action, status: 200 }); } }); }); }, }; };