conditional build for addons

This commit is contained in:
Jörg Breitbart
2019-10-25 17:29:38 +02:00
parent f30c38f773
commit 25c18e8e07
2 changed files with 41 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
const path = require('path');
const cp = require('child_process');
const fs = require('fs');
const PACKAGE_ROOT = path.join(__dirname, '..');
// install addon deps
const addonsPath = path.join(PACKAGE_ROOT, 'addons');
if (fs.existsSync(addonsPath)) {
console.log('pulling addon dependencies...');
// whether to use yarn or npm
let hasYarn = false;
try {
cp.execSync('yarn --version').toString();
hasYarn = true;
} catch(e) {}
// walk all addon folders
fs.readdir(addonsPath, (err, files) => {
files.forEach(folder => {
const addonPath = path.join(addonsPath, folder);
// install only if there are dependencies listed
const packageJson = require(path.join(addonPath, 'package.json'));
if ((packageJson.devDependencies && Object.keys(packageJson.devDependencies).length)
|| (packageJson.dependencies && Object.keys(packageJson.dependencies).length))
{
console.log('Preparing', folder);
if (hasYarn) {
cp.execSync('yarn', {cwd: addonPath});
} else {
cp.execSync('npm install', {cwd: addonPath});
}
} else {
console.log('Skipped', folder);
}
});
});
}
+1
View File
@@ -8,6 +8,7 @@
"repository": "https://github.com/xtermjs/xterm.js",
"license": "MIT",
"scripts": {
"postinstall": "node -e \"try { require('./bin/install-addons'); } catch(e) {}\"",
"prepackage": "npm run build",
"package": "webpack",
"start": "node demo/start",