Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conditional build for addons #2516

Merged
merged 6 commits into from
Oct 26, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions bin/install-addons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const path = require('path');
jerch marked this conversation as resolved.
Show resolved Hide resolved
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
// also skip addon if it does not contain any package.json
// (might happen after branch switches)
let packageJson;
try {
packageJson = require(path.join(addonPath, 'package.json'));
} catch (e) {}
Tyriar marked this conversation as resolved.
Show resolved Hide resolved
jerch marked this conversation as resolved.
Show resolved Hide resolved
if (packageJson
&& (
(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);
}
});
});
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"repository": "https://github.com/xtermjs/xterm.js",
"license": "MIT",
"scripts": {
"postinstall": "node -e \"try { require('./bin/install-addons'); } catch(e) {}\"",
jerch marked this conversation as resolved.
Show resolved Hide resolved
"prepackage": "npm run build",
"package": "webpack",
"start": "node demo/start",
"lint": "tslint 'src/**/*.ts' 'addons/**/*.ts'",
"lint": "tslint 'src/**/*.ts' 'addons/*/src/**/*.ts'",
"test": "npm run test-unit",
"posttest": "npm run lint",
"test-api": "mocha \"**/*.api.js\"",
Expand Down