-
Notifications
You must be signed in to change notification settings - Fork 13
/
after-build.js
28 lines (20 loc) · 925 Bytes
/
after-build.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
const fs = require('fs').promises;
const path = require('path');
const EXAMPLES_SOURCE_PATH = './src/after-build-examples/';
const EXAMPLES_TARGET_PATH = './dist/';
const run = async () => {
let filePath = `dist/shelly-porssisahko.js`;
let mainCode = (await fs.readFile(filePath)).toString();
//Creating all examples
let files = await fs.readdir(EXAMPLES_SOURCE_PATH, { recursive: false });
for (let file of files) {
const sourcePath = path.join(EXAMPLES_SOURCE_PATH, file);
const destPath = path.join(EXAMPLES_TARGET_PATH, file);
let data = (await fs.readFile(sourcePath)).toString();
//Replacing the main script placeholder with actualy code
data = data.replace('//__REPLACED_WITH_MAIN_CODE__', mainCode);
console.log("Example file:", path.join(EXAMPLES_TARGET_PATH, file));
await fs.writeFile(path.join(EXAMPLES_TARGET_PATH, file), Buffer.from(data, 'utf8'));
}
}
run();