forked from Dunks1980/bay.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
26 lines (23 loc) · 959 Bytes
/
build.js
File metadata and controls
26 lines (23 loc) · 959 Bytes
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
const fs = require("fs");
const path = require('path');
var dir = './dist';
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
const bayFile = fs.readFileSync('./bay.min.js');
const bay = bayFile.toString();
fs.readdir(path.join(__dirname, 'src'), (error, files) => {
if (error) {
console.log(error);
return;
}
files.forEach( file => {
console.log(file);
const templateFile = fs.readFileSync('./src/' + file);
const template = '\n' + templateFile.toString().replaceAll('`', '\\`').replaceAll('${', '\\${');
let filename = file.split('.')[0];
if (filename.indexOf('-') === -1) filename = `bay-${filename}`;
const outputFile = `(function(){${bay};window.requestAnimationFrame(function(){var ea=[];var e=document.querySelector('${filename}');if(e){ea=Array.from(e.attributes).map(a=>a.name);}window.bay.create('${filename}',\`${template}\`,ea);});}())`;
fs.writeFileSync(`dist/${filename}.js`, outputFile);
});
});