-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
3 changed files
with
54 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const fs = require('fs'); | ||
|
||
/** | ||
* @description Read the patches from the patches directory | ||
* | ||
* @returns {Promise<Array<string>>} | ||
*/ | ||
async function getPatches() { | ||
console.log('Getting patches...'); | ||
return new Promise((resolve, reject) => { | ||
fs.readdir('./dist/patches', (err, files) => { | ||
if (err) reject(err); | ||
console.log('Got patches.'); | ||
resolve(files); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* @description Updates the patchFile so that `patch-package` can notice them from node_modules directory | ||
* | ||
* @param {string} file - Path to the patch file | ||
* @returns {Promise<void>} | ||
*/ | ||
async function updatePatchFile(file) { | ||
console.log(`Updating ${file}...`); | ||
return new Promise((resolve, reject) => { | ||
fs.readFile(`./dist/patches/${file}`, 'utf8', (err, data) => { | ||
if (err) reject(err); | ||
const newData = data.replaceAll('node_modules', '..'); | ||
fs.writeFile(`./dist/patches/${file}`, newData, 'utf8', (err) => { | ||
if (err) reject(err); | ||
console.log(`Updated ${file}`); | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
async function main() { | ||
console.log('Start building patches...'); | ||
const patches = await getPatches(); | ||
return Promise.all(patches.map((patchFile) => updatePatchFile(patchFile))); | ||
} | ||
|
||
main().then(() => console.log('Done.')); |
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,3 +1,8 @@ | ||
{ | ||
"include": [".eslintrc.js", ".prettierrc.js", "scripts/**/*.ts", "bili.config.ts"] | ||
"include": [ | ||
".eslintrc.js", | ||
".prettierrc.js", | ||
"scripts/**/*.*s", | ||
"bili.config.ts" | ||
] | ||
} |