Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function updateJsonFile(tree: Tree, path: string, jsonData: any) {
try {
// if (tree.exists(path)) {
tree.overwrite(path, serializeJson(jsonData));
// }
return tree;
} catch (err) {
// console.warn(err);
throw new SchematicsException(`${path}: ${err}`);
}
}
it('should coerce a version with a tilde into a valid version', async () => {
tree.create(
'package.json',
serializeJson({
devDependencies: {
'@angular/cli': '~8.0.0'
}
})
);
const result = await schematicRunner
.runSchematicAsync('upgrade-cli-8-3', {}, tree)
.toPromise();
expect(
readJsonInTree(result, 'package.json').devDependencies['@angular/cli']
).toEqual('^8.3.3');
});
tap(existingPrettierConfig => {
if (!existingPrettierConfig) {
host.create(
'.prettierrc',
serializeJson(DEFAULT_NRWL_PRETTIER_CONFIG)
);
}
}),
mapTo(host)
function createDefaultAppTsConfig(host: Tree, project: any) {
const offset = offsetFromRoot(project.root);
const defaultAppTsConfig = {
extends: `${offset}tsconfig.json`,
compilerOptions: {
outDir: `${offset}dist/out-tsc/${project.root}`,
module: 'es2015'
},
include: ['**/*.ts'],
exclude: ['src/test.ts', '**/*.spec.ts']
};
createOrUpdate(
host,
`${project.root}/tsconfig.app.json`,
serializeJson(defaultAppTsConfig)
);
}
const tsConfig = readJsonInTree(
host,
`${project.root}/src/tsconfig.e2e.json`
);
tsConfig.extends = `${offset}tsconfig.json`;
tsConfig.compilerOptions = {
...tsConfig.compilerOptions,
outDir: `${offset}dist/out-tsc/${project.root}`
};
delete tsConfig.include;
delete tsConfig.exclude;
createOrUpdate(
host,
`${project.root}/tsconfig.e2e.json`,
serializeJson(tsConfig)
);
host.delete(`${project.root}/src/tsconfig.e2e.json`);
} else {
createDefaultE2eTsConfig(host, project);
}
}
});
return host;
function createTslintJson(host: Tree, project: any) {
const offset = offsetFromRoot(project.root);
createOrUpdate(
host,
`${project.root}/tslint.json`,
serializeJson({
extends: `${offset}tslint.json`,
rules: {
'directive-selector': [true, 'attribute', project.prefix, 'camelCase'],
'component-selector': [true, 'element', project.prefix, 'kebab-case']
}
})
);
}
project.architect.build &&
project.architect.build.options.main.startsWith('apps')
) {
const offset = offsetFromRoot(project.root);
const originalTsConfigPath = `${project.root}/src/tsconfig.app.json`;
if (host.exists(originalTsConfigPath)) {
const tsConfig = readJsonInTree(host, originalTsConfigPath);
if (!(tsConfig.exclude as string[]).includes('src/test.ts')) {
tsConfig.exclude.push('src/test.ts');
}
createOrUpdate(
host,
`${project.root}/tsconfig.app.json`,
serializeJson({
...tsConfig,
extends: `${offset}tsconfig.json`,
compilerOptions: {
...tsConfig.compilerOptions,
outDir: `${offset}dist/out-tsc/${project.root}`
},
include: tsConfig.include.map((include: string) => {
if (include.startsWith('../../../')) {
include = include.substring(3);
}
if (include.includes('/libs/') && include.endsWith('index.ts')) {
include = include.replace('index.ts', 'src/index.ts');
}
return include;
})
beforeEach(() => {
initialTree.overwrite(
'package.json',
serializeJson({
devDependencies: {
jest: '23.10.5',
'jest-preset-angular': '6.0.2'
}
})
);
initialTree.create(
'jest.config.js',
`module.exports = {
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
transform: {
'^.+\\.(ts|js|html)$': 'jest-preset-angular/preprocessor.js'
},
resolver: '@nrwl/builders/plugins/jest/resolver',
moduleFileExtensions: ['ts', 'js', 'html'],
coverageReporters: ['html']
return (host: Tree, _context: SchematicContext) => {
const workspaceJson = readJsonInTree(host, 'angular.json');
host.create(
'nx.json',
serializeJson({
npmScope: options.npmScope,
implicitDependencies: {
'angular.json': '*',
'package.json': '*',
'tsconfig.json': '*',
'tslint.json': '*',
'nx.json': '*'
},
projects: {
[options.name]: {
tags: []
},
[getE2eKey(workspaceJson) + '-e2e']: {
tags: []
}
}