MCPcopy Index your code
hub / github.com/bufferhead-code/nextjs-use-php / copyCurrentDirectoryToDist

Function copyCurrentDirectoryToDist

build.ts:6–25  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

4const cp = require("child_process");
5
6function 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
27function findClosingBrace(string: String) {
28 let codeBlocksCounter = 0;

Callers

nothing calls this directly

Calls 1

findClosingBraceFunction · 0.85

Tested by

no test coverage detected