I have an angular schematic where I create a new project, then call ng-add to add a package to that new project.
It looks like this:
export function createProject(options) {
return () => {
return chain([
externalSchematic('@schematics/angular', 'ng-new', options),
installPackages(options)
]);
}
}
function installPackages(options) {
return (tree, ctx) => {
const taskId = ctx.addTask(new NodePackageInstallTask({
packageName: 'my-package',
workingDirectory: options.name
}));
ctx.addTask(new RunSchematicTask('addExternals', options), [taskId]);
}
}
export function addExternals(options) {
return () => {
return externalSchematic('my-package', 'ng-add', {
...options
}, {
scope: options.name
});
}
}
To summarize:
- Generate a new angular project
- Install the package that I want to call ng-add
- After npm install is completed, call the ng-add schematic.
This works unless the ng-add schematic I call in step 3 also calls an external schematic. If it does, then it completely loses the scope. If options.name
equals 'my-app', I would expect that the scope argument would result in all commands from my external schematic to be called from the 'my-app' folder. But that doesn't seem to be happening.
When you generate a new angular project in a schematic, is there a way to change the execution scope for the following commands to be in the newly created folder? Or is there a way to cd into that folder for subsequent commands?