Nx: codebase deliverable for a single app

Created on 24 Nov 2018  路  2Comments  路  Source: nrwl/nx

Current Behavior

There is no easy way for a development team that works on multiple projects for multiple clients to deliver the codebase for a single app

Expected Behavior

It would be nice if nx had a 'deliver-codebase' (or similar) command to create a codebase deliverable for a single app in dist.

nx deliver-codebase app1 creates dist/codebases/app1

More Context

I'm part of a rapid prototyping team that works on multiple angular apps across multiple client accounts. For all of our client engagements, we've been required to deliver a build artifact (ng build --prod) as well as a codebase. I see the codebase deliverable requirement as a big reason why our team hasn't adopted monorepo style development. For various reasons, we would not want to hand over the entire monorepo to fulfill the requirement for a codebase deliverable; so it's just easier to deliver codebases of standalone angular apps.

If my team was to adopt nx and monorepo style development, I think the laziest (manual) way for us to meet the codebase deliverable requirement for 'app1' would be something along the lines of:
1) create a new nx workspace (deliverable workspace)
2) create app1 in deliverable workspace (just to create entries in angular.json and nx.json)
3) copy package.json from dev workspace into deliverable workspace
4) copy apps/app1 directory from dev workspace into deliverable workspace
5) copy entire libs directory from dev workspace into deliverable workspace

It would be nice if NX had a command to accomplish this in a more intelligent way. Ideally, the command 'nx deliver-codebase app1' (or something similar) would create a codebase deliverable in dist/codebases/app1. That command should leverage the advanced code analysis behind dep-graph to only include libs that app1 depends on.

dist/codebases/app1 would not necessarily have to be a whole new nx workspace (I don't know how I feel about workspace-ception). It might be simpler for dist/codebases/app1 to be structured like a standalone angular app. Something like:

    -apps/
        -app1/
    -....
    -dist/
        -....
        -codebases/
            -app1/
                -src/
                -e2e/
                -libs/
                -.....
                -package.json

I'd also be interested in any guidance for adopting monorepo style development in a "multi-project, multi-client" environment.

core feature

Most helpful comment

I think this is an interesting feature. What is the interest in the community for this kind of feature?

This is not something which pertains to the main goal of Nx which is to allow monorepo development for a single organization. Thus, it is unlikely this becomes a first party feature.

However, you can implement this for your own workspace. Here's how I would do it (It might seem complex but it seems like it would save you time by automating the process):

  1. Use yarn dep-graph --file dependencies.json to generate a JSON file containing the dependency graph.
  2. Use a workspace-schematic to use the information in dependencies.json + other places.
  3. Create a directory for a new workspace
  4. Read nx.json and determine which implicitDependencies affect <targetApp>
  5. Copy the root of <targetApp>
  6. Recursively copy the dependencies of <targetApp>
  7. Do other modifications where it makes sense. (some files might have configuration for multiple projects.. Here are some that come to mind.
    a. tsconfig.json
    b. tslint.json
    c. nx.json
    d. angular.json
    e. Others..
  8. Invoke the workspace schematic yarn workspace-schematic <workspaceSchematic> <targetApp>

All 2 comments

I think this is an interesting feature. What is the interest in the community for this kind of feature?

This is not something which pertains to the main goal of Nx which is to allow monorepo development for a single organization. Thus, it is unlikely this becomes a first party feature.

However, you can implement this for your own workspace. Here's how I would do it (It might seem complex but it seems like it would save you time by automating the process):

  1. Use yarn dep-graph --file dependencies.json to generate a JSON file containing the dependency graph.
  2. Use a workspace-schematic to use the information in dependencies.json + other places.
  3. Create a directory for a new workspace
  4. Read nx.json and determine which implicitDependencies affect <targetApp>
  5. Copy the root of <targetApp>
  6. Recursively copy the dependencies of <targetApp>
  7. Do other modifications where it makes sense. (some files might have configuration for multiple projects.. Here are some that come to mind.
    a. tsconfig.json
    b. tslint.json
    c. nx.json
    d. angular.json
    e. Others..
  8. Invoke the workspace schematic yarn workspace-schematic <workspaceSchematic> <targetApp>

Sorry, I don't think this will be a feature anytime soon within Nx. However, if someone wants to create a plugin in the community, please check out this guide: https://nx.dev/react/guides/nx-plugin

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZempTime picture ZempTime  路  3Comments

zpydee picture zpydee  路  3Comments

elliotmendiola picture elliotmendiola  路  3Comments

zachnewburgh picture zachnewburgh  路  3Comments

kmkatsma picture kmkatsma  路  3Comments