Created
May 24, 2023 07:13
-
-
Save pratheeshrussell/2f69a0e6a4e8b61b40c1ac4d70c33bf2 to your computer and use it in GitHub Desktop.
Angular Elements build script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs-extra'); | |
const path = require('path'); | |
const concat = require('concat'); | |
const buildFolder = './dist/hello-world/';//end with / | |
const outputFile = 'hello-world.js'; | |
(async function build() { | |
// Get file list | |
fs.readdir(buildFolder, async (err, fileList)=> { | |
if (err) { | |
return console.log('Unable to scan directory: ' + err); | |
} | |
let files = []; | |
fileList.filter((file)=> { | |
return file.trim().endsWith(".js"); | |
}).forEach((file)=> { | |
files.push((path.join(buildFolder,file)).trim()); | |
}); | |
files = sortArray(files); | |
await fs.ensureDir('elements'); | |
await concat(files, `elements/${outputFile}`); | |
await fs.copyFile(`${buildFolder}styles.css`, 'elements/styles.css'); | |
// await fs.copy(`${buildFolder}/assets/`, 'elements/assets/' ); | |
console.log('Element built and can be found in folder "elements"'); | |
}); | |
})() | |
function sortArray(arr) { | |
const runtimeIndex = arr.findIndex(item => item.endsWith('runtime.js')); | |
const mainIndex = arr.findIndex(item => item.endsWith('main.js')); | |
if (runtimeIndex !== -1 && mainIndex !== -1) { | |
const runtime = arr.splice(runtimeIndex, 1)[0]; | |
const main = arr.splice(mainIndex, 1)[0]; | |
arr.push(main); | |
arr.unshift(runtime); | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment