ryuu
Version:
Domo App Dev Studio CLI, The main tool used to create, edit, and publish app designs to Domo
55 lines • 2.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs-extra");
const path = require("path");
const extract = require("extract-zip");
const shell = require("shelljs");
const login_1 = require("../util/login");
const log_1 = require("../util/log");
const prompts_1 = require("../util/prompts");
module.exports = (program) => {
program
.command('download')
.description('download a Custom App design')
.option('-i, --design-id <id>', 'design id')
.option('-d, --design-version <design-version>', 'design version')
.action(async (args) => {
try {
const client = await new login_1.Login().getClient();
let designId = args.designId;
let version = args.designVersion;
if (!designId) {
designId = await (0, prompts_1.createInput)('design id');
}
if (!version) {
version = await (0, prompts_1.createInput)('version', 'latest');
}
const req = await client.download(designId, version);
if (req.status === 200) {
const regexp = /filename="(.*)"/;
const name = req.headers['content-disposition'].match(regexp)[1] || 'domoapp';
const writeStream = fs.createWriteStream('./' + name + '.zip', {
flags: 'w+',
mode: 0o666,
});
req.data.pipe(writeStream);
writeStream.on('finish', () => {
const source = path.resolve('./' + name + '.zip');
const target = path.resolve('./' + name);
extract(source, { dir: target }).catch(() => {
shell.chmod('-R', 'u+w', target);
fs.remove(source);
log_1.log.fail('Extraction of design from its compressed zip file failed, removing downloaded zip.');
});
});
}
else {
log_1.log.fail('Design not found. Make sure you have the correct design id.');
}
}
catch {
log_1.log.clientRequestFailed('Unable to download design ' + args.designId);
}
});
};
//# sourceMappingURL=download.js.map