-
Notifications
You must be signed in to change notification settings - Fork 27
/
promise.js
40 lines (38 loc) · 881 Bytes
/
promise.js
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
'use strict';
const fs = require('fs'),
path = require('path'),
writeAsync = function (name, content) {
return new Promise((resolve, reject) => {
fs.writeFile(name, content, 'utf8', (err, result) => {
if (err) {
return reject(err);
}
resolve(result);
});
});
};
module.exports = function (params, context) {
const css = `
#header {
font: italic 200% Helvetica;
white-space: nowrap;
color: blue;
overflow: visible;
}
`,
html = `
<html>
<head>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="header">${params.name}</div>
</body>
</html>
`,
cssFile = path.join(context.outputDir, 'style.css'),
htmlFile = path.join(context.outputDir, 'result.html');
return writeAsync(cssFile, css)
.then(() => writeAsync(htmlFile, html))
.then(() => path.basename(htmlFile));
};