https://github.com/gadicc/meteor-package-json
Package authors: fetch and watch changes in app's package.json
https://github.com/gadicc/meteor-package-json
Last synced: 10 months ago
JSON representation
Package authors: fetch and watch changes in app's package.json
- Host: GitHub
- URL: https://github.com/gadicc/meteor-package-json
- Owner: gadicc
- Created: 2016-05-15T09:43:07.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-18T12:13:42.000Z (about 10 years ago)
- Last Synced: 2025-02-17T21:19:05.135Z (over 1 year ago)
- Language: JavaScript
- Size: 19.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# meteor-package-json
A helper for Meteor **build plugin** authors (for now) who need info from the apps `package.json`. Watches the file and has a callback for your package to accept changes to it's relevant section, otherwise quits Meteor asking for the user to restart.
## Quick Start
For the examples below, assume we are developing `john:doe` and have the following `package.json`:
```js
{
"john:doe": {
"experimental": false
}
}
```
**Simple Fetch**
```js
const config = packageJson.getPackageConfig('john:doe');
expect(config).to.deep.equal({ experimental: true });
```
If the `john:doe` section is modified, Meteor will exit. If any other part of the file is modified, nothing happens. But it's even better if you can accept the changes to avoid a restart.
**Accepting Changes**
```js
// The callback below is only ever called if prev does not deep equal next
const config = packageJson.getPackageConfig('john:doe', (prev, next) => {
if (prev.experimental !== next.experiemnetal) {
enableExperimentalFeatures(next.experimental);
}
// We can accept this change; no need to restart Meteor.
return true;
});
// On initial load
if (config.experimental)
enableExperimentalFeatures(true);
```
## API
* `packageJson.getPackageConfig('sectionName', [acceptHandler]);`
* Returns the `sectionName` property from `package.json`.
* If the properties in `sectionName` have *changed* (are not deeply equal), then, Meteor will quite if no `acceptHandler` is given, or if `acceptHandler(prevSection, newSection)` does not return `true`.
* For both the initial return and acceptHandler, if the section is undefined, an empty object (` {} `) will be returned, so no need to test for this in your code.
## Development && testing
`npm test` or with Wallaby.js.