Skip to content

Instantly share code, notes, and snippets.

@hansl
Last active January 11, 2018 22:20
Show Gist options
  • Save hansl/bd83c81179202600a829866ed2bea250 to your computer and use it in GitHub Desktop.
Save hansl/bd83c81179202600a829866ed2bea250 to your computer and use it in GitHub Desktop.
import { Rule, SchematicContext, Tree, chain, externalSchematic } from '@angular-devkit/schematics';
const licenseText = `
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
`;
export function myComponent(options: any): Rule {
return chain([
externalSchematic('@schematics/angular', 'component', options),
(tree: Tree, _context: SchematicContext) => {
tree.getDir(options.sourceDir)
.visit(filePath => {
if (!filePath.endsWith('.ts')) {
return;
}
const content = tree.read(filePath);
if (!content) {
return;
}
// Prevent from writing license to files that already have one.
if (content.indexOf(licenseText) == -1) {
tree.overwrite(filePath, licenseText + content);
}
});
return tree;
},
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment