Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | 2x 2x 2x 2x 4x 4x 4x 4x 2x 2x 2x 2x 2x 2x 4x 4x 4x 4x | import { Construct, ISynthesisSession, Tokenization, DefaultTokenResolver, StringConcat } from 'constructs';
import * as fs from 'fs-extra';
import * as path from 'path';
import { Project } from './project';
export interface FileBaseOptions {
/**
* Indicates whether this file should be committed to git or ignored. By
* default, all generated files are committed and anti-tamper is used to
* protect against manual modifications.
*
* @default true
*/
readonly committed?: boolean;
/**
* Update the project's .gitignore file
* @default true
*/
readonly editGitignore?: boolean;
}
export abstract class FileBase extends Construct {
public readonly path: string;
constructor(project: Project, filePath: string, options: FileBaseOptions = { }) {
super(project, filePath);
this.path = filePath;
const gitignore = options.editGitignore ?? true;
if (gitignore) {
const committed = options.committed ?? true;
const pattern = `/${this.path}`;
Eif (committed) {
project.gitignore.comment('synthesized by projen, (do not modify by hand)');
project.gitignore.include(pattern);
} else {
project.gitignore.comment('synthesized by projen');
project.gitignore.exclude(pattern);
}
} else {
Iif (options.committed != null) {
throw new Error('"gitignore" is disabled, so it does not make sense to specify "committed"');
}
}
}
protected abstract get data(): string;
public onSynthesize(session: ISynthesisSession): void {
const filePath = path.join(session.outdir, this.path);
fs.mkdirpSync(path.dirname(filePath));
const post = Tokenization.resolve(this.data, {
resolver: new DefaultTokenResolver(new StringConcat()),
scope: this,
preparing: false,
});
fs.writeFileSync(filePath, post);
}
} |