Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The big clean up #32

Merged
merged 8 commits into from
Feb 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
40 changes: 32 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ Daemon is ready
$ npm i registry-mirror -g
```

## Run registry-mirror
# Usage

Wait for the `Updated directory listing` log.

```bash
$ registry-mirror daemon
IPFS mode ON
registry-mirror [info] using output directory /npm-registry/
registry-mirror [info] listening on 127.0.0.1:50321
registry-mirror [info] Cloning NPM OFF
Expand Down Expand Up @@ -80,27 +79,52 @@ Usage: registry-mirror COMMAND [OPTIONS]

Available commands:

daemon Mirror npm registry
daemon Mirror npm registry
ls Check modules available in the mirror
npm publish Publish an IPNS record with your current npm list
npm update Update your npm list of modules from IPNS
```

## Commands

### daemon

> starts the registry-mirror daemon

`$ registry-mirror daemon`

Options:
- `--folder` - Name of the directory where the registry gets downloaded to
- `--blob-store` - Custom blob-store support (must follow [abstract-blob-store]() interface)
- `--clone` - Download the entire npm (Otherwise it just tries to read)
- `--ipfs=false` - To not use local IPFS Node (must support the files/mfs API, available from version 0.4.0 onwards)
- `--port` Listen on the specified port
- `--host` Listen on the specified port
- `--port=<port>` Listen on the specified port
- `--host=<host>` Listen on the specified port

### ls

> lists all the modules available on the IPFS accessible registry and their respective hashes

`$ registry-mirror ls`

### npm update

> update your local registry cache

`$ registry npm update`

### npm publish

> publish the version of the cache you have from npm

`$ registry npm publish`

## Important

If you are on Mac OS X, make sure to increase the limit of files open (with `ulimit -Sn 4096`), otherwise the ipfs daemon will be sad and throw 502 replies.

# Development

In order to run the tests, you have to have an IPFS 0.4.0 available for them, to do so:
`cp $GOPATH/bin/ipfs node_modules/go-ipfs/bin/ipfs`

# Acknowledgements

This module takes a lot of inspiration from [reginabox](https://www.npmjs.com/package/reginabox). Big thank you to everyone that contributed with code or to the [discussion](https://github.com/ipfs/notes/issues/2) to make this happen.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"registry-mirror": "src/cli/bin.js"
},
"scripts": {
"test": "mocha tests/test-*.js",
"test": "mocha tests/test-*/index.js",
"lint": "standard"
},
"pre-commit": [
Expand Down
44 changes: 25 additions & 19 deletions src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
var Command = require('ronin').Command
var mirror = require('./../../')
var path = require('path')
var rm = require('./../../index.js')
var async = require('async')
var config = require('./../../config.js')

module.exports = Command.extend({
desc: 'Mirror npm registry',

options: {
folder: {
type: 'string',
default: path.join(process.cwd(), 'registry')
},
'blob-store': {
type: 'string'
},
clone: {
type: 'boolean',
default: false
Expand All @@ -29,16 +23,28 @@ module.exports = Command.extend({
}
},

run: function (folder, blobStore, clone, port, host, logRoot) {
blobStore = path.resolve(__dirname, '../../ibs.js')

mirror({
outputDir: '/npm-registry/',
blobStore: blobStore,
clone: clone,
port: port,
host: host,
logRootPath: logRoot
run: function (clone, port, host, logRoot) {
async.series([
rm.registryCache.connect,
rm.registryCache.cacheRegistry,
(callback) => {
if (clone) {
rm.clone()
}
callback()
},
(callback) => {
if (port) { config.mirror.port = port }
if (host) { config.mirror.host = host }
rm.mirror(callback)
},
(callback) => {
// TODO logRoot
callback()
}
], (err, results) => {
if (err) { return console.log(err) }
console.log('Updated registry cache to:', results[1])
})
}
})
41 changes: 17 additions & 24 deletions src/cli/commands/ls.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var Command = require('ronin').Command
var fetchIPNS = require('../../fetch-ipns')
var ipfsAPI = require('ipfs-api')
var rm = require('./../../index.js')
var async = require('async')
var debug = require('debug')
var log = debug('registry-mirror')
log.err = debug('registry-mirror:error')
Expand All @@ -16,29 +16,22 @@ module.exports = Command.extend({
}
},

run: function (update, name) {
run: function (update) {
const series = []
if (update) {
fetchIPNS({ blobStore: true }, function (err) {
if (err) {
log.err('Failed to update /npm-registry mDAG node', err)
}
ls()
})
} else {
ls()
series.push(rm.registryCache.connect)
series.push(rm.registryCache.cacheRegistry)
}
}
})
series.push(rm.ls)

function ls () {
var apiCtl = ipfsAPI('/ip4/127.0.0.1/tcp/5001')
apiCtl.files.ls('/npm-registry', function (err, res) {
if (err) {
return log.err(err)
}
res.Entries.forEach(function (module) {
console.log(module.Name, '\t', module.Hash)
})
})
}
async.series(series, (err, results) => {
if (err) { return console.log(err) }

results[0].Entries.forEach((module) => {
console.log(module.Name, '\t', module.Hash)
})

console.log('Updated registry cache to:', results[1])
})
}
})
28 changes: 2 additions & 26 deletions src/cli/commands/npm/publish.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var Command = require('ronin').Command
var ipfsAPI = require('ipfs-api')
var rm = require('../../../index.js')
var debug = require('debug')
var log = debug('registry-mirror')
log.err = debug('registry-mirror:error')
Expand All @@ -10,30 +10,6 @@ module.exports = Command.extend({
options: {},

run: function (name) {
var ctl = ipfsAPI('/ip4/127.0.0.1/tcp/5001')

ctl.files.stat('/npm-registry', function (err, res) {
if (err) {
return log.err('stat', err)
}
ctl.block.get(res.Hash, function (err, stream) {
if (err) {
return log.err('block get', err)
}
ctl.add(stream, function (err, res) {
if (err) {
return log.err('add', err)
}
ctl.name.publish('/ipfs/' + res[0].Hash, function (err, res) {
if (err) {
return log.err('name publish', err)
}
log('Published:')
log('IPNS: ', '/ipns/' + res.Name)
log('IPFS: ', res.Value)
})
})
})
})
rm.registryCache.publish()
}
})
24 changes: 9 additions & 15 deletions src/cli/commands/npm/update.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var Command = require('ronin').Command
var fetchIPNS = require('../../../fetch-ipns')
var ipfsAPI = require('ipfs-api')
var rm = require('../../../index.js')
var async = require('async')
var debug = require('debug')
var log = debug('registry-mirror')
log.err = debug('registry-mirror:error')
Expand All @@ -15,20 +15,14 @@ module.exports = Command.extend({
},

run: function (ipns, name) {
if (ipns) {
var ctl = ipfsAPI('/ip4/127.0.0.1/tcp/5001')
fetchIPNS.copyNpmRegistry(ctl, ipns, result)
} else {
fetchIPNS({
blobStore: true // so that it knows it has to copy
}, result)
}
function result (err, res) {
async.series([
rm.registryCache.connect,
rm.registryCache.cacheRegistry
], (err, results) => {
if (err) {
console.log(err)
return log.err('Failed: ', err)
return console.log(err)
}
console.log('updated local registry list copy to:', res)
}
console.log('Updated registry cache to:', results[1])
})
}
})
9 changes: 4 additions & 5 deletions src/clone-npm.js → src/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ const debug = require('debug')
const log = debug('registry-mirror')
log.err = debug('registry-mirror:error')

module.exports = (config) => {
module.exports = () => {
const opts = [
'-o', config.outputDir,
'-d', 'localhost'
'-o', '/npm-registry/',
'-d', 'localhost',
'--blobstore=' + path.resolve(__dirname, 'ibs.js')
]

if (config.blobStore) { opts.push('--blobstore=' + config.blobStore) }

const rspath = path.resolve(require.resolve('registry-static'), '../../bin/registry-static')
const child = spawn(rspath, opts, { stdio: 'inherit' })

Expand Down
18 changes: 18 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var ipfsAPI = require('ipfs-api')

module.exports = {
apiCtl: ipfsAPI('/ip4/127.0.0.1/tcp/5001'),
nodes: {
biham: '/ip4/188.40.114.11/tcp/4001/ipfs/QmZY7MtK8ZbG1suwrxc7xEYZ2hQLf1dAWPRHhjxC8rjq8E'
},
registryHash: '/ipns/QmZY7MtK8ZbG1suwrxc7xEYZ2hQLf1dAWPRHhjxC8rjq8E',
blobStore: {
baseDir: '/npm-registry',
port: 5001,
host: '127.0.0.1'
},
mirror: {
port: '9876',
host: '127.0.0.1'
}
}
56 changes: 0 additions & 56 deletions src/fetch-ipns.js

This file was deleted.

Loading