parent
ad6569c744
commit
b05baa59e0
@ -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),
|
||||
]);
|
||||
};
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user