Permalink
Browse files

added install and uninstall targets to makefile, also meant renaming …

…utils to util due to some module namespacing issue
  • Loading branch information...
1 parent 30f8b07 commit 43ad9bb997d4c932531fde1b436088f51ee9fd90 @caolan committed Sep 29, 2010
View
2 .gitignore
@@ -3,3 +3,5 @@ test/fixtures/testpackage_put/
test/fixtures/cp_file2
test/fixtures/cpm_test_db_clone/
test/fixtures/cpm_test_repository_clone/
+dist
+stamp-build
View
37 Makefile
@@ -1,8 +1,43 @@
-all:
+PACKAGE = cpm
+NODEJS = $(if $(shell test -f /usr/bin/nodejs && echo "true"),nodejs,node)
+
+PREFIX ?= /usr/local
+BINDIR ?= $(PREFIX)/bin
+DATADIR ?= $(PREFIX)/share
+LIBDIR ?= $(PREFIX)/lib
+NODEJSLIBDIR ?= $(LIBDIR)/$(NODEJS)
+
+BUILDDIR = dist
+
+$(shell if [ ! -d $(BUILDDIR) ]; then mkdir $(BUILDDIR); fi)
+
+all: build
git submodule init
git submodule update
+build: stamp-build
+
+stamp-build: $(wildcard deps/* lib/*)
+ touch $@;
+ mkdir -p $(BUILDDIR)/cpm
+ cp -R deps lib/* $(BUILDDIR)/cpm
+ find $(BUILDDIR)/cpm/ -type f | xargs sed -i 's/\.\.\/deps/.\/deps/'
+ printf '#!/bin/sh\n$(NODEJS) $(NODEJSLIBDIR)/$(PACKAGE)/cli.js $$@' > $(BUILDDIR)/cpm.sh
+ printf "module.exports = require('$(PACKAGE)/cpm')" > $(BUILDDIR)/cpm.js
+
test:
node ./deps/nodeunit/lib/cli.js test
+install: build
+ install --directory $(NODEJSLIBDIR)
+ cp -a $(BUILDDIR)/cpm $(NODEJSLIBDIR)
+ install --mode=0644 $(BUILDDIR)/cpm.js $(NODEJSLIBDIR)
+ install --mode=0755 $(BUILDDIR)/cpm.sh $(BINDIR)/cpm
+
+uninstall:
+ rm -rf $(NODEJSLIBDIR)/cpm $(NODEJSLIBDIR)/cpm.js $(BINDIR)/cpm
+
+clean:
+ rm -rf $(BUILDDIR) stamp-build
+
.PHONY: all test
View
16 lib/commands/help.js
@@ -9,7 +9,7 @@
*/
var logger = require('../logger'),
- utils = require('../../lib/utils');
+ util = require('../util');
/**
* Output for the help command
@@ -18,31 +18,31 @@ var logger = require('../logger'),
module.exports = function (args, options) {
var col_width = 35;
logger.info(
- utils.padRight('help', col_width),
+ util.padRight('help', col_width),
'Display this help message'
);
logger.info(
- utils.padRight('push url [package]', col_width),
+ util.padRight('push url [package]', col_width),
'Upload a package to a CouchDB database'
);
logger.info(
- utils.padRight('publish package [repository]', col_width),
+ util.padRight('publish package [repository]', col_width),
'Publish a package to a repository'
);
logger.info(
- utils.padRight('unpublish package [repository]', col_width),
+ util.padRight('unpublish package [repository]', col_width),
'Unpublish a package from a repository'
);
logger.info(
- utils.padRight('list [repository]', col_width),
+ util.padRight('list [repository]', col_width),
'Lists the packages available in a repository'
);
logger.info(
- utils.padRight('info package [repository]', col_width),
+ util.padRight('info package [repository]', col_width),
'Show information on a package'
);
logger.info(
- utils.padRight('clone url path', col_width),
+ util.padRight('clone url path', col_width),
'Clone a package from a CouchDB database'
);
logger.end();
View
2 lib/commands/info.js
@@ -11,7 +11,7 @@
var logger = require('../logger'),
transports = require('../transports'),
settings = require('../settings'),
- utils = require('../../lib/utils'),
+ util = require('../util'),
help = require('./help'),
url = require('url');
View
4 lib/commands/list.js
@@ -11,7 +11,7 @@
var logger = require('../logger'),
transports = require('../transports'),
settings = require('../settings'),
- utils = require('../../lib/utils'),
+ util = require('../util'),
help = require('./help'),
url = require('url');
@@ -29,7 +29,7 @@ module.exports = function (args, options) {
if (err) return logger.error(err);
var names = Object.keys(packages);
names.forEach(function (n) {
- console.log(utils.padRight(n,30) + packages[n].join(', '));
+ console.log(util.padRight(n,30) + packages[n].join(', '));
});
logger.end(
names.length + ' result' +
View
1 lib/commands/unpublish.js
@@ -9,7 +9,6 @@
*/
var logger = require('../logger'),
- utils = require('../../lib/utils'),
transports = require('../transports'),
repository = transports.repository,
settings = require('../settings'),
View
4 lib/settings.js
@@ -11,7 +11,7 @@
var fs = require('fs'),
path = require('path'),
async = require('../deps/async'),
- utils = require('./utils'),
+ util = require('./util'),
_ = require('../deps/underscore/underscore')._;
@@ -39,7 +39,7 @@ exports.loadSettings = function (project_path, callback) {
async.reduce([home_file, project_file], settings, function (s, p, cb) {
path.exists(p, function (exists) {
if (!exists) return cb(null, s);
- utils.readJSON(p, function (err, settings) {
+ util.readJSON(p, function (err, settings) {
cb(err, _.extend(s, settings));
});
});
View
36 lib/transports/filesystem.js
@@ -8,7 +8,7 @@
* Module dependencies
*/
-var utils = require('../../lib/utils'),
+var util = require('../util'),
async = require('../../deps/async'),
modules = require('../modules'),
couchdb = require('../couchdb'),
@@ -33,9 +33,9 @@ var utils = require('../../lib/utils'),
exports.getPackageFull = function (settings, d, callback) {
var metadata = path.join(d, 'package.json');
// remove trailing slash and make dir absolute
- d = utils.abspath(d.replace(/\/$/, ''));
+ d = util.abspath(d.replace(/\/$/, ''));
- utils.readJSON(metadata, function(err, pkg){
+ util.readJSON(metadata, function(err, pkg){
if(err) return callback(err);
// ensure package.json includes the correct information
@@ -104,8 +104,8 @@ exports.getPackage = exports.getPackageFull;
exports.loadProperties = function (settings, dir, p, _design, callback) {
exports.loadFiles(dir, p, _design, {
parser: function (content, f) {
- _design.cpm.properties_files[utils.relpath(f, dir)] = content;
- return utils.stringifyFunctions( utils.evalSandboxed(content, f) );
+ _design.cpm.properties_files[util.relpath(f, dir)] = content;
+ return util.stringifyFunctions( util.evalSandboxed(content, f) );
},
filter: function (filename) {
return /\.js$/.exec(filename);
@@ -186,7 +186,7 @@ exports.loadAttachments = function (settings, dir, p, _design, callback) {
return new RegExp(pattern);
});
- utils.descendants(fullpath, function (err, files) {
+ util.descendants(fullpath, function (err, files) {
if(err) return callback(err);
// if the path was a filename not a directory, force into array
if(!(files instanceof Array)) files = [files];
@@ -195,7 +195,7 @@ exports.loadAttachments = function (settings, dir, p, _design, callback) {
return re.test(f);
});
if (!ignore) {
- var relpath = utils.relpath(f, dir);
+ var relpath = util.relpath(f, dir);
_design._attachments[relpath] = f;
_design.cpm.files.push(relpath);
}
@@ -231,7 +231,7 @@ exports.loadFiles = function (dir, p, _design, options, callback) {
return x;
};
- utils.descendants(fullpath, function (err, files) {
+ util.descendants(fullpath, function (err, files) {
if(err) return callback(err);
// if a directory with no files, return with the design doc unmodified
@@ -245,9 +245,9 @@ exports.loadFiles = function (dir, p, _design, options, callback) {
fs.readFile(f, function (err, content) {
if(err) return callback(err);
- var relpath = utils.relpath(f, dir);
+ var relpath = util.relpath(f, dir);
var val = options.parser(content.toString(), f);
- utils.setPropertyPath(_design, relpath, val);
+ util.setPropertyPath(_design, relpath, val);
_design.cpm.files.push(relpath);
callback();
@@ -326,7 +326,7 @@ exports.redirect = function (app, _design, module, props) {
// functions should be redirected
var path = props.join('/');
var fn = exports.redirectFn(module, props);
- utils.setPropertyPath(_design, path, fn);
+ util.setPropertyPath(_design, path, fn);
break;
default:
throw new Error('Cannot redirect type: ' + typeof x);
@@ -364,7 +364,7 @@ exports.redirectFn = function (module, props) {
*/
exports.getMetadata = function (settings, loc, callback) {
- utils.readJSON(path.join(loc, 'package.json'), callback);
+ util.readJSON(path.join(loc, 'package.json'), callback);
};
/**
@@ -451,7 +451,7 @@ function propertyToFile(dir, pkg, f, callback) {
function writeAttachment(pkg, f, output, callback) {
// ensure the parent directories of the output filename exist
- utils.ensureDir(path.dirname(output), function (err) {
+ util.ensureDir(path.dirname(output), function (err) {
if (err) return callback(err);
var loc = pkg._attachments[f];
@@ -464,7 +464,7 @@ function writeAttachment(pkg, f, output, callback) {
break;
case 'filesystem':
// cp files
- utils.cp(loc, output, callback);
+ util.cp(loc, output, callback);
break;
default:
callback(
@@ -487,11 +487,11 @@ function writeAttachment(pkg, f, output, callback) {
function writeModule(pkg, p, output, callback) {
// get module source from package
- try { var val = utils.getPropertyPath(pkg, p.replace(/\.js$/, '')); }
+ try { var val = util.getPropertyPath(pkg, p.replace(/\.js$/, '')); }
catch (e) { return callback(e); }
// ensure the parent directories of the output filename exist
- utils.ensureDir(path.dirname(output), function (err) {
+ util.ensureDir(path.dirname(output), function (err) {
if (err) return callback(err);
// write the module source to the output file
@@ -512,7 +512,7 @@ function writeModule(pkg, p, output, callback) {
function writePropertiesFile(pkg, p, output, callback) {
// ensure the parent directories of the output filename exist
- utils.ensureDir(path.dirname(output), function (err) {
+ util.ensureDir(path.dirname(output), function (err) {
if (err) return callback(err);
// write the module source to the output file
@@ -538,7 +538,7 @@ function writeTemplate(pkg, p, output, callback) {
catch (e) { return callback(e); }
// ensure the parent directories of the output filename exist
- utils.ensureDir(path.dirname(output), function (err) {
+ util.ensureDir(path.dirname(output), function (err) {
if (err) return callback(err);
// write the module source to the output file
View
0 lib/utils.js → lib/util.js
File renamed without changes.
View
30 test/test-settings.js
@@ -1,5 +1,5 @@
var settings = require('../lib/settings'),
- utils = require('../lib/utils'),
+ util = require('../lib/util'),
path = require('path');
@@ -16,13 +16,13 @@ exports['loadSettings with local .cpmrc'] = function (test) {
});
};
- var _readJSON = utils.readJSON;
- utils.readJSON = function (p, callback) {
+ var _readJSON = util.readJSON;
+ util.readJSON = function (p, callback) {
test.equals(p, '/home/user/.cpmrc');
process.nextTick(function () {
callback(null, {a:1,b:2});
});
- utils.readJSON = function (p, callback) {
+ util.readJSON = function (p, callback) {
test.equals(p, 'projectdir/.cpmrc');
process.nextTick(function () {
callback(null, {b:3,c:4});
@@ -45,7 +45,7 @@ exports['loadSettings with local .cpmrc'] = function (test) {
c:4
});
process.env['HOME'] = _home;
- utils.readJSON = _readJSON;
+ util.readJSON = _readJSON;
settings.validate = _validate;
path.exists = _exists;
test.done();
@@ -68,13 +68,13 @@ exports['loadSettings without local .cpmrc'] = function (test) {
});
};
- var _readJSON = utils.readJSON;
- utils.readJSON = function (p, callback) {
+ var _readJSON = util.readJSON;
+ util.readJSON = function (p, callback) {
test.equals(p, '/home/user/.cpmrc');
process.nextTick(function () {
callback(null, {a:1,b:2});
});
- utils.readJSON = function (p, callback) {
+ util.readJSON = function (p, callback) {
test.ok(false, 'should not be called for local .cpmrc');
process.nextTick(function () {
callback(null, {b:3,c:4});
@@ -96,7 +96,7 @@ exports['loadSettings without local .cpmrc'] = function (test) {
b:2
});
process.env['HOME'] = _home;
- utils.readJSON = _readJSON;
+ util.readJSON = _readJSON;
settings.validate = _validate;
path.exists = _exists;
test.done();
@@ -116,8 +116,8 @@ exports['loadSettings return errors from readJSON'] = function (test) {
});
};
- var _readJSON = utils.readJSON;
- utils.readJSON = function (p, callback) {
+ var _readJSON = util.readJSON;
+ util.readJSON = function (p, callback) {
test.equals(p, '/home/user/.cpmrc');
process.nextTick(function () {
callback('error', null);
@@ -132,7 +132,7 @@ exports['loadSettings return errors from readJSON'] = function (test) {
settings.loadSettings('projectdir', function (err, s) {
test.equals(err, 'error');
process.env['HOME'] = _home;
- utils.readJSON = _readJSON;
+ util.readJSON = _readJSON;
settings.validate = _validate;
path.exists = _exists;
test.done();
@@ -152,8 +152,8 @@ exports['loadSettings return errors from validate'] = function (test) {
});
};
- var _readJSON = utils.readJSON;
- utils.readJSON = function (p, callback) {
+ var _readJSON = util.readJSON;
+ util.readJSON = function (p, callback) {
callback();
};
@@ -165,7 +165,7 @@ exports['loadSettings return errors from validate'] = function (test) {
settings.loadSettings('projectdir', function (err, s) {
test.equals(err.message, 'validation error');
process.env['HOME'] = _home;
- utils.readJSON = _readJSON;
+ util.readJSON = _readJSON;
settings.validate = _validate;
path.exists = _exists;
test.done();
View
64 test/test-utils.js
@@ -1,22 +1,22 @@
-var utils = require('../lib/utils'),
+var util = require('../lib/util'),
path = require('path'),
fs = require('fs'),
child_process = require('child_process');
exports['setPropertyPath'] = function (test) {
var obj = {test: 'test'};
- utils.setPropertyPath(obj, 'some/example/path.js', 'val');
+ util.setPropertyPath(obj, 'some/example/path.js', 'val');
test.same(obj, {test: 'test', some: {example: {path: 'val'}}});
- utils.setPropertyPath(obj, 'some/other/path.js', 'val2');
+ util.setPropertyPath(obj, 'some/other/path.js', 'val2');
test.same(obj, {
test: 'test',
some: {
example: {path: 'val'},
other: {path: 'val2'}
}
});
- utils.setPropertyPath(obj, './test', 'test2');
+ util.setPropertyPath(obj, './test', 'test2');
test.same(obj, {
test: 'test2',
some: {
@@ -35,16 +35,16 @@ exports['getPropertyPath'] = function (test) {
other: {path: 'val2'}
}
};
- test.equals(utils.getPropertyPath(obj, 'test'), 'test');
- test.equals(utils.getPropertyPath(obj, 'some/example/path'), 'val');
- test.same(utils.getPropertyPath(obj, 'some/other'), {path: 'val2'});
- test.same(utils.getPropertyPath(obj, ''), obj);
+ test.equals(util.getPropertyPath(obj, 'test'), 'test');
+ test.equals(util.getPropertyPath(obj, 'some/example/path'), 'val');
+ test.same(util.getPropertyPath(obj, 'some/other'), {path: 'val2'});
+ test.same(util.getPropertyPath(obj, ''), obj);
test.done();
};
exports['descendants'] = function (test) {
var dir = __dirname + '/fixtures/descendants_test';
- utils.descendants(dir, function (err, files) {
+ util.descendants(dir, function (err, files) {
if(err) throw err;
test.same(files.sort(), [
dir + '/file1',
@@ -61,7 +61,7 @@ exports['descendants'] = function (test) {
exports['readJSON'] = function (test) {
test.expect(2);
var p = __dirname + '/fixtures/valid_json';
- utils.readJSON(p, function (err, settings) {
+ util.readJSON(p, function (err, settings) {
test.ok(!err);
test.same(settings, {one:1,two:2});
test.done();
@@ -71,7 +71,7 @@ exports['readJSON'] = function (test) {
exports['readJSON'] = function (test) {
test.expect(1);
var p = __dirname + '/fixtures/invalid_json';
- utils.readJSON(p, function (err, settings) {
+ util.readJSON(p, function (err, settings) {
test.ok(err, 'return JSON parsing errors');
test.done();
});
@@ -80,22 +80,22 @@ exports['readJSON'] = function (test) {
exports['relpath'] = function (test) {
var dir = '/some/test/path';
test.equals(
- utils.relpath('/some/test/path/some/file.ext', dir),
+ util.relpath('/some/test/path/some/file.ext', dir),
'some/file.ext'
);
test.equals(
- utils.relpath('/some/test/file.ext', dir),
+ util.relpath('/some/test/file.ext', dir),
'../file.ext'
);
test.equals(
- utils.relpath('some/test/file.ext', dir),
+ util.relpath('some/test/file.ext', dir),
'some/test/file.ext'
);
test.equals(
- utils.relpath('/some/dir/../test/path/file.ext', dir),
+ util.relpath('/some/dir/../test/path/file.ext', dir),
'file.ext'
);
- test.equals(utils.relpath('file.ext', dir), 'file.ext');
+ test.equals(util.relpath('file.ext', dir), 'file.ext');
test.done();
};
@@ -116,7 +116,7 @@ exports['stringifyFunctions'] = function (test) {
g: undefined,
h: ['one', 'two', 3]
}
- var stringified = utils.stringifyFunctions(obj);
+ var stringified = util.stringifyFunctions(obj);
test.same(
stringified,
{
@@ -145,24 +145,24 @@ exports['stringifyFunctions'] = function (test) {
exports['evalSandboxed'] = function (test) {
test.expect(5);
var obj = {test: 'test'};
- try { utils.evalSandboxed("require('sys').puts('fail!')"); }
+ try { util.evalSandboxed("require('sys').puts('fail!')"); }
catch (e) { test.ok(e, 'should throw an error'); }
- try { utils.evalSandboxed("process.env['HOME']")}
+ try { util.evalSandboxed("process.env['HOME']")}
catch (e) { test.ok(e, 'should throw an error'); }
- try { utils.evalSandboxed("obj.test = 'asdf'")}
+ try { util.evalSandboxed("obj.test = 'asdf'")}
catch (e) { test.ok(e, 'should throw an error'); }
test.equals(obj.test, 'test');
- test.same(utils.evalSandboxed("{a: {b: 123}}"), {a: {b: 123}});
+ test.same(util.evalSandboxed("{a: {b: 123}}"), {a: {b: 123}});
test.done();
};
exports['padRight'] = function (test) {
// pad strings below min length
- test.equals(utils.padRight('test', 20), 'test ');
+ test.equals(util.padRight('test', 20), 'test ');
// don't pad strings equals to min length
- test.equals(utils.padRight('1234567890', 10), '1234567890');
+ test.equals(util.padRight('1234567890', 10), '1234567890');
// don't shorten strings above min length
- test.equals(utils.padRight('123456789012345', 10), '123456789012345');
+ test.equals(util.padRight('123456789012345', 10), '123456789012345');
test.done();
};
@@ -174,7 +174,7 @@ exports['ensureDir - new dirs'] = function (test) {
var rm = child_process.spawn('rm', ['-rf', dir]);
rm.on('error', function (err) { throw err; });
rm.on('exit', function (code) {
- utils.ensureDir(p, function (err) {
+ util.ensureDir(p, function (err) {
if (err) throw err;
path.exists(p, function (exists) {
test.ok(exists);
@@ -188,7 +188,7 @@ exports['ensureDir - existing dir'] = function (test) {
test.expect(1);
var p = __dirname + '/fixtures/testpackage'
fs.readdir(p, function (err, files) {
- utils.ensureDir(p, function (err) {
+ util.ensureDir(p, function (err) {
if (err) throw err;
fs.readdir(p, function (err, new_files) {
// test the contents of the directory are unchanged
@@ -202,22 +202,22 @@ exports['ensureDir - existing dir'] = function (test) {
exports['cp'] = function (test) {
var from = __dirname + '/fixtures/cp_file';
var to = __dirname + '/fixtures/cp_file2';
- utils.cp(from, to, function (err) {
+ util.cp(from, to, function (err) {
if (err) throw err;
fs.readFile(to, function (err, content) {
if (err) throw err;
// TODO: sometimes the file is not written when this callback fires!
- // see notes in lib/utils.js
+ // see notes in lib/util.js
test.equals(content.toString(), 'test content\n');
test.done();
});
});
};
exports['abspath'] = function (test) {
- test.equals(utils.abspath('/some/path'), '/some/path');
- test.equals(utils.abspath('some/path'), process.cwd() + '/some/path');
- test.equals(utils.abspath('some/path', '/cwd'), '/cwd/some/path');
- test.equals(utils.abspath('/some/path', '/cwd'), '/some/path');
+ test.equals(util.abspath('/some/path'), '/some/path');
+ test.equals(util.abspath('some/path'), process.cwd() + '/some/path');
+ test.equals(util.abspath('some/path', '/cwd'), '/cwd/some/path');
+ test.equals(util.abspath('/some/path', '/cwd'), '/some/path');
test.done();
};

0 comments on commit 43ad9bb

Please sign in to comment.