-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpublish.js
38 lines (33 loc) · 977 Bytes
/
publish.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
/**
* Please do not remove this file as it is needed by
* GitHub actions to publish the library to our Antwerp CDN.
*/
const fs = require('fs');
const path = require('path');
function copyFolderRecursiveSync(source, target) {
const nodePackageFile = JSON.parse(fs.readFileSync(`${__dirname}/package.json`));
const version = nodePackageFile.version;
let files = [];
if (!fs.existsSync(target)) {
fs.mkdirSync(target);
files = fs.readdirSync(target);
if (!fs.existsSync(`${target}/${version}`)) {
fs.mkdirSync(`${target}/${version}`);
}
}
files = fs.readdirSync(source);
files.forEach((file) => {
const sourceFile = path.join(source, file);
const targetFile = path.join(target, version, file);
const data = fs.readFileSync(sourceFile, 'utf-8');
fs.writeFileSync(targetFile, data);
});
}
async function run() {
try {
await copyFolderRecursiveSync('lib', 'dist');
} catch (e) {
console.log(e);
}
}
run();