From cd2b88634cd63d44884f696506bab1b3a2169844 Mon Sep 17 00:00:00 2001 From: Rob Eisenberg Date: Mon, 8 Dec 2014 15:09:22 -0500 Subject: [PATCH] chore(*): prepare release This release is primarily focused around experimentation with jspm configuration. --- .gitignore | 1 - config.js | 6 +-- dist/amd/annotations.js | 54 +++++++++++++++++++++++ dist/amd/index.js | 10 +++++ dist/amd/origin.js | 46 +++++++++++++++++++ dist/amd/resource-type.js | 19 ++++++++ dist/commonjs/annotations.js | 52 ++++++++++++++++++++++ dist/commonjs/index.js | 8 ++++ dist/commonjs/origin.js | 44 ++++++++++++++++++ dist/commonjs/resource-type.js | 17 +++++++ dist/es6/annotations.js | 81 ++++++++++++++++++++++++++++++++++ dist/es6/index.js | 3 ++ dist/es6/origin.js | 69 +++++++++++++++++++++++++++++ dist/es6/resource-type.js | 30 +++++++++++++ doc/CHANGELOG.md | 2 + package.json | 7 ++- test/annotations.spec.js | 2 +- 17 files changed, 443 insertions(+), 8 deletions(-) create mode 100644 dist/amd/annotations.js create mode 100644 dist/amd/index.js create mode 100644 dist/amd/origin.js create mode 100644 dist/amd/resource-type.js create mode 100644 dist/commonjs/annotations.js create mode 100644 dist/commonjs/index.js create mode 100644 dist/commonjs/origin.js create mode 100644 dist/commonjs/resource-type.js create mode 100644 dist/es6/annotations.js create mode 100644 dist/es6/index.js create mode 100644 dist/es6/origin.js create mode 100644 dist/es6/resource-type.js create mode 100644 doc/CHANGELOG.md diff --git a/.gitignore b/.gitignore index f5543b4..784886a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ node_modules jspm_packages bower_components -dist .idea .DS_STORE \ No newline at end of file diff --git a/config.js b/config.js index 3953507..0bd2a6a 100644 --- a/config.js +++ b/config.js @@ -1,7 +1,5 @@ System.config({ "paths": { - "*": "*.js", - "~/*": "lib/*.js" + "*": "*.js" } -}); - +}); \ No newline at end of file diff --git a/dist/amd/annotations.js b/dist/amd/annotations.js new file mode 100644 index 0000000..24c0e02 --- /dev/null +++ b/dist/amd/annotations.js @@ -0,0 +1,54 @@ +define(["exports"], function (exports) { + "use strict"; + + exports.normalize = normalize; + exports.getAnnotation = getAnnotation; + exports.getAllAnnotations = getAllAnnotations; + exports.addAnnotation = addAnnotation; + function normalize(fn) { + if (typeof fn.annotations === "function") { + fn.annotations = fn.annotations(); + } + } + + function getAnnotation(fn, annotationType) { + var annotations = fn.annotations, i, ii, annotation; + + if (annotations === undefined) { + return null; + } + + for (i = 0, ii = annotations.length; i < ii; ++i) { + annotation = annotations[i]; + + if (annotation instanceof annotationType) { + return annotation; + } + } + + return null; + } + + function getAllAnnotations(fn, annotationType) { + var annotations = fn.annotations, found = [], i, ii, annotation; + + if (annotations === undefined) { + return found; + } + + for (i = 0, ii = annotations.length; i < ii; ++i) { + annotation = annotations[i]; + + if (annotation instanceof annotationType) { + found.push(annotation); + } + } + + return found; + } + + function addAnnotation(fn, annotation) { + var annotations = fn.annotations || (fn.annotations = []); + annotations.push(annotation); + } +}); \ No newline at end of file diff --git a/dist/amd/index.js b/dist/amd/index.js new file mode 100644 index 0000000..eff89a4 --- /dev/null +++ b/dist/amd/index.js @@ -0,0 +1,10 @@ +define(["exports", "./origin", "./resource-type", "./annotations"], function (exports, _origin, _resourceType, _annotations) { + "use strict"; + + exports.Origin = _origin.Origin; + exports.ResourceType = _resourceType.ResourceType; + exports.getAnnotation = _annotations.getAnnotation; + exports.getAllAnnotations = _annotations.getAllAnnotations; + exports.addAnnotation = _annotations.addAnnotation; + exports.normalize = _annotations.normalize; +}); \ No newline at end of file diff --git a/dist/amd/origin.js b/dist/amd/origin.js new file mode 100644 index 0000000..4c224f2 --- /dev/null +++ b/dist/amd/origin.js @@ -0,0 +1,46 @@ +define(["exports"], function (exports) { + "use strict"; + + function ensureType(value) { + if (value instanceof Origin) { + return value; + } + + return new Origin(value); + } + + var Origin = (function () { + var Origin = function Origin(moduleId, moduleMember) { + this.moduleId = moduleId; + this.moduleMember = moduleMember; + }; + + Origin.get = function (fn) { + var origin = fn.__origin__; + + if (origin !== undefined) { + return origin; + } + + if (typeof fn.origin === "function") { + return fn.__origin__ = ensureType(fn.origin()); + } + + if (fn.origin !== undefined) { + return fn.__origin__ = ensureType(fn.origin); + } + + return null; + }; + + Origin.set = function (fn, origin) { + if (Origin.get(fn) === null) { + fn.__origin__ = origin; + } + }; + + return Origin; + })(); + + exports.Origin = Origin; +}); \ No newline at end of file diff --git a/dist/amd/resource-type.js b/dist/amd/resource-type.js new file mode 100644 index 0000000..372740a --- /dev/null +++ b/dist/amd/resource-type.js @@ -0,0 +1,19 @@ +define(["exports"], function (exports) { + "use strict"; + + var ResourceType = (function () { + var ResourceType = function ResourceType() {}; + + ResourceType.prototype.load = function (container, target) { + return this; + }; + + ResourceType.prototype.register = function (registry, name) { + throw new Error("All descendents of \"ResourceType\" must implement the \"register\" method."); + }; + + return ResourceType; + })(); + + exports.ResourceType = ResourceType; +}); \ No newline at end of file diff --git a/dist/commonjs/annotations.js b/dist/commonjs/annotations.js new file mode 100644 index 0000000..bc86b4c --- /dev/null +++ b/dist/commonjs/annotations.js @@ -0,0 +1,52 @@ +"use strict"; + +exports.normalize = normalize; +exports.getAnnotation = getAnnotation; +exports.getAllAnnotations = getAllAnnotations; +exports.addAnnotation = addAnnotation; +function normalize(fn) { + if (typeof fn.annotations === "function") { + fn.annotations = fn.annotations(); + } +} + +function getAnnotation(fn, annotationType) { + var annotations = fn.annotations, i, ii, annotation; + + if (annotations === undefined) { + return null; + } + + for (i = 0, ii = annotations.length; i < ii; ++i) { + annotation = annotations[i]; + + if (annotation instanceof annotationType) { + return annotation; + } + } + + return null; +} + +function getAllAnnotations(fn, annotationType) { + var annotations = fn.annotations, found = [], i, ii, annotation; + + if (annotations === undefined) { + return found; + } + + for (i = 0, ii = annotations.length; i < ii; ++i) { + annotation = annotations[i]; + + if (annotation instanceof annotationType) { + found.push(annotation); + } + } + + return found; +} + +function addAnnotation(fn, annotation) { + var annotations = fn.annotations || (fn.annotations = []); + annotations.push(annotation); +} \ No newline at end of file diff --git a/dist/commonjs/index.js b/dist/commonjs/index.js new file mode 100644 index 0000000..54cf2b1 --- /dev/null +++ b/dist/commonjs/index.js @@ -0,0 +1,8 @@ +"use strict"; + +exports.Origin = require("./origin").Origin; +exports.ResourceType = require("./resource-type").ResourceType; +exports.getAnnotation = require("./annotations").getAnnotation; +exports.getAllAnnotations = require("./annotations").getAllAnnotations; +exports.addAnnotation = require("./annotations").addAnnotation; +exports.normalize = require("./annotations").normalize; \ No newline at end of file diff --git a/dist/commonjs/origin.js b/dist/commonjs/origin.js new file mode 100644 index 0000000..3719120 --- /dev/null +++ b/dist/commonjs/origin.js @@ -0,0 +1,44 @@ +"use strict"; + +function ensureType(value) { + if (value instanceof Origin) { + return value; + } + + return new Origin(value); +} + +var Origin = (function () { + var Origin = function Origin(moduleId, moduleMember) { + this.moduleId = moduleId; + this.moduleMember = moduleMember; + }; + + Origin.get = function (fn) { + var origin = fn.__origin__; + + if (origin !== undefined) { + return origin; + } + + if (typeof fn.origin === "function") { + return fn.__origin__ = ensureType(fn.origin()); + } + + if (fn.origin !== undefined) { + return fn.__origin__ = ensureType(fn.origin); + } + + return null; + }; + + Origin.set = function (fn, origin) { + if (Origin.get(fn) === null) { + fn.__origin__ = origin; + } + }; + + return Origin; +})(); + +exports.Origin = Origin; \ No newline at end of file diff --git a/dist/commonjs/resource-type.js b/dist/commonjs/resource-type.js new file mode 100644 index 0000000..cf93357 --- /dev/null +++ b/dist/commonjs/resource-type.js @@ -0,0 +1,17 @@ +"use strict"; + +var ResourceType = (function () { + var ResourceType = function ResourceType() {}; + + ResourceType.prototype.load = function (container, target) { + return this; + }; + + ResourceType.prototype.register = function (registry, name) { + throw new Error("All descendents of \"ResourceType\" must implement the \"register\" method."); + }; + + return ResourceType; +})(); + +exports.ResourceType = ResourceType; \ No newline at end of file diff --git a/dist/es6/annotations.js b/dist/es6/annotations.js new file mode 100644 index 0000000..cd4cac9 --- /dev/null +++ b/dist/es6/annotations.js @@ -0,0 +1,81 @@ +/** + * Normalizes a function's annotation representation. + * + * @method normalize + * @param {Function} fn The function whose annotations may require normalization. + * @for export + */ +export function normalize(fn){ + if(typeof fn.annotations === 'function'){ + fn.annotations = fn.annotations(); + } +} + +/** + * Searches a function's metadata for an annotation of a particular type. + * + * @method getAnnotation + * @param {Function} fn The function whose annotations are being inspected. + * @param {Function} annotationType The annotation type to look for. + * @return {Object} Returns an instance of the specified annotation type if found; otherwise null. + * @for export + */ +export function getAnnotation(fn, annotationType){ + var annotations = fn.annotations, + i, ii, annotation; + + if(annotations === undefined){ + return null; + } + + for(i = 0, ii = annotations.length; i < ii; ++i){ + annotation = annotations[i]; + + if(annotation instanceof annotationType){ + return annotation; + } + } + + return null; +} + +/** + * Searches a function's metadata for all annotations of a particular type. + * + * @method getAllAnnotations + * @param {Function} fn The function whose annotations are being inspected. + * @param {Function} annotationType The annotation type to look for. + * @return {Array} Returns an array of the specified annotation type. + * @for export + */ +export function getAllAnnotations(fn, annotationType){ + var annotations = fn.annotations, + found = [], i, ii, annotation; + + if(annotations === undefined){ + return found; + } + + for(i = 0, ii = annotations.length; i < ii; ++i){ + annotation = annotations[i]; + + if(annotation instanceof annotationType){ + found.push(annotation); + } + } + + return found; +} + +/** + * Adds metadata to a function. + * + * @method addAnnotation + * @param {Function} fn The function being tagged with metadata. + * @param {Object} annotation The annotation instance to add. + * @for export + */ +export function addAnnotation(fn, annotation){ + var annotations = fn.annotations || (fn.annotations = []); + annotations.push(annotation); +} \ No newline at end of file diff --git a/dist/es6/index.js b/dist/es6/index.js new file mode 100644 index 0000000..20142e6 --- /dev/null +++ b/dist/es6/index.js @@ -0,0 +1,3 @@ +export {Origin} from './origin'; +export {ResourceType} from './resource-type'; +export {getAnnotation, getAllAnnotations, addAnnotation, normalize} from './annotations'; \ No newline at end of file diff --git a/dist/es6/origin.js b/dist/es6/origin.js new file mode 100644 index 0000000..7ca259e --- /dev/null +++ b/dist/es6/origin.js @@ -0,0 +1,69 @@ +/** + * Utilities for reading and writing the metadata of JavaScript functions. + * + * @module metadata + */ + +function ensureType(value){ + if(value instanceof Origin){ + return value; + } + + return new Origin(value); +} + +/** +* A metadata annotation that describes the origin module of the function to which it's attached. +* +* @class Origin +* @constructor +* @param {string} moduleId The origin module id. +* @param {string} moduleMember The name of the export in the origin module. +*/ +export class Origin { + constructor(moduleId, moduleMember){ + this.moduleId = moduleId; + this.moduleMember = moduleMember; + } + + /** + * Get the Origin annotation for the specified function. + * + * @method get + * @static + * @param {Function} fn The function to inspect for Origin metadata. + * @return {Origin} Returns the Origin metadata. + */ + static get(fn){ + var origin = fn.__origin__; + + if(origin !== undefined){ + return origin; + } + + if(typeof fn.origin === 'function'){ + return fn.__origin__ = ensureType(fn.origin()); + } + + if(fn.origin !== undefined){ + return fn.__origin__ = ensureType(fn.origin); + } + + return null; + } + + /** + * Set the Origin annotation for the specified function. + * + * @method set + * @static + * @param {Function} fn The function to set the Origin metadata on. + * @param {origin} fn The Origin metadata to store on the function. + * @return {Origin} Returns the Origin metadata. + */ + static set(fn, origin){ + if(Origin.get(fn) === null){ + fn.__origin__ = origin; + } + } +} \ No newline at end of file diff --git a/dist/es6/resource-type.js b/dist/es6/resource-type.js new file mode 100644 index 0000000..828b476 --- /dev/null +++ b/dist/es6/resource-type.js @@ -0,0 +1,30 @@ +/** +* An abstract base class used to designate resources which can be loaded and registered in a framework. +* +* @class ResourceType +* @constructor +*/ +export class ResourceType { + /** + * Implemented by resource metadata to allow it to self-configure and load dependencies. + * + * @method load + * @param {Container} container The dependency injection container to use for service resolution. + * @param {Object} target The target that is decorated by this ResourceType metadata. + * @return {Promise} Returns a promise for itself, resolving when all dependent resources are loaded. + */ + load(container, target){ + return this; + } + + /** + * Implemented by resources to allow them to register themselved in a resource registry. + * + * @method register + * @param {ResourceRegistry} registry The resource registry that this resource needs to be registered in. + * @param {String} [name] A possible name override for the resource. + */ + register(registry, name){ + throw new Error('All descendents of "ResourceType" must implement the "register" method.'); + } +} \ No newline at end of file diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md new file mode 100644 index 0000000..de2392a --- /dev/null +++ b/doc/CHANGELOG.md @@ -0,0 +1,2 @@ +### 0.0.2 (2014-12-08) + diff --git a/package.json b/package.json index 6a0c409..e673d6b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-metadata", - "version": "0.0.1", + "version": "0.0.2", "description": "Utilities for reading and writing the metadata of JavaScript functions.", "keywords": [ "aurelia", @@ -24,7 +24,10 @@ "lib": "dist" }, "main": "commonjs/index", - "browser": "amd/index" + "browser": "amd/index", + "map": { + "aurelia-metadata": "/dist/amd/index" + } }, "devDependencies": { "conventional-changelog": "0.0.11", diff --git a/test/annotations.spec.js b/test/annotations.spec.js index 8728824..e4610fb 100644 --- a/test/annotations.spec.js +++ b/test/annotations.spec.js @@ -3,7 +3,7 @@ import { getAllAnnotations, addAnnotation, normalize -} from '~/index'; +} from '../lib/index'; describe('annotations', () => { it('can be located by type', () => {