Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(angular): ng-add throws when not run against Angular CLI's initia… #17597

Merged
merged 3 commits into from Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions angular/src/schematics/add/index.ts
@@ -1,20 +1,20 @@
import {
Rule,
SchematicContext,
SchematicsException,
Tree,
apply,
chain,
mergeWith,
move,
Rule,
SchematicContext,
SchematicsException,
template,
Tree,
url
} from '@angular-devkit/schematics';
import { Path, join } from '@angular-devkit/core';
import { join, Path } from '@angular-devkit/core';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
import { addPackageToPackageJson } from './../utils/package';
import { addModuleImportToRootModule } from './../utils/ast';
import { addStyle, getWorkspace, addArchitectBuilder } from './../utils/config';
import { addArchitectBuilder, addStyle, getWorkspace } from './../utils/config';
import { Schema as IonAddOptions } from './schema';

function addIonicAngularToPackageJson(): Rule {
Expand All @@ -36,10 +36,11 @@ function addIonicAngularToolkitToPackageJson(): Rule {
};
}

function addIonicAngularModuleToAppModule(): Rule {
function addIonicAngularModuleToAppModule(projectSourceRoot): Rule {
return (host: Tree) => {
addModuleImportToRootModule(
host,
projectSourceRoot,
'IonicModule.forRoot()',
'@ionic/angular'
);
Expand Down Expand Up @@ -118,14 +119,14 @@ export default function ngAdd(options: IonAddOptions): Rule {

const sourcePath = join(project.root as Path, 'src');
const rootTemplateSource = apply(url('./files/root'), [
template({ ...options }),
template({...options}),
move(sourcePath)
]);
return chain([
// @ionic/angular
addIonicAngularToPackageJson(),
addIonicAngularToolkitToPackageJson(),
addIonicAngularModuleToAppModule(),
addIonicAngularModuleToAppModule(sourcePath),
addIonicBuilder(),
addIonicStyles(),
mergeWith(rootTemplateSource),
Expand Down
3 changes: 2 additions & 1 deletion angular/src/schematics/utils/ast.ts
Expand Up @@ -27,12 +27,13 @@ export function getSourceFile(host: Tree, path: string): ts.SourceFile {
*/
export function addModuleImportToRootModule(
host: Tree,
projectSourceRoot,
moduleName: string,
importSrc: string
) {
addModuleImportToModule(
host,
normalize(`src/app/app.module.ts`),
normalize(`${projectSourceRoot}/app/app.module.ts`),
moduleName,
importSrc
);
Expand Down