perak / kitchen-cli

Meteor Kitchen - Command Line Interface
226 stars 9 forks source link

Make application json available to the application [ER] #18

Open paulbalomiri opened 8 years ago

paulbalomiri commented 8 years ago

Would you consider adding the json content to the /private folder and either or both

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.

paulbalomiri commented 8 years ago

OK, i really need this, and as i now found out, the package load order is

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_filedirectives:

"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"
}
]

client side

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.

paulbalomiri commented 8 years ago

@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?