-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathwordpress-cloning-inlinecss-script.js
More file actions
63 lines (57 loc) · 1.51 KB
/
wordpress-cloning-inlinecss-script.js
File metadata and controls
63 lines (57 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const juice = require('juice');
const fs = require('fs').promises;
const GitHubWriter = require('./github_writer');
// List of HTML files to be updated
const htmlFiles = [
'dist/index.html',
'dist/index-ar.html',
'dist/index-cs.html',
'dist/index-de.html',
'dist/index-es.html',
'dist/index-fr.html',
'dist/index-it.html',
'dist/index-ja.html',
'dist/index-ko.html',
'dist/index-pl.html',
'dist/index-pt.html',
'dist/index-ru.html',
'dist/index-tr.html',
'dist/index-zh-CN.html',
'dist/index-zh-TW.html'
];
const writer = new GitHubWriter();
const inlineCssAndWriteFile = async (htmlFile) => {
try {
const inlinedHtml = await new Promise((resolve, reject) => {
juice.juiceFile(htmlFile, {}, (err, result) => {
if (err) {
reject(`Skipping inlining CSS for file ${htmlFile}: \n ${err}`);
} else {
resolve(result);
}
});
});
await fs.writeFile(htmlFile, inlinedHtml, 'utf8');
await writer.writeSummary(`- CSS inlined successfully for file ${htmlFile}\n`);
} catch (error) {
await writer.writeSummary(`- ${error}\n`);
throw error;
}
};
const processFiles = async () => {
try {
for (const htmlFile of htmlFiles) {
try {
await inlineCssAndWriteFile(htmlFile);
} catch (error) {
continue;
}
}
await writer.writeOutput('script-success', 'true');
} catch (error) {
await writer.writeOutput('script-success', 'false');
process.exit(1);
}
};
// Start the process
processFiles();