I'd like to use the angular-cli to generate a new workspace
The only way to do this at the moment is to run:
ng new asdf
cd asdf
ng g application whatever
but then all of the src/
files remain (and the original angular.json info for a project that is now inconsistently stored). There's no way to create a new repo without the src
folder... and when I do this using a custom schematic by essentially duplicating angular-cli's ng-new
and removing https://github.com/angular/angular-cli/blob/6449a753641340d8fc19a752e1a1ced75f974efa/packages/schematics/angular/ng-new/index.ts#L61 schematic('application', applicationOptions),
Whenever I run it...
$ ng new asdf -c=my-schematic
$ cd asdf
$ ng g application whatever
{"inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","style":"css","skipTests":false,"skipPackageJson":false,"name":"whatever"}
CREATE projects/whatever-e2e/protractor.conf.js (752 bytes)
CREATE projects/whatever-e2e/src/app.e2e-spec.ts (304 bytes)
CREATE projects/whatever-e2e/src/app.po.ts (208 bytes)
CREATE projects/whatever-e2e/tsconfig.e2e.json (219 bytes)
Only the e2e files get put into projects/
and the angular.json
file remains mostly empty:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {},
"cli": {
"defaultCollection": "my-schematic"
}
}
I suspect this has to do with something silently failing in the application schematic or a path being off... but I wanted to check first if there was an easier / more preferred way.
$ ng --version
Angular CLI: 6.1.0-rc.0
Node: 10.1.0
OS: win32 x64
Angular: 6.0.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
------------------------------------------------------
@angular-devkit/architect 0.7.0-rc.0
@angular-devkit/core 0.6.8
@angular-devkit/schematics 0.6.8
@angular/cdk 6.3.1
@angular/cli 6.1.0-rc.0
@angular/material 6.3.1
@schematics/angular 0.6.8
@schematics/update 0.7.0-rc.0
rxjs 6.2.1
typescript 2.7.2
Editing to note I'm familiar about 3rd-party libraries (e.g. Nrwl/Nx) but I'm trying to avoid those. I also posted this issue to GitHub: https://github.com/angular/angular-cli/issues/11402
I here is a guide how to do this using Nx and Angular CLI here The easiest is just to start with generating an empty Angular CLI project:
or if you use NX:
From here you can generate apps in the app folder with:
And generate libs in the libs folder with:
If you are using NX schematics this will also prompt you for a lot of extra configuration options such as generating lazy loaded modules, routing, use Jest etc...
Try
ng g application {project-name}
instead.Result
And
Angular.json
If you don't want your initial application to resides in /src, you can follow these 2 steps:
--create-application
tells the Angular CLI not to generate an initial application.--defaults
tells the Angular CLI not to prompt you about routing and CSS preprocessorWith these two steps, you will end up with a file structure like this:
And you will find your application and its corresponding e2e application in the
projects
folder:Okay it's too easy to create a monorepo architecture
let's see
apart from you can run all your applications on different different ports and create the build as separately
There currently isn't a way to do this the way I intend.
The hacky workaround is to run:
ng new <mono-repo name>
cd into it (
cd <mono-repo name>
)generate the first app name (
ng generate application <app-name>
)and then remove the original src / e2e folders (
rm -rf src e2e
) and the corresponding entry in angular.json.From then on whenever libraries / applications are generated everything will be in the projects folder.