'use strict'; var path = require('path'); var findIndex = require('find-index'); var flattenGlob = function(arr){ var out = []; var flat = true; for(var i = 0; i < arr.length; i++) { if (typeof arr[i] !== 'string') { flat = false; break; } out.push(arr[i]); } // last one is a file or specific dir // so we pop it off if (flat) { out.pop(); } return out; }; var flattenExpansion = function(set) { var first = set[0]; var toCompare = set.slice(1); // find index where the diff is var idx = findIndex(first, function(v, idx){ if (typeof v !== 'string') { return true; } var matched = toCompare.every(function(arr){ return v === arr[idx]; }); return !matched; }); return first.slice(0, idx); }; var setToBase = function(set) { // normal something/*.js if (set.length <= 1) { return flattenGlob(set[0]); } // has expansion return flattenExpansion(set); }; module.exports = function(glob) { var set = glob.minimatch.set; var baseParts = setToBase(set); var basePath = path.normalize(baseParts.join(path.sep))+path.sep; return basePath; };
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19553 | swellard | Move and rename clients | ||
//guest/perforce_software/helix-web-services/main/source/clients/2016.1.0/javascript/node_modules/glob2base/index.js | |||||
#1 | 18810 | tjuricek |
First-pass at JavaScript client SDK. JavaScript requires Node with Gulp to "browserfy" the library. It's the easiest way I found to use the swagger-js project; bundle up a wrapping method. There is no JavaScript reference guide. The swagger-js doesn't really document what they do very well, actually. Overall I'm not particularly impressed by swagger-js, it was hard to even figure out what the right method syntax was. We may want to invest time in doing it better. This required setting CORS response headers, which are currently defaulted to a fairly insecure setting. |