git ssb

0+

kyrias-defunct / git-ssb



forked from cel / git-ssb

Tree: 05400635357441688f9ff0834b3d7058a5fb7aa3

Files: 05400635357441688f9ff0834b3d7058a5fb7aa3 / bin.js

1438 bytesRaw
1#!/bin/sh
2':' //; exec "$(command -v nodejs || command -v node)" "$0" "$@"
3// http://unix.stackexchange.com/questions/65235/universal-node-js-shebang
4// vi: ft=javascript
5
6var path = require('path')
7
8var progname = path.basename(process.argv[1])
9if (progname == 'git-remote-ssb') {
10 require('git-remote-ssb/git-remote-ssb')
11 return
12}
13
14var spawn = require('child_process').spawn
15var ssbGit = require('ssb-git-repo')
16var pull = require('pull-stream')
17
18var args = process.argv.slice(2)
19switch (args[0]) {
20 case 'create':
21 createRepo(args[1] || 'ssb')
22 break
23
24 case 'web':
25 require('git-ssb-web/server')
26 break
27
28 case undefined:
29 case '-h':
30 console.log([
31 'Usage: git ssb [command]',
32 '',
33 'Commands:',
34 ' create Create a git repo on SSB.',
35 ' web Serve a web server for repos.',
36 ].join('\n'))
37 process.exit(0)
38
39 default:
40 console.error([
41 'Usage: git ssb [command]',
42 '',
43 'No such command "' + args[0] + '"'
44 ].join('\n'))
45 process.exit(1)
46}
47
48function getSbot(cb) {
49 require('./lib/client')(cb)
50}
51
52function createRepo(remoteName) {
53 getSbot(function (err, sbot) {
54 if (err) throw err
55 ssbGit.createRepo(sbot, function (err, repo) {
56 if (err) throw err
57 var url = 'ssb://' + repo.id
58 console.log(url)
59 repo.close()
60 sbot.close()
61 spawn('git', ['remote', 'add', remoteName, url], {stdio: 'inherit'})
62 })
63 })
64}
65

Built with git-ssb-web