2025-04-30 17:58:11 +02:00
|
|
|
import fs from 'fs-extra';
|
|
|
|
import concat from 'concat';
|
|
|
|
const packageJson = fs.readJSONSync('./package.json');
|
|
|
|
const VERSION = packageJson.version;
|
2022-04-07 09:50:07 +02:00
|
|
|
const ovWebcomponentRCPath = './dist/openvidu-webcomponent-rc';
|
|
|
|
const ovWebcomponentProdPath = './dist/openvidu-webcomponent';
|
2022-01-24 11:18:23 +01:00
|
|
|
|
2025-04-30 17:58:11 +02:00
|
|
|
export const 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() {
|
2025-04-30 17:58:11 +02:00
|
|
|
const files = [`${ovWebcomponentRCPath}/polyfills.js`, /*`${ovWebcomponentRCPath}/runtime.js`,*/ `${ovWebcomponentRCPath}/main.js`];
|
2022-01-24 11:18:23 +01:00
|
|
|
try {
|
2025-04-30 17:58:11 +02:00
|
|
|
for (const file of files) {
|
|
|
|
if (!fs.existsSync(file)) {
|
|
|
|
console.error(`Error: File ${file} does not exist`);
|
|
|
|
throw new Error(`Missing required file: ${file}`);
|
|
|
|
}
|
|
|
|
}
|
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`);
|
2025-04-30 17:58:11 +02:00
|
|
|
|
|
|
|
if (fs.existsSync(`${ovWebcomponentRCPath}/assets`)) {
|
|
|
|
await fs.copy(`${ovWebcomponentRCPath}/assets`, `${ovWebcomponentProdPath}/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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-30 17:58:11 +02:00
|
|
|
await buildWebcomponent();
|