Skip to content

feat: Add --all as a build option #11023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
klauskpm opened this issue May 25, 2018 · 2 comments
Closed

feat: Add --all as a build option #11023

klauskpm opened this issue May 25, 2018 · 2 comments
Labels
area: @angular/cli feature Issue that requests a new feature

Comments

@klauskpm
Copy link
Contributor

Feature requested

Add the --all (or --projects) option for the ng build schematic. This option would build libraries, then applications, then the default project; because of how they are dependent of each other. It should ignore the e2e projects.

To make it easier to find, and order which project should be built first, it would be better to change the generate schematics of application and library to change the angular.json file adding libraries and applications as attributes holding an array of strings.

{
  ...
  "libraries": ["foo-lib", "bar-lib"],
  "applications": ["example-foo"],
  "defaultProject": "project"
}

Case of use

Building several libraries and applications in a monorepo that all packages/projects have the same semantic version.

When working with several libraries and applications on a monorepo, it is a pain to create a npm script for each project, and update the build:all npm script. Running a single command to build all projects is less painfull and has less chance of mistakes (forgetting, skipping).

Example / attempt

As much as this example works for me, I still can't order the libraries and applications. If I have a library that needs another, and it builds first, it would break.

const fs = require('fs');
const { exec } = require('child_process');
const projectTypes = {
  library: 'libraries',
  application: 'applications'
};

function readAngularJson() {
  try {
    const data = fs.readFileSync('./angular.json', 'utf8');
    return JSON.parse(data);
  } catch (err) {
    throw err;
  }
}

function generateBuildProjects() {
  const angularJson = readAngularJson();
  const projects = angularJson.projects;
  const projectsKeys = Object.keys(projects).filter((key) => {
    return key.indexOf('e2e') < 0 && key !== angularJson.defaultProject;
  });
  const buildProjects = {
    libraries: [],
    applications: [],
    defaultProject: angularJson.defaultProject
  };

  projectsKeys.forEach((pk) => {
    const project = projects[pk];
    const projectType = projectTypes[project.projectType];

    buildProjects[projectType].push(pk);
  });

  return buildProjects;
}

function buildAll() {
  const bp = generateBuildProjects();
  const projects = [
    ...bp.libraries,
    ...bp.applications,
    bp.defaultProject
  ];
  build(projects);
}

function build(projects) {
  const project = projects.shift();
  console.log('Started building', project);

  const child = exec(`ng build ${project} --prod`, (err, stdout, stderr) => {
    if (stdout) console.log(stdout);
    if (stderr) console.log(stderr);
  });

  child.on('close', () => {
    if (projects.length) build(projects);
    else console.log('finished');
  });
}

buildAll();
@alan-agius4
Copy link
Collaborator

Duplicate of #11002

@alan-agius4 alan-agius4 marked this as a duplicate of #11002 Jan 4, 2019
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular/cli feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

4 participants