Answer the question
In order to leave comments, you need to log in
How to add project to angular json?
I made an angular schematics.
Everything creates fine when executing the command. Now there is a need for the configuration to be written to angular.json.
Any thoughts on how this can be achieved?
export function customComponent(_options: SchemaD): Rule {
return (tree: Tree, _context: SchematicContext) => {
const workspaceConfigBuffer = tree.read('angular.json');
if (!workspaceConfigBuffer) {
throw new SchematicsException('Not angular cli workspace');
}
const workspaceConfig = JSON.parse(workspaceConfigBuffer.toString());
const projectName = _options.project || workspaceConfig.defaultProject;
const project = workspaceConfig.projects[projectName];
const defaultProjectPath = buildDefaultPath(project);
const parsedPath = parseName(defaultProjectPath, _options.name);
const { name, path } = parsedPath;
const sourceTemplates = url('./templateWithRouter');
const sourceParametrizeTemplates = apply(sourceTemplates, [
template({
..._options,
...strings,
name,
}),
move(path),
]);
return mergeWith(sourceParametrizeTemplates)(tree, _context);
};
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question