Created
July 8, 2022 17:54
-
-
Save i-rocky/0eaa85ddd1d363a97772eb948b67836e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| tasks.fix_generator = function () { | |
| const config = grunt.config('fix_generator'); | |
| const files = grunt.file.expand({}, config.dist.src); | |
| files.forEach((file) => { | |
| const contents = fs.readFileSync(file).toString('utf-8'); | |
| const match = contents.match(/\ndefine\(\s*(\[|function)/); | |
| if (match) { | |
| const prepended = contents.substring(0, match.index); | |
| let body = contents.substring(match.index); | |
| let append = ''; | |
| const sourcemap = body.match(/\/\/#\ssourceMappingURL/); | |
| if (sourcemap) { | |
| append = body.substring(sourcemap.index); | |
| body = body.substring(0, sourcemap.index); | |
| } | |
| fs.writeFileSync(file, `${body}\n${prepended}\n${append}`.trim()); | |
| } | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment