Skip to content

Commit edc0957

Browse files
authored
Merge pull request #2516 from jerch/addon_build
conditional `yarn` for addons
2 parents f30c38f + 5b3a093 commit edc0957

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

bin/install-addons.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
3+
* @license MIT
4+
*
5+
* Script to initialize addon packages under "addons/" with outer deps.
6+
*/
7+
8+
const path = require('path');
9+
const cp = require('child_process');
10+
const fs = require('fs');
11+
12+
const PACKAGE_ROOT = path.join(__dirname, '..');
13+
14+
// install addon deps
15+
const addonsPath = path.join(PACKAGE_ROOT, 'addons');
16+
if (fs.existsSync(addonsPath)) {
17+
console.log('pulling addon dependencies...');
18+
19+
// whether to use yarn or npm
20+
let hasYarn = false;
21+
try {
22+
cp.execSync('yarn --version').toString();
23+
hasYarn = true;
24+
} catch(e) {}
25+
26+
// walk all addon folders
27+
fs.readdir(addonsPath, (err, files) => {
28+
files.forEach(folder => {
29+
const addonPath = path.join(addonsPath, folder);
30+
31+
// install only if there are dependencies listed
32+
let packageJson;
33+
try {
34+
packageJson = require(path.join(addonPath, 'package.json'));
35+
} catch (e) {
36+
// swallow as changing branches can leave folders around
37+
}
38+
if (packageJson
39+
&& (
40+
(packageJson.devDependencies && Object.keys(packageJson.devDependencies).length)
41+
|| (packageJson.dependencies && Object.keys(packageJson.dependencies).length)
42+
)
43+
)
44+
{
45+
console.log('Preparing', folder);
46+
if (hasYarn) {
47+
cp.execSync('yarn', {cwd: addonPath});
48+
} else {
49+
cp.execSync('npm install', {cwd: addonPath});
50+
}
51+
} else {
52+
console.log('Skipped', folder);
53+
}
54+
});
55+
});
56+
}

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
"prepackage": "npm run build",
1212
"package": "webpack",
1313
"start": "node demo/start",
14-
"lint": "tslint 'src/**/*.ts' 'addons/**/*.ts'",
14+
"lint": "tslint 'src/**/*.ts' 'addons/*/src/**/*.ts'",
1515
"test": "npm run test-unit",
1616
"posttest": "npm run lint",
1717
"test-api": "mocha \"**/*.api.js\"",
1818
"test-unit": "node ./bin/test.js",
1919
"build": "tsc -b ./tsconfig.all.json",
20-
"prepare": "npm run build",
20+
"prepare": "npm run setup",
21+
"setup": "npm run build",
22+
"presetup": "node ./bin/install-addons.js",
2123
"prepublishOnly": "npm run package",
2224
"watch": "tsc -b -w ./tsconfig.all.json --preserveWatchOutput",
2325
"benchmark": "NODE_PATH=./out xterm-benchmark -r 5 -c test/benchmark/benchmark.json",

0 commit comments

Comments
 (0)