react-middleware
Version:
Connect middleware for serving React components from a standard folder structure.
57 lines (46 loc) • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require("lodash");
var _lodash2 = _interopRequireDefault(_lodash);
var _template = require("./template");
var _template2 = _interopRequireDefault(_template);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Returns the set of template files.
* @param paths: The middleware folder paths object.
*/
exports.default = function (paths) {
var template = function template(sourceDir, sourceFile, targetFolder) {
sourceDir = _lodash2.default.isString(sourceDir) ? sourceDir + "/" : "";
var sourcePath = "../templates/" + sourceDir + sourceFile;
var targetPath = targetFolder + "/" + sourceFile;
return new _template2.default(sourcePath, targetPath);
};
var templates = {
routes: template(null, "routes.js", paths.base),
html: template("Html", "Html.jsx", paths.layouts + "/Html"),
htmlCss: template("Html", "Html.styl", paths.layouts + "/Html"),
home: template("Home", "Home.jsx", paths.pages + "/Home"),
homeCss: template("Home", "Home.styl", paths.pages + "/Home"),
homeEntry: template("Home", "entry.js", paths.pages + "/Home"),
normalizeCss: template("css", "normalize.css", paths.css),
globalMixins: template("css", "global.mixin.styl", paths.css),
scripts: template("scripts", "index.js", paths.scripts),
imageMoon1x: template("images", "moon.jpg", paths.public + "/images"),
imageMoon2x: template("images", "moon@2x.jpg", paths.public + "/images"),
/**
* Creates all template files if they don't already exist.
*/
createSync: function createSync() {
paths.createSync();
_lodash2.default.forIn(templates, function (file) {
if (file instanceof _template2.default) {
file.copySync();
}
});
}
};
return templates;
};