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"的更多相关文章

  1. Angular Schematics 三部曲之 Add

    前言 因工作繁忙,差不多有三个月没有写过技术文章了,自八月份第一次编写 schematics 以来,我一直打算分享关于 schematics 的编写技巧,无奈还是拖到了年底. Angular Sche ...

  2. 在库中使用schematics——ng add与ng update

    起步 创建一个angular库 ng new demo --create-application=false ng g library my-lib 可见如下目录结构 ├── node_modules ...

  3. ng 服务端渲染

    官网文档 教学视屏 ng-toolkit @ng-toolkit/universal 注意: 使用 npm和yarn安装项目依赖,不要使用cnpm ng add @ng-toolkit/univers ...

  4. 试用 Angular v6 的 Ivy compiler

    “Ivy” 是 Angular v6 的新一代渲染器.从 v6.0.0-beta.1 开始,Ivy 已经作为体验 API 发布. 作为下一代的 Angular 的视图引擎,重点在于彻底缩减代码尺寸并增 ...

  5. Vivado Design Suite用户指南之约束的使用第二部分(约束方法论)

    Constraints Methodology(约束方法论) 关于约束方法论 设计约束定义了编译流程必须满足的要求,以使设计在板上起作用. 并非所有步骤都使用所有约束在编译流程中. 例如,物理约束仅在 ...

  6. Angular CLI: 1.6.7 入门

    当你使用npm或者yarn也安装不了angular-cli时,请使用淘宝镜像. Step1 npm i -g cnpm --registry=https://registry.npm.taobao.o ...

  7. 为什么angular library的build不能将assets静态资源打包进去(转)

    Versions Angular CLI: 6.0.7 Node: 9.3.0 OS: darwin x64 Angular: 6.0.3 ... animations, common, compil ...

  8. Angular7.1.4+Typescript3.1框架学习(二)

    接着第一部分,这篇文章就 Angular cli进行介绍总结: 1. ng g:列出当前命令 ng g 需在angular工程文件夹下执行: C:\Users\zb\angulardemo\heroe ...

  9. 从 10.x 到 ArcGIS Pro 的 Python 迁移

    与 ArcGIS Pro 结合使用 Python 的方式与包括 ArcGIS Desktop.ArcGIS Server 以及 ArcGIS Engine 在内的其他 ArcGIS 产品不同. 地理处 ...

随机推荐

  1. Delphi 开发微信公众平台 (一)- 定义数据结构

    先定义数据类型: unit rtcMW.Wechat.Types; interface uses Generics.Collections, Rest.Json, System.Json.Serial ...

  2. linux初识1

    linux 操作系统 概念性的理解 1.Linux内置解释器bash 相当于pyhon解释器 2.Linux的内部大多是使用python去书写 云计算 1.只需要 花钱,买腾讯,阿里云服务器 2.专人 ...

  3. 17.Python略有小成(包,logging模块)

    Python(包,logging模块) 一.包 什么是包 官网解释 : 包是一种通过使用'.模块名'来组织python模块名称空间的方式 , 具体来讲 , 包就是一个包含有__ init __.py文 ...

  4. 中国大学MOOC-翁恺-C语言程序设计习题集(二)

    04-0. 求符合给定条件的整数集(15)给定不超过6的正整数A,考虑从A开始的连续4个数字.请输出所有由它们组成的无重复数字的3位数. 输入格式: 输入在一行中给出A. 输出格式: 输出满足条件的的 ...

  5. FIFO形成3x3矩阵

    Verilog生成矩阵一般是使用shift_ip核,但其实用两个FIFO也行.最近刚好学到这种方法,把原理总结一下. 要求 现在有10x5的数据和对应数据有效指示信号,数据为0~49,要用FPGA对其 ...

  6. AS3灰色图像

    一开始觉得AS3的滤镜很难使用,尤其是那些矩阵,让人望而生畏.最近写一个聊天模块,要用到离线状态下的灰色头像,于是认真研究了ColorMatrixFilter,发现其实也没有那么难.所谓的矩阵其实就是 ...

  7. Spark 系列(十二)—— Spark SQL JOIN 操作

    一. 数据准备 本文主要介绍 Spark SQL 的多表连接,需要预先准备测试数据.分别创建员工和部门的 Datafame,并注册为临时视图,代码如下: val spark = SparkSessio ...

  8. node-red 安装

    介绍 Node-RED背景介绍• Node-Red是IBM公司开发的一个可视化的编程工具.它允许程序员通过组合各部件来编写应用程序.这些部件可以是硬件设备(如:Arduino板子).Web API(如 ...

  9. devextreme组装数据导出excel

    $.get("", function (grid_dataSource) { var grid_config = dxConfig.grid(grid_dataSource); g ...

  10. 14 Scroll 滚动搜索

      Scroll的用法: 第一次搜的时候,要指定 快照保留时间1min,分页的大小:2条/页: 对于第一次搜索,ES会返回一个这个scroll的id: 下次再搜的时候,就带着这个scrollid去搜就 ...