summaryrefslogtreecommitdiff
path: root/node_modules/pkginfo
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/pkginfo')
-rw-r--r--node_modules/pkginfo/.npmignore2
-rw-r--r--node_modules/pkginfo/LICENSE19
-rw-r--r--node_modules/pkginfo/README.md80
-rw-r--r--node_modules/pkginfo/examples/all-properties.js19
-rw-r--r--node_modules/pkginfo/examples/array-argument.js20
-rw-r--r--node_modules/pkginfo/examples/multiple-properties.js19
-rw-r--r--node_modules/pkginfo/examples/object-argument.js22
-rw-r--r--node_modules/pkginfo/examples/package.json10
-rw-r--r--node_modules/pkginfo/examples/single-property.js19
-rw-r--r--node_modules/pkginfo/examples/subdir/package.json11
-rw-r--r--node_modules/pkginfo/examples/target-dir.js20
-rw-r--r--node_modules/pkginfo/lib/pkginfo.js133
-rw-r--r--node_modules/pkginfo/package.json58
-rw-r--r--node_modules/pkginfo/test/pkginfo-test.js83
14 files changed, 515 insertions, 0 deletions
diff --git a/node_modules/pkginfo/.npmignore b/node_modules/pkginfo/.npmignore
new file mode 100644
index 0000000..9303c34
--- /dev/null
+++ b/node_modules/pkginfo/.npmignore
@@ -0,0 +1,2 @@
+node_modules/
+npm-debug.log \ No newline at end of file
diff --git a/node_modules/pkginfo/LICENSE b/node_modules/pkginfo/LICENSE
new file mode 100644
index 0000000..ed4a4e7
--- /dev/null
+++ b/node_modules/pkginfo/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2010 Charlie Robbins.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE. \ No newline at end of file
diff --git a/node_modules/pkginfo/README.md b/node_modules/pkginfo/README.md
new file mode 100644
index 0000000..97d7a7f
--- /dev/null
+++ b/node_modules/pkginfo/README.md
@@ -0,0 +1,80 @@
+# node-pkginfo
+
+An easy way to expose properties on a module from a package.json
+
+### Installing pkginfo
+```
+ npm install pkginfo
+```
+
+## Motivation
+How often when writing node.js modules have you written the following line(s) of code?
+
+* Hard code your version string into your code
+
+``` js
+ exports.version = '0.1.0';
+```
+
+* Programmatically expose the version from the package.json
+
+``` js
+ exports.version = require('/path/to/package.json').version;
+```
+
+In other words, how often have you wanted to expose basic information from your package.json onto your module programmatically? **WELL NOW YOU CAN!**
+
+## Usage
+
+Using `pkginfo` is idiot-proof, just require and invoke it.
+
+``` js
+ var pkginfo = require('pkginfo')(module);
+
+ console.dir(module.exports);
+```
+
+By invoking the `pkginfo` module all of the properties in your `package.json` file will be automatically exposed on the callee module (i.e. the parent module of `pkginfo`).
+
+Here's a sample of the output:
+
+```
+ { name: 'simple-app',
+ description: 'A test fixture for pkginfo',
+ version: '0.1.0',
+ author: 'Charlie Robbins <charlie.robbins@gmail.com>',
+ keywords: [ 'test', 'fixture' ],
+ main: './index.js',
+ scripts: { test: 'vows test/*-test.js --spec' },
+ engines: { node: '>= 0.4.0' } }
+```
+
+### Expose specific properties
+If you don't want to expose **all** properties on from your `package.json` on your module then simple pass those properties to the `pkginfo` function:
+
+``` js
+ var pkginfo = require('pkginfo')(module, 'version', 'author');
+
+ console.dir(module.exports);
+```
+
+```
+ { version: '0.1.0',
+ author: 'Charlie Robbins <charlie.robbins@gmail.com>' }
+```
+
+If you're looking for further usage see the [examples][0] included in this repository.
+
+## Run Tests
+Tests are written in [vows][1] and give complete coverage of all APIs.
+
+```
+ npm install
+ npm test
+```
+
+[0]: https://github.com/indexzero/node-pkginfo/tree/master/examples
+[1]: http://vowsjs.org
+
+#### Author: [Charlie Robbins](http://github.com/indexzero)
+#### License: MIT
diff --git a/node_modules/pkginfo/examples/all-properties.js b/node_modules/pkginfo/examples/all-properties.js
new file mode 100644
index 0000000..fd1d831
--- /dev/null
+++ b/node_modules/pkginfo/examples/all-properties.js
@@ -0,0 +1,19 @@
+/*
+ * all-properties.js: Sample of including all properties from a package.json file
+ *
+ * (C) 2011, Charlie Robbins
+ *
+ */
+
+var util = require('util'),
+ pkginfo = require('../lib/pkginfo')(module);
+
+exports.someFunction = function () {
+ console.log('some of your custom logic here');
+};
+
+console.log('Inspecting module:');
+console.dir(module.exports);
+
+console.log('\nAll exports exposed:');
+console.error(Object.keys(module.exports)); \ No newline at end of file
diff --git a/node_modules/pkginfo/examples/array-argument.js b/node_modules/pkginfo/examples/array-argument.js
new file mode 100644
index 0000000..b1b6848
--- /dev/null
+++ b/node_modules/pkginfo/examples/array-argument.js
@@ -0,0 +1,20 @@
+/*
+ * array-argument.js: Sample of including specific properties from a package.json file
+ * using Array argument syntax.
+ *
+ * (C) 2011, Charlie Robbins
+ *
+ */
+
+var util = require('util'),
+ pkginfo = require('../lib/pkginfo')(module, ['version', 'author']);
+
+exports.someFunction = function () {
+ console.log('some of your custom logic here');
+};
+
+console.log('Inspecting module:');
+console.dir(module.exports);
+
+console.log('\nAll exports exposed:');
+console.error(Object.keys(module.exports)); \ No newline at end of file
diff --git a/node_modules/pkginfo/examples/multiple-properties.js b/node_modules/pkginfo/examples/multiple-properties.js
new file mode 100644
index 0000000..b4b5fd6
--- /dev/null
+++ b/node_modules/pkginfo/examples/multiple-properties.js
@@ -0,0 +1,19 @@
+/*
+ * multiple-properties.js: Sample of including multiple properties from a package.json file
+ *
+ * (C) 2011, Charlie Robbins
+ *
+ */
+
+var util = require('util'),
+ pkginfo = require('../lib/pkginfo')(module, 'version', 'author');
+
+exports.someFunction = function () {
+ console.log('some of your custom logic here');
+};
+
+console.log('Inspecting module:');
+console.dir(module.exports);
+
+console.log('\nAll exports exposed:');
+console.error(Object.keys(module.exports)); \ No newline at end of file
diff --git a/node_modules/pkginfo/examples/object-argument.js b/node_modules/pkginfo/examples/object-argument.js
new file mode 100644
index 0000000..28420c8
--- /dev/null
+++ b/node_modules/pkginfo/examples/object-argument.js
@@ -0,0 +1,22 @@
+/*
+ * object-argument.js: Sample of including specific properties from a package.json file
+ * using Object argument syntax.
+ *
+ * (C) 2011, Charlie Robbins
+ *
+ */
+
+var util = require('util'),
+ pkginfo = require('../lib/pkginfo')(module, {
+ include: ['version', 'author']
+ });
+
+exports.someFunction = function () {
+ console.log('some of your custom logic here');
+};
+
+console.log('Inspecting module:');
+console.dir(module.exports);
+
+console.log('\nAll exports exposed:');
+console.error(Object.keys(module.exports)); \ No newline at end of file
diff --git a/node_modules/pkginfo/examples/package.json b/node_modules/pkginfo/examples/package.json
new file mode 100644
index 0000000..1f2f01c
--- /dev/null
+++ b/node_modules/pkginfo/examples/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "simple-app",
+ "description": "A test fixture for pkginfo",
+ "version": "0.1.0",
+ "author": "Charlie Robbins <charlie.robbins@gmail.com>",
+ "keywords": ["test", "fixture"],
+ "main": "./index.js",
+ "scripts": { "test": "vows test/*-test.js --spec" },
+ "engines": { "node": ">= 0.4.0" }
+}
diff --git a/node_modules/pkginfo/examples/single-property.js b/node_modules/pkginfo/examples/single-property.js
new file mode 100644
index 0000000..4f44561
--- /dev/null
+++ b/node_modules/pkginfo/examples/single-property.js
@@ -0,0 +1,19 @@
+/*
+ * single-property.js: Sample of including a single specific properties from a package.json file
+ *
+ * (C) 2011, Charlie Robbins
+ *
+ */
+
+var util = require('util'),
+ pkginfo = require('../lib/pkginfo')(module, 'version');
+
+exports.someFunction = function () {
+ console.log('some of your custom logic here');
+};
+
+console.log('Inspecting module:');
+console.dir(module.exports);
+
+console.log('\nAll exports exposed:');
+console.error(Object.keys(module.exports)); \ No newline at end of file
diff --git a/node_modules/pkginfo/examples/subdir/package.json b/node_modules/pkginfo/examples/subdir/package.json
new file mode 100644
index 0000000..aa85410
--- /dev/null
+++ b/node_modules/pkginfo/examples/subdir/package.json
@@ -0,0 +1,11 @@
+{
+ "name": "simple-app-subdir",
+ "description": "A test fixture for pkginfo",
+ "version": "0.1.0",
+ "author": "Charlie Robbins <charlie.robbins@gmail.com>",
+ "keywords": ["test", "fixture"],
+ "main": "./index.js",
+ "scripts": { "test": "vows test/*-test.js --spec" },
+ "engines": { "node": ">= 0.4.0" },
+ "subdironly": "true"
+}
diff --git a/node_modules/pkginfo/examples/target-dir.js b/node_modules/pkginfo/examples/target-dir.js
new file mode 100644
index 0000000..88770e6
--- /dev/null
+++ b/node_modules/pkginfo/examples/target-dir.js
@@ -0,0 +1,20 @@
+/*
+ * multiple-properties.js: Sample of including multiple properties from a package.json file
+ *
+ * (C) 2011, Charlie Robbins
+ *
+ */
+
+var util = require('util'),
+ path = require('path'),
+ pkginfo = require('../lib/pkginfo')(module, { dir: path.resolve(__dirname, 'subdir' )});
+
+exports.someFunction = function () {
+ console.log('some of your custom logic here');
+};
+
+console.log('Inspecting module:');
+console.dir(module.exports);
+
+console.log('\nAll exports exposed:');
+console.error(Object.keys(module.exports)); \ No newline at end of file
diff --git a/node_modules/pkginfo/lib/pkginfo.js b/node_modules/pkginfo/lib/pkginfo.js
new file mode 100644
index 0000000..47ab248
--- /dev/null
+++ b/node_modules/pkginfo/lib/pkginfo.js
@@ -0,0 +1,133 @@
+/*
+ * pkginfo.js: Top-level include for the pkginfo module
+ *
+ * (C) 2011, Charlie Robbins
+ *
+ */
+
+var path = require('path');
+
+//
+// ### function pkginfo ([options, 'property', 'property' ..])
+// #### @pmodule {Module} Parent module to read from.
+// #### @options {Object|Array|string} **Optional** Options used when exposing properties.
+// #### @arguments {string...} **Optional** Specified properties to expose.
+// Exposes properties from the package.json file for the parent module on
+// it's exports. Valid usage:
+//
+// `require('pkginfo')()`
+//
+// `require('pkginfo')('version', 'author');`
+//
+// `require('pkginfo')(['version', 'author']);`
+//
+// `require('pkginfo')({ include: ['version', 'author'] });`
+//
+var pkginfo = module.exports = function (pmodule, options) {
+ var args = [].slice.call(arguments, 2).filter(function (arg) {
+ return typeof arg === 'string';
+ });
+
+ //
+ // **Parse variable arguments**
+ //
+ if (Array.isArray(options)) {
+ //
+ // If the options passed in is an Array assume that
+ // it is the Array of properties to expose from the
+ // on the package.json file on the parent module.
+ //
+ options = { include: options };
+ }
+ else if (typeof options === 'string') {
+ //
+ // Otherwise if the first argument is a string, then
+ // assume that it is the first property to expose from
+ // the package.json file on the parent module.
+ //
+ options = { include: [options] };
+ }
+
+ //
+ // **Setup default options**
+ //
+ options = options || {};
+
+ // ensure that includes have been defined
+ options.include = options.include || [];
+
+ if (args.length > 0) {
+ //
+ // If additional string arguments have been passed in
+ // then add them to the properties to expose on the
+ // parent module.
+ //
+ options.include = options.include.concat(args);
+ }
+
+ var pkg = pkginfo.read(pmodule, options.dir).package;
+ Object.keys(pkg).forEach(function (key) {
+ if (options.include.length > 0 && !~options.include.indexOf(key)) {
+ return;
+ }
+
+ if (!pmodule.exports[key]) {
+ pmodule.exports[key] = pkg[key];
+ }
+ });
+
+ return pkginfo;
+};
+
+//
+// ### function find (dir)
+// #### @pmodule {Module} Parent module to read from.
+// #### @dir {string} **Optional** Directory to start search from.
+// Searches up the directory tree from `dir` until it finds a directory
+// which contains a `package.json` file.
+//
+pkginfo.find = function (pmodule, dir) {
+ if (! dir) {
+ dir = path.dirname(pmodule.filename || pmodule.id);
+ }
+
+ if (dir === path.dirname(dir)) {
+ throw new Error('Could not find package.json up from ' +
+ (pmodule.filename || pmodule.id));
+ }
+ else if (!dir || dir === '.') {
+ throw new Error('Cannot find package.json from unspecified directory');
+ }
+
+ var contents;
+ try {
+ contents = require(dir + '/package.json');
+ } catch (error) {}
+
+ if (contents) return contents;
+
+ return pkginfo.find(pmodule, path.dirname(dir));
+};
+
+//
+// ### function read (pmodule, dir)
+// #### @pmodule {Module} Parent module to read from.
+// #### @dir {string} **Optional** Directory to start search from.
+// Searches up the directory tree from `dir` until it finds a directory
+// which contains a `package.json` file and returns the package information.
+//
+pkginfo.read = function (pmodule, dir) {
+ return {
+ dir: dir,
+ package: pkginfo.find(pmodule, dir),
+ };
+};
+
+//
+// Call `pkginfo` on this module and expose version.
+//
+pkginfo(module, {
+ dir: __dirname,
+ include: ['version'],
+ target: pkginfo
+});
diff --git a/node_modules/pkginfo/package.json b/node_modules/pkginfo/package.json
new file mode 100644
index 0000000..acb13c4
--- /dev/null
+++ b/node_modules/pkginfo/package.json
@@ -0,0 +1,58 @@
+{
+ "_from": "pkginfo@0.x.x",
+ "_id": "pkginfo@0.4.1",
+ "_inBundle": false,
+ "_integrity": "sha1-tUGO8EOd5UJfxJlQQtztFPsqhP8=",
+ "_location": "/pkginfo",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "pkginfo@0.x.x",
+ "name": "pkginfo",
+ "escapedName": "pkginfo",
+ "rawSpec": "0.x.x",
+ "saveSpec": null,
+ "fetchSpec": "0.x.x"
+ },
+ "_requiredBy": [
+ "/prompt"
+ ],
+ "_resolved": "https://registry.npmjs.org/pkginfo/-/pkginfo-0.4.1.tgz",
+ "_shasum": "b5418ef0439de5425fc4995042dced14fb2a84ff",
+ "_spec": "pkginfo@0.x.x",
+ "_where": "/data/dev/Projets/Bingoloto Remote/node_modules/prompt",
+ "author": {
+ "name": "Charlie Robbins",
+ "email": "charlie.robbins@gmail.com"
+ },
+ "bugs": {
+ "url": "https://github.com/indexzero/node-pkginfo/issues"
+ },
+ "bundleDependencies": false,
+ "deprecated": false,
+ "description": "An easy way to expose properties on a module from a package.json",
+ "devDependencies": {
+ "vows": "0.8.0"
+ },
+ "engines": {
+ "node": ">= 0.4.0"
+ },
+ "homepage": "https://github.com/indexzero/node-pkginfo#readme",
+ "keywords": [
+ "info",
+ "tools",
+ "package.json"
+ ],
+ "license": "MIT",
+ "main": "./lib/pkginfo.js",
+ "name": "pkginfo",
+ "repository": {
+ "type": "git",
+ "url": "git+ssh://git@github.com/indexzero/node-pkginfo.git"
+ },
+ "scripts": {
+ "test": "vows test/*-test.js --spec"
+ },
+ "version": "0.4.1"
+}
diff --git a/node_modules/pkginfo/test/pkginfo-test.js b/node_modules/pkginfo/test/pkginfo-test.js
new file mode 100644
index 0000000..a59f077
--- /dev/null
+++ b/node_modules/pkginfo/test/pkginfo-test.js
@@ -0,0 +1,83 @@
+/*
+ * pkginfo-test.js: Tests for the pkginfo module.
+ *
+ * (C) 2011, Charlie Robbins
+ *
+ */
+
+var assert = require('assert'),
+ exec = require('child_process').exec,
+ fs = require('fs'),
+ path = require('path'),
+ vows = require('vows'),
+ pkginfo = require('../lib/pkginfo');
+
+function assertProperties (source, target) {
+ assert.lengthOf(source, target.length + 1);
+ target.forEach(function (prop) {
+ assert.isTrue(!!~source.indexOf(prop));
+ });
+}
+
+function compareWithExample(targetPath) {
+ var examplePaths = ['package.json'];
+
+ if (targetPath) {
+ examplePaths.unshift(targetPath);
+ }
+
+ return function(exposed) {
+ var pkg = fs.readFileSync(path.join.apply(null, [__dirname, '..', 'examples'].concat(examplePaths))).toString(),
+ keys = Object.keys(JSON.parse(pkg));
+
+ assertProperties(exposed, keys);
+ };
+}
+
+function testExposes (options) {
+ return {
+ topic: function () {
+ exec('node ' + path.join(__dirname, '..', 'examples', options.script), this.callback);
+ },
+ "should expose that property correctly": function (err, stdout, stderr) {
+ assert.isNull(err);
+
+ var exposed = stderr.match(/'(\w+)'/ig).map(function (p) {
+ return p.substring(1, p.length - 1);
+ });
+
+ return !options.assert
+ ? assertProperties(exposed, options.properties)
+ : options.assert(exposed);
+ }
+ }
+}
+
+vows.describe('pkginfo').addBatch({
+ "When using the pkginfo module": {
+ "and passed a single `string` argument": testExposes({
+ script: 'single-property.js',
+ properties: ['version']
+ }),
+ "and passed multiple `string` arguments": testExposes({
+ script: 'multiple-properties.js',
+ properties: ['version', 'author']
+ }),
+ "and passed an `object` argument": testExposes({
+ script: 'object-argument.js',
+ properties: ['version', 'author']
+ }),
+ "and passed an `array` argument": testExposes({
+ script: 'array-argument.js',
+ properties: ['version', 'author']
+ }),
+ "and read from a specified directory": testExposes({
+ script: 'target-dir.js',
+ assert: compareWithExample('subdir')
+ }),
+ "and passed no arguments": testExposes({
+ script: 'all-properties.js',
+ assert: compareWithExample()
+ })
+ }
+}).export(module);