git ssb

3+

cel / ssb-npm-registry



Commit e676e96236abb944e30a518e7e52778a2aadc397

bootstrap script: make npm implicit

Allow specifying a different command with --exec option.

This makes usage of bootstrap/bin.js more similar to that of the ssb-npm
command.
cel committed on 8/30/2018, 3:21:34 AM
Parent: e3dc59bd63e1aee4cb776449e47d41f18b72b205

Files changed

bootstrap/bin.jschanged
bootstrap/usage.txtchanged
index.jschanged
bootstrap/bin.jsView
@@ -48,8 +48,9 @@
4848 function main(args) {
4949 var viewerUrl = null
5050 var wsUrl = null
5151
52 + var cmd
5253 var cmdArgs = []
5354 while (args.length) {
5455 var arg = args.shift()
5556 switch (arg) {
@@ -61,8 +62,9 @@
6162 case '--blobs-url': blobsUrl = shift(args); break
6263 case '--ws-url': wsUrl = shift(args); break
6364 case '--viewer-url': viewerUrl = shift(args); break
6465 case '--branch': branches.push(shift(args)); break
66 + case '--exec': cmd = shift(args); break
6567 case '--': cmdArgs.push.apply(cmdArgs, args.splice(0)); break
6668 default: cmdArgs.push(arg); break
6769 }
6870 }
@@ -88,11 +90,10 @@
8890 blobsUrl = viewerUrl + '/%s'
8991 msgsUrl = viewerUrl + '/%s.json'
9092 }
9193
92- if (!port && !cmdArgs.length) {
93- port = 8989
94- }
94 + var doExec = cmdArgs.length > 0 || cmd != null
95 + if (!doExec) port = 8990
9596
9697 server = http.createServer(serve)
9798 server.listen(port, host, function () {
9899 port = server.address().port
@@ -111,20 +112,23 @@
111112 host: host,
112113 npm: ssbNpmConfig
113114 })
114115
115- if (cmdArgs.length) {
116- var cmd = cmdArgs.shift()
117-
116 + if (doExec) {
118117 var registryUrl = 'http://' + (host || 'localhost') + ':' + port
119- + '/npm/' + branches.map(encodeURIComponent).join(',') + '/'
118 + + '/npm/' + branches.map(encodeURIComponent).join(',')
120119 var env = {}
121120 for (var k in process.env) env[k] = process.env[k]
122121 env.npm_config_registry = registryUrl
122 + if (!cmd) cmd = 'npm'
123123 if (cmd === 'npm') {
124124 cmdArgs.unshift('--no-update-notifier')
125125 cmdArgs.unshift('--fetch-retries=0')
126- cmdArgs.unshift('--download=' + registryUrl + '-/prebuild/{name}-v{version}-{runtime}-v{abi}-{platform}{libc}-{arch}.tar.gz')
126 + cmdArgs.unshift('--download={registry}/-/prebuild/{name}-v{version}-{runtime}-v{abi}-{platform}{libc}-{arch}.tar.gz')
127 + cmdArgs.unshift('--' + registryUrl.replace(/^https?:/, '') + ':_authToken=1')
128 + cmdArgs.unshift('--registry={registry}')
129 + } else if (cmd === 'yarn') {
130 + cmdArgs.unshift('--registry={registry}')
127131 }
128132 cmdArgs.forEach(function (arg, i) {
129133 cmdArgs[i] = arg.replace(/\{registry\}/g, registryUrl)
130134 })
bootstrap/usage.txtView
@@ -2,5 +2,6 @@
22 [--port <port>] [--host <host>]
33 [--msgs-url <url>] [--blobs-url <url>]
44 [--ws-url <url>] [--viewer-url <url>]
55 [--branch <id>]...
6- [--] [<cmd> <args...>]
6 + [--exec <cmd>]
7 + [--] [<args...>]
index.jsView
@@ -594,9 +594,9 @@
594594 var pkgMsgs = pkgsInfo.map(function (info) { return info.msgId })
595595 var globalPkgs = pkgsInfo.map(function (info) {
596596 return info.name + '@' + info.version
597597 }).join(' ')
598- var npmCmd = 'npm install -g ' + globalPkgs
598 + var npmCmd = 'install -g ' + globalPkgs
599599 var pkgTmpText = '/tmp/' + ssbNpmRegistryName + '.tar.gz'
600600 var tarballLink = self.wsLink + '/blobs/get/' + ssbNpmRegistryBlobId
601601
602602 var script =

Built with git-ssb-web