forked from lgwebdream/fe-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemitCode.js
More file actions
21 lines (18 loc) · 686 Bytes
/
emitCode.js
File metadata and controls
21 lines (18 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const path = require('path');
const { mkdir, writeFile } = require('../../utils/fileSystem');
const emitCode = async (codeConfig, output, emitType) => {
const dir = path.resolve(output, emitType);
await mkdir(dir, { recursive: true });
const emitStatus = [];
for (const code of await Promise.all(codeConfig)) {
const filePath = path.resolve(dir, `${code.filename}${code.ext || '.ts'}`);
const awaitFilePath = new Promise((resolve, reject) => {
writeFile(filePath, code.code)
.then(() => resolve(filePath))
.catch(err => reject(err));
});
emitStatus.push(awaitFilePath);
}
await Promise.all(emitStatus);
};
module.exports = emitCode;