Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/bazel/src/schematics/ng-new/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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) {
Expand Down Expand Up @@ -175,6 +199,7 @@ export default function(options: Schema): Rule {
addDevDependenciesToPackageJson(options),
schematic('bazel-workspace', options),
overwriteMainAndIndex(options),
overwriteGitignore(options),
updateWorkspaceFileToUseBazelBuilder(options),
]);
};
Expand Down
9 changes: 9 additions & 0 deletions packages/bazel/src/schematics/ng-new/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down