ember-cli-node-assets
Advanced tools
Comparing version 0.2.0-beta.1 to 0.2.0-beta.2
@@ -0,1 +1,5 @@ | ||
## 0.2.0-beta.2 (February 1, 2017) | ||
### Fixed | ||
- Dynamic configuration functions are called with the correct `this` value ([#8](https://github.com/dfreeman/ember-cli-node-assets/issues/8)) | ||
## 0.2.0-beta.1 (January 31, 2017) | ||
@@ -2,0 +6,0 @@ ### Added |
@@ -28,3 +28,4 @@ /* eslint-env node */ | ||
var userOptions = this.app ? this.app.options : this.parent.options; | ||
this._options = normalizeUserOptions(userOptions && userOptions.nodeAssets || {}); | ||
var assetOptions = userOptions && userOptions.nodeAssets || {}; | ||
this._options = normalizeUserOptions(this.app || this.parent, assetOptions); | ||
} | ||
@@ -35,3 +36,3 @@ return this._options; | ||
function normalizeUserOptions(options) { | ||
function normalizeUserOptions(parent, options) { | ||
var normalizePackageConfig = require('./lib/normalize-package-config'); | ||
@@ -41,3 +42,3 @@ return Object.keys(options).map(function(packageName) { | ||
name: packageName, | ||
config: normalizePackageConfig(packageName, options[packageName]) | ||
config: normalizePackageConfig(packageName, parent, options[packageName]) | ||
}; | ||
@@ -44,0 +45,0 @@ }); |
@@ -12,9 +12,9 @@ 'use strict'; | ||
*/ | ||
module.exports = function normalizePackageConfig(name, inputConfig) { | ||
module.exports = function normalizePackageConfig(packageName, parent, inputConfig) { | ||
return function() { | ||
var config = typeof inputConfig === 'function' ? inputConfig() : clone(inputConfig); | ||
var config = typeof inputConfig === 'function' ? inputConfig.call(parent) : clone(inputConfig); | ||
if (!config || ('enabled' in config && !config.enabled)) { return; } | ||
computeTreeConfig(config, 'vendor', name); | ||
computeTreeConfig(config, 'import', name); | ||
computeTreeConfig(config, 'vendor', packageName); | ||
computeTreeConfig(config, 'import', packageName); | ||
computeTreeConfig(config, 'public', 'assets'); | ||
@@ -21,0 +21,0 @@ |
{ | ||
"name": "ember-cli-node-assets", | ||
"version": "0.2.0-beta.1", | ||
"version": "0.2.0-beta.2", | ||
"description": "Include CSS, images and other assets in your app or addon directly from node modules", | ||
@@ -5,0 +5,0 @@ "directories": { |
@@ -1,2 +0,2 @@ | ||
# ember-cli-node-assets [![Build Status](https://travis-ci.org/dfreeman/ember-cli-node-assets.svg?branch=master)](https://travis-ci.org/dfreeman/ember-cli-node-assets) | ||
# ember-cli-node-assets [![Build Status](https://travis-ci.org/dfreeman/ember-cli-node-assets.svg?branch=master)](https://travis-ci.org/dfreeman/ember-cli-node-assets) [![Ember Observer Score](https://emberobserver.com/badges/ember-cli-node-assets.svg)](https://emberobserver.com/addons/ember-cli-node-assets) | ||
@@ -16,2 +16,4 @@ Incorporate stylesheets, images, globals-style scripts and other assets directly from npm packages into your Ember app or addon. | ||
This addon allows you to add files from an npm package into an application's `public` and/or `vendor` trees at build time. Files in `public` will automatically be available in the final output in `dist/`, which is useful for assets like images or fonts. Files in `vendor` will be available to [`import()`](https://ember-cli.com/user-guide/#javascript-assets), allowing things like third party JavaScript or CSS to be built into the final output. | ||
Configuration for ember-cli-node-assets goes in the options you pass to `EmberApp` in an app's `ember-cli-build.js`, or in an `options` hash in an addon's `index.js` export. | ||
@@ -81,6 +83,6 @@ | ||
vendor: { | ||
include: ['js/widget.js'] | ||
include: ['js/widget.js', `css/${this.addonOptions.theme}.css`] | ||
}, | ||
public: { | ||
include: ['css/widget-theme-' + this.addonOptions.theme + '.css'] | ||
include: [`icons/${this.addonOptions.theme}/*.png`] | ||
} | ||
@@ -98,3 +100,7 @@ }; | ||
this.addonOptions.theme = this.addonOptions.theme || 'light'; | ||
this._super.included.apply(this, arguments); | ||
this.import('vendor/some-node-module/js/widget.js'); | ||
this.import(`vendor/some-node-module/css/${this.addonOptions.theme}.css`); | ||
} | ||
@@ -195,3 +201,3 @@ ``` | ||
The configuration below is equivalent to all other sample `slick-carousel` config in this README, except that no manual `app.import` calls are required. Notice that the `import` paths are relative to the package root, just as they are for `vendor` — the calls to `import()` will automatically be prefixed with `vendor/<destDir>/`. | ||
The configuration below is equivalent to all other sample `slick-carousel` config in this README, except that no manual `app.import` calls are required. Notice that the `import` paths are relative to the package root, just as they are for `vendor`. When ember-cli-node-assets calls `import()` for you, it will automatically prefix the paths with `vendor/<destDir>/`. | ||
@@ -198,0 +204,0 @@ ```js |
'use strict'; | ||
var sinon = require('sinon'); | ||
var chai = require('chai'), expect = chai.expect; | ||
@@ -8,3 +9,3 @@ var normalizePackageConfig = require('../lib/normalize-package-config'); | ||
it('passes through full funnel configuration untouched', function() { | ||
var optionsFn = normalizePackageConfig('test-pkg', { | ||
var optionsFn = normalizePackageConfig('test-pkg', null, { | ||
srcDir: 'joint-src-dir', | ||
@@ -51,3 +52,3 @@ destDir: 'joint-dest-dir', | ||
it('passes through arbitrary additional configuration', function() { | ||
var optionsFn = normalizePackageConfig('test-pkg', { | ||
var optionsFn = normalizePackageConfig('test-pkg', null, { | ||
vendor: { | ||
@@ -70,3 +71,4 @@ foo: 'bar', | ||
it('accepts a function returning configuration', function() { | ||
var optionsFn = normalizePackageConfig('test-pkg', function() { | ||
var parent = {}; | ||
var configFn = sinon.spy(function() { | ||
return { | ||
@@ -78,2 +80,4 @@ srcDir: 'foo', | ||
var optionsFn = normalizePackageConfig('test-pkg', parent, configFn); | ||
expect(optionsFn()).to.deep.equal({ | ||
@@ -87,2 +91,5 @@ srcDir: 'foo', | ||
}); | ||
expect(configFn.thisValues.length).to.equal(1); | ||
expect(configFn.thisValues[0]).to.equal(parent); | ||
}); | ||
@@ -92,3 +99,3 @@ | ||
it('extracts import options to be dealt with later', function() { | ||
var optionsFn = normalizePackageConfig('test-pkg', { | ||
var optionsFn = normalizePackageConfig('test-pkg', null, { | ||
import: { | ||
@@ -113,3 +120,3 @@ include: [ | ||
it('leaves non-import config alone', function() { | ||
var optionsFn = normalizePackageConfig('test-pkg', { | ||
var optionsFn = normalizePackageConfig('test-pkg', null, { | ||
vendor: { | ||
@@ -132,3 +139,3 @@ include: [{ path: 'foo.js', type: 'test' }] | ||
it('defaults to the package name for vendor/import destDir', function() { | ||
var optionsFn = normalizePackageConfig('test-pkg', { | ||
var optionsFn = normalizePackageConfig('test-pkg', null, { | ||
vendor: { | ||
@@ -157,3 +164,3 @@ include: ['foo'], | ||
it('defaults to `assets` for the public destDir', function() { | ||
var optionsFn = normalizePackageConfig('test-pkg', { | ||
var optionsFn = normalizePackageConfig('test-pkg', null, { | ||
public: { | ||
@@ -174,3 +181,3 @@ include: ['foo'] | ||
it('treats plain arrays as shorthand for `include`', function() { | ||
var optionsFn = normalizePackageConfig('test-pkg', { | ||
var optionsFn = normalizePackageConfig('test-pkg', null, { | ||
srcDir: 'joint-src-dir', | ||
@@ -205,3 +212,3 @@ destDir: 'joint-dest-dir', | ||
it('applies default srcDir/destDir options when funnel-specific ones are unspecified', function() { | ||
var optionsFn = normalizePackageConfig('test-pkg', { | ||
var optionsFn = normalizePackageConfig('test-pkg', null, { | ||
srcDir: 'joint-src-dir', | ||
@@ -250,3 +257,3 @@ destDir: 'joint-dest-dir', | ||
it('returns nothing when explicitly disabled', function() { | ||
var optionsFn = normalizePackageConfig('test-pkg', { | ||
var optionsFn = normalizePackageConfig('test-pkg', null, { | ||
enabled: false, | ||
@@ -262,3 +269,3 @@ vendor: { | ||
it('returns nothing when the input function returns nothing', function() { | ||
var optionsFn = normalizePackageConfig('test-pkg', function() {}); | ||
var optionsFn = normalizePackageConfig('test-pkg', null, function() {}); | ||
@@ -265,0 +272,0 @@ expect(optionsFn()).to.equal(undefined); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
223076
660
209
0