Permalink
Browse files

build: update the build system

- use yarn instead of npm
- add TravisCI configuration
- upgrade development dependencies
- fix issues revealed by newer eslint
  • Loading branch information...
eventualbuddha committed May 19, 2016
1 parent 8b8cdad commit eab2faa2aeb7d1846b06d33d522b6f5d7e3b5885
View
@@ -1,3 +1,3 @@
{
"presets": ["es2015"]
"presets": ["env"]
}
View
@@ -1,9 +1,17 @@
{
"extends": "eslint:recommended",
"extends": "prettier",
"plugins": [
"prettier"
],
"env": {
"es6": true
},
"parserOptions": {
"sourceType": "module"
},
"rules": {
"prettier/prettier": ["error", {
"singleQuote": true
}]
}
}
View
@@ -2,3 +2,4 @@ lib
node_modules
*.map
dist
*.log
View
1 .npmrc
@@ -0,0 +1 @@
registry = "https://registry.yarnpkg.com/"
View
@@ -0,0 +1,26 @@
sudo: false
language: node_js
cache:
yarn: true
directories:
- node_modules
notifications:
email: false
node_js:
- '8'
- '6'
- '4'
before_install:
- yarn global add greenkeeper-lockfile@1
before_script:
- greenkeeper-lockfile-update
after_script:
- greenkeeper-lockfile-upload
after_success:
- 'curl -Lo travis_after_all.py https://git.io/travis_after_all'
- python travis_after_all.py
- export $(cat .to_export_back) &> /dev/null
- semantic-release pre && ./script/build && npm publish && semantic-release post
branches:
except:
- /^v\d+\.\d+\.\d+$/
View
@@ -21,18 +21,21 @@
"author": "Square, Inc.",
"license": "Apache-2.0",
"devDependencies": {
"babel": "^6.5.2",
"babel-preset-es2015": "^6.9.0",
"babel-preset-es2015-rollup": "^1.1.1",
"babel-register": "^6.9.0",
"babelrc-rollup": "^1.0.0",
"eslint": "^2.10.2",
"babel-core": "^6.26.0",
"babel-preset-env": "^1.6.0",
"babel-preset-es2015": "^6.24.1",
"babel-register": "^6.26.0",
"eslint": "^4.7.2",
"eslint-config-prettier": "^2.6.0",
"eslint-plugin-prettier": "^2.3.1",
"file-size": "^1.0.0",
"gzip-size": "^3.0.0",
"mocha": "^2.4.5",
"rollup": "^0.26.3",
"rollup-plugin-babel": "^2.4.0",
"uglify-js": "^2.6.2"
"gzip-size": "^4.0.0",
"mocha": "^3.5.3",
"prettier": "^1.7.0",
"rollup": "^0.50.0",
"rollup-plugin-babel": "^3.0.2",
"semantic-release": "^8.0.3",
"uglify-js": "^3.1.2"
},
"files": [
"dist"
View
@@ -4,38 +4,56 @@
let rollup = require('rollup').rollup;
let babel = require('rollup-plugin-babel');
let babelrc = require('babelrc-rollup').default;
let filesize = require('file-size');
let gzipSize = require('gzip-size').sync;
let stat = require('fs').statSync;
let readFileSync = require('fs').readFileSync;
let minify = require('uglify-js').minify;
rollup({
entry: 'src/lgtm.js',
plugins: [babel(babelrc())]
}).then(bundle => {
return Promise.all([
bundle.write({
dest: 'dist/lgtm.js',
format: 'umd',
moduleName: 'LGTM',
sourceMap: true
}),
bundle.write({
dest: 'dist/lgtm.mjs',
format: 'es6',
sourceMap: true
input: 'src/lgtm.js',
plugins: [
babel({
babelrc: false,
presets: [
[
'env',
{
targets: ['last 2 versions', 'ie 11'],
modules: false
}
]
]
})
]);
}).then(() => {
printFileInfo('dist/lgtm.js');
}).catch(err => console.error(err.stack));
]
})
.then(bundle => {
return Promise.all([
bundle.write({
file: 'dist/lgtm.js',
format: 'umd',
name: 'LGTM',
sourcemap: true
}),
bundle.write({
file: 'dist/lgtm.mjs',
format: 'es',
sourcemap: true
})
]);
})
.then(() => {
printFileInfo('dist/lgtm.js');
})
.catch(err => console.error(err.stack));
function printFileInfo(path) {
let size = stat(path).size;
let minified = minify(path, { acorn: true }).code;
let code = readFileSync(path);
let minified = minify(code.toString('utf8'));
console.log(
`${path} (raw: ${filesize(size).human('si')} / min: ${filesize(minified.length).human('si')} ` +
`/ min+gzip: ${filesize(gzipSize(minified)).human('si')})`
`${path} (raw: ${filesize(code.length).human('si')} / min: ${filesize(
minified.code.length
).human('si')} ` +
`/ min+gzip: ${filesize(gzipSize(minified.code)).human('si')})`
);
}
View
@@ -2,7 +2,13 @@ import ObjectValidator from './lgtm/object_validator.js';
import ValidatorBuilder from './lgtm/validator_builder.js';
import config from './lgtm/config.js';
import { get } from './lgtm/utils.js';
import { present, checkEmail, checkMinLength, checkMaxLength, register as core_register } from './lgtm/helpers/core.js';
import {
present,
checkEmail,
checkMinLength,
checkMaxLength,
register as core_register
} from './lgtm/helpers/core.js';
core_register();
@@ -71,8 +77,8 @@ function getPromise() {
configure('Promise', RSVP.Promise);
warn(
`Implicitly using RSVP.Promise. This will be removed in LGTM 2.0. ` +
`Instead, use 'LGTM.configure("Promise", RSVP.Promise)' to ` +
`continue using RSVP promises.`
`Instead, use 'LGTM.configure("Promise", RSVP.Promise)' to ` +
`continue using RSVP promises.`
);
return RSVP.Promise;
}
@@ -83,8 +89,8 @@ function getPromise() {
configure('Promise', Promise);
warn(
`Implicitly using require("rsvp").Promise. This will be removed in LGTM 2.0. ` +
`Instead, use 'LGTM.configure("Promise", require("rsvp").Promise)' to ` +
`continue using RSVP promises.`
`Instead, use 'LGTM.configure("Promise", require("rsvp").Promise)' to ` +
`continue using RSVP promises.`
);
return Promise;
} catch (err) {
@@ -99,7 +105,7 @@ function getPromise() {
throw new Error(
`'Promise' could not be found. Configure LGTM with your promise library using ` +
`e.g. 'LGTM.configure("Promise", RSVP.Promise)'.`
`e.g. 'LGTM.configure("Promise", RSVP.Promise)'.`
);
}
@@ -112,8 +118,8 @@ configure('get', (object, property) => {
configure('get', get);
warn(
`Implicitly using 'get' implementation that uses a 'get' method when available. ` +
`This will be removed in LGTM 2.0. Instead, use e.g. 'LGTM.configure("get", Ember.get)' ` +
`if you rely on this behavior.`
`This will be removed in LGTM 2.0. Instead, use e.g. 'LGTM.configure("get", Ember.get)' ` +
`if you rely on this behavior.`
);
return get(object, property);
});
View
@@ -10,7 +10,7 @@ function present(value) {
const STRICT_CHARS = /^[\x20-\x7F]*$/;
// http://stackoverflow.com/a/46181/11236
const EMAIL = /^(([^<>()\[\]\\.,;:\s@\"]+(\.[^<>()\[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
const EMAIL = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
function checkEmail(options) {
if (!options) {
@@ -2,13 +2,13 @@ import config from './config.js';
import { all, resolve, contains, keys, uniq } from './utils.js';
function ObjectValidator() {
this._validations = {};
this._validations = {};
this._dependencies = {};
}
ObjectValidator.prototype = {
_validations : null,
_dependencies : null,
_validations: null,
_dependencies: null,
addValidation(attr, fn, message) {
let list = this._validations[attr];
@@ -40,11 +40,7 @@ ObjectValidator.prototype = {
},
attributes() {
return uniq(
keys(this._validations).concat(
keys(this._dependencies)
)
);
return uniq(keys(this._validations).concat(keys(this._dependencies)));
},
validate(/* object, attributes..., callback */) {
@@ -67,7 +63,8 @@ ObjectValidator.prototype = {
for (let i = 0; i < attributes.length; i++) {
let attr = attributes[i];
validationPromises = validationPromises.concat(
this._validateAttribute(object, attr, alreadyValidating));
this._validateAttribute(object, attr, alreadyValidating)
);
}
let promise = all(validationPromises).then(
@@ -83,39 +80,42 @@ ObjectValidator.prototype = {
callback(err);
}
throw err;
});
}
);
if (!callback) {
return promise;
}
},
_validateAttribute(object, attr, alreadyValidating) {
let value = config.get(object, attr);
let value = config.get(object, attr);
let validations = this._validations[attr];
let results = [];
let results = [];
if (validations) {
validations.forEach(function(pair) {
let fn = pair[0];
let fn = pair[0];
let message = pair[1];
let promise = resolve()
.then(() => fn(value, attr, object))
.then(isValid => [ attr, isValid ? null : message ]);
.then(isValid => [attr, isValid ? null : message]);
results.push(promise);
});
} else if (contains(this.attributes(), attr)) {
results.push([ attr, null ]);
results.push([attr, null]);
}
let dependents = this._getDependentsFor(attr);
for (let i = 0; i < dependents.length; i++) {
let dependent = dependents[i];
if (alreadyValidating.indexOf(dependent) < 0) {
alreadyValidating.push(dependent);
results = results.concat(this._validateAttribute(object, dependent, alreadyValidating));
results = results.concat(
this._validateAttribute(object, dependent, alreadyValidating)
);
}
}
@@ -124,12 +124,14 @@ ObjectValidator.prototype = {
_collectResults(results) {
let result = {
valid : true,
errors : {}
valid: true,
errors: {}
};
for (let i = 0; i < results.length; i++) {
if (!results[i]) { continue; }
if (!results[i]) {
continue;
}
let attr = results[i][0];
let message = results[i][1];
View
@@ -27,7 +27,6 @@ function keys(object) {
export { forEach, keys };
/**
* Property access
*/
@@ -49,7 +48,6 @@ function getProperties(object, properties) {
export { get, getProperties };
/**
* Array manipulation
*/
@@ -73,7 +71,6 @@ function uniq(array) {
export { contains, uniq };
/**
* Promises
*/
Oops, something went wrong.

0 comments on commit eab2faa

Please sign in to comment.