UNPKG

ryuu

Version:

Domo App Dev Studio CLI, The main tool used to create, edit, and publish app designs to Domo

158 lines 5.45 kB
"use strict"; 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 }); exports.ManifestUtils = void 0; var fs = require("fs-extra"); var path = require("path"); var semver = require("semver"); var glob = require("glob"); var log_1 = require("../util/log"); var isValidJSName_1 = require("../util/isValidJSName"); /** * Get the local manifest.json file, ensuring it's valid. */ var getManifest = function (manifestName, verifyValid) { if (manifestName === void 0) { manifestName = 'manifest.json'; } if (verifyValid === void 0) { verifyValid = false; } var manifestPath = findManifest(manifestName); var rawmanifest; try { rawmanifest = fs.readFileSync(path.resolve(manifestPath)); } catch (e) { if (verifyValid) { log_1.log.fail("No ".concat(manifestName, " file in this directory"), "Please publish from a directory containing a Custom App design ".concat(manifestName, " file")); } else { return; } } var manifest; try { manifest = JSON.parse(rawmanifest.toString()); } catch (e) { log_1.log.fail("Your ".concat(manifestName, " file is not valid JSON"), e.message); } if (verifyValid) { manifest = updateManifestProperties(manifest); validateManifest(manifest); } // add the manifest name, so it's attached to the object manifest.fileName = manifestName; /* waiting to deploy below line until I have time to refactor oauth log.info(`Getting manifest located in ${ path.resolve(manifestPath) }`) */ return manifest; }; var hasManifest = function (manifestName) { return fs.existsSync(findManifest(manifestName)); }; /** * update the manifest (in memory and on disk) */ var persistDesignId = function (id, manifest) { var newManifest = __assign(__assign({}, manifest), { id: id }); updateManifest(newManifest); return id; }; var updateManifest = function (manifest) { var manifestPath = findManifest(manifest.fileName); fs.writeJsonSync(manifestPath, manifest, { spaces: 2 }); }; /** * Validate the manifest file. */ var validateManifest = function (manifest) { // validate manifest file for required fields requireProperty(manifest, 'name'); requireProperty(manifest, 'version'); // validate semver if (!semver.valid(manifest.version)) { log_1.log.fail('Invalid version', 'Please make sure the `version` in your manifest.json file is a valid semantic version. See http://semver.org/'); } return manifest; }; var requireProperty = function (obj, prop) { if (!obj[prop]) { log_1.log.fail('Missing required property: ' + prop, 'Please add the missing `' + prop + '` property to your manifest.json file.'); } }; var updateManifestProperties = function (manifest) { var updatedManifest = __assign({}, manifest); if (updatedManifest.hasOwnProperty('mapping')) { updatedManifest.datasetsMapping = updatedManifest.mapping; delete updatedManifest.mapping; } else if (!updatedManifest.hasOwnProperty('datasetsMapping')) { updatedManifest.datasetsMapping = []; } if (updatedManifest.hasOwnProperty('collections')) { updatedManifest.collectionsMapping = updatedManifest.collections; delete updatedManifest.collections; } if (updateManifest.hasOwnProperty('appContextId')) { updatedManifest.proxyId = updatedManifest['appContextId']; delete updatedManifest['appContextId']; } else if (updateManifest.hasOwnProperty('cardId')) { updatedManifest.proxyId = updatedManifest['cardId']; delete updatedManifest['cardId']; } updateManifest(updatedManifest); return updatedManifest; }; /** * Alias must be a valid JS property */ function ensureValidAlias(name) { if (!(0, isValidJSName_1.default)(name)) { log_1.log.fail('Alias names must be valid JavaScript properties', 'Please rename the ' + JSON.stringify(name) + ' alias and update any /data/v1/<alias> calls with the new alias name'); } } /** * Finds the manifest file in the current directory, or sub files */ var findManifest = function (name) { if (fs.existsSync(name)) { return name; } if (fs.existsSync("public/".concat(name))) { return "public/".concat(name); } if (fs.existsSync("src/".concat(name))) { return "src/".concat(name); } // find any matching files (one layer deep while ignoring dist, templates and build folders) var matches = glob.sync("*/".concat(name), { ignore: ['dist/*', 'build/*', 'templates/*'], }); if (matches.length > 0) { return matches[0]; } return name; }; exports.ManifestUtils = { getManifest: getManifest, hasManifest: hasManifest, persistDesignId: persistDesignId, updateManifest: updateManifest, updateManifestProperties: updateManifestProperties, findManifest: findManifest, }; //# sourceMappingURL=manifest.js.map