fix(bazel): Add /bazel-out to .gitignore (#27874)

PR Close #27874
This commit is contained in:
Suguru Inatomi 2018-12-31 13:08:51 +09:00 committed by Andrew Kushnir
parent ad6569c744
commit b05baa59e0
2 changed files with 34 additions and 0 deletions

View File

@ -77,6 +77,30 @@ function overwriteMainAndIndex(options: Schema) {
};
}
function overwriteGitignore(options: Schema) {
return (host: Tree) => {
const gitignore = `${options.name}/.gitignore`;
if (!host.exists(gitignore)) {
return host;
}
const gitIgnoreContent = host.read(gitignore);
if (!gitIgnoreContent) {
throw new Error('Failed to read .gitignore content');
}
if (gitIgnoreContent.includes('/bazel-out\n')) {
return host;
}
const lines = gitIgnoreContent.toString().split(/\n/g);
const recorder = host.beginUpdate(gitignore);
const compileOutput = lines.findIndex((line: string) => line === '# compiled output');
recorder.insertRight(compileOutput, '\n/bazel-out');
host.commitUpdate(recorder);
return host;
};
}
function replacePropertyInAstObject(
recorder: UpdateRecorder, node: JsonAstObject, propertyName: string, value: JsonValue,
indent: number) {
@ -176,6 +200,7 @@ export default function(options: Schema): Rule {
addDevDependenciesToPackageJson(options),
schematic('bazel-workspace', options),
overwriteMainAndIndex(options),
overwriteGitignore(options),
updateWorkspaceFileToUseBazelBuilder(options),
]);
};

View File

@ -80,6 +80,15 @@ describe('Ng-new Schematic', () => {
expect(content).toMatch('<script src="/bundle.min.js"></script>');
});
it('should overwrite .gitignore for bazel-out directory', () => {
const options = {...defaultOptions};
const host = schematicRunner.runSchematic('ng-new', options);
const {files} = host;
expect(files).toContain('/demo/.gitignore');
const content = host.readContent('/demo/.gitignore');
expect(content).toMatch('/bazel-out');
});
it('should update angular.json to use Bazel builder', () => {
const options = {...defaultOptions};
const host = schematicRunner.runSchematic('ng-new', options);