[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 产品不同. 地理处 ...
随机推荐
- [hdu 4841]圆桌问题 | 约瑟夫问题 STL-vector
原题 问题描述: 经典的约瑟夫问题,有2n个人,其中n个好人n个坏人,使得删去n人后,剩下的全为好人.m为每次数的人数. n<=32767 题解: 首先考虑n的范围,暴力肯定行不通,所以会想到线 ...
- AX 2012 model应用
说句实话,AX2012 model真心不好用,当你开发好,把Model到入到客户环境时, 要防止有冲突,假如出现冲突的话,还必须去删除另外一个Model里面冲突的代码,真心麻烦. 下面给一个ax 导入 ...
- [高清] Excel函数速记手册
------ 郑重声明 --------- 资源来自网络,纯粹共享交流, 如果喜欢,请您务必支持正版!! --------------------------------------------- 下 ...
- zookerper入门、核心概念和使用场景
zookeeper是一个分布式程序的高性能协调服务,提供集中式信息存储服务,数据存储于内存中,类似文件系统的树形结构,高吞吐量和低延时,集群高可靠,基于zookeeper可以实现分布式统一配置中心.分 ...
- PowerShell命令批量添加、导出AD用户
导入单个AD用户命令 New-ADUser -Name "周八" -Surname "周" -GivenName "八"-SamAccoun ...
- gcc 编译控制选项
gcc 编译控制选项前面已经讲过, gcc 的基本用法是:$ gcc [选项] [文件名]gcc 有很多编译控制选项,使得 gcc 可以根据不同的参数进行不同的编译处理,可供 gcc调用的参数大约有 ...
- Mac 达芬奇【Davinci Resolve】 无法添加媒体
参考 : https://zhidao.baidu.com/question/182613491787331404.html 打开软件,点击默认的未命名项目: 点击左上角图中箭头位置: 选中系统-&g ...
- [React] 函数定义组件
函数定义组件的例子 function Welcome(props) { return <h1>Hello, {props.name}</h1>; } 该函数是一个有效的 Rea ...
- springboot学习入门简易版七---springboot2.0使用@Async异步执行方法(17)
1启动类开启异步调用注解 @SpringBootApplication @EnableAsync //开启异步调用 public class StartApplication { 不开启则异步调用无效 ...
- elk使用不足及弥补报警措施
全部都是6.6.2版本,就这还是没有敢选太新的 场景:每个收集点部署filebeat收集响应日志,然后发送到logstash,logstash发送到elasticsearch,和file,这里插一句, ...