2022-04-07 09:50:07 +02:00
|
|
|
const fs = require('fs-extra');
|
|
|
|
const concat = require('concat');
|
|
|
|
const VERSION = require('./package.json').version;
|
|
|
|
const ovWebcomponentRCPath = './dist/openvidu-webcomponent-rc';
|
|
|
|
const ovWebcomponentProdPath = './dist/openvidu-webcomponent';
|
2022-01-24 11:18:23 +01:00
|
|
|
|
|
|
|
module.exports.buildWebcomponent = async () => {
|
2022-04-07 09:50:07 +02:00
|
|
|
console.log('Building OpenVidu Web Component (' + VERSION + ')');
|
|
|
|
const tutorialWcPath = '../../openvidu-tutorials/openvidu-webcomponent/web';
|
|
|
|
const e2eWcPath = './e2e/webcomponent-app';
|
|
|
|
|
2022-01-24 11:18:23 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
await buildElement();
|
|
|
|
await copyFiles(tutorialWcPath);
|
|
|
|
await copyFiles(e2eWcPath);
|
2022-03-16 12:15:22 +01:00
|
|
|
await renameWebComponentTestName(e2eWcPath);
|
2022-01-24 11:18:23 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
console.log(`OpenVidu Web Component (${VERSION}) built`);
|
2022-01-24 11:18:23 +01:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
async function buildElement() {
|
2022-04-07 09:50:07 +02:00
|
|
|
const files = [`${ovWebcomponentRCPath}/runtime.js`, `${ovWebcomponentRCPath}/main.js`, `${ovWebcomponentRCPath}/polyfills.js`];
|
2022-01-24 11:18:23 +01:00
|
|
|
|
|
|
|
try {
|
2022-04-07 09:50:07 +02:00
|
|
|
await fs.ensureDir('./dist/openvidu-webcomponent');
|
2024-07-02 19:19:05 +02:00
|
|
|
await concat(files, `${ovWebcomponentProdPath}/openvidu-webcomponent-${VERSION}.js`);
|
|
|
|
await fs.copy(`${ovWebcomponentRCPath}/styles.css`, `${ovWebcomponentProdPath}/openvidu-webcomponent-${VERSION}.css`);
|
2022-04-07 09:50:07 +02:00
|
|
|
// await fs.copy(
|
|
|
|
// "./dist/openvidu-webcomponent/assets",
|
|
|
|
// "./openvidu-webcomponent/assets"
|
|
|
|
// );
|
2022-01-24 11:18:23 +01:00
|
|
|
} catch (err) {
|
2024-07-02 19:19:05 +02:00
|
|
|
console.error('Error executing build function in webcomponent-builds.js');
|
2022-01-24 11:18:23 +01:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-16 12:15:22 +01:00
|
|
|
function renameWebComponentTestName(dir) {
|
2024-07-02 19:19:05 +02:00
|
|
|
fs.renameSync(`${dir}/openvidu-webcomponent-${VERSION}.js`, `${dir}/openvidu-webcomponent-dev.js`);
|
|
|
|
fs.renameSync(`${dir}/openvidu-webcomponent-${VERSION}.css`, `${dir}/openvidu-webcomponent-dev.css`);
|
2022-03-16 12:15:22 +01:00
|
|
|
}
|
|
|
|
|
2022-01-24 11:18:23 +01:00
|
|
|
async function copyFiles(destination) {
|
|
|
|
if (fs.existsSync(destination)) {
|
|
|
|
try {
|
2022-04-07 09:50:07 +02:00
|
|
|
console.log(`Copying openvidu-webcomponent files from: ${ovWebcomponentProdPath} to: ${destination}`);
|
|
|
|
await fs.ensureDir(ovWebcomponentProdPath);
|
|
|
|
await fs.copy(ovWebcomponentProdPath, destination);
|
2022-01-24 11:18:23 +01:00
|
|
|
} catch (err) {
|
2022-04-07 09:50:07 +02:00
|
|
|
console.error('Error executing copy function in webcomponent-builds.js');
|
2022-01-24 11:18:23 +01:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.buildWebcomponent();
|