Added value retrieval to package builder.
This patch adds getValues and getValue to the package builder library, to allow retrieval of package-level variables from an authoritative source during the various project configuraiton stages.
This commit is contained in:
parent
2e40d06226
commit
e8db0834b8
|
@ -37,9 +37,33 @@
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the values of the current package.
|
||||
*
|
||||
* @returns {{}} A cloned map of the values.
|
||||
*/
|
||||
function getValues () {
|
||||
return JSON.parse(JSON.stringify(pkgContent));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific value from the package.json file.
|
||||
*
|
||||
* @param {String} name The name of the value.
|
||||
* @returns {{}} A clone of the referenced value.
|
||||
*/
|
||||
function getValue (name) {
|
||||
if (pkgContent.hasOwnProperty(name)) {
|
||||
return JSON.parse(JSON.stringify(pkgContent[name]));
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fromJSON: readPackage,
|
||||
toJSON: writePackage,
|
||||
setValues: setValues
|
||||
setValues: setValues,
|
||||
getValues: getValues,
|
||||
getValue: getValue
|
||||
};
|
||||
})();
|
||||
|
|
|
@ -51,5 +51,27 @@
|
|||
expect(parsedResult.lol).toBe("cat");
|
||||
expect(parsedResult.foo).toBeUndefined();
|
||||
});
|
||||
|
||||
describe('getValues()', function () {
|
||||
it('should permit retrieving the entire package block.',
|
||||
function () {
|
||||
builder.fromJSON('{"name":"foo"}');
|
||||
expect(builder.getValues()).toEqual({name: 'foo'});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getValue()', function () {
|
||||
it('should permit retrieving values from the package.',
|
||||
function () {
|
||||
builder.fromJSON('{"name":"foo"}');
|
||||
expect(builder.getValue('name')).toBe('foo');
|
||||
});
|
||||
|
||||
it('should return undefined if the value is not set.',
|
||||
function () {
|
||||
builder.fromJSON('{"name":"foo"}');
|
||||
expect(builder.getValue('invalidname')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue