'use strict'; var defaults = require('defaults'); var path = require('path'); var through2 = require('through2'); var mkdirp = require('mkdirp'); var fs = require('graceful-fs'); var writeContents = require('./writeContents'); function dest(outFolder, opt) { opt = opt || {}; if (typeof outFolder !== 'string' && typeof outFolder !== 'function') { throw new Error('Invalid output folder'); } var options = defaults(opt, { cwd: process.cwd() }); if (typeof options.mode === 'string') { options.mode = parseInt(options.mode, 8); } var cwd = path.resolve(options.cwd); function saveFile (file, enc, cb) { var basePath; if (typeof outFolder === 'string') { basePath = path.resolve(cwd, outFolder); } if (typeof outFolder === 'function') { basePath = path.resolve(cwd, outFolder(file)); } var writePath = path.resolve(basePath, file.relative); var writeFolder = path.dirname(writePath); // wire up new properties file.stat = file.stat ? file.stat : new fs.Stats(); file.stat.mode = (options.mode || file.stat.mode); file.cwd = cwd; file.base = basePath; file.path = writePath; // mkdirp the folder the file is going in mkdirp(writeFolder, function(err){ if (err) { return cb(err); } writeContents(writePath, file, cb); }); } var stream = through2.obj(saveFile); // TODO: option for either backpressure or lossy stream.resume(); return stream; } module.exports = dest;
# | 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/vinyl-fs/lib/dest/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. |