Files
mowesta/web-angular/ng-element-concat.js
T
Adriano Markovic 05c26fa0a8
LocationBasedServices/mowesta/ng-webcomponent This commit looks good
LocationBasedServices/mowesta/master This commit looks good
Modified gradle build script.
2020-04-16 22:05:30 +02:00

51 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const fs = require('fs-extra');
const proc = require('process');
const concat = require('concat');
// Configuration
// const elementName = 'weather-forecast-today';
// const distDir = `./dist/${elementName}`;
// const outputDir = distDir;
// const cssDir = distDir;
let elementName, distDir, outputDir, cssDir;
/**
 * Builds the web component through concatenating all javascript files.
 * 
 * @param {string} versionString The ECMAScript version. Either ES5 or ES2015.
 */
async function buildElement(versionString) {
const files = fs.readdirSync(distDir)
.filter(item => item.includes(versionString) && !item.includes('.map'))
.map(filtered => `${distDir}/${filtered}`);
await concat(files, `${outputDir}/${elementName}${versionString}.js`);
files.forEach(value => fs.removeSync(value));
}
/**
* Copying and renaming the global styles.css file of the main web app.
*/
async function copyStylesCss() {
const styleFile = fs.readdirSync(cssDir)
.filter(item => item.includes('styles') && item.includes('css'))
.map(filtered => `${cssDir}/${filtered}`);
if (styleFile.length !== 0) {
await fs.renameSync(styleFile[0], `${outputDir}/${elementName}.css`);
} else {
throw new Error(`No styles.css file found in ./dist/${cssDir} folder!`);
}
}
(async function() {
if (proc.argv.length !== 3) { throw new Error('You have to pass the name of the web component!'); }
elementName = proc.argv[2];
distDir = `./dist/${elementName}`;
outputDir = cssDir = distDir;
if (!fs.pathExistsSync(outputDir)) { fs.mkdirSync(outputDir); }
    buildElement('-es5');
    buildElement('-es2015');
copyStylesCss();
    console.log(`${elementName} build finished!`);
})();