react-middleware
Version:
Connect middleware for serving React components from a standard folder structure.
74 lines (53 loc) • 2.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /* eslint global-require:0 */
var _fsExtra = require('fs-extra');
var _fsExtra2 = _interopRequireDefault(_fsExtra);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Represents a template file.
*/
var Template = function () {
function Template(sourcePath, targetPath) {
_classCallCheck(this, Template);
this.sourcePath = _path2.default.join(__dirname, '../templates', sourcePath);
this.targetPath = targetPath;
}
/**
* Determines whether the file for the template already exists.
*/
_createClass(Template, [{
key: 'existsSync',
value: function existsSync() {
return _fsExtra2.default.existsSync(this.targetPath);
}
/**
* Copies the template file to the target path.
*/
}, {
key: 'copySync',
value: function copySync() {
if (!this.existsSync()) {
_fsExtra2.default.copySync(this.sourcePath, this.targetPath);
}
return this;
}
/**
* Imports the target file as a module.
*/
}, {
key: 'import',
value: function _import() {
this.copySync();
return require(this.targetPath).default;
}
}]);
return Template;
}();
exports.default = Template;
//# sourceMappingURL=template.js.map