UNPKG

1.11 kBJavaScriptView Raw
1var Manifest = require('../util/manifest');
2var log = require('../util/log');
3var validator = require('validator');
4
5module.exports = {
6 /**
7 * Takes up to two args to check for a valid design id and gives priority to
8 * the first argument
9 * @param {String} arg1 designId arg that will take priority if both args
10 * are defined and valid
11 * @param {String} arg2 designId arg that will be the fallback if the first
12 * arg is null or undefined
13 * @param {Object} man object defining the program manifest of the current
14 * context
15 * @return {String} Returns id with this priority: arg1, arg2,
16 * manifest.id, null
17 */
18 getDesignId: function(arg1, arg2, man) {
19 var id = arg1 || arg2;
20
21 if (id) {
22 if (!validator.isUUID(id)) return log.fail('The value specified for option -i is not a valid design ID', id);
23 } else {
24 var manifest = Manifest.get(man);
25 if (!manifest || !manifest.id) return log.fail('No manifest found. Please supply design id using -i or change to a directory with a valid manifest file');
26 id = manifest.id;
27 }
28 return id;
29 }
30}