Skip to content

Commit

Permalink
Use babel for older node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
1602 committed Jul 26, 2016
1 parent d139a48 commit c4f16b4
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 33 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "presets": ["es2015"] }
6 changes: 5 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"node": true,
"browser": false
"browser": false,
"es6": true
},
"ecmaFeatures": {
"arrowFunctions": true,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ docs/man
npm-debug.log
.idea
.coveralls.yml
build
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ JS_FILES = $(shell find . -type f -name "*.js" \

check:
@$(JSHINT) $(JS_FILES)
test: check
test:
$(TESTER) $(OPTS) $(TESTS)
test-verbose:
$(TESTER) $(OPTS) --reporter spec $(TESTS)
Expand Down Expand Up @@ -51,6 +51,7 @@ man: $(MAN_DOCS)
html: $(HTML_DOCS)

build: man
babel -d build/ $(shell find ./lib/ -type f -name "*.js") *.js

web: html
cp ./docs/html/* ../docs
Expand Down
2 changes: 2 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ general:

test:
override:
- nvm use 0.10.26 && npm run test-ci-babel
- nvm use 4.4.7 && npm run test-ci-babel
- nvm use 6.3.0 && npm run test-ci
- npm i coveralls && export COVERALLS_GIT_COMMIT=`git rev-parse HEAD` && cat ./coverage/lcov.info | coveralls
52 changes: 31 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
var fs = require('fs');
var path = require('path');
'use strict';

var Schema = exports.Schema = require('./lib/schema').Schema;
exports.AbstractClass = require('./lib/model.js');
const { Schema } = require('./lib/schema');
const AbstractClass = require('./lib/model.js');

var baseSQL = './lib/sql';
module.exports = {

exports.__defineGetter__('BaseSQL', function () {
return require(baseSQL);
});
Schema,

exports.loadSchema = function(filename, settings, compound) {
return require('./legacy-compound-schema-loader')(filename, settings, compound);
};
AbstractClass,

exports.init = function (compound) {
return require('./legacy-compound-init')(compound);
};
// deprecated api
loadSchema: function(filename, settings, compound) {
return require('./legacy-compound-schema-loader')(Schema, filename, settings, compound);
},

init: function init(compound) {
return require('./legacy-compound-init')(compound, Schema, AbstractClass);
},

get BaseSQL() {
return require('./lib/sql');
},

exports.__defineGetter__('version', function () {
return JSON.parse(fs.readFileSync(__dirname + '/package.json')).version;
});
get version() {
return require(
process.versions.node >= '6'
? './package.json'
: '../package.json'
).version;
},

get test() {
return require('./test/common_test');
}

};

var commonTest = './test/common_test';
exports.__defineGetter__('test', function () {
return require(commonTest);
});
11 changes: 7 additions & 4 deletions legacy-compound-init.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
'use strict';

module.exports = function(compound) {
var loadSchema = require('./legacy-compound-schema-loader');

module.exports = function init(compound, Schema, AbstractClass) {

if (global.railway) {
global.railway.orm = exports;
} else {
compound.orm = {
Schema: exports.Schema,
AbstractClass: exports.AbstractClass
Schema,
AbstractClass
};
if (compound.app.enabled('noeval schema')) {
compound.orm.schema = exports.loadSchema(
compound.orm.schema = loadSchema(
Schema,
compound.root + '/db/schema',
compound.app.get('database'),
compound
Expand Down
2 changes: 1 addition & 1 deletion legacy-compound-schema-loader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

module.exports = function(filename, settings, compound) {
module.exports = function(Schema, filename, settings, compound) {
var schema = [];
var definitions = require(filename);
Object.keys(definitions).forEach(function(k) {
Expand Down
9 changes: 7 additions & 2 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ module.exports = AbstractClass;
var setImmediate = global.setImmediate || process.nextTick;
var util = require('util');
var assert = require('assert');
var validations = require('./validations.js');
var ValidationError = validations.ValidationError;
const { ValidationError } = require('./validations.js');
var List = require('./list.js');
var when = require('when');
require('./hooks.js');
Expand Down Expand Up @@ -456,6 +455,12 @@ AbstractClass.fetch = function fetch(id) {
});
};

AbstractClass.expand = function(object) {
return Object.assign({}, object, {
pets: [ {} ]
});
};

/**
* Find all instances of Model, matched by query
* make sure you have marked as `index: true` fields for filter or sort
Expand Down
11 changes: 11 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var isNodeSix = process.versions.node >= '6';

if (!isNodeSix) {
global.Promise = require('when').Promise;
}

module.exports = isNodeSix
? require('./index')
: require('./build/index');


11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@
"type": "git",
"url": "https://github.com/1602/jugglingdb"
},
"main": "index.js",
"main": "main.js",
"scripts": {
"test": "make test",
"test": "mocha --bail --reporter spec --check-leaks test/",
"test-babel": "mocha --compilers js:babel-register --bail --reporter spec --check-leaks test/",
"prepublish": "make build",
"test-coverage": "istanbul cover node_modules/.bin/_mocha -- --reporter landing --no-exit --check-leaks test/",
"test-ci": "eslint lib/ && istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
"test-ci-babel": "node_modules/mocha/bin/_mocha --compilers js:babel-register --reporter spec --check-leaks test/"
"test-ci-native": "eslint lib/ && istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --compilers js:babel-register --check-leaks test/"
},
"man": [
"./docs/man/jugglingdb.3",
Expand All @@ -69,6 +71,9 @@
"node >= 0.6"
],
"devDependencies": {
"babel-cli": "^6.11.4",
"babel-preset-es2015": "^6.9.0",
"babel-register": "^6.11.5",
"eslint": "^3.1.1",
"expect": "^1.20.2",
"istanbul": "^0.4.4",
Expand Down

0 comments on commit c4f16b4

Please sign in to comment.