diff --git a/.flowconfig b/.flowconfig index cc0fe3b3..35dd2d8c 100644 --- a/.flowconfig +++ b/.flowconfig @@ -1,5 +1,8 @@ [ignore] ./build_node +./build +./build_test +./y.js [include] ./src diff --git a/.gitignore b/.gitignore index f4b37d9d..19217bd7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ node_modules bower_components build +build_test .directory .c9 .codio diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 00000000..3c3629e6 --- /dev/null +++ b/.jshintignore @@ -0,0 +1 @@ +node_modules diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..997b3f7d --- /dev/null +++ b/.jshintrc @@ -0,0 +1,10 @@ +{ + "node": true, + + "curly": true, + "latedef": true, + "quotmark": true, + "undef": true, + "unused": true, + "trailing": true +} diff --git a/.validate.json b/.validate.json new file mode 100644 index 00000000..b2f964be --- /dev/null +++ b/.validate.json @@ -0,0 +1,6 @@ +{ + "scripts": { + "lint": "jshint ." + }, + "pre-commit": ["lint", "validate", "test"] +} diff --git a/gulpfile.js b/gulpfile.js index a6e7f27d..b6b4d97e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,5 +1,42 @@ /*eslint-env node */ +/** Gulp Commands + + gulp command* [--export ModuleType] [--name ModuleName] [--testport TestPort] + + Module name (ModuleName): + Compile this to "y.js" (default) + + Supported module types (ModuleType): + - amd + - amdStrict + - common + - commonStrict + - ignore (default) + - system + - umd + - umdStrict + + Test port (TestPort): + Serve the tests on port 8888 (default) + + Commands: + - build: + Build this library + - develop: + Watch the ./src directory. + Builds and tests the library on changes. + Starts an http-server and serves the test suite on http://127.0.0.1:8888. + - build_test: + Builds the test suite + - test: + Test this library + - lint: + Lint this library. A successful lint is required for committing to this repository! + +*/ + + var gulp = require("gulp"); var sourcemaps = require("gulp-sourcemaps"); var babel = require("gulp-babel"); @@ -7,71 +44,74 @@ var uglify = require("gulp-uglify"); var minimist = require("minimist"); var eslint = require("gulp-eslint"); var jasmine = require("gulp-jasmine"); +var jasmineBrowser = require("gulp-jasmine-browser"); var concat = require("gulp-concat"); - -var moduleName = "y.js"; +var watch = require("gulp-watch"); var files = { y: ["src/**/*.js"], lint: ["src/**/*.js", "gulpfile.js"], - tests: ["tests/**/*.js"] + tests: ["tests/**/*.js"], + build_test: ["build_test/y.js"] }; var options = minimist(process.argv.slice(2), { - string: "export", - default: { export: "ignore" } + string: ["export", "name", "testport"], + default: { + export: "ignore", + name: "y.js", + testport: "8888" + } }); -gulp.task("test", function () { +gulp.task("build_test", function () { return gulp.src(files.y.concat(files.tests)) .pipe(sourcemaps.init()) - .pipe(concat(moduleName)) - .pipe(babel({ - loose: "all", - modules: "common" - })) - .pipe(uglify()) - .pipe(gulp.dest("build")) - .pipe(jasmine({ - verbose: true, - includeStuckTrace: true - })) - .pipe(sourcemaps.write(".")); -}); - -gulp.task("build_browser", function () { - return gulp.src(files.y) - .pipe(sourcemaps.init()) + .pipe(concat(options.name)) .pipe(babel({ loose: "all", modules: "ignore" })) - .pipe(concat(moduleName)) + .pipe(uglify()) + .pipe(sourcemaps.write()) + .pipe(gulp.dest("build_test")); +}); + +gulp.task("build", function () { + return gulp.src(files.y) + .pipe(sourcemaps.init()) + .pipe(concat(options.name)) + .pipe(babel({ + loose: "all", + modules: options.export + })) .pipe(uglify()) .pipe(sourcemaps.write(".")) .pipe(gulp.dest(".")); }); -gulp.task("build_node", function(){ - gulp.src(files.y) - .pipe(sourcemaps.init()) - .pipe(babel({ - loose: "all", - modules: "common" - })) - .pipe(sourcemaps.write(".")) - .pipe(gulp.dest("./build_node")); +gulp.task("test", ["build_test"], function () { + return gulp.src(files.build_test) + .pipe(jasmine({ + verbose: true, + includeStuckTrace: true + })); }); gulp.task("lint", function(){ - return gulp.y(files.lint) + return gulp.src(files.lint) .pipe(eslint()) .pipe(eslint.format()) .pipe(eslint.failOnError()); }); -gulp.task("develop", function(){ - return gulp.watch(files.src, ["build"]); +gulp.task("develop", ["build_test", "build"], function(){ + gulp.src(files.build_test) + .pipe(watch(files.build_test)) + .pipe(jasmineBrowser.specRunner()) + .pipe(jasmineBrowser.server({port: options.testport})); + gulp.watch(files.src, ["build_test", "build"]); + return gulp.watch(files.build_test, ["test"]); }); gulp.task("default", ["build"]); diff --git a/package.json b/package.json index 4f9a9929..2742e4fc 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,13 @@ "description": "A framework for real-time p2p shared editing on arbitrary complex data types", "main": "y.js", "scripts": { - "test": "gulp test" + "test": "gulp test", + "lint": "gulp lint" }, + "pre-commit": [ + "lint", + "test" + ], "repository": { "type": "git", "url": "https://github.com/y-js/yjs.git" @@ -34,8 +39,11 @@ "gulp-concat": "^2.5.2", "gulp-eslint": "^0.13.2", "gulp-jasmine": "^2.0.1", + "gulp-jasmine-browser": "^0.1.3", "gulp-sourcemaps": "^1.5.2", "gulp-uglify": "^1.2.0", - "minimist": "^1.1.1" + "gulp-watch": "^4.2.4", + "minimist": "^1.1.1", + "precommit-hook": "^2.0.1" } } diff --git a/src/Buffer.js b/src/Buffer.js index e4ce420a..62b89229 100644 --- a/src/Buffer.js +++ b/src/Buffer.js @@ -1,14 +1,18 @@ /* @flow */ +/* global Buffer */ -class Buffer { +class Buffer { //eslint-disable-line no-unused-vars i : number; constructor () { this.i = 4; } } + function add(x : string){ return x + 4; } + add("5"); +add("6"); diff --git a/src/y.js b/src/y.js index 8c1dc3e6..2f989f89 100644 --- a/src/y.js +++ b/src/y.js @@ -1,4 +1,4 @@ /* @flow */ /* global Buffer */ -var buffer = new Buffer(3); +export default Buffer; diff --git a/tests/Buffer.js b/tests/Buffer.js index 88bb0d5a..87454745 100644 --- a/tests/Buffer.js +++ b/tests/Buffer.js @@ -3,6 +3,6 @@ describe("A suite", function() { it("contains spec with an expectation", function() { - expect(new Buffer(3)).toBe(true); + expect(true).toBe(true); }); }); diff --git a/y.js b/y.js index 8ab374a4..7638fbb7 100644 --- a/y.js +++ b/y.js @@ -1,30 +1,2 @@ -/* @flow */ - -"use strict"; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var Buffer = function Buffer() { - _classCallCheck(this, Buffer); -}; - -function add(x) { - return x + 4; -} - -add("5"); - -/* @flow */ -/* global Buffer */ - -var buffer = new Buffer(3); - -/* @flow */ -/*eslint-env node, jasmine */ - -describe("A suite", function () { - it("contains spec with an expectation", function () { - throw new Error("dtrn"); - expect(new Buffer()).toBe(true); - }); -}); \ No newline at end of file +"use strict";function _classCallCheck(e,a){if(!(e instanceof a))throw new TypeError("Cannot call a class as a function")}function add(e){return e+4}exports.__esModule=!0;var Buffer=function e(){_classCallCheck(this,e),this.i=4};add("5"),add("6");var buffer=new Buffer(3);exports["default"]=Buffer,module.exports=exports["default"]; +//# sourceMappingURL=y.js.map \ No newline at end of file diff --git a/y.js.map b/y.js.map new file mode 100644 index 00000000..2f10700d --- /dev/null +++ b/y.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["y.js","Buffer.js"],"names":["_classCallCheck","instance","Constructor","TypeError","add","x","exports","__esModule","Buffer","this","i","buffer","module"],"mappings":"AAEA,YAIA,SAASA,iBAAgBC,EAAUC,GAAe,KAAMD,YAAoBC,IAAgB,KAAM,IAAIC,WAAU,qCCIhH,QAAAC,KAAAC,GACA,MAAAA,GAAA,EDPAC,QAAQC,YAAa,CAIrB,ICNAC,QAEA,QAFAA,KDOER,gBAAgBS,KCPlBD,GAGAC,KAAAC,EAAA,EAUAN,KAAA,KACAA,IAAA,IDbA,IAAAO,QAAA,GAAAH,QAAA,EAuBAF,SAAQ,WArBRE,OAsBAI,OAAON,QAAUA,QAAQ","file":"y.js","sourcesContent":["/* @flow */\n/* global Buffer */\n\nvar buffer = new Buffer(3);\n\nexport default Buffer\n","/* @flow */\n\nclass Buffer {\n i : number;\n constructor () {\n this.i = 4;\n }\n}\n\n\nfunction add(x : string){\n return x + 4;\n}\n\n\nadd(\"5\");\nadd(\"6\");\n"],"sourceRoot":"/source/"} \ No newline at end of file