|
| 1 | +let { readFile, stat } = require("fs").promises; |
1 | 2 | let path = require("path"); |
2 | | -let { promisify } = require("faucet-pipeline-core/lib/util"); |
3 | 3 | let FileFinder = require("faucet-pipeline-core/lib/util/files/finder"); |
4 | 4 |
|
5 | | -let readFile = promisify(require("fs").readFile); |
6 | | -let stat = promisify(require("fs").stat); |
7 | | - |
8 | 5 | module.exports = { |
9 | 6 | key: "static", |
10 | 7 | bucket: "static", |
@@ -69,24 +66,32 @@ function processFiles(fileNames, config) { |
69 | 66 | return Promise.all(fileNames.map(fileName => processFile(fileName, config))); |
70 | 67 | } |
71 | 68 |
|
72 | | -function processFile(fileName, |
| 69 | +async function processFile(fileName, |
73 | 70 | { source, target, targetDir, fingerprint, assetManager, plugins }) { |
74 | 71 | let sourcePath = path.join(source, fileName); |
75 | 72 | let targetPath = path.join(target, fileName); |
76 | 73 |
|
77 | | - return readFile(sourcePath). |
78 | | - then(content => { |
79 | | - let type = determineFileType(sourcePath); |
80 | | - let plugin = type && plugins[type]; |
81 | | - return plugin ? plugin(content) : content; |
82 | | - }). |
83 | | - then(content => { |
84 | | - let options = { targetDir }; |
85 | | - if(fingerprint !== undefined) { |
86 | | - options.fingerprint = fingerprint; |
87 | | - } |
88 | | - return assetManager.writeFile(targetPath, content, options); |
89 | | - }); |
| 74 | + try { |
| 75 | + var content = await readFile(sourcePath); // eslint-disable-line no-var |
| 76 | + } catch(err) { |
| 77 | + if(err.code !== "ENOENT") { |
| 78 | + throw err; |
| 79 | + } |
| 80 | + console.error(`WARNING: \`${sourcePath}\` no longer exists`); |
| 81 | + return; |
| 82 | + } |
| 83 | + |
| 84 | + let type = determineFileType(sourcePath); |
| 85 | + if(type && plugins[type]) { |
| 86 | + let plugin = plugins[type]; |
| 87 | + content = await plugin(content); |
| 88 | + } |
| 89 | + |
| 90 | + let options = { targetDir }; |
| 91 | + if(fingerprint !== undefined) { |
| 92 | + options.fingerprint = fingerprint; |
| 93 | + } |
| 94 | + return assetManager.writeFile(targetPath, content, options); |
90 | 95 | } |
91 | 96 |
|
92 | 97 | function determineFileType(sourcePath) { |
|
0 commit comments