pon-shared-pon.universe.frontend.shared.componentlibrary
Version:
shared components for Pon Universe
67 lines (50 loc) • 1.67 kB
JavaScript
const { exec } = require("child_process");
const packageJson = require("./../../../package.json");
class Installer {
constructor() {
this.registry =
"https://nexus.valtech.nl/repository/Pon.Universe.Frontend.Shared/";
this.regex = {
private: /^pu-/,
public: /^(?!pu-).*$/
};
this.dependencies = packageJson.dependencies;
this.devDependencies = packageJson.devDependencies;
this.puPackages = [];
this.publicPackages = [];
this.initInstaller();
}
static async execute(command) {
await exec(command);
}
static mergeObjectKeys(...objects) {
return objects.reduce((acc, curr) => acc.concat(...Object.keys(curr)), []);
}
static filterByRegex(array) {
return regex => array.filter(item => regex.test(item));
}
static async install(packageArray, registry) {
if (!packageArray.length) {
return;
}
const command = `npm i ${packageArray.join(" ")} ${
registry ? `--reg ${registry}` : ""
}`;
await Installer.execute(command);
}
setPackages() {
const filterPackages = Installer.filterByRegex(
Installer.mergeObjectKeys(this.dependencies, this.devDependencies)
);
this.puPackages = filterPackages(this.regex.private);
this.publicPackages = filterPackages(this.regex.public);
}
async initInstaller() {
console.log("installing packages");
this.setPackages();
await Installer.execute("npm clear cache --force");
await Installer.install(this.puPackages, this.registry);
await Installer.install(this.publicPackages);
}
}
new Installer();