Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
Merge pull request #920 from spmjs/source-registry
Browse files Browse the repository at this point in the history
Update source to registry
  • Loading branch information
sorrycc committed Aug 5, 2014
2 parents f0c289d + 42d6f31 commit 5a0dd79
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 46 deletions.
4 changes: 2 additions & 2 deletions bin/spm-doc
Expand Up @@ -9,7 +9,7 @@ require('colorful').colorful();
commander.usage('[options]');

commander
.option('-s, --source <name>', 'source name in spmrc')
.option('--registry <url>', 'registry url of yuan server')
.option('-p, --port <port>', 'local server port, default: 8000')
.option('-f, --force', 'force build without cache')
.option('-v, --verbose', 'show more logging')
Expand All @@ -32,7 +32,7 @@ commander.on('--help', function() {
console.log(' $ spm doc watch');
console.log(' $ spm doc watch --port 8080');
console.log(' $ spm doc publish');
console.log(' $ spm doc publish -s alipay');
console.log(' $ spm doc publish -r http://spm.alipay.im');
});

commander.parse(process.argv);
Expand Down
4 changes: 2 additions & 2 deletions bin/spm-info
Expand Up @@ -7,7 +7,7 @@ var spm = require('..');
commander.usage('[options] name[@version]');

commander
.option('-s, --source <name>', 'source name in spmrc')
.option('--registry <url>', 'registry url of yuan server')
.option('-q, --quiet', 'show less log')
.option('--verbose', 'show more log')
.option('--no-color', 'disable colorful print');
Expand Down Expand Up @@ -37,7 +37,7 @@ if (!commander.args[0]) {
// run install
console.log();
spm.info({
source: commander.source,
registry: commander.registry,
query: commander.args[0],
quiet: commander.quiet,
verbose: commander.verbose
Expand Down
4 changes: 2 additions & 2 deletions bin/spm-install
Expand Up @@ -9,7 +9,7 @@ var spmrc = require('spmrc');
commander.usage('[options] name[@version]');

commander
.option('-s, --source <name>', 'source name in spmrc')
.option('--registry <url>', 'registry url of yuan server')
.option('-I, --input-directory <dir>', 'input directory, default: current working directory')
.option('-d, --destination <dir>', 'output directory, default: sea-modules')
.option('-f, --force', 'force to download a unstable module')
Expand Down Expand Up @@ -45,7 +45,7 @@ if (commander.global) {
// run install
console.log();
spm.install({
source: commander.source,
registry: commander.registry,
base: commander.base,
destination: commander.destination,
force: commander.force,
Expand Down
4 changes: 2 additions & 2 deletions bin/spm-login
Expand Up @@ -6,9 +6,9 @@ var spm = require('..');
commander.usage('[options]');

commander
.option('--registry <url>', 'registry url of yuan server')
.option('-u, --username <username>', 'username of your account')
.option('-a, --authkey <authkey>', 'authkey of your account')
.option('-s, --source <name>', 'source name in spmrc');
.option('-a, --authkey <authkey>', 'authkey of your account');

commander.parse(process.argv);

Expand Down
10 changes: 5 additions & 5 deletions bin/spm-publish
Expand Up @@ -9,11 +9,11 @@ require('colorful').colorful();
commander.usage('[options] name');

commander
.option('--tag <tag>', 'publish module with a tag, default: stable')
.option('--doc <dir>', 'upload docs instead of package')
.option('-s, --source <name>', 'source name in spmrc')
.option('--registry <url>', 'registry url of yuan server')
.option('-f, --force', 'force to publish an exists module')
.option('-q, --quiet', 'show less logs')
.option('--tag <tag>', 'publish module with a tag, default: stable')
.option('--doc <dir>', 'upload docs instead of package')
.option('--verbose', 'show more logs')
.option('--no-tarball', 'do not upload a tarball')
.option('--no-color', 'disable colorful print');
Expand All @@ -26,9 +26,9 @@ commander.on('--help', function() {
console.log();
console.log(' $ ' + 'spm publish'.to.magenta.color);
console.log();
console.log(' publish to a specified source');
console.log(' publish to a specified registry');
console.log();
console.log(' $ ' + 'spm publish'.to.magenta.color + ' -s'.to.cyan.color + ' arale');
console.log(' $ ' + 'spm publish'.to.magenta.color + ' -r'.to.cyan.color + ' http://spm.alipay.im');
console.log();
});

Expand Down
4 changes: 2 additions & 2 deletions bin/spm-search
Expand Up @@ -7,7 +7,7 @@ var spm = require('..');
commander.usage('[options] <query>');

commander
.option('-s, --source <name>', 'source name in spmrc')
.option('--registry <url>', 'registry url of yuan server')
.option('--verbose', 'show more log')
.option('--no-color', 'disable colorful print');

Expand All @@ -33,4 +33,4 @@ if (!commander.args[0]) {

// run install
console.log();
spm.search({source: commander.source, query: commander.args[0]});
spm.search({registry: commander.registry, query: commander.args[0]});
4 changes: 2 additions & 2 deletions bin/spm-unpublish
Expand Up @@ -7,7 +7,7 @@ var spm = require('..');
commander.usage('[options] name[@version]');

commander
.option('-s, --source <name>', 'source name in spmrc')
.option('--registry <url>', 'registry url of yuan server')
.option('--verbose', 'show more log')
.option('--no-color', 'disable colorful print');

Expand Down Expand Up @@ -35,4 +35,4 @@ if (!commander.args[0]) {

// run install
console.log();
spm.unpublish({source: commander.source, query: commander.args[0]});
spm.unpublish({registry: commander.registry, query: commander.args[0]});
5 changes: 1 addition & 4 deletions lib/doc.js
Expand Up @@ -30,14 +30,11 @@ module.exports = function(commander, callback) {
}

if (commander.publish) {
// spm 和 nico 同时用到了 source ,这里只给 spm 用
var source = commander.source || 'default';
commander.source = '';
cleanDoc();
nico.build(commander);
spm.upload({
doc: DOC_PATH,
source: source
registry: commander.registry
});
}

Expand Down
3 changes: 1 addition & 2 deletions lib/install.js
Expand Up @@ -39,9 +39,8 @@ function install(options, callback) {
options = options || {};
config.parallel = options.parallel || defaults.parallel;
config.base = options.base || process.cwd();
config.source = options.source;
config.registry = options.registry;
config.cache = options.cache || defaults.cache;
config.server = options.server;
config.force = options.force;
config.save = options.save;
config.saveDev = options.saveDev;
Expand Down
17 changes: 4 additions & 13 deletions lib/sdk/yuan.js
Expand Up @@ -27,27 +27,18 @@ var userAgent = util.format(
function Yuan(options) {
options = options || {};

var source = options.source || 'default';
this.server = options.registry || spmrc.get('registry') || 'http://spmjs.io';
this.server = this.server.replace(/\/$/, '');
options.proxy = options.proxy || spmrc.get('proxy');

this.server = options.server || spmrc.get('source.' + source + '.url');
this.mirror = options.mirror || spmrc.get('source.' + source + '.mirror');
options.proxy = options.proxy || spmrc.get('source.' + source + '.proxy');

this.server = (this.server || 'http://spmjs.io').replace(/\/$/, '');
this.mirror = (this.mirror || this.server).replace(/\/$/, '');

this.authKey = 'source.' + source + '.auth';
this.authKey = 'auth';
this.options = options;
}

Yuan.prototype.request = function(data, callback) {
callback = callback || function() {};

data.url = util.format('%s/%s', this.server, data.urlpath);
if (data.method.toLowerCase() === 'get' && data.urlpath.indexOf('repository/search') !== 0) {
// mirror is faster
data.url = util.format('%s/%s', this.mirror, data.urlpath);
}
log.debug(data.method.toLowerCase(), data.url);

data.headers = data.headers || {};
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -82,6 +82,7 @@
},
"scripts": {
"preinstall": "node scripts/preinstall.js",
"postinstall": "node scripts/postinstall.js",
"test": "make test"
}
}
13 changes: 13 additions & 0 deletions scripts/postinstall.js
@@ -0,0 +1,13 @@
#!/usr/bin/env node

var spmrc = require('spmrc');

var registry = spmrc.get('source.default.url');
var auth = spmrc.get('source.default.auth');

if (!spmrc.get('registry') && registry && registry !== 'http://spmjs.io') {
spmrc.set('registry', registry);
}
if (!spmrc.get('auth') && auth) {
spmrc.set('auth', auth);
}
4 changes: 2 additions & 2 deletions tests/info.js
Expand Up @@ -25,7 +25,7 @@ describe('spm info', function() {
}).listen(port, function() {
info({
query: 'arale-base@1.0.0',
server: 'http://127.0.0.1:' + port
registry: 'http://127.0.0.1:' + port
});
done();
});
Expand All @@ -38,7 +38,7 @@ describe('spm info', function() {
}).listen(port, function() {
info({
query: 'arale-base',
server: 'http://127.0.0.1:' + port
registry: 'http://127.0.0.1:' + port
});
done();
});
Expand Down
12 changes: 6 additions & 6 deletions tests/install.js
Expand Up @@ -46,7 +46,7 @@ describe('spm install', function() {
destination: dest,
cache: cache,
query: ['example@1.0.0'],
server: 'http://127.0.0.1:' + port
registry: 'http://127.0.0.1:' + port
}, function() {
file.exists(dest + '/example/1.0.0').should.eql(true);
done();
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('spm install', function() {
destination: dest,
cache: cache,
query: ['example@1.0.0'],
server: 'http://127.0.0.1:' + port
registry: 'http://127.0.0.1:' + port
}, function() {
done();
});
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('spm install', function() {
cache: cache,
query: ['example@1.0.0'],
force: true,
server: 'http://127.0.0.1:' + port
registry: 'http://127.0.0.1:' + port
}, function() {
file.rmdir(dest);
done();
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('spm install', function() {
destination: dest,
cache: cache,
query: ['example-no-cache@1.0.0'],
server: 'http://127.0.0.1:' + port
registry: 'http://127.0.0.1:' + port
}, function() {
file.exists(dest + '/example-no-cache/1.0.0').should.eql(true);
file.exists(dest + '/example-no-cache/1.0.0/src/base.js').should.eql(true);
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('spm install', function() {
destination: dest,
cache: cache,
query: ['example2@1.0.0'],
server: 'http://127.0.0.1:' + port
registry: 'http://127.0.0.1:' + port
}, function() {
file.exists(dest + '/example/1.0.0').should.eql(true);
file.exists(dest + '/example2/1.0.0').should.eql(true);
Expand Down Expand Up @@ -211,7 +211,7 @@ describe('spm install', function() {
query: ['example@1.0.0'],
save: true,
saveDev: true,
server: 'http://127.0.0.1:' + port
registry: 'http://127.0.0.1:' + port
}, function() {
var pkg = file.readJSON('package.json');
pkg.spm.dependencies.example.should.eql('1.0.0');
Expand Down
2 changes: 1 addition & 1 deletion tests/publish.js
Expand Up @@ -30,7 +30,7 @@ describe('spm publish', function() {
res.end(JSON.stringify(data));
}).listen(port, function() {
publish.publish({
server: 'http://127.0.0.1:' + port
registry: 'http://127.0.0.1:' + port
}, {
name: 'arale-base',
version: '1.0.0'
Expand Down
2 changes: 1 addition & 1 deletion tests/search.js
Expand Up @@ -30,7 +30,7 @@ describe('spm search', function() {
res.end(JSON.stringify(data));
}).listen(port, function() {
search({
server: 'http://127.0.0.1:' + port,
registry: 'http://127.0.0.1:' + port,
query: 'arale'
}, function() {
done();
Expand Down

0 comments on commit 5a0dd79

Please sign in to comment.