Commit Graph

21 Commits

Author SHA1 Message Date
Raymond Feng 20ed867d79 Merge pull request #34 from cajoy/master
documentation fix
2014-08-07 08:23:37 -07:00
Alex 1ae0167b7c documentation fix 2014-08-07 10:12:35 -04:00
Fabien Franzen f98d2cb89c Implemented modelSources, bootDirs and bootScripts options 2014-08-04 10:33:03 +02:00
Miroslav Bajtoš c4b09c6b7a executor: remove `Base` arg from model function
Simplify the contract for functions exported by `models/*.js` files
by removing the second argument `Base`. The base class can be accessed
using `ModelCtor.base`.

An updated example of a model js file:

```js
module.exports = function(Customer) {
  Customer.setup = function() {
    Customer.base.setup.apply(this, arguments);
    // etc.
  };
};
```
2014-07-22 10:59:50 +02:00
Miroslav Bajtoš 6bf995c55b compiler: return a clone of instructions
When executor passes the instruction to loopback methods,
loopback modifies the data. Since we are loading the data using
`require` such changes affects also code that calls
`require` for one of the instructions files.

This change adds a deep clone step to prevent this issue.
2014-07-17 18:44:15 +02:00
Miroslav Bajtoš 3129f6495c Rename `models.json` to `model-config.json`
The name `models.json` was potentially confusing since there are no
models defined in that file.
2014-07-15 11:09:39 +02:00
Miroslav Bajtoš a3c347d073 compiler: fix references to loopback 2014-06-26 14:53:47 +02:00
Miroslav Bajtoš d5cd0a3b50 Merge branch 'master' into 2.0
Conflicts:
	README.md
	docs/configuration.md
	lib/executor.js
	package.json

Changes in the docs were merged manually and updated to correctly
describe the 2.x layout.
2014-06-26 14:40:24 +02:00
Miroslav Bajtoš 230360ef28 executor: remove direct reference to loopback
Modify the executor to access the loopback object via `app.loopback`.

Fall back to `require('loopback')` only when `app.loopback` is not set
(loopback versions before 1.9).
2014-06-25 14:12:53 +02:00
Miroslav Bajtoš ac16d92a8b Rename `app.json` to `config.json`
The new loopback project layout adds a concept of components like
'rest server' and 'isomorphic client', each component having its own set
of boot files. The name `app.json` is confusing, since it is configuring
a component, not the app (which is the whole project).
2014-06-25 08:18:04 +02:00
Miroslav Bajtoš 0a0a6f5d01 Merge branch 'master' into 2.0
Conflicts:
	index.js
	package.json
2014-06-16 19:49:45 +02:00
Miroslav Bajtoš 57e96b0d38 compiler: Sort models topologically
Sort models topologically using Base->Model as edges. This way
the base models are defined before the models extending them.
2014-06-16 19:45:34 +02:00
Miroslav Bajtoš ef72efa70b executor: Split model boot into two phases
In the first phase, all models are defined.

In the second phase, models are configured, attached to data-sources
and exposed on the app object.

This way when the `attached` Model event is emitted, all models are
already defined and thus a listener can get reference of any other
model used in the app.
2014-06-16 16:41:12 +02:00
Miroslav Bajtoš b887b33b57 compiler: Move model-sources cfg to models.json
Remove `modelSources` option from `boot()` options, add `_meta.sources`
to `models.json`.

```json
{
  "_meta": {
    "sources": ["./custom/path/to/models"]
  },
  "Car": {
    "dataSource": "db"
  }
}
```
2014-06-16 16:41:12 +02:00
Miroslav Bajtoš c3a9a09941 Drop peer dep on loopback; add a runtime check
Replace peerDependency with a run-time check based on
`app.loopback.version`.
2014-06-16 15:23:32 +02:00
Miroslav Bajtoš a204fdc1c9 Rework model configuration
Rework the way how models are configured, the goal is to allow
loopback-boot to automatically determine the correct order
of the model definitions to ensure base models are defined
before they are extended.

 1. The model .js file no longer creates the model, it exports
 a config function instead:

  ```js
  module.exports = function(Car, Base) {
    // Car is the model constructor
    // Base is the parent model (e.g. loopback.PersistedModel)

    Car.prototype.honk = function(duration, cb) {
      // make some noise for `duration` seconds
      cb();
    };
  };
  ```

 2. The model is created by loopback-boot from model .json file.
  The .js file must have the same base file name.

 3. The `boot()` function has a new parameter `modelSources` to
  specify the list of directories where to look for model definitions.
  The parameter defaults to `['./models']`.

As a side effect, only models configured in `models.json` and their
base clases are defined. This should keep the size of the browserified
bundle small, because unused models are not included.
2014-06-13 19:40:52 +02:00
Miroslav Bajtoš 43993bf975 Remove auto-attach.
Breaking change.

The bootstrapper no longer calls `loopback.autoAttach`. Applications
have to explicitly configure datasources for their models
via `models.json`.
2014-06-10 09:24:16 +02:00
Miroslav Bajtoš 47b5bb5f5c Change models.json to configure existing models
Breaking change.

In the new 2.x project layout, definition of loopback Models is out of
scope of the boot process. The bootstrapper only configures existing
models - attaches them to a dataSource and the app object.
2014-06-10 09:21:15 +02:00
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š 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