[Schematics] 0. Schematics "Hello World"
1. Install schematics cli:
- npm i -g @angular-devkit/schematics-cli@latest
2. Then run schematics
to create a new blank project:
- schematics blank --name=my-component
It creates folder with number of files for you.
CREATE /my-component/README.md (639 bytes)
CREATE /my-component/package.json (539 bytes)
CREATE /my-component/tsconfig.json (656 bytes)
CREATE /my-component/.gitignore (191 bytes)
CREATE /my-component/.npmignore (64 bytes)
CREATE /my-component/src/collection.json (231 bytes)
CREATE /my-component/src/my-component/index.ts (318 bytes)
CREATE /my-component/src/my-component/index_spec.ts (474 bytes)
3. One important thing to do now, open .npmignore, remove line:
- *.ts
It is because when you do `npm pack` to publish your schematics, it will remove all ts files, which is not what we want.
4. src/collection.json:
- {
- "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
- "schematics": {
- "my-component": {
- "description": "A blank schematic.",
- "factory": "./my-component/index#myComponent"
- }
- }
- }
The highlighted part, is the name of your schematics. Run the following command from the my-component
directory.
- schematics .:my-component
By default schematics run in staging mode, which means it won't generate any files for you. Instaed you can run:
- schematics .:my-component --dry-run=false
5. Let’s do something slightly more interesting than making sure it runs and create a hello.ts
file. Modify my-component/index.ts
to have a tree.create()
command.
- import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
- export function myComponent(_options: any): Rule {
- return (tree: Tree, _context: SchematicContext) => {
- tree.create('hello.ts', 'console.log("Hello, World")');
- return tree;
- };
- }
- describe('my-component', () => {
- it('works', () => {
- const runner = new SchematicTestRunner('schematics', collectionPath);
- const tree = runner.runSchematic('my-component', {}, Tree.empty());
- expect(tree.files).toEqual(['/hello.ts']);
- });
- });
[Schematics] 0. Schematics "Hello World"的更多相关文章
- Angular Schematics 三部曲之 Add
前言 因工作繁忙,差不多有三个月没有写过技术文章了,自八月份第一次编写 schematics 以来,我一直打算分享关于 schematics 的编写技巧,无奈还是拖到了年底. Angular Sche ...
- 在库中使用schematics——ng add与ng update
起步 创建一个angular库 ng new demo --create-application=false ng g library my-lib 可见如下目录结构 ├── node_modules ...
- ng 服务端渲染
官网文档 教学视屏 ng-toolkit @ng-toolkit/universal 注意: 使用 npm和yarn安装项目依赖,不要使用cnpm ng add @ng-toolkit/univers ...
- 试用 Angular v6 的 Ivy compiler
“Ivy” 是 Angular v6 的新一代渲染器.从 v6.0.0-beta.1 开始,Ivy 已经作为体验 API 发布. 作为下一代的 Angular 的视图引擎,重点在于彻底缩减代码尺寸并增 ...
- Vivado Design Suite用户指南之约束的使用第二部分(约束方法论)
Constraints Methodology(约束方法论) 关于约束方法论 设计约束定义了编译流程必须满足的要求,以使设计在板上起作用. 并非所有步骤都使用所有约束在编译流程中. 例如,物理约束仅在 ...
- Angular CLI: 1.6.7 入门
当你使用npm或者yarn也安装不了angular-cli时,请使用淘宝镜像. Step1 npm i -g cnpm --registry=https://registry.npm.taobao.o ...
- 为什么angular library的build不能将assets静态资源打包进去(转)
Versions Angular CLI: 6.0.7 Node: 9.3.0 OS: darwin x64 Angular: 6.0.3 ... animations, common, compil ...
- Angular7.1.4+Typescript3.1框架学习(二)
接着第一部分,这篇文章就 Angular cli进行介绍总结: 1. ng g:列出当前命令 ng g 需在angular工程文件夹下执行: C:\Users\zb\angulardemo\heroe ...
- 从 10.x 到 ArcGIS Pro 的 Python 迁移
与 ArcGIS Pro 结合使用 Python 的方式与包括 ArcGIS Desktop.ArcGIS Server 以及 ArcGIS Engine 在内的其他 ArcGIS 产品不同. 地理处 ...
随机推荐
- Django-03-静态文件配置
一.django静态文件配置原理 静态文件配置就是为了让用户请求时django服务器能找到静态文件返回. 首先要理解几个概念: 媒体文件:用户上传的文件 静态文件:css,js,image等 开发环境 ...
- quartz2.3.0(十)xml配置方式定义quartz定时任务
1.新增pom依赖 除了按照<quartz2.3.0系列目录——带您由浅入深全面掌握quartz2.3.0>添加依赖之外,pom.xml里新增加依赖: <dependency> ...
- 为什么重写equals一定要重写hashCode方法?
大家都知道,equals和hashcode是java.lang.Object类的两个重要的方法,在实际应用中常常需要重写这两个方法,但至于为什么重写这两个方法很多人都搞不明白. 下面我们看下Objec ...
- 使用Jenkins自带功能(不用shell)构建Docker镜像并推送到远程仓库
意义: 一开始实现这个目的是在Jenkins中使用的shell脚本,也就是如下的这个: bash # 进入到生成jar包的根目录 cd ${WORKSPACE}/${module_filename} ...
- NIO(2):Channel
Channel可以理解为铁轨,Buffer是铁轨上的火车.铁轨的两端连接这文件描述符或者说文件的缓冲区和程序运行时的内存.借助NIO是一种更加符合OS底层文件系统的调用方式,使用NIO可以用更小的开销 ...
- cocos版本说明
一直知道cocos是做游戏的,想学习一下,结果去官网一看就懵逼了.Cocos Creator,Cocos2d-x,cocos studio,Cocos2d-js,Cocos2d-x-lua,那一种才是 ...
- Oracle数据库连接超时
关于Oracle数据库的连接失败问题,有N种情况都会导致,这次遇到的是一般开发或者运维人员难以发现的 场景: 有一台机A能够正常连接数据库并正常运行,机器B连接失败 32位WebService程序基于 ...
- C# 使用代理实现方法过滤
一.为什么要进行方法过滤 一些情况下我们需要再方法调用前记录方法的调用时间和使用的参数,再调用后需要记录方法的结束时间和返回结果,当方法出现异常的时候,需要记录异常的堆栈和原因,这些都是与业务无关的代 ...
- Java任务调度框架Quartz教程
一.什么是quartz作业调度? Quartz框架是一个全功能.开源的任务调度服务,可以集成几乎任何的java应用程序—从小的单片机系统到大型的电子商务系统.Quartz可以执行上千上万的任务调度. ...
- VBA 字符串-相关函数(6-12)
Mid()函数 Mid()函数返回给定输入字符串中指定数量的字符. 语法 Mid(String,start[,Length]) 参数 String - 必需的参数.输入从中返回指定数量的字符的字符串. ...