UNPKG

@angular-plugins/stryker

Version:

Stryker Plugin for Angular and Nx Repos

74 lines (73 loc) 3.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const schematics_1 = require("@angular-devkit/schematics"); const workspace_1 = require("@nrwl/workspace"); const schematics_2 = require("@angular-devkit/schematics"); const core_1 = require("@angular-devkit/core"); const init_1 = require("../init/init"); function isNrwlWorkspace(host) { const workspaceJson = workspace_1.readJsonInTree(host, 'angular.json'); return new Map(workspaceJson).has('newProjectRoot'); } function concatPath(value, path, startPath = './') { const finalPath = `${startPath}${value}${path}`; return finalPath; } function generateFile(options) { return (host, context) => { const workspaceJson = workspace_1.readJsonInTree(host, 'angular.json'); const projectConfig = workspace_1.getProjectConfig(host, options.project); const root = projectConfig.root.length === 0 ? '' : `${projectConfig.root}/`; let libsFolder = (workspaceJson.newProjectRoot && workspaceJson.newProjectRoot.length) ? workspaceJson.newProjectRoot : 'libs'; return schematics_2.mergeWith(schematics_1.apply(schematics_1.url('./files'), [ schematics_1.template(Object.assign(Object.assign({ tmpl: '' }, options), { files: [ concatPath(libsFolder, '/**/*.ts'), concatPath(libsFolder, '/**/*.html'), concatPath(root, 'src/**/*.ts'), concatPath(root, 'src/**/*.html'), concatPath(root, 'src/**/*.scss'), concatPath(root, '*.json'), concatPath(root, '*.js'), concatPath('', '*.js'), concatPath('', 'tsconfig.json'), concatPath('', 'package.json'), ], mutate: [ concatPath(root, 'src/**/*.ts'), concatPath(root, 'src/**/*.spec.ts', '!./'), concatPath(root, 'src/main.ts', '!./'), concatPath(root, 'src/**/*.module.ts', '!./'), ] })), schematics_1.move(projectConfig.root), ]))(host, context); }; } function updateWorkspaceJson(options) { return workspace_1.updateWorkspaceInTree(json => { const projectConfig = json.projects[options.project]; projectConfig.architect.mutate = { builder: '@angular-plugins/stryker:mutate', options: { configFile: core_1.join(core_1.normalize(projectConfig.root), 'stryker.config.js'), } }; return json; }); } function check(options) { return (host, context) => { const projectConfig = workspace_1.getProjectConfig(host, options.project); if (projectConfig.architect.mutate) { throw new Error(`${options.project} already has a mutate architect option.`); } return host; }; } function default_1(options) { return schematics_1.chain([ init_1.default(), check(options), generateFile(options), updateWorkspaceJson(options) ]); } exports.default = default_1;