Files
flipper/scripts/yarn-install.js
Hilal Alsibai 2a46f93eab Fix install for Windows (#138)
Summary:
This lets `yarn` work properly on Windows. Tested in a Cygwin environment. I also added a note about yarn compatibility to the readme.
Closes https://github.com/facebook/Sonar/pull/138

Reviewed By: danielbuechele

Differential Revision: D8734197

Pulled By: xiphirx

fbshipit-source-id: 19be8bb0653a2b0381224b065df0cac579d72c3b
2018-07-05 03:32:30 -07:00

50 lines
1.4 KiB
JavaScript

/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
const glob = require('glob');
const path = require('path');
const {spawn} = require('child_process');
const PACKAGES = ['static', 'src/plugins/*', 'src/fb/plugins/*'];
const WINDOWS = /^win/.test(process.platform);
const YARN_PATH =
process.argv.length > 2 ? path.join(__dirname, process.argv[2]) : 'yarn' + (WINDOWS ? '.cmd' : '');
Promise.all(
PACKAGES.map(
pattern =>
new Promise((resolve, reject) => {
glob(
path.join(__dirname, '..', pattern, 'package.json'),
(err, matches) => {
if (err) {
reject(err);
} else {
resolve(matches);
}
},
);
}),
),
)
.then(packages =>
Promise.all(
packages.reduce((acc, cv) => acc.concat(cv), []).map(
pkg =>
new Promise(resolve => {
const cwd = pkg.replace('/package.json', '');
const yarn = spawn(YARN_PATH, ['--mutex', 'file'], {
cwd,
});
yarn.stderr.on('data', e => console.error(e.toString()));
yarn.on('close', code => resolve(code));
}),
),
),
)
// eslint-disable-next-line
.then(() => console.log('📦 Installed all dependencies!'));