index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _path = require("path");
  6. var _path2 = _interopRequireDefault(_path);
  7. var _concatStream = require("concat-stream");
  8. var _concatStream2 = _interopRequireDefault(_concatStream);
  9. var _lodash = require("lodash.template");
  10. var _lodash2 = _interopRequireDefault(_lodash);
  11. var _mapStream = require("map-stream");
  12. var _mapStream2 = _interopRequireDefault(_mapStream);
  13. var _vinylFs = require("vinyl-fs");
  14. var _vinylFs2 = _interopRequireDefault(_vinylFs);
  15. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  16. exports.default = createModule;
  17. function createModule(dir) {
  18. return new Promise(function (resolve, reject) {
  19. _vinylFs2.default.src(_path2.default.resolve(__dirname, "..", "templates", "**", "*"), { dot: true }).pipe(renameFiles({ gitignore: ".gitignore" })) // See: https://github.com/npm/npm/issues/3763
  20. .pipe(templateFiles({ name: _path2.default.basename(dir) })).once("error", reject).pipe(_vinylFs2.default.dest(dir)).pipe(collectFiles(resolve));
  21. });
  22. }
  23. function renameFiles(renames) {
  24. return (0, _mapStream2.default)(function (file, cb) {
  25. if (file.basename in renames) {
  26. file.basename = renames[file.basename];
  27. }
  28. cb(null, file);
  29. });
  30. }
  31. function templateFiles(data) {
  32. return (0, _mapStream2.default)(function (file, cb) {
  33. file.contents = new Buffer((0, _lodash2.default)(file.contents)(data));
  34. cb(null, file);
  35. });
  36. }
  37. function collectFiles(cb) {
  38. return (0, _concatStream2.default)(function (files) {
  39. return cb(files.map(function (file) {
  40. return file.path;
  41. }));
  42. });
  43. }