Skip to content

Instantly share code, notes, and snippets.

@meriturva
Last active July 21, 2020 20:21
Show Gist options
  • Save meriturva/0fade34d3b057c799fb5e5f689ad3ff1 to your computer and use it in GitHub Desktop.
Save meriturva/0fade34d3b057c799fb5e5f689ad3ff1 to your computer and use it in GitHub Desktop.
A simple example how to load and to parse angular.json using @angular-devkit packages
import { workspaces, } from '@angular-devkit/core';
import { NodeJsSyncHost } from '@angular-devkit/core/node';
import { ProjectType } from '@schematics/angular/utility/workspace-models';
(async () => {
const { workspace } = await workspaces.readWorkspace(
process.cwd(),
workspaces.createWorkspaceHost(new NodeJsSyncHost()),
);
for (const [name, project] of workspace.projects) {
// How to know if it is a library of an application
if (project.extensions.projectType === ProjectType.Application) {
console.log(`Project ${name} is an application`);
}
if (project.extensions.projectType === ProjectType.Library) {
console.log(`Project ${name} is a library`);
// Get if application could target build/test/lint
if (project.targets.has('build')) {
console.log(`Project ${name} has build target`);
}
if (project.targets.has('test')) {
console.log(`Project ${name} has test target`);
}
if (project.targets.has('lint')) {
console.log(`Project ${name} has lint target`);
}
}
}
})().catch(e => {
// Deal with the fact the something goes wrong
console.error(e);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment