Comparing version 0.1.0 to 0.1.1
@@ -48,7 +48,8 @@ #!/usr/bin/env node | ||
.option('-p, --path <path>', 'path to store protos locally') | ||
.action((proto, { sha, path: pth = 'protos' }) => { | ||
.option('-b, --branch <branch>', 'branch of the .proto file in git') | ||
.action((proto, { sha, path: pth = 'protos', branch = 'master' }) => { | ||
logo(); | ||
const protoPath = path.join(process.cwd(), pth); | ||
return (proto | ||
? get(pth, [ proto, sha ]) | ||
? get(pth, [ proto, sha, branch ]) | ||
: init()) | ||
@@ -55,0 +56,0 @@ .then(({ met, unmet }) => { |
@@ -50,3 +50,3 @@ const { parse, join } = require('path'); | ||
const resolver = ([ proto, sha ]) => { | ||
const resolver = ([ proto, sha, branch = 'master' ]) => { | ||
if (attempts[proto]) | ||
@@ -58,3 +58,3 @@ return () => Promise.resolve({}); | ||
? get(proto, sha) | ||
: contents(proto, sha) | ||
: contents(proto, sha, branch) | ||
.then(({ proto, content, encoding, sha }) => | ||
@@ -61,0 +61,0 @@ set(proto, content, encoding, sha, isLatest))) |
@@ -16,5 +16,5 @@ const all = require('./utils/all'); | ||
.map(k => [ k, ...[ dependencies[k] !== 'latest' ? dependencies[k] : undefined ] ]); | ||
return all(...lnks).then(() => get(path, ...deps)); | ||
return all(...lnks).then(() => get(path, 'not needed', ...deps)); | ||
}); | ||
module.exports = init; |
@@ -28,3 +28,4 @@ const { parse } = require('path'); | ||
const createGithubError = (err, proto, sha) => | ||
`${proto} | ||
`${proto}${sha ? ` | ||
- ${chalk.underline('sha')}: ${chalk.italic(sha)}`: ''} | ||
@@ -80,13 +81,15 @@ github responded with: ${err.statusCode} - ${err.message.toLowerCase()} | ||
const getBySHA = (repoPath, sha) => | ||
new Promise((resolve, reject) => | ||
new Promise((resolve, reject) => { | ||
client() | ||
.then(cl => { | ||
cl.repo(repoPath) | ||
.blob(sha, (err, { sha, content, encoding }) => { | ||
.blob(sha, (err, file) => { | ||
if (err) return reject(err); | ||
const { sha, content, encoding } = file; | ||
return resolve({ sha, content, encoding }); | ||
}) | ||
})); | ||
}) | ||
}); | ||
const getByFilePath = (repoPath, filePath) => | ||
const getByFilePath = (repoPath, filePath, branch) => | ||
new Promise((resolve, reject) => | ||
@@ -96,3 +99,3 @@ client() | ||
cl.repo(repoPath) | ||
.contents(filePath, (err, file) => { | ||
.contents(filePath, branch, (err, file) => { | ||
if (err) return reject(err); | ||
@@ -105,3 +108,3 @@ if (Array.isArray(file)) return reject(new Error('supplied proto path is folder')); | ||
const contents = (proto, sha) => { | ||
const contents = (proto, sha, branch) => { | ||
return new Promise((resolve, reject) => { | ||
@@ -113,2 +116,5 @@ const { | ||
} = parseProto(proto); | ||
// console.log('branch'branch); | ||
if (host !== 'github.com') { | ||
@@ -120,3 +126,3 @@ return reject(new UnmetError(createUnknownError(proto), proto)); | ||
? getBySHA(repoPath, sha) | ||
: getByFilePath(repoPath, filePath)) | ||
: getByFilePath(repoPath, filePath, branch)) | ||
.then(({ sha, content, encoding }) => ({ | ||
@@ -123,0 +129,0 @@ sha, content, encoding, proto, file, |
{ | ||
"name": "gggp", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "go go gadget proto - dependency management for .proto files", | ||
@@ -5,0 +5,0 @@ "bin": "./cli/bin.js", |
@@ -18,2 +18,8 @@ | ||
#### installation | ||
``` | ||
npm install -g gggp | ||
``` | ||
#### usage | ||
@@ -20,0 +26,0 @@ |
22723
544
128