1 | import Promise from "bluebird";
|
2 | import { loadJson } from "./util";
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export const getLocalPackage = (id, localFolder) => {
|
12 | return new Promise((resolve, reject) => {
|
13 | loadJson(`${ localFolder }/package.json`)
|
14 | .then(file => resolve({ id, exists: file.exists, json: file.json }))
|
15 | .catch(err => reject(err));
|
16 | });
|
17 | };
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | export const getRemotePackage = (id, repo, subFolder, branch) => {
|
30 | return new Promise((resolve, reject) => {
|
31 | repo.get(`${ subFolder }/package.json`, { branch })
|
32 | .then(result => {
|
33 | const file = result.files[0];
|
34 | if (file) {
|
35 | try {
|
36 | const json = JSON.parse(file.toString());
|
37 | resolve({ id, exists: true, json });
|
38 | } catch (err) { reject(err); }
|
39 |
|
40 | } else {
|
41 | resolve({ id, exists: false });
|
42 | }
|
43 | })
|
44 | .catch(err => reject(err));
|
45 | });
|
46 | };
|