Skip to content

Commit

Permalink
Improved rebuild script
Browse files Browse the repository at this point in the history
  • Loading branch information
croqaz committed Mar 30, 2022
1 parent af65bed commit b1e5e68
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion packages/rrweb-snapshot/scripts/rebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,35 @@ const rrWeb = './dist/rrweb-snapshot.js';
const rrFile = process.argv[2];
const waitSec = parseInt(process.argv[3] || 60);
const PAGE_TIMEOUT = 5000;
let HTML_FILE = 'temp.html';

function delay(time) {
return new Promise((resolve) => setTimeout(resolve, time))
}

const describe = (jsHandle) => {
function sluggify(str) {
return str
.replace(/[^a-zA-Z0-9 -]/gi, '-')
.replace(/ /g, '-')
.replace(/-+/g, '-')
.replace(/-+$/, '')
}

function describe(jsHandle) {
return jsHandle.executionContext().evaluate((obj) => {
return typeof obj === 'string' ? obj : `${typeof obj}=${obj}`
}, jsHandle)
}

process.on('exit', function() {
try {
fs.unlinkSync(HTML_FILE);
console.log(`Removed temp HTML file: ${HTML_FILE}`);
} catch (err) {
console.error(err);
}
});

(async function main() {
const browser = await puppeteer.launch({
args: [
Expand Down Expand Up @@ -83,6 +101,14 @@ const describe = (jsHandle) => {
})();`);

await page.waitForSelector('*', { timeout: PAGE_TIMEOUT });

const htm = await page.content();
const title = (/<title>(.+)<\/title>/i).exec(htm)[1];
HTML_FILE = `${sluggify(title)}.html`;
await fs.promises.writeFile(HTML_FILE, htm.trim(), { encoding: 'utf8' });
console.log(`Written temp HTML file: ${HTML_FILE}`);

await page.goto(`file://${process.cwd()}/${HTML_FILE}`, { waitUntil: 'networkidle0', timeout: PAGE_TIMEOUT });
await delay(waitSec * 1000);

await browser.close();
Expand Down

0 comments on commit b1e5e68

Please sign in to comment.