-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from hayes/fix-config-order
Fix config order
- Loading branch information
Showing
6 changed files
with
86 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,50 @@ | ||
#!/usr/bin/env node | ||
|
||
var nopt = require('nopt') | ||
, unpm = require('../index') | ||
var load_config = require('../lib/config') | ||
, backend = require('unpm-fs-backend') | ||
, path = require('path') | ||
, nopt = require('nopt') | ||
, unpm = require('../') | ||
|
||
var noptions = { | ||
'port': Number | ||
, 'verbose': Boolean | ||
, 'log': Boolean | ||
, 'logdir': String | ||
, 'datadir': String | ||
} | ||
|
||
var shorts = { | ||
'p': ['--port'] | ||
, 'v': ['--verbose'] | ||
, 'l': ['--log'] | ||
, 'L': ['--logdir'] | ||
, 'd': ['--datadir'] | ||
} | ||
|
||
var options = nopt(noptions, shorts) | ||
var config = nopt(noptions, shorts) | ||
|
||
unpm(options) | ||
var CWD = process.cwd() | ||
|
||
var unpm_service | ||
, tarballs_dir | ||
, user_dir | ||
, meta_dir | ||
, data_dir | ||
|
||
config = load_config(config || {}) | ||
|
||
data_dir = config.datadir || path.join(CWD, 'data') | ||
|
||
if(!config.backend) { | ||
tarballs_dir = path.join(data_dir, 'tarballs') | ||
user_dir = path.join(data_dir, 'users') | ||
meta_dir = path.join(data_dir, 'meta') | ||
|
||
config.backend = backend(meta_dir, user_dir, tarballs_dir) | ||
} | ||
|
||
unpm_service = unpm(config) | ||
unpm_service.server.listen(unpm_service.config.port) | ||
|
||
unpm_service.log.info('Started unpm on port %s', unpm_service.config.port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,59 @@ | ||
var backend = require('unpm-fs-backend') | ||
, unpm = require('./lib/index') | ||
, path = require('path') | ||
var SessionStore = require('./lib/models/SessionStore') | ||
, packages = require('./lib/controllers/packages') | ||
, auth = require('./lib/controllers/auth') | ||
, handler = require('./lib/handler') | ||
, logging = require('./lib/logging') | ||
, ns = require('./lib/context').ns | ||
, Router = require('unpm-router') | ||
, http = require('http') | ||
|
||
module.exports = function(config) { | ||
var data_dir = path.join(process.cwd(), 'data') | ||
, unpm_service | ||
module.exports = setup | ||
|
||
var tarballs_dir = path.join(data_dir, 'tarballs') | ||
, user_dir = path.join(data_dir, 'users') | ||
, meta_dir = path.join(data_dir, 'meta') | ||
function setup(config) { | ||
return ns.run(function(context) { | ||
unpm.call(context, ns, config) | ||
}) | ||
} | ||
|
||
function unpm(ns, config) { | ||
var router = Router(config.base_pathname) | ||
|
||
handler = ns.bind(handler) | ||
|
||
config.backend = backend(meta_dir, user_dir, tarballs_dir) | ||
this.sessions = config.sessions || SessionStore() | ||
this.server = http.createServer(handler) | ||
this.log = logging(config) | ||
this.port = config.port || 8123 | ||
this.backend = config.backend | ||
this.handler = handler | ||
this.router = router | ||
this.config = config | ||
|
||
unpm_service = unpm(config) | ||
unpm_service.server.listen(unpm_service.port) | ||
// auth | ||
router.add('GET', routes.get_user, auth.user) | ||
router.add('PUT', routes.register, auth.register) | ||
router.add('PUT', routes.update_user, auth.update) | ||
router.add('POST', routes.session, auth.sessions.create) | ||
|
||
// packages | ||
router.add('PUT', routes.publish, packages.publish) | ||
router.add('GET', routes.get_tarball, packages.get_tarball) | ||
router.add('GET', routes.get_package, packages.get_package) | ||
|
||
// clone from public npm | ||
router.add('POST', routes.clone, packages.clone) | ||
router.add('POST', routes.get_deps, packages.get_deps) | ||
} | ||
|
||
unpm_service.log.info('Started unpm on port %s', unpm_service.port) | ||
var routes = { | ||
index: '/' | ||
, get_package: '/:name/:version?' | ||
, get_user: '/-/user/org.couchdb.user:*' | ||
, get_tarball: '/:name/-/*-*.tgz' | ||
, publish: '/:name' | ||
, clone: '/clone/:name/:version?' | ||
, get_deps: '/get_deps/:name/:version?' | ||
, session: '/_session' | ||
, register: '/-/user/org.couchdb.user:*' | ||
, update_user: '/-/user/org.couchdb.user:*/*' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters