diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/webrtc/tools/html-codemod.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webrtc/tools/html-codemod.js')
-rw-r--r-- | testing/web-platform/tests/webrtc/tools/html-codemod.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webrtc/tools/html-codemod.js b/testing/web-platform/tests/webrtc/tools/html-codemod.js new file mode 100644 index 0000000000..6a31e8c4c6 --- /dev/null +++ b/testing/web-platform/tests/webrtc/tools/html-codemod.js @@ -0,0 +1,34 @@ +/* + * extract script content from a series of html files, run a + * jscodeshift codemod on them and overwrite the original file. + * + * Usage: node html-codemod.js codemod-file list of files to process + */ +const { JSDOM } = require('jsdom'); +const fs = require('fs'); +const {execFileSync} = require('child_process'); + +const codemod = process.argv[2]; +const filenames = process.argv.slice(3); +filenames.forEach((filename) => { + const originalContent = fs.readFileSync(filename, 'utf-8'); + const dom = new JSDOM(originalContent); + const document = dom.window.document; + const scriptTags = document.querySelectorAll('script'); + const lastTag = scriptTags[scriptTags.length - 1]; + const script = lastTag.innerHTML; + if (!script) { + console.log('NO SCRIPT FOUND', filename); + return; + } + const scriptFilename = filename + '.codemod.js'; + const scriptFile = fs.writeFileSync(scriptFilename, script); + // exec jscodeshift + const output = execFileSync('./node_modules/.bin/jscodeshift', ['-t', codemod, scriptFilename]); + console.log(filename, output.toString()); // output jscodeshift output. + // read back file, resubstitute + const newScript = fs.readFileSync(scriptFilename, 'utf-8').toString(); + const modifiedContent = originalContent.split(script).join(newScript); + fs.writeFileSync(filename, modifiedContent); + fs.unlinkSync(scriptFilename); +}); |