# generate new schematics project
schematics blank --name=[schematics Name]
# add collection
schematics blank --name=[collenction Name]
# building
npm run build
# local checking
schematics .:[collenction名] [--Options]
In ng-new
, use workspace
, application
.
# Run on exists project
schematics blank --name=application
# global link
npm link ${generate schematics project path}
./src/application/index.ts
import { Rule, SchematicContext, Tree, chain, externalSchematic } from '@angular-devkit/schematics';
export function application(options: any): Rule {
return chain([
externalSchematic('@schematics/angular', 'application', options),
]);
}
- generate my project
ng new --collection=[schematics Name] [application name]
# angular-cli initialize
ng new my-project
cd my-project
# global link
npm link ${generate schematics project path}
# generate my collection
ng g [schematics名]:[Collection名] [--Options]
Update existing code
function readTypeScript(options: any): Rule {
return (host: Tree, context: SchematicContext) => {
host.getDir('/files').visit(filePath => {
if (!filePath.endsWith('.ts')) {
return ;
}
const text = host.read(filePath);
if (text === null) {
throw new SchematicsException(`File ${filePath} does not exist.`);
}
const declarationRecorder = host.beginUpdate(filePath);
/**
* Update existing code
**/
host.commitUpdate(declarationRecorder);
});
return host;
};
}
export function updateCode(options: any): Rule {
return branchAndMerge(chain([
readTypeScript(options),
]));
}
sample of how to make
take a look
ng new --collenction [SchematicsName]