|
| 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 | +} |
0 commit comments