(filePath: string)
| 4 | const cp = require("child_process"); |
| 5 | |
| 6 | function copyCurrentDirectoryToDist(filePath: string) { |
| 7 | |
| 8 | fse.copySync(filePath, filePath + '.original'); |
| 9 | |
| 10 | const content = fse.readFileSync(filePath, "utf8"); |
| 11 | const isServerActionFile = content.startsWith('\'use server\''); |
| 12 | |
| 13 | const splits = content.split(/'use php'/); |
| 14 | let result = splits[0]; |
| 15 | for (let i = 1; i < splits.length; i++) { |
| 16 | const endOfPhpCode = findClosingBrace(splits[i]); |
| 17 | const phpCode = splits[i].slice(0, endOfPhpCode); |
| 18 | if (!isServerActionFile) { |
| 19 | result += `"use server";\n`; |
| 20 | } |
| 21 | result += `return require('child_process').spawnSync('php', ['-r', \`${phpCode}\`]).stdout.toString()` |
| 22 | result += splits[i].slice(endOfPhpCode, splits[i].length); |
| 23 | } |
| 24 | fse.writeFileSync(filePath, result, "utf8") |
| 25 | } |
| 26 | |
| 27 | function findClosingBrace(string: String) { |
| 28 | let codeBlocksCounter = 0; |
nothing calls this directly
no test coverage detected