kitchen-cli
kitchen-cli copied to clipboard
Make application json available to the application [ER]
Would you consider adding the json content to the /private
folder and either or both
- Add the json on load to Meteor.settings.server.private.kitchen
- provide a function
Kitchen.loadAppJson
?
This way packages could use the app json to provide additional functionality at runtime.
Anyone needing a simple solution to this can structure the project like this:
app/
app.json
files/
read_app.js
with read_app.js
:
if (Meteor.isServer){
if(!Meteor.settings) Meteor.settings={};
if(!Meteor.settings.public) Meteor.settings.public={};
Meteor.settings.public.app= JSON.parse(Assets.getText('app.json')).application;
}
and a copy_files
directive:
{
"source": "app.json",
"dest": "OUTPUT_DIR/private/app.json"
}
The reason i am proposing this is that if you want to add packages to the app providing kitchen-configuration related features there is no way to access the json from a reliable point.
Also putting the Assets.getText
in the lib
Folder makes JSON loading precede package loading which is a must if you have to generate stuff the appcode relies upon before Meteor.startup
time.
ATM if you wanted to use an external package with meteor kitchen and rely on the JSON you would have to supply above explanation and related instructions to users of the package.
OK, i really need this, and as i now found out, the package load order is
- package
- appcode
- lib
- other files/dirs
- main
- package startup
- appcode startup
Thus it is impossible to access the json from a package earlier than at Meteor.startup
time.
EDIT: This is because the earliest i get to use Assets
at the app level are when all packages are loaded.
Therefor i created a package to be copied into the /packages directory together with the json. kitchen-settings.zip
##Introducing kitchen-settings package
the package contains
/
package.js
kitchen-settings.js
application.json -- This needs to be generated/copied here
Package Usage
To use the package unzip it at <FILES_LOCATION>
Add these copy_file
directives:
"copy_files": [
{
"source": "application.json",
"dest": "OUTPUT_DIR/packages/kitchen-settings/application.json"
},
{
"source": "files/kitchen-settings/kitchen-settings.js",
"dest": "OUTPUT_DIR/packages/kitchen-settings/kitchen-settings.js"
},
{
"source": "files/kitchen-settings/package.js",
"dest": "OUTPUT_DIR/packages/kitchen-settings/package.js"
}
]
- Your source location for
application.json
may vary - it is assumed that the zip file has been extracted to
./files
directory where the current directory is the directory above the generated files (where you runmeteor-kitchen
)
client side
- create a dependency in
<your dependent package>
to 'kitchen-settings'. (Note there is no developer prefix, as it is a generated - app-specific package) - access the json with
app_json.application
- to prevent loadorder issues you can use
app_json.isReady()
which will be true when the json has been sent over the wire. - You can also access
app_json.application
by using app_json.get() - both
app_json.isReady()
andapp_json.get()
are reactive.
server side
just create a dependency on kichen-settings
, then use app_json
,which has the same structure as the json read from the application.json
file.
@perak is there any chance of getting this in the next version?
Basically it's just default copy directives for the two files and automatic write of the application.json into packages/kitchen-settings/application.json
?