-
Notifications
You must be signed in to change notification settings - Fork 0
/
addGlobal.js
33 lines (24 loc) · 876 Bytes
/
addGlobal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { deleteFromYarnCache, yarn, cleanYarnLock, YARN_CMD } from '%/util';
import { build } from '%/api';
import { getAppRootPath, spawnChildProcess, readJSONFile } from '@jspencev/node-util';
import path from 'path';
let repoName;
let yarnGlobalDir;
(async function() {
const appRootPath = await getAppRootPath(__dirname);
const polyConfig = await readJSONFile(path.join(appRootPath, 'config.poly'));
repoName = polyConfig.repository_name;
yarnGlobalDir = (await spawnChildProcess(YARN_CMD, 'global dir', {stdio: 'pipe'})).result;
const {tarballPath} = await build();
await clean();
try {
await yarn('global remove polyman');
} catch (e) {}
await clean();
await yarn(`global add file:${tarballPath}`);
await clean();
})();
async function clean() {
await cleanYarnLock(yarnGlobalDir, repoName);
await deleteFromYarnCache('polyman');
}