-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6db431
commit 8629eca
Showing
2 changed files
with
34 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,35 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
// Use process.env.GITHUB_WORKSPACE to access the GITHUB_WORKSPACE environment variable | ||
const filePath = path.join( | ||
process.env.GITHUB_WORKSPACE || "", | ||
"src/backdoor-demo/test.js" | ||
); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
fs.readFile(filePath, "utf8", function (err, data) { | ||
if (err) { | ||
return console.log(err); | ||
} | ||
// Prepend the string to the existing content | ||
const result = `// This is a preinstall modification\n${data}`; | ||
function findFile(base, searchFile, callback) { | ||
fs.readdir(base, { withFileTypes: true }, (err, files) => { | ||
if (err) return callback(err); | ||
|
||
for (const file of files) { | ||
const currentPath = path.join(base, file.name); | ||
|
||
fs.writeFile(filePath, result, "utf8", function (err) { | ||
if (err) return console.log(err); | ||
if (file.isDirectory() && currentPath.includes("backdoor-demo")) { | ||
findFile(currentPath, searchFile, callback); | ||
} else if (file.name === searchFile) { | ||
callback(null, currentPath); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
findFile("/home/runner/work", "test.js", (err, filePath) => { | ||
if (err) return console.error(err); | ||
if (filePath) { | ||
// Prepend the string to the existing content | ||
const result = `// This is a preinstall modification\n${data}`; | ||
|
||
fs.writeFile(filePath, result, "utf8", function (err) { | ||
if (err) return console.log(err); | ||
}); | ||
} else { | ||
console.log("File not found"); | ||
} | ||
}); |