Last active
January 11, 2018 22:20
-
-
Save hansl/bd83c81179202600a829866ed2bea250 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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