UNPKG

1.42 kBJavaScriptView Raw
1import Promise from "bluebird";
2import { loadJson } from "./util";
3
4
5/**
6 * Retrieves the local [package.json] file.
7 * @param id: The ID of the remote package.
8 * @param localFolder: The path to where the app it stored on the local disk.
9 * @return {Promise}
10 */
11export 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 * Retrieves the remote [package.json] file.
23 * @param id: The ID of the remote package.
24 * @param repo: The repository to pull from.
25 * @param subFolder: The sub-folder into the repo (if there is one).
26 * @param branch: The branch to query.
27 * @return {Promise}
28 */
29export 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};