UNPKG

ng-apimock

Version:

Node plugin that provides the ability to use scenario based api mocking of angular apps

55 lines 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var glob = require("glob"); var fs = require("fs-extra"); var path = require("path"); var Processor = (function () { function Processor() { } Processor.prototype.processMocks = function (directory) { var mocks = []; glob.sync('**/*.json', { cwd: directory, root: '/' }).forEach(function (file) { return mocks.push(fs.readJsonSync(path.join(directory, file))); }); return mocks; }; Processor.prototype.generateProtractorMock = function (directory, baseUrl) { var from = path.join(Processor.PTD, 'protractor.mock.js'); var to = path.join(directory, 'protractor.mock.js'); if (baseUrl) { try { var data = fs.readFileSync(from, 'utf-8'); var newValue = data.replace(/const requestUrl = undefined;/gi, 'const requestUrl = \'' + baseUrl + '\';'); fs.writeFileSync(to, newValue, 'utf-8'); } catch (error) { console.error('Unable to rewrite protractor.mock.js', error); } } else { fs.copySync(from, to); } }; Processor.prototype.generateMockingInterface = function (directory) { var anmd = !fs.existsSync(path.join(Processor.PNMD, 'angular')) ? path.join(process.cwd(), 'node_modules') : Processor.PNMD, arnmd = !fs.existsSync(path.join(Processor.PNMD, 'angular-resource')) ? path.join(process.cwd(), 'node_modules') : Processor.PNMD, angularJs = path.join(anmd, 'angular', 'angular.min.js'), angularResource = path.join(arnmd, 'angular-resource', 'angular-resource.min.js'); glob.sync('**/*', { cwd: Processor.PTID, root: '/' }).forEach(function (file) { return fs.copySync(path.join(Processor.PTID, file), path.join(directory, file)); }); fs.copySync(angularJs, path.join(directory, 'js', 'angular.min.js')); fs.copySync(angularResource, path.join(directory, 'js', 'angular-resource.min.js')); }; Processor.PCWD = path.resolve(__dirname, '..'); Processor.PNMD = path.join(Processor.PCWD, 'node_modules'); Processor.PTD = path.join(Processor.PCWD, 'templates'); Processor.PTID = path.join(Processor.PTD, 'interface'); return Processor; }()); exports.default = Processor; //# sourceMappingURL=processor.js.map