Alan Agius bede23226a feat(@schematics/angular): add solutions style tsconfig structure
In version 3.9, TypeScript introduced the concept of "Solutions Style" tsconfig to improve developer experience.

More info: https://devblogs.microsoft.com/typescript/announcing-typescript-3-9-rc/#solution-style-tsconfig

Closes #17493 and closes #8138
2020-05-20 12:12:33 -07:00

77 lines
2.2 KiB
TypeScript

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { join, normalize, strings } from '@angular-devkit/core';
import {
Rule,
SchematicsException,
Tree,
apply,
applyTemplates,
chain,
mergeWith,
move,
url,
} from '@angular-devkit/schematics';
import { relativePathToWorkspaceRoot } from '../utility/paths';
import { addTsConfigProjectReferences, verifyBaseTsConfigExists } from '../utility/tsconfig';
import { getWorkspace, updateWorkspace } from '../utility/workspace';
import { Builders } from '../utility/workspace-models';
import { Schema as E2eOptions } from './schema';
export default function (options: E2eOptions): Rule {
return async (host: Tree) => {
const appProject = options.relatedAppName;
const workspace = await getWorkspace(host);
const project = workspace.projects.get(appProject);
if (!project) {
throw new SchematicsException(`Project name "${appProject}" doesn't not exist.`);
}
verifyBaseTsConfigExists(host);
const root = join(normalize(project.root), 'e2e');
project.targets.add({
name: 'e2e',
builder: Builders.Protractor,
options: {
protractorConfig: `${root}/protractor.conf.js`,
devServerTarget: `${options.relatedAppName}:serve`,
},
configurations: {
production: {
devServerTarget: `${options.relatedAppName}:serve:production`,
},
},
});
const e2eTsConfig = `${root}/tsconfig.json`;
const lintTarget = project.targets.get('lint');
if (lintTarget && lintTarget.options && Array.isArray(lintTarget.options.tsConfig)) {
lintTarget.options.tsConfig =
lintTarget.options.tsConfig.concat(e2eTsConfig);
}
return chain([
updateWorkspace(workspace),
mergeWith(
apply(url('./files'), [
applyTemplates({
utils: strings,
...options,
relativePathToWorkspaceRoot: relativePathToWorkspaceRoot(root),
}),
move(root),
])),
addTsConfigProjectReferences([
e2eTsConfig,
]),
]);
};
}