improved gulpfile

This commit is contained in:
Kevin Jahns 2015-06-16 14:36:00 +02:00
parent 159f37474d
commit f99853529e
12 changed files with 117 additions and 71 deletions

View File

@ -1,5 +1,8 @@
[ignore]
./build_node
./build
./build_test
./y.js
[include]
./src

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
node_modules
bower_components
build
build_test
.directory
.c9
.codio

1
.jshintignore Normal file
View File

@ -0,0 +1 @@
node_modules

10
.jshintrc Normal file
View File

@ -0,0 +1,10 @@
{
"node": true,
"curly": true,
"latedef": true,
"quotmark": true,
"undef": true,
"unused": true,
"trailing": true
}

6
.validate.json Normal file
View File

@ -0,0 +1,6 @@
{
"scripts": {
"lint": "jshint ."
},
"pre-commit": ["lint", "validate", "test"]
}

View File

@ -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"]);

View File

@ -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"
}
}

View File

@ -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");

View File

@ -1,4 +1,4 @@
/* @flow */
/* global Buffer */
var buffer = new Buffer(3);
export default Buffer;

View File

@ -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);
});
});

32
y.js
View File

@ -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);
});
});
"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

1
y.js.map Normal file
View File

@ -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/"}