UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

76 lines (70 loc) 2.43 kB
'use strict'; var typescriptEstree = require('@typescript-eslint/typescript-estree'); var recast = require('recast'); var addImport = require('./add-import.cjs'); function _interopNamespaceDefault(e) { var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n.default = e; return Object.freeze(n); } var recast__namespace = /*#__PURE__*/_interopNamespaceDefault(recast); function updateBuildConfig({ content, pluginName, pluginImportPath }) { const ast = recast__namespace.parse(content, { parser: { parse: (source) => typescriptEstree.parse(source, { loc: true, range: true, tokens: true, comment: true }) } }); const b = recast__namespace.types.builders; recast__namespace.types.visit(ast, { visitCallExpression(path) { const { node } = path; if (node.callee.type === "Identifier" && node.callee.name === "build" && node.arguments.length > 0 && node.arguments[0].type === "ObjectExpression") { const buildOptions = node.arguments[0]; let pluginsProperty = buildOptions.properties.find( (p) => p.type === "Property" && (p.key.type === "Identifier" && p.key.name === "plugins" || p.key.type === "Literal" && p.key.value === "plugins") ); if (!pluginsProperty) { pluginsProperty = b.property("init", b.identifier("plugins"), b.arrayExpression([b.identifier(pluginName)])); buildOptions.properties.push(pluginsProperty); } else if (pluginsProperty.value.type === "ArrayExpression") { const hasPlugin = pluginsProperty.value.elements.some( (el) => el?.type === "Identifier" && el.name === pluginName ); if (!hasPlugin) { pluginsProperty.value.elements.push(b.identifier(pluginName)); } } } return false; } }); let modifiedCode = recast__namespace.print(ast).code; modifiedCode = addImport.addImport({ content: modifiedCode, importName: pluginName, importPath: pluginImportPath }); return modifiedCode; } exports.updateBuildConfig = updateBuildConfig; //# sourceMappingURL=update-build-config.cjs.map