ryuu
Version:
Domo App Dev Studio CLI, The main tool used to create, edit, and publish app designs to Domo
240 lines • 9.18 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var inquirer = require("inquirer");
var _ = require("lodash");
var open = require("open");
var manifest_1 = require("../util/manifest");
var login_1 = require("../util/login");
var glob = require("glob");
var fs = require("fs-extra");
var log_1 = require("../util/log");
var appStructure = require("../util/appStructure");
var models_1 = require("../models");
var multichoice_1 = require("../util/multichoice");
module.exports = function (program) {
program
.command('publish')
.description('publish a new or existing Custom App design')
.option('-g, --go', 'navigate to design in Asset Library after publishing')
.action(function (options) {
var manifest = manifest_1.ManifestUtils.getManifest(program.opts().manifest, true);
new login_1.Login()
.getClient()
.then(function (client) {
if (client.getRefreshToken() === undefined) {
log_1.log.notAuthenticated();
}
checkFileNames(manifest);
if (!manifest.id) {
createDesign(client, manifest, options);
}
else {
client
.getDesign(manifest.id, { parts: 'versions' })
.then(function (result) {
checkMapping(result, manifest);
return publishAssets(client, manifest).then(function () {
return linkToDomoWeb(options, client, manifest);
});
})
.catch(function (e) { return publishErrors(e, client, manifest); });
}
})
.catch(log_1.log.notAuthenticated);
});
};
var createDesign = function (domo, manifest, options) {
return domo
.createDesign(manifest)
.then(function (designResult) {
var newManifestId = manifest_1.ManifestUtils.persistDesignId(designResult.id, manifest);
manifest = __assign(__assign({}, manifest), { id: newManifestId });
log_1.log.ok('New design created on ' + domo.getInstance());
})
.catch(function (e) {
log_1.log.fail('Error when creating new design:', e.message);
})
.then(function () { return domo.uploadAllAssets(manifest); })
.then(function (files) {
//@ts-ignore
return logUploadSuccess(files);
})
.catch(function (e) {
log_1.log.fail(e || 'Error uploading assets in uploading assets for a new design');
})
.then(function () {
linkToDomoWeb(options, domo, manifest);
});
};
var logUploadSuccess = function (files) {
files.forEach(function (file) {
log_1.log.ok('Uploaded: ' + file.path);
});
};
var linkToDomoWeb = function (options, domo, manifest) {
console.log('Design can be found at https://' +
domo.getInstance() +
'/assetlibrary?designId=' +
manifest.id);
if (options && options['go']) {
open('https://' + domo.getInstance() + '/assetlibrary?designId=' + manifest.id);
}
};
var checkMapping = function (result, manifest) {
var latestVersionNumber = result.latestVersion;
var latestVersion = result.versions.filter(function (obj) {
return obj.version === latestVersionNumber;
});
var oldMapping = latestVersion[0].datasetsMapping[0];
var newMapping = manifest.datasetsMapping[0];
if (oldMapping) {
delete oldMapping.dql;
}
if (!_.isEqual(oldMapping, newMapping)) {
log_1.log.warn('Mapping has changed. Check current cards for potential miss-mappings.');
}
};
var checkFileNames = function (manifest) {
var ignore = ['**/*/node_modules/**/*', 'node_modules/**/*'];
var userIgnore = manifest.ignore;
if (userIgnore) {
if (userIgnore instanceof Array) {
ignore = ignore.concat(userIgnore);
}
else {
log_1.log.fail('The manifest.json "ignore" property must be an Array');
}
}
var badFileList = glob.sync('**/*', { ignore: ignore }).filter(function (file) {
console.log(file);
return (
// special characters except "/" in file names are not allowed
/[~`!#$%\^&*+=\[\]\\';,{}|\\":<>\?]/g.test(file) ||
(!fs.lstatSync(file).isDirectory() && file.indexOf(' ') !== -1));
});
if (badFileList.length > 0) {
log_1.log.fail('Special characters in file/directory names are not allowed as well as spaces in file names. Please rename the following file/directory(s): ' +
badFileList);
}
if (!appStructure.hasThumbnail()) {
log_1.log.warn(models_1.constant.THUMBNAIL_CREATE_WARNING, models_1.constant.CREATE_THUMBNAIL);
}
};
var recreateDesign = function (domo, manifest) {
inquirer
.prompt((0, multichoice_1.default)({
type: 'list',
message: 'This design has been deleted. Would you like to undelete this design and publish to it, or create a new design with these assets?',
name: 'askRecreate',
choices: ['Undelete', 'Create New Design'],
}))
.then(function (answers) {
if (answers.askRecreate) {
if (answers.askRecreate == 'Create New Design') {
manifest.id = null;
createDesign(domo, manifest);
}
else if (answers.askRecreate == 'Undelete') {
domo.unDeleteDesign(manifest.id).then(function () {
publishAssets(domo, manifest);
});
}
else {
log_1.log.ok('Exited without republishing design');
}
}
});
};
var publishErrors = function (e, domo, manifest) {
var _a, _b;
if (e.statusCode === 400 && !e.message.startsWith('DA')) {
log_1.log.fail('Design failed to publish with error:', e.message);
}
else if (e.statusCode === 401) {
log_1.log.notAuthenticated(domo.getRefreshToken());
}
else if (e.statusCode === 403) {
log_1.log.fail('You do not have access to the design with id ' +
manifest.id +
' on ' +
domo.getInstance() +
'.\nIf that seems unlikely, other possibilities are that you are publishing this design to a new environment other than the one in which it was first created.' +
'\nAlternatively, you may have inadvertently changed the design id.');
}
else if (((_a = e.message) === null || _a === void 0 ? void 0 : _a.substr(0, 23)) == 'Design has been deleted')
recreateDesign(domo, manifest);
else if (((_b = e.message) === null || _b === void 0 ? void 0 : _b.substr(0, 15)) == 'No design found') {
inquirer
.prompt({
type: 'confirm',
message: 'This design does not exist on ' +
domo.getInstance() +
'. Would you like to create a new design with these assets?',
name: 'askCreate',
})
.then(function (answers) {
if (answers.askCreate) {
manifest.id = null;
createDesign(domo, manifest);
}
});
}
else if (e.message && e.message.startsWith('DA')) {
switch (e.message.substr(0, 6)) {
case 'DA0086':
log_1.log.warn(e.message);
inquirer
.prompt([
{
type: 'confirm',
message: 'This design has been deleted. Would you like to publish a new design with these assets?',
name: 'askRecreate',
},
])
.then(function (answers) {
if (answers.askRecreate) {
manifest.id = null;
createDesign(domo, manifest);
}
});
break;
default:
// Pass on error messages that aren't in the set of documented errors.
log_1.log.fail(e.message);
break;
}
}
else {
//Error uploading assets
log_1.log.fail(log_1.log.handleErrorMessage(e, 'Error uploading assets in the upload all assets'));
}
};
var publishAssets = function (domo, manifest) {
return domo
.uploadAllAssets(manifest)
.then(function (files) {
log_1.log.ok('Publishing ' +
manifest.name +
' to ' +
domo.getInstance() +
' on ' +
new Date());
//@ts-ignore
logUploadSuccess(files);
})
.catch(function (e) {
publishErrors(e, domo, manifest);
});
};
//# sourceMappingURL=publish.js.map