Commit Graph

47 Commits

Author SHA1 Message Date
Diana Lau d598c3738a chore: update dependencies 2018-07-25 21:59:39 -04:00
Zak Barbuto a78a05f9b4 Ignore source maps in boot 2017-09-21 16:35:14 +09:30
Raymond Feng 3bb519d5e9 Upgrade deps and fix style issues 2017-05-08 14:48:48 -07:00
Raymond Feng ac1571ccf1 Refactor for modular and pluggable design
- refactor logic of processing artifacts into their own classes
- introduce Container as the main class for bootstrapping and build a
  registry of handlers during boot to organize them by a hierarchy
  denoted by path
- adopt middleware like registration and invocation
- container.use(path, handler)
- container.run(context, done)
- allow more phases during boot
- boot is now asynchronous
2016-11-22 13:38:28 -05:00
Doped Dude 129938bacd Configurable dir for components and middleware
Add two new options `middlewareRootDir` and `componentRootDir`
allowing users to load middleware and/or components from a custom
place
2016-07-27 16:09:46 +02:00
Ryan Graham 5eaa909006
update copyright notices and license 2016-05-05 21:52:36 -07:00
Miroslav Bajtoš 902005ed8e Use eslint with loopback config
Drop jshint and jscs in favour of eslint.
2016-04-05 15:42:58 +02:00
Raymond Feng b081d828b2 Allow middleware array merge by a key in item objects 2015-08-10 17:17:09 -07:00
Raymond Feng 7362cc489e Enhance middleware config merge 2015-08-07 15:53:28 -07:00
Raymond Feng 02c826337c Fix the model-config/datasource merge 2015-07-31 10:01:53 -07:00
Hage Yaapa 66cc099d1d allow middleware to be optional 2015-06-25 19:32:40 +02:00
Miroslav Bajtoš a63ae8e44b Excl. mod. main path from middleware instructions
When loading middleware configured in "middleware.json", loopback-boot
used to require() the full path to middleware's module main file,
for example "node_modules/strong-express-metrics/index.js".

This is breaking strong-agent probes, as it's difficult to detect
when the intercepted module (e.g. "strong-express-metrics") was loaded.

This commit modifies the compiler to omit the tail (the path to the
module main source file) when requiring middleware.
2015-06-24 17:21:22 +02:00
Miroslav Bajtoš 140180f667 Merge pull request #131 from PradnyaBaviskar/lb-issue-79-mixinsources
support 'mixinsources' option
2015-05-07 16:04:14 +02:00
Pradnya Baviskar 53f51820f5 support 'mixinsources' option
- By default looks for mixinsources in  directory

- Loads only mixins used through models
2015-05-07 14:35:55 +05:30
Miroslav Bajtoš 0563840006 Fix coding style issues, add API docs 2015-05-05 11:28:58 +02:00
Shlomi Assaf b6c60a297d Extend options arg to support custom model definitions
Extend the options argument of boot/compile to allow the developer
to supply custom model definitions (to replace the result of
findModelDefinitions). Together with the existing options.models,
it allows to specify all model-related data and still use the benefits
which loopback-boot provides (most notably loading models in order
defined by inheritance, i.e. base models are loaded before models that
are extending them).
2015-05-05 11:24:02 +02:00
Pradnya Baviskar 9bb988713e add support for mixins
- [mixinDirs]: List of directories to look for files
 containing model mixin definition.
2015-04-24 12:42:56 +05:30
Pradnya Baviskar 39d820a657 Use filename as default value for Model name 2015-04-08 14:04:57 +05:30
Pradnya Baviskar 07d276977a Improve the resolution of relative paths
- resolve module relative path for component
 - prioritize coffeescript over json
2015-04-07 13:38:57 +05:30
Pradnya Baviskar 3a7b9739d9 Resolve module paths as relative to appRootDir - for middleware 2015-03-20 18:32:45 +05:30
Pradnya Baviskar 187a105333 Resolve missing file extension for module relative paths 2015-03-17 11:42:04 +05:30
Pradnya Baviskar 4913b3ffb9 Resolve module paths as relative to appRootDir 2015-03-16 14:43:37 +05:30
Pradnya Baviskar 6e6eaccadd Resolve relative paths in using appRootDir 2015-03-11 11:07:28 +05:30
Miroslav Bajtoš f8247be23c Configure components via `component-config.json`
Load configuration of components from `component-config`
and configure all components as specified.

Sample JSON:

    {
      "loopback-component-foobar": {
        "option1": "value1",
        "option2": "value2"
      }
    }

The component is expected to export the following function:

    module.exports = function(app, options) { /* ... */ };
2015-01-06 14:00:26 +01:00
Eric Satterwhite 301031b78f Dedupe boot scripts
Remove duplicated entries in the array of boot scripts to run.
Because the bootDirs defaults to process.cwd(), if the user manually
includes scripts in the same directory, without specifying a bootDir,
those scripts will be included multiple times.
2014-12-19 15:18:37 +01:00
Miroslav Bajtoš 8cc2518cb0 compiler: resolve paths in middleware params
Introduce a convention for specifying relative paths in middleware
params: values prefixed with `$!` and starting with `./` or `../`
are resolved relatively to `middleware.json`.

Example:

    {
      "files": {
        "loopback#static": {
          "params": "$!../client"
        },
        "loopback#static": {
          "params": "$!./public"
        }
      }
    }
2014-11-28 12:17:27 +01:00
Raymond Feng 2f72006c88 Implement shorthand notation for middleware paths
When the middleware name (path) is in the format {module}#{filename},
loopback-boot resolves the path by trying multiple locations and
using the first one that exists:

 - {module} and check the {filename} property of the exports
     -> e.g. loopback.rest
- {module}/server/middleware/{filename}
    -> e.g. loopback/server/middleware/rest
 - {module}/middleware/{filename}
    -> e.g. loopback/middleware/rest

Values in any other format will bypass this resolution algorithm and
they will be used in the original form:

 - a full path in a module: loopback/server/middleware/rest
 - a relative path: ./middleware/custom, ./custom, ../logger
 - an absolute path: /usr/local/lib/node_modules/compression
2014-11-25 11:43:00 +01:00
Miroslav Bajtoš 1114bc9227 Load middleware and phases from `middleware.json`
Sample JSON:

        {
          "routes:before": {
            "morgan": {
              "params": ["dev"]
            }
          },
          "routes": {
            "loopback/server/middleware/rest": {
            }
          },
          "subapps": {
            "./adminer": {
            },
          }
        }

The JSON file can be customized using the usual conventions:
  - middleware.local.{js|json}
  - middleware.{env}.{js|json}

It is also possible to mount the same middleware in the same phase
multiple times with different configuration.

Example config:

    {
      "auth": {
        "oauth2": [
          {
            "params": "first"
          },
          {
            "params": "second"
          }
        ]
      },
    });
2014-11-19 09:45:04 +01:00
Miroslav Bajtoš 5b5071864b Add jscs style check, fix violations found 2014-11-13 15:54:59 +01:00
Miroslav Bajtoš e2aff71bf9 Use `chai` instead of `must`
As of 1.10, chai supports nonary assertions, there are no more reasons
for using a different variant.
2014-11-13 15:31:35 +01:00
bitmage e936deffe2 support coffee-script models and client code
Load models for any filetypes registered in require.extensions.

 - Server side coffee-script requires a `require('coffee-script/register');`

 - Client side coffee-script requires Coffeeify.
2014-10-24 10:42:30 -07:00
Miroslav Bajtoš aa4cbdd80f compiler: support module-relative model sources
Interpret model sources in the same way how `require.resolve`
interprets the path:

 - values starting with `./` and `../` are relative to the file
   where they are specified

 - other values are relative to node modules folders

This way it's possible to specify a source `loopback/common/models`
and have it resolved to whatever place the loopback is installed.
2014-10-21 18:10:22 +02:00
Miroslav Bajtoš 38c4944e2e Merge pull request #54 from strongloop/feature/support-nested-values-in-config-overrides
Support nested values in config overrides
2014-10-09 19:33:13 +02:00
johnsoftek 18121a4208 Custom rootDir for app config 2014-10-09 16:36:19 +02:00
Miroslav Bajtoš f0836719c9 compiler: improve merging of Arrays and Objects
Add more unit-tests to cover various edge cases. Fix issues discovered
by these new tests.
2014-10-08 17:15:32 +02:00
Shelby Sanders e1d870dced config-loader: deeply merge Array and Object vals 2014-10-08 17:15:32 +02:00
Fabien Franzen 217f0ce32f Fix typo 2014-08-04 10:35:13 +02:00
Fabien Franzen f98d2cb89c Implemented modelSources, bootDirs and bootScripts options 2014-08-04 10:33:03 +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š 92455f569c test: fix jshint warnings 2014-06-26 14:54:07 +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š 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š 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š 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š 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š 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