Skip to content

Commit

Permalink
clone and registryCache
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Feb 1, 2016
1 parent 9d2094c commit 557ff3f
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 81 deletions.
32 changes: 14 additions & 18 deletions src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
var Command = require('ronin').Command
var mirror = require('./../../')
var path = require('path')
var regmirror = require('./../../index.js')
var async = require('async')

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 +22,19 @@ module.exports = Command.extend({
}
},

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

mirror({
outputDir: '/npm-registry/',
blobStore: blobStore,
clone: clone,
port: port,
host: host,
logRootPath: logRoot
async.series([
regmirror.registryCache.connect,
regmirror.registryCache.cacheRegistry
], (err, results) => {
if (err) {
return console.log(err)
}
console.log('latest registry ->', results[1])
})
}
})
2 changes: 1 addition & 1 deletion src/cli/commands/ls.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var Command = require('ronin').Command
var fetchIPNS = require('../../fetch-ipns')
var fetchIPNS = require('../../index.js').registryCache
var ipfsAPI = require('ipfs-api')
var debug = require('debug')
var log = debug('registry-mirror')
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/npm/update.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var Command = require('ronin').Command
var fetchIPNS = require('../../../fetch-ipns')
var fetchIPNS = require('../../../index.js').registryCache
var ipfsAPI = require('ipfs-api')
var debug = require('debug')
var log = debug('registry-mirror')
Expand Down
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
5 changes: 5 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var ipfsAPI = require('ipfs-api')

module.exports = {
apiCtl: ipfsAPI('/ip4/127.0.0.1/tcp/5001')
}
56 changes: 0 additions & 56 deletions src/fetch-ipns.js

This file was deleted.

2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
exports.mirror = require('./mirror')
exports.clone = require('./clone')
exports.registryCache = require('./registry-cache')
48 changes: 48 additions & 0 deletions src/registry-cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const debug = require('debug')
const log = debug('registry-mirror')
const async = require('async')
log.error = debug('registry-mirror:error')
const config = require('./config')

exports = module.exports

exports.connect = (callback) => {
// TODO support connection to more than one node
// TODO check which nodes are missing from the list first
const updaterNodes = {
biham: '/ip4/188.40.114.11/tcp/4001/ipfs/QmZY7MtK8ZbG1suwrxc7xEYZ2hQLf1dAWPRHhjxC8rjq8E'
}

config.apiCtl.swarm.connect(updaterNodes.biham, callback)
}

exports.cacheRegistry = (callback) => {
var registry = '/ipns/QmZY7MtK8ZbG1suwrxc7xEYZ2hQLf1dAWPRHhjxC8rjq8E'

async.waterfall([
(cb) => {
config.apiCtl.name.resolve(registry, (err, res) => {

This comment has been minimized.

Copy link
@dignifiedquire

dignifiedquire Feb 2, 2016

Member

config.apiCtl seems like a really hard thing to type and read, why not just call it config.api?

This comment has been minimized.

Copy link
@dignifiedquire

dignifiedquire Feb 2, 2016

Member

Even better as you are using it all over the place just do const api = config.api at the beginning

This comment has been minimized.

Copy link
@daviddias

daviddias Feb 2, 2016

Author Member

apiCtl came because there is the ipfsAPI which creates apiCtl. Added the const api for simplification :)

cb(err, res.Path)
})
},
config.apiCtl.cat,
(stream, cb) => {
config.apiCtl.block.put(stream, (err, res) => {
cb(err, '/ipfs/' + res.Key)
})
},
(ipfsHash, cb) => {
config.apiCtl.files.mv(['/npm-registry', '/npm-registry.bak-' + Date.now().toString()], (err) => {
cb(err, ipfsHash)
})
},
(ipfsHash, cb) => {
config.apiCtl.files.cp([ipfsHash, '/npm-registry'], (err) => {
cb(err, ipfsHash)
})
}
], (err, ipfsHash) => {
callback(err, ipfsHash)
})

This comment has been minimized.

Copy link
@dignifiedquire

dignifiedquire Feb 2, 2016

Member

you can simplify this to , callback)

}

0 comments on commit 557ff3f

Please sign in to comment.