INNER CODE UNIT · TypeScript

addImportLine

maciejtreder/ng-toolkit · schematics/_utils/index.ts:79

export function addImportLine(tree: Tree, filePath: string, importLine: string): void {
    if (getFileContent(tree, filePath).indexOf(importLine) == -1) {
        const changeRecorder = tree.beginUpdate(filePath);
        changeRecorder.insertLeft(0, importLine + '\n');
        tree.commitUpdate(changeRecorder);
    }
}
function getTsSourceFile(tree: Tree, path: string): ts.SourceFile {
    const buffer = tree.read(path);
    if (!buffer) {
        throw new SchematicsException(`Could not read file (${path}).`);
    }
    const content = buffer.toString();
    const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);

    return source;
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…