UNPKG

@valantic/spartacus-mock

Version:

This project offers you the possibility to mock the OCC Endpoints of your Composable Storefront (Spartacus). It uses the Mock Service Worker to mock the API calls.

61 lines 2.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addPackageJsonDependencies = addPackageJsonDependencies; exports.enhanceAngularJsonAssets = enhanceAngularJsonAssets; exports.installPackageJsonDependencies = installPackageJsonDependencies; const dependencies_1 = require("@schematics/angular/utility/dependencies"); const package_utils_1 = require("./package-utils"); const workspace_utils_1 = require("./workspace-utils"); function addPackageJsonDependencies(dependencies, packageJson) { return (tree, _context) => { for (const dependency of dependencies) { if (!(0, package_utils_1.dependencyExists)(dependency, packageJson)) { (0, dependencies_1.addPackageJsonDependency)(tree, dependency); } } return tree; }; } function enhanceAngularJsonAssets() { return (tree, _context) => { const { path, workspaceConfig } = (0, workspace_utils_1.getWorkspace)(tree); const projectName = Object.keys(workspaceConfig.projects)[0]; const architect = workspaceConfig.projects[projectName].architect; // `build` architect section const architectBuild = architect?.build; const buildOptions = { ...architectBuild?.options, assets: [...architectBuild?.options?.assets, 'src/mockServiceWorker.js'], }; const updatedAngularJson = { ...workspaceConfig, projects: { ...workspaceConfig.projects, [projectName]: { ...workspaceConfig.projects[projectName], architect: { ...architect, build: { ...architectBuild, options: buildOptions, }, }, }, }, }; const initialContent = tree.read(path)?.toString('utf-8') ?? ''; const toUpdate = JSON.stringify(updatedAngularJson, null, 2); // prevent the unnecessary Angular logs about the files being updated if (initialContent !== toUpdate) { tree.overwrite(path, toUpdate); } return tree; }; } function installPackageJsonDependencies() { return (tree, context) => { (0, package_utils_1.createNodePackageInstallationTask)(context); return tree; }; } //# sourceMappingURL=lib-utils.js.map