@nx-plugins/astro
Version:
The Nx Plugin for Astro that contains executors, generators, and utilities for managing Astro applications and libraries within an Nx workspace.
59 lines • 1.76 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.addImport = exports.astroVersion = exports.nxPluginVersion = void 0;
const ts = require("typescript");
const devkit_1 = require("@nrwl/devkit");
// eslint-disable-next-line @typescript-eslint/no-var-requires
exports.nxPluginVersion = require('../package.json').version;
exports.astroVersion = '1.0.4';
function findNodes(node, kind, max = Infinity) {
if (!node || max == 0) {
return [];
}
const arr = [];
const hasMatch = Array.isArray(kind)
? kind.includes(node.kind)
: node.kind === kind;
if (hasMatch) {
arr.push(node);
max--;
}
if (max > 0) {
for (const child of node.getChildren()) {
findNodes(child, kind, max).forEach((node) => {
if (max > 0) {
arr.push(node);
}
max--;
});
if (max <= 0) {
break;
}
}
}
return arr;
}
function addImport(source, statement) {
const allImports = findNodes(source, ts.SyntaxKind.ImportDeclaration);
if (allImports.length > 0) {
const lastImport = allImports[allImports.length - 1];
return [
{
type: devkit_1.ChangeType.Insert,
index: lastImport.end + 1,
text: `\n${statement}\n`,
},
];
}
else {
return [
{
type: devkit_1.ChangeType.Insert,
index: 0,
text: `\n${statement}\n`,
},
];
}
}
exports.addImport = addImport;
//# sourceMappingURL=utils.js.map
;