Files
mowesta/web-angular/ng-element-concat.js
T
handte ac8b771ecf
LocationBasedServices/mowesta/pipeline/head This commit looks good
Cleanup Angular elements and improve nodejs build scripts to support incremental builds.
Change project structure to get rid of copied assets and configuration files.
Import fonts in css using absolute paths to avoid duplication by webpack pipeline.
Stage output of ng build executions in build directory to separate ng app and elements.
Change concat scripts to assemble final output in dist folder without modifying build directory.
Add video.js files to supported modules (https://github.com/videojs/video.js/issues/6978).
Move baseRef option in angular file to new location to get rid of deprecation warning.
Change name and location of scripts to avoid copying assets.
Change name of custom element to include mowesta brand name as prefix.
2021-01-24 16:25:11 +01:00

53 lines
1.7 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;
let outputDir;
let inputDir;
/**
 * 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(inputDir)
.filter(item => item.includes(versionString) && !item.includes('.map'))
.map(filtered => `${inputDir}/${filtered}`);
await concat(files, `${outputDir}/${elementName}${versionString}.js`);
}
/**
* Copying and renaming the global styles.css file of the main web app.
*/
async function copyStylesCss() {
const styleFile = fs.readdirSync(inputDir)
.filter(item => item.includes('styles') && item.includes('css'))
.map(filtered => `${inputDir}/${filtered}`);
if (styleFile.length !== 0) {
await fs.copySync(styleFile[0], `${outputDir}/${elementName}.css`);
} else {
throw new Error(`Missing styles*.css in ${inputDir}.`);
}
}
(async function() {
if (proc.argv.length !== 3) { throw new Error('Web component missing.'); }
elementName = proc.argv[2];
inputDir = `./build/outputs/${elementName}`;
outputDir = `./dist/`;
if (!fs.pathExistsSync(outputDir)) {
fs.mkdirSync(outputDir);
}
    buildElement('-es5');
    buildElement('-es2015');
copyStylesCss();
    console.log(`Finished building ${elementName}.`);
})();