mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
fix(angular): update ng-add schematic
This commit is contained in:
@ -1,20 +1,9 @@
|
|||||||
import {
|
|
||||||
apply,
|
|
||||||
chain,
|
|
||||||
mergeWith,
|
|
||||||
move,
|
|
||||||
Rule,
|
|
||||||
SchematicContext,
|
|
||||||
SchematicsException,
|
|
||||||
template,
|
|
||||||
Tree,
|
|
||||||
url
|
|
||||||
} from '@angular-devkit/schematics';
|
|
||||||
import { join, Path } from '@angular-devkit/core';
|
import { join, Path } from '@angular-devkit/core';
|
||||||
|
import { apply, chain, mergeWith, move, Rule, SchematicContext, SchematicsException, template, Tree, url } from '@angular-devkit/schematics';
|
||||||
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
|
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
|
||||||
import { addPackageToPackageJson } from './../utils/package';
|
|
||||||
import { addModuleImportToRootModule } from './../utils/ast';
|
import { addModuleImportToRootModule } from './../utils/ast';
|
||||||
import { addArchitectBuilder, addStyle, getWorkspace } from './../utils/config';
|
import { addArchitectBuilder, addStyle, getWorkspace, addAsset } from './../utils/config';
|
||||||
|
import { addPackageToPackageJson } from './../utils/package';
|
||||||
import { Schema as IonAddOptions } from './schema';
|
import { Schema as IonAddOptions } from './schema';
|
||||||
|
|
||||||
function addIonicAngularToPackageJson(): Rule {
|
function addIonicAngularToPackageJson(): Rule {
|
||||||
@ -68,6 +57,18 @@ function addIonicStyles(): Rule {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addIonicons(): Rule {
|
||||||
|
return (host: Tree) => {
|
||||||
|
const ioniconsGlob = {
|
||||||
|
glob: '**/*.svg',
|
||||||
|
input: 'node_modules/ionicons/dist/ionicons/svg',
|
||||||
|
output: './svg'
|
||||||
|
};
|
||||||
|
addAsset(host, ioniconsGlob);
|
||||||
|
return host;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function addIonicBuilder(): Rule {
|
function addIonicBuilder(): Rule {
|
||||||
return (host: Tree) => {
|
return (host: Tree) => {
|
||||||
addArchitectBuilder(host, 'ionic-cordova-serve', {
|
addArchitectBuilder(host, 'ionic-cordova-serve', {
|
||||||
@ -119,7 +120,7 @@ export default function ngAdd(options: IonAddOptions): Rule {
|
|||||||
|
|
||||||
const sourcePath = join(project.root as Path, 'src');
|
const sourcePath = join(project.root as Path, 'src');
|
||||||
const rootTemplateSource = apply(url('./files/root'), [
|
const rootTemplateSource = apply(url('./files/root'), [
|
||||||
template({...options}),
|
template({ ...options }),
|
||||||
move(sourcePath)
|
move(sourcePath)
|
||||||
]);
|
]);
|
||||||
return chain([
|
return chain([
|
||||||
@ -129,6 +130,7 @@ export default function ngAdd(options: IonAddOptions): Rule {
|
|||||||
addIonicAngularModuleToAppModule(sourcePath),
|
addIonicAngularModuleToAppModule(sourcePath),
|
||||||
addIonicBuilder(),
|
addIonicBuilder(),
|
||||||
addIonicStyles(),
|
addIonicStyles(),
|
||||||
|
addIonicons(),
|
||||||
mergeWith(rootTemplateSource),
|
mergeWith(rootTemplateSource),
|
||||||
// install freshly added dependencies
|
// install freshly added dependencies
|
||||||
installNodeDeps()
|
installNodeDeps()
|
||||||
|
@ -64,6 +64,18 @@ export function addStyle(host: Tree, stylePath: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function addAsset(host: Tree, asset: string | {glob: string; input: string; output: string}) {
|
||||||
|
const config = readConfig(host);
|
||||||
|
const appConfig = getAngularAppConfig(config);
|
||||||
|
|
||||||
|
if (appConfig) {
|
||||||
|
appConfig.architect.build.options.assets.push(asset);
|
||||||
|
writeConfig(host, config);
|
||||||
|
} else {
|
||||||
|
throw new SchematicsException(`Cannot find valid app`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function addArchitectBuilder(host: Tree, builderName: string, builderOpts: any){
|
export function addArchitectBuilder(host: Tree, builderName: string, builderOpts: any){
|
||||||
const config = readConfig(host);
|
const config = readConfig(host);
|
||||||
const appConfig = getAngularAppConfig(config);
|
const appConfig = getAngularAppConfig(config);
|
||||||
|
Reference in New Issue
Block a user