2019-11-28 05:17:01 -09:00
|
|
|
import cp from 'child_process';
|
2023-07-25 09:30:19 -08:00
|
|
|
|
2019-11-28 05:17:01 -09:00
|
|
|
import ms from 'ms';
|
2023-07-25 09:30:19 -08:00
|
|
|
import queue from 'queue';
|
|
|
|
|
|
2019-11-28 05:17:01 -09:00
|
|
|
import {yarn, plugs} from '../config/paths';
|
2017-08-21 16:07:50 -08:00
|
|
|
|
2021-03-28 12:13:49 -08:00
|
|
|
export const install = (fn: (err: string | null) => void) => {
|
2019-12-10 01:56:04 -09:00
|
|
|
const spawnQueue = queue({concurrency: 1});
|
2021-03-28 12:13:49 -08:00
|
|
|
function yarnFn(args: string[], cb: (err: string | null) => void) {
|
2019-12-10 01:56:04 -09:00
|
|
|
const env = {
|
|
|
|
|
NODE_ENV: 'production',
|
|
|
|
|
ELECTRON_RUN_AS_NODE: 'true'
|
|
|
|
|
};
|
2020-03-25 02:15:08 -08:00
|
|
|
spawnQueue.push((end) => {
|
2019-12-10 01:56:04 -09:00
|
|
|
const cmd = [process.execPath, yarn].concat(args).join(' ');
|
|
|
|
|
console.log('Launching yarn:', cmd);
|
2017-08-21 16:07:50 -08:00
|
|
|
|
2019-12-10 01:56:04 -09:00
|
|
|
cp.execFile(
|
|
|
|
|
process.execPath,
|
|
|
|
|
[yarn].concat(args),
|
|
|
|
|
{
|
|
|
|
|
cwd: plugs.base,
|
|
|
|
|
env,
|
|
|
|
|
timeout: ms('5m'),
|
|
|
|
|
maxBuffer: 1024 * 1024
|
|
|
|
|
},
|
|
|
|
|
(err, stdout, stderr) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
cb(stderr);
|
|
|
|
|
} else {
|
|
|
|
|
cb(null);
|
2017-09-10 05:35:10 -08:00
|
|
|
}
|
2019-12-25 00:52:32 -09:00
|
|
|
end?.();
|
2019-12-10 01:56:04 -09:00
|
|
|
spawnQueue.start();
|
|
|
|
|
}
|
|
|
|
|
);
|
2017-08-21 16:07:50 -08:00
|
|
|
});
|
2019-12-10 01:56:04 -09:00
|
|
|
|
|
|
|
|
spawnQueue.start();
|
2017-08-21 16:07:50 -08:00
|
|
|
}
|
2019-12-10 01:56:04 -09:00
|
|
|
|
2021-03-28 12:13:49 -08:00
|
|
|
yarnFn(['install', '--no-emoji', '--no-lockfile', '--cache-folder', plugs.cache], (err) => {
|
2019-12-10 01:56:04 -09:00
|
|
|
if (err) {
|
|
|
|
|
return fn(err);
|
|
|
|
|
}
|
|
|
|
|
fn(null);
|
|
|
|
|
});
|
2017-08-21 16:07:50 -08:00
|
|
|
};
|