如何使用 angular-cli (6.x) 创建单仓库项目结构 [英] How to create a mono-repo project structure with angular-cli (6.x)
问题描述
我想使用 angular-cli 来生成一个新的工作区
目前唯一的方法是运行:
ng 新的 asdfcd asdfng g 应用程序
但随后所有 src/
文件都保留了下来(以及现在不一致存储的项目的原始 angular.json 信息).没有 src
文件夹就无法创建新的存储库......当我使用自定义原理图通过基本上复制 angular-cli 的 ng-new
并删除 https://github.com/angular/angular-cli/blob/6449a753641340d8fc19a752e1a1ced75f974efa/packages/schematics/angular/ng-new/index.ts#L61 schematic('application', application
,
每当我运行它...
$ ng new asdf -c=my-schematic$ cd asdf$ ng g 应用程序{"inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","style":"css","skipTests":false,"skipPackageJson":false,"name":任何"}创建项目/whatever-e2e/protractor.conf.js(752 字节)创建项目/whatever-e2e/src/app.e2e-spec.ts(304 字节)创建项目/whatever-e2e/src/app.po.ts(208 字节)创建项目/whatever-e2e/tsconfig.e2e.json(219 字节)
只有 e2e 文件被放入 projects/
而 angular.json
文件大部分仍然是空的:
<代码>{"$schema": "./node_modules/@angular/cli/lib/config/schema.json",版本":1,"newProjectRoot": "项目",项目":{},cli":{defaultCollection":我的示意图"}}
我怀疑这与应用程序原理图中的某些静默失败或路径断开有关...但我想首先检查是否有更简单/更首选的方法.
$ ng --version角 CLI:6.1.0-rc.0节点:10.1.0操作系统:win32 x64角度:6.0.7... 动画、通用、编译器、编译器-cli、核心、表单... http、语言服务、平台浏览器... 平台浏览器动态,路由器套餐版本------------------------------------------------------@angular-devkit/architect 0.7.0-rc.0@angular-devkit/核心 0.6.8@angular-devkit/schematics 0.6.8@angular/cdk 6.3.1@angular/cli 6.1.0-rc.0@角度/材料 6.3.1@原理图/角度 0.6.8@原理图/更新 0.7.0-rc.0rxjs 6.2.1打字稿 2.7.2
编辑以注意我对 3rd-party 库(例如 Nrwl/Nx)很熟悉,但我试图避免使用它们.我也将此问题发布到 GitHub:https://github.com/angular/angular-cli/issues/11402
目前没有一种方法可以按照我的意图进行.
hacky 的解决方法是运行:
ng new
cd 进入它 (cd
)
生成第一个应用名称(ng generate application
)
然后删除原来的src/e2e文件夹(rm -rf src e2e
)和angular.json中对应的条目.
从那时起,无论何时生成库/应用程序,所有内容都将在项目文件夹中.
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
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.
这篇关于如何使用 angular-cli (6.x) 创建单仓库项目结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!