UNPKG

inngest-setup-redwoodjs

Version:

Setup Inngest in RedwoodJS

20 lines (19 loc) 959 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); module.exports = function (file, api, { functionImportConfig }) { const j = api.jscodeshift; const root = j(file.source); functionImportConfig.forEach(config => { // Add the new import statement const newImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(`{ ${config.import} }`))], j.literal(`src/jobs/inngest/${config.from}`)); const existingImports = root.find(j.ImportDeclaration); existingImports.at(1).insertAfter(newImport); // Add the new identifier to the inngestFunctions array const inngestFunctions = root.find(j.VariableDeclaration, { declarations: [{ id: { name: 'inngestFunctions' } }], }); const newFunction = j.identifier(config.import); inngestFunctions.find(j.ArrayExpression).get('elements').push(newFunction); }); return root.toSource(); };