UNPKG

@nrwl/schematics

Version:

Extensible Dev Tools for Monorepos: Schematics

57 lines (56 loc) 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const schematics_1 = require("@angular-devkit/schematics"); const workspace_1 = require("@nrwl/workspace"); const workspace_2 = require("@nrwl/workspace"); const ts = require("typescript"); const ast_utils_1 = require("@nrwl/workspace/src/utils/ast-utils"); const setDefaults = workspace_2.updateWorkspaceInTree(json => { if (!json.schematics) { json.schematics = {}; } if (!json.schematics['@nrwl/schematics:library']) { json.schematics['@nrwl/schematics:library'] = {}; } if (!json.schematics['@nrwl/schematics:library'].framework) { json.schematics['@nrwl/schematics:library'].framework = 'angular'; } return json; }); const updateDependencies = workspace_1.updateJsonInTree('package.json', json => { json.devDependencies = json.devDependencies || {}; if (json.devDependencies['jest']) { json.devDependencies['jest'] = '24.1.0'; } if (json.devDependencies['@types/jest']) { json.devDependencies['@types/jest'] = '24.0.9'; } if (json.devDependencies['jest-preset-angular']) { json.devDependencies['jest-preset-angular'] = '7.0.0'; } return json; }); function updateJestConfig(host) { if (host.exists('jest.config.js')) { const contents = host.read('jest.config.js').toString(); const sourceFile = ts.createSourceFile('jest.config.js', contents, ts.ScriptTarget.Latest); const changes = []; ast_utils_1.getSourceNodes(sourceFile).forEach(node => { if (ts.isPropertyAssignment(node) && ts.isStringLiteral(node.initializer) && node.initializer.text === 'jest-preset-angular/preprocessor.js') { changes.push(new ast_utils_1.ReplaceChange('jest.config.js', node.initializer.getStart(sourceFile), node.initializer.getText(sourceFile), "'ts-jest'")); } }); workspace_1.insert(host, 'jest.config.js', changes); } } function default_1() { return schematics_1.chain([ setDefaults, updateDependencies, updateJestConfig, workspace_2.formatFiles() ]); } exports.default = default_1;