Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose library version to ember #24

Merged
merged 7 commits into from
Dec 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,8 @@ insert_final_newline = true
indent_style = space
indent_size = 2

[*.js]
indent_style = space
indent_size = 2

[*.hbs]
insert_final_newline = false
indent_style = space
indent_size = 2

[*.css]
indent_style = space
indent_size = 2

[*.html]
indent_style = space
indent_size = 2

[*.{diff,md}]
trim_trailing_whitespace = false
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# See https://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
Expand All @@ -13,5 +13,5 @@
/connect.lock
/coverage/*
/libpeerconnection.log
npm-debug.log
npm-debug.log*
testem.log
32 changes: 32 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"predef": [
"document",
"window",
"-Promise"
],
"browser": true,
"boss": true,
"curly": true,
"debug": false,
"devel": true,
"eqeqeq": true,
"evil": true,
"forin": false,
"immed": false,
"laxbreak": false,
"newcap": true,
"noarg": true,
"noempty": false,
"nonew": false,
"nomen": false,
"onevar": false,
"plusplus": false,
"regexp": false,
"undef": true,
"sub": true,
"strict": false,
"white": false,
"eqnull": true,
"esversion": 6,
"unused": true
}
14 changes: 9 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
---
language: node_js
node_js:
- "4"
- "stable"

sudo: false

cache:
directories:
- node_modules
- $HOME/.npm
- $HOME/.cache # includes bowers cache

env:
- EMBER_TRY_SCENARIO=default
- EMBER_TRY_SCENARIO=ember-1.13
# we recommend testing LTS's and latest stable release (bonus points to beta/canary)
- EMBER_TRY_SCENARIO=ember-lts-2.4
- EMBER_TRY_SCENARIO=ember-lts-2.8
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
Expand All @@ -25,7 +27,9 @@ before_install:
- if [[ `npm -v` != 3* ]]; then npm i -g npm@3; fi
- npm config set spin false
- npm install -g bower
- bower --version
- npm install phantomjs-prebuilt
- node_modules/phantomjs-prebuilt/bin/phantomjs --version

install:
- npm install
Expand All @@ -34,4 +38,4 @@ install:
script:
# Usually, it's ok to finish the test scenario without reverting
# to the addon's original dependency state, skipping "cleanup".
- ember try $EMBER_TRY_SCENARIO test --skip-cleanup
- ember try:one $EMBER_TRY_SCENARIO test --skip-cleanup
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# `ember-d3` Changelog

### 0.3.1 (December 8, 2016)

- Refctored internal recasting Funnel.
- Stopped logging D3 version number to stdout.
- Register D3 version number with `Ember.libraries` so it's visiable in Ember Inspector.

### 0.3.0 (October 17, 2016)

- [BREAKING] - Removed D3 v3.x support (See [v3 branch](https://github.com/brzpegasus/ember-d3/tree/v3)),
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ D3 modules are loaded from NPM as ES2015 modules. It includes `d3-shape` and all
If you need a specified d3 version, add this to your project:

```
npm install --save-dev d3@4.1.1
npm install --save-dev d3@4.2.7
```

## Example usage:
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ember-d3",
"dependencies": {
"ember": "~2.6.0",
"ember-cli-shims": "0.1.1"
"ember": "~2.10.0",
"ember-cli-shims": "0.1.3"
}
}
17 changes: 11 additions & 6 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
/* jshint node:true*/
/*jshint node:true*/
module.exports = {
scenarios: [
{
name: 'default',
name: 'ember-lts-2.4',
bower: {
dependencies: { }
dependencies: {
'ember': 'components/ember#lts-2-4'
},
resolutions: {
'ember': 'lts-2-4'
}
}
},
{
name: 'ember-1.13',
name: 'ember-lts-2.8',
bower: {
dependencies: {
'ember': '~1.13.0'
'ember': 'components/ember#lts-2-8'
},
resolutions: {
'ember': '~1.13.0'
'ember': 'lts-2-8'
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion config/environment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* jshint node:true*/
/*jshint node:true*/
'use strict';

module.exports = function(/* environment, appConfig */) {
Expand Down
20 changes: 15 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var path = require('path');
var rename = require('broccoli-stew').rename;
var AMDDefineFilter = require('./lib/amd-define-filter');
var RecastFilter = require('./lib/recast-filter');
var rewriteAMDFunction = require('./lib/rewrite-amd-definition');
var replaceVersionString = require('./lib/replace-version-string');
var d3DepsForPackage = require('./lib/d3-deps-for-package');
// var pathToD3Source = require('./lib/path-to-d3-module-src');
var d3Version = require('./lib/d3-version');
var inclusionFilter = require('./lib/inclusion-filter');
var exclusionFilter = require('./lib/exclusion-filter');

Expand Down Expand Up @@ -65,8 +67,10 @@ module.exports = {
*/
var _this = this;
this.d3Modules.forEach(function(pkg) {
_this.import(path.join('vendor', pkg.name, `${pkg.name }.js`));
_this.import(path.join('vendor', pkg.name, `${ pkg.name }.js`));
});

app.import(path.join('vendor', 'ember-d3', 'register-d3-version.js'));
},

getD3Modules(config) {
Expand All @@ -87,7 +91,13 @@ module.exports = {
var trees = [];

if (tree) {
trees.push(tree);
let versionTree = new RecastFilter(tree, null, replaceVersionString, {
version: d3Version('d3', this.parent.nodeModulesPath)
});

trees.push(rename(versionTree, function() {
return path.join('ember-d3', 'register-d3-version.js');
}));
}

this.d3Modules.forEach(function(pkg) {
Expand All @@ -101,7 +111,7 @@ module.exports = {
annotation: `Funnel: D3 Source [${ pkg.name }]`
});

var srcTree = new AMDDefineFilter(tree, pkg.name);
var srcTree = new RecastFilter(tree, pkg.name, rewriteAMDFunction);
trees.push(rename(srcTree, function() {
return `/${ pkg.name }/${ pkg.name }.js`;
}));
Expand Down
4 changes: 1 addition & 3 deletions lib/d3-deps-for-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ module.exports = function(packageName, nodeModulesPath, ui) {

var pkg = require(pathToPackageDefinition);

ui.writeInfoLine(`Using ${pkg.name}@${pkg.version}`);

// TODO: Generalize use of d3 and externalize predicate
var dependencyNames = Object.keys(pkg.dependencies).filter(isD3Dependency);

Expand All @@ -57,7 +55,7 @@ module.exports = function(packageName, nodeModulesPath, ui) {
}

// Import existing builds from node d3 packages, which are UMD packaged.
var packageBuildPath = path.join('build', `${packageName }.js`);
var packageBuildPath = path.join('build', `${ packageName }.js`);

return {
name: packageName,
Expand Down
24 changes: 24 additions & 0 deletions lib/d3-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var path = require('path');
var fs = require('fs');
var lookupPackage = require('./lookup-package-build');

function pickPath(paths) {
return paths.filter(function(p) {
try {
fs.statSync(p).isFile();
return true;
} catch(err) {
return false;
}
})[0];
}

module.exports = function(packageName, nodeModulesPath) {
var pathToPackageDefinition = pickPath([
path.join(nodeModulesPath, packageName, 'package.json'),
path.join(lookupPackage(packageName), 'package.json')
]);

var pkg = require(pathToPackageDefinition);
return pkg.version;
};
19 changes: 10 additions & 9 deletions lib/amd-define-filter.js → lib/recast-filter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint "no-var":off, "ember-suave/prefer-destructuring":off */

var Filter = require('broccoli-filter');
var rewriteAMDFunction = require('./rewrite-amd-definition');

/**
/*
* Loading an actual AMD package using Ember's loader.js
* requires some hacks. Basically proper AMD packages check for define.amd, which
* loader.js doesn't define (because reasons).
Expand All @@ -12,18 +11,20 @@ var rewriteAMDFunction = require('./rewrite-amd-definition');
* package does.
*/

function AMDDefineFilter(inputNode, packageName, options) {
function RecastFilter(inputNode, packageName, recastFn, options) {
options = options || {};
Filter.call(this, inputNode, {
annotation: options.annotation || `Rewriting package: ${ packageName}`
annotation: options.annotation || `Recasting package: ${ packageName}`
});
this.packageName = packageName;
this.recastFn = recastFn;
this.options = options;
}

AMDDefineFilter.prototype = Object.create(Filter.prototype);
AMDDefineFilter.prototype.constructor = AMDDefineFilter;
AMDDefineFilter.prototype.processString = function(code) {
return rewriteAMDFunction(code, this.packageName);
RecastFilter.prototype = Object.create(Filter.prototype);
RecastFilter.prototype.constructor = RecastFilter;
RecastFilter.prototype.processString = function(code) {
return this.recastFn.apply(this, [code, this.packageName, this.options]);
};

module.exports = AMDDefineFilter;
module.exports = RecastFilter;
22 changes: 22 additions & 0 deletions lib/replace-version-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint "no-var":off, "ember-suave/prefer-destructuring":off */

var recast = require('recast');
var types = recast.types;
var b = recast.types.builders;

module.exports = function replaceVersionString(code, packageName, options) {
let version = options.version;

var ast = recast.parse(code);
types.visit(ast, {
visitLiteral(path) {
if (path.node.value === '<D3_VERSION>') {
return b.literal(version);
} else {
this.traverse(path);
}
}
});

return recast.print(ast).code;
};
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-d3",
"version": "0.2.0",
"version": "0.3.0",
"description": "Ember CLI addon to include D3 as an ES2015 module in your app.",
"directories": {
"doc": "doc",
Expand All @@ -13,7 +13,8 @@
},
"repository": "https://github.com/brzpegasus/ember-d3",
"engines": {
"node": ">= 4.0.0"
"node": ">= 4.0.0",
"npm":">= 3.0.0"
},
"author": "Estelle DeBlois",
"contributors": [
Expand All @@ -23,16 +24,16 @@
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.4.2",
"ember-ajax": "^2.0.1",
"ember-cli": "^2.6.3",
"ember-cli-app-version": "^1.0.0",
"ember-cli-dependency-checker": "^1.2.0",
"ember-ajax": "^2.4.1",
"ember-cli": "^2.10.0",
"ember-cli-app-version": "^2.0.0",
"ember-cli-dependency-checker": "^1.3.0",
"ember-cli-eslint": "3.0.0",
"ember-cli-htmlbars": "^1.0.5",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-inject-live-reload": "^1.4.0",
"ember-cli-qunit": "^2.0.0",
"ember-cli-release": "1.0.0-beta.1",
"ember-cli-htmlbars": "^1.0.10",
"ember-cli-htmlbars-inline-precompile": "^0.3.3",
"ember-cli-inject-live-reload": "^1.4.1",
"ember-cli-qunit": "^3.0.1",
"ember-cli-release": "^1.0.0-beta.1",
"ember-cli-sri": "^2.1.0",
"ember-cli-test-loader": "1.1.0",
"ember-cli-uglify": "^1.2.0",
Expand All @@ -41,7 +42,7 @@
"ember-load-initializers": "^0.5.1",
"ember-resolver": "^2.0.3",
"eslint-plugin-ember-suave": "^1.0.0",
"loader.js": "^4.0.1"
"loader.js": "^4.0.10"
},
"keywords": [
"ember-addon",
Expand Down
Loading