UNPKG

@nxext/stencil

Version:

Nx plugin for stenciljs

32 lines 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.insertStatement = insertStatement; const devkit_1 = require("@nx/devkit"); const typescript_1 = require("typescript"); /** * Insert a statement after the last import statement in a file. * * For origin of this function, see link below. * * @see https://github.com/nrwl/nx/blob/master/packages/workspace/src/generators/utils/insert-statement.ts */ function insertStatement(tree, path, statement) { const contents = tree.read(path, 'utf-8'); const sourceFile = (0, typescript_1.createSourceFile)(path, contents, typescript_1.ScriptTarget.ESNext); const importStatements = sourceFile.statements.filter(typescript_1.isImportDeclaration); const index = importStatements.length > 0 ? importStatements[importStatements.length - 1].getEnd() : 0; if (importStatements.length > 0) { statement = `\n${statement}`; } const newContents = (0, devkit_1.applyChangesToString)(contents, [ { type: devkit_1.ChangeType.Insert, index, text: statement, }, ]); tree.write(path, newContents); } //# sourceMappingURL=insert-statement.js.map