Commit Graph

114 Commits

Author SHA1 Message Date
Miroslav Bajtoš c3bbc13fd8 Merge pull request #126 from strongloop/fix/number-isFinite
executor: fix port lookup
2015-04-23 09:26:29 +02:00
Miroslav Bajtoš e5fd8c7975 executor: fix port lookup
Use the global `isFinite` function to find the first valid port
number. This is the same behaviour as `_.isFinite` in lodash@2.x.

As a result, only values that are a valid number are accepted, e.g.
"0" is accepted but "0xy" is not.
2015-04-23 08:51:24 +02:00
Miroslav Bajtoš acb3d1815f Clean up compiler.tryResolveAppPath
Enable the strict mode by default.
2015-04-22 09:52:06 +02:00
Bryan Clark 044a4df07a Upgrade lodash and drop underscore.string
Update to the latest version of "lodash" to use the string functions
included and drop the usage of "underscore.string".

Existing tests run checks for `flying-car` definitions to be named
`FlyingCar` so there doesn’t seem to be a need to add more checks.

`isFinite` changed from the older version of lodash to no longer coerce
strings into numbers, this commit adds a call of `parseInt` before
checking whether the value is a finite number.

`parseInt` on an undefined returns NaN which isFinite does not identify
as a number.

While changing this part, the code was reworked to use `Number.isFinite`
and thus the executor no longer depends on lodash. This should reduce
the size of the browser bundle.
2015-04-15 17:40:14 +02:00
Bryan Clark 1d8bd15a77 add console.error message to a bad require in a boot script
This change produces the following error message in the tests:
`Failed loading boot script badScript.js`
`Cannot find module 'doesnt-exist’`
2015-04-14 09:09:18 -07:00
Miroslav Bajtoš acf1868ba4 Support per-application registry of models 2015-04-09 17:56:56 +02:00
Pradnya Baviskar 39d820a657 Use filename as default value for Model name 2015-04-08 14:04:57 +05:30
Miroslav Bajtoš 6526ffeb3d compiler: code cleanup
Refactor and simplify the internal method tryResolveAppPath.

Fix a bug in the resolver of middleware paths which was discovered
by the refactoring.
2015-04-07 10:42:49 +02:00
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
Miroslav Bajtoš d7c67c803a Merge pull request #113 from PradnyaBaviskar/lb-boot-issue-73-4
Resolve module paths as relative to appRootDir - for middleware
2015-03-20 16:32:24 +01:00
Pradnya Baviskar 3a7b9739d9 Resolve module paths as relative to appRootDir - for middleware 2015-03-20 18:32:45 +05:30
Krishna Raman 311b892a0f Support for multiple apps in browserified bundle. 2015-03-19 09:57:32 -07:00
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
Miroslav Bajtoš cb7ca7d9ad Merge pull request #104 from PradnyaBaviskar/lb-explorer-issue-65
Resolve relative paths in bootScripts using appRootDir
2015-03-11 08:43:39 +01:00
Pradnya Baviskar 6e6eaccadd Resolve relative paths in using appRootDir 2015-03-11 11:07:28 +05:30
Pradnya Baviskar 2c4b6f06a4 Add feature to disable component 2015-03-10 15:03:20 +05:30
Berkeley Martinez d8bf8687a8 Save instructions.json in root dir
Saving in node_modules dir causes complaints and missing files
fixes https://github.com/strongloop/loopback-boot/issues/94
2015-02-19 13:38:13 -08:00
Clark Wang 6424534831 executor: pass correct `this` to middleware
Fix the bug "can't configure passport#initialize in middleware.json"
2015-02-02 18:54:22 +01:00
Miroslav Bajtoš 2a1f07aad9 Merge pull request #88 from STRML/master
Don't swallow error when a sub-dependency doesn't resolve.
2015-01-13 10:34:29 +01:00
Samuel Reed 30a7b6d9b8 Don't swallow error when a sub-dependency doesn't resolve.
This prevents an occurence where an error is completely swallowed if a script
required by loopback-boot has a bad require() call. The script is never ran
but execution continues.
2015-01-13 10:23:54 +01:00
Miroslav Bajtoš 4f8514a454 Fix "incompatible loopback version" check & msg
Use `util.format` to build the error message, `Error` constructors
does not support placeholders like `%s`.

Detect pre-release versions and handle them in the same way as regular
releases.
2015-01-12 16:00:06 +01:00
Miroslav Bajtoš c47bde9281 Merge pull request #77 from strongloop/feature/add-boot-completion-check
Add "booting" flag and emit "booted" event
2015-01-07 16:41:29 +01:00
Simon Ho 1f7d8e56e8 Add "booting" flag and emit "booted" event 2015-01-06 21:27:32 -08:00
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
Ryan Graham e1f7c592a1 Replace underscore with lodash
Replace 2 uses of underscore and 1 use of a lodash submodule with full
lodash module.
2014-12-02 22:10:52 -08: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
Raymond Feng db917bf03b Fix the test for built-in models on Windows
See https://github.com/strongloop/loopback/issues/756
2014-11-10 08:22:57 -08:00
Raymond Feng ed59cb2483 Fix jsdoc 2014-10-30 13:34:59 -07:00
Miroslav Bajtoš d7bdbd31b1 compiler: fix coding style violations 2014-10-27 11:13:02 +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š 26abb43ad4 Skip definitions of built-in loopback models
LoopBack built-in models are special: they follow the loopback-boot
structure and provide `common/models/{name}.json` files, but they are
also automatically loaded (created) by loopback.

This change modifies `executor` to recognize built-in models and do not
redefine them.
2014-10-21 18:10:22 +02:00
Raymond Feng e0abff007e Merge pull request #50 from strongloop/feature/support-async-scripts
Add support async scripts
2014-10-09 12:19:21 -07:00
Raymond Feng 94cb4d6342 Add support for async boot scripts 2014-10-09 12:18:36 -07: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
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