1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.insertStatement = void 0;
|
4 | const devkit_1 = require("@nrwl/devkit");
|
5 | const typescript_1 = require("typescript");
|
6 |
|
7 |
|
8 |
|
9 | function insertStatement(tree, path, statement) {
|
10 | const contents = tree.read(path, 'utf-8');
|
11 | const sourceFile = (0, typescript_1.createSourceFile)(path, contents, typescript_1.ScriptTarget.ESNext);
|
12 | const importStatements = sourceFile.statements.filter(typescript_1.isImportDeclaration);
|
13 | const index = importStatements.length > 0
|
14 | ? importStatements[importStatements.length - 1].getEnd()
|
15 | : 0;
|
16 | if (importStatements.length > 0) {
|
17 | statement = `\n${statement}`;
|
18 | }
|
19 | const newContents = (0, devkit_1.applyChangesToString)(contents, [
|
20 | {
|
21 | type: devkit_1.ChangeType.Insert,
|
22 | index,
|
23 | text: statement,
|
24 | },
|
25 | ]);
|
26 | tree.write(path, newContents);
|
27 | }
|
28 | exports.insertStatement = insertStatement;
|
29 |
|
\ | No newline at end of file |