UNPKG

@enonic/mock-xp

Version:

Mock Enonic XP API JavaScript Library

74 lines (73 loc) 2.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.App = void 0; var memfs_1 = require("memfs"); var path_1 = require("path"); var Asset_1 = require("./app/Asset"); var Controller_1 = require("./app/Controller"); var Resource_1 = require("./app/Resource"); var App = (function () { function App(_a) { var _b = _a.config, config = _b === void 0 ? {} : _b, _c = _a.displayName, displayName = _c === void 0 ? null : _c, _d = _a.maxSystemVersion, maxSystemVersion = _d === void 0 ? null : _d, _e = _a.minSystemVersion, minSystemVersion = _e === void 0 ? null : _e, key = _a.key, _f = _a.version, version = _f === void 0 ? '1.0.0' : _f; this.vol = memfs_1.vol; this.config = config; this.displayName = displayName; this.maxSystemVersion = maxSystemVersion; this.minSystemVersion = minSystemVersion; this.key = key; this.version = version; this.vol.fromJSON({}, '/'); } App.prototype.addAsset = function (_a) { var data = _a.data, path = _a.path; if (!this.vol.existsSync(Asset_1.Asset.path)) { this.vol.mkdirSync(Asset_1.Asset.path); } this.vol.writeFileSync(Asset_1.Asset.prefixPath(path), data.toString()); return this; }; App.prototype.addController = function (_a) { var data = _a.data, path = _a.path; var absPath = path.startsWith('/') ? path : "/".concat(path); var parent = (0, path_1.dirname)(absPath); if (!this.vol.existsSync(parent)) { this.vol.mkdirSync(parent, { recursive: true }); } new Controller_1.Controller({ app: this, path: absPath, }); this.vol.writeFileSync(absPath, data.toString()); return this; }; App.prototype.addResource = function (_a) { var data = _a.data, path = _a.path; var absPath = path.startsWith('/') ? path : "/".concat(path); var parent = (0, path_1.dirname)(absPath); if (!this.vol.existsSync(parent)) { this.vol.mkdirSync(parent, { recursive: true }); } this.vol.writeFileSync(absPath, data.toString()); return this; }; App.prototype.getAsset = function (path) { return new Asset_1.Asset({ app: this, path: path, }); }; App.prototype.getController = function (path) { return new Controller_1.Controller({ app: this, path: path, }); }; App.prototype.getResource = function (path) { return new Resource_1.Resource({ app: this, path: path, }); }; return App; }()); exports.App = App;