Commit Graph

7 Commits

Author SHA1 Message Date
Miroslav Bajtoš 5f85971d11 Implement compileToBrowserify and bootBrowserApp
Hide `compile` and `execute` and provide a better API for browserified
applications:

 - `boot.compileToBrowserify(options, bundler)` calls `compile` under
   the hood and adds all instructions and scripts to the bundler.

 - `bootBrowserApp(app)` is exported by loopback-boot when the module
   is loaded in a browser, the function loads the instructions as
   bundled by `compileToBrowserify`.

This new API hides all implementation details from the user and makes
it easy to add loopback-boot to any build script.
2014-06-03 14:08:34 +02:00
Miroslav Bajtoš b14800416a Split the boot process into two steps
Split bootLoopBackApp into two steps:
 - compile
 - execute

Most of the changes are just shuffling the existing code around.

What has changed:

 - `loopback.autoAttach()` is called after `models/*` are required.
   The calls were made in the opposite order before this commit.
2014-06-03 08:13:14 +02:00
Miroslav Bajtoš 255217f6a7 Ignore models/ and boot/ subdirs without index
Sub-directories of `models/` and `boot/` that cannot be required
(they don't have an index.js file) are silently skipped now.

This enables developers to put test files into `models/test/`.
2014-05-27 16:44:21 +02:00
Miroslav Bajtoš 3ba43e1197 Pass `app` to fn exported by auto-required script
When a script in `models/` or `boot/` exports a function which is not
a loopback.Model constructor, the bootstrapper immediatelly calls
this exported function wit the current `app` object.

This is providing a dependency injection mechanism for boot scripts,
so that they no longer need to know where to find the `app` object.

Note: the dependency injection is optional. Existing code getting
`app` reference via `require('../app')` will continue to work.
2014-05-27 16:11:54 +02:00
Miroslav Bajtoš 2a619773d4 Custom rootDir for models and datasources
Support custom project layouts where model & datasource config files
are located in a different place from the app config.

Example:

    # API server
    server/app.config.json
    server/datasources.json

    # shared between server & client
    models.json
    models/

    # isomorphic client
    client/app.config.json
    client/datasources.json
2014-05-27 14:49:11 +02:00
Miroslav Bajtoš c1743dc2ff Load datasources and app cfg from multiple files
Modify loading of `appConfig` and `dataSourceConfig` to look for
the following files:

  - app.json
  - app.local.{js|json}
  - app.{$env}.{js|json}

  - datasources.json
  - datasources.local.{js|json}
  - datasources.{$env}.{js|json}

where $env is the value of `app.get('env')`, which usually defaults
to `process.env.NODE_ENV`.

The values in the additional files are applied to the config object,
overwritting any existing values. The new values must be value types
like String or Number; Object and Array are not supported.

Additional datasource config files cannot define new datasources,
only modify existing ones.

The commit includes refactoring of the config-loading code into
a standalone file.
2014-05-27 14:08:58 +02:00
Miroslav Bajtoš a4402a3979 Initial implementation
Move `app.boot()` and its tests from loopback.

Fix jshint warnings.

Clean up unit tests - remove dependency on global variables created
by loopback's test/support.js
2014-05-23 16:50:40 +02:00