Angular cli ng生成特定格式或自定义生成的代码

时间:2017-08-29 14:49:37

标签: angular angular-cli

我们现在开源我们的项目,作为开源要求,项目中的每个文件都需要在文件顶部包含许可评论。

用户下载代码后,可以在项目中添加更多组件,指令,管道等。我们希望,当用户在项目目录中运行任何ng命令时,新创建的组件,指令或堆也将使用文件顶部的许可证注释生成。

例如,生成组件的组件具有以下代码格式

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-restaurant',
  templateUrl: './restaurant.component.html',
  styleUrls: ['./restaurant.component.scss']
})
export class RestaurantComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

我希望它是这样的。

/*
* Copyright 2017 shepherd contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-restaurant',
  templateUrl: './restaurant.component.html',
  styleUrls: ['./restaurant.component.scss']
})
export class RestaurantComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

我们可以用当前的角度cli来实现吗?

1 个答案:

答案 0 :(得分:1)

刚刚添加了自定义模板的功能,现在可以在测试版中使用:https://github.com/angular/angular-cli/issues/2377#issuecomment-325910253

但是,目前还没有文档,因此在文档可用之前可能会有点试错。