mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Update web-platform-tests to revision 7a6f5673ff5d146ca5c09c6a1b42b7706cfee328
This commit is contained in:
parent
e2fca1b228
commit
4787b28da3
261 changed files with 8195 additions and 4689 deletions
34
tests/wpt/web-platform-tests/webrtc/tools/html-codemod.js
Normal file
34
tests/wpt/web-platform-tests/webrtc/tools/html-codemod.js
Normal file
|
@ -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);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue