fixed some bugs & linted & prettyfied gulpfile
This commit is contained in:
parent
82b3e50d49
commit
2a601ac6f6
117
gulpfile.js
117
gulpfile.js
@ -30,7 +30,7 @@
|
|||||||
Commands:
|
Commands:
|
||||||
- build:
|
- build:
|
||||||
Build this library
|
Build this library
|
||||||
- develop:
|
- dev:
|
||||||
Watch the ./src directory.
|
Watch the ./src directory.
|
||||||
Builds and specs the library on changes.
|
Builds and specs the library on changes.
|
||||||
Starts an http-server and serves the test suite on http://127.0.0.1:8888.
|
Starts an http-server and serves the test suite on http://127.0.0.1:8888.
|
||||||
@ -49,11 +49,6 @@ var jasmine = require('gulp-jasmine')
|
|||||||
var jasmineBrowser = require('gulp-jasmine-browser')
|
var jasmineBrowser = require('gulp-jasmine-browser')
|
||||||
var concat = require('gulp-concat')
|
var concat = require('gulp-concat')
|
||||||
var watch = require('gulp-watch')
|
var watch = require('gulp-watch')
|
||||||
var ignore = require('gulp-ignore')
|
|
||||||
|
|
||||||
var polyfills = [
|
|
||||||
'./node_modules/gulp-babel/node_modules/babel-core/node_modules/regenerator/runtime.js'
|
|
||||||
]
|
|
||||||
|
|
||||||
var options = minimist(process.argv.slice(2), {
|
var options = minimist(process.argv.slice(2), {
|
||||||
string: ['export', 'name', 'testport', 'testfiles'],
|
string: ['export', 'name', 'testport', 'testfiles'],
|
||||||
@ -64,49 +59,57 @@ var options = minimist(process.argv.slice(2), {
|
|||||||
testfiles: 'src/**/*.js'
|
testfiles: 'src/**/*.js'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
var yfiles = polyfills.concat(['src/y.js', 'src/Connector.js', 'src/OperationStore.js', 'src/Struct.js', 'src/Utils.js',
|
|
||||||
'src/OperationStores/RedBlackTree.js', 'src/Memory.js', 'src/**/*.js'])
|
var polyfills = [
|
||||||
|
'./node_modules/gulp-babel/node_modules/babel-core/node_modules/regenerator/runtime.js'
|
||||||
|
]
|
||||||
|
|
||||||
|
var concatOrder = [
|
||||||
|
'Helper.spec.js',
|
||||||
|
'y.js',
|
||||||
|
'Connector.js',
|
||||||
|
'OperationStore.js',
|
||||||
|
'Struct.js',
|
||||||
|
'Utils.js',
|
||||||
|
'OperationStores/RedBlackTree.js',
|
||||||
|
'OperationStores/Memory.js',
|
||||||
|
'OperationStores/IndexedDB.js',
|
||||||
|
'Connectors/Test.js',
|
||||||
|
'Connectors/WebRTC.js',
|
||||||
|
'Types/Array.js',
|
||||||
|
'Types/Map.js',
|
||||||
|
'Types/TextBind.js'
|
||||||
|
]
|
||||||
|
|
||||||
var files = {
|
var files = {
|
||||||
y: yfiles.concat(['!src/**/*.spec.js']),
|
production: polyfills.concat(concatOrder.map(function (f) {
|
||||||
test: yfiles.concat([options.testfiles]),
|
return 'src/' + f
|
||||||
build_test: ['build_test/y.js']
|
})),
|
||||||
|
test: concatOrder.map(function (f) {
|
||||||
|
return 'build/' + f
|
||||||
|
}).concat(['build/**/*.spec.js'])
|
||||||
}
|
}
|
||||||
|
|
||||||
gulp.task('build', function () {
|
gulp.task('build:deploy', function () {
|
||||||
/*
|
gulp.src('src/**/*.js')
|
||||||
return gulp.src(files.y)
|
|
||||||
.pipe(sourcemaps.init())
|
.pipe(sourcemaps.init())
|
||||||
.pipe(concat(options.name))
|
.pipe(concat('y.js'))
|
||||||
.pipe(babel({
|
|
||||||
loose: "all",
|
|
||||||
modules: options.export,
|
|
||||||
// blacklist: "regenerator" // you can't uglify when regenerator is blacklisted!
|
|
||||||
}))
|
|
||||||
.pipe(uglify())
|
|
||||||
.pipe(sourcemaps.write("."))
|
|
||||||
.pipe(gulp.dest("."));*/
|
|
||||||
return gulp.src(files.y)
|
|
||||||
.pipe(sourcemaps.init())
|
|
||||||
.pipe(concat(options.name))
|
|
||||||
.pipe(babel({
|
.pipe(babel({
|
||||||
loose: 'all',
|
loose: 'all',
|
||||||
modules: 'ignore',
|
modules: 'ignore',
|
||||||
optional: ['es7.asyncFunctions'],
|
|
||||||
blacklist: ['regenerator'],
|
|
||||||
experimental: true
|
experimental: true
|
||||||
}))
|
}))
|
||||||
.pipe(sourcemaps.write('.'))
|
.pipe(uglify())
|
||||||
|
.pipe(sourcemaps.write())
|
||||||
.pipe(gulp.dest('.'))
|
.pipe(gulp.dest('.'))
|
||||||
})
|
})
|
||||||
|
|
||||||
gulp.task('testbuild', function () {
|
gulp.task('build:test', function () {
|
||||||
gulp.src('src/**/*.js')
|
gulp.src('src/**/*.js')
|
||||||
.pipe(sourcemaps.init())
|
.pipe(sourcemaps.init())
|
||||||
.pipe(babel({
|
.pipe(babel({
|
||||||
loose: 'all',
|
loose: 'all',
|
||||||
modules: 'ignore',
|
modules: 'ignore',
|
||||||
// optional: ['es7.asyncFunctions'],
|
|
||||||
blacklist: 'regenerator',
|
blacklist: 'regenerator',
|
||||||
experimental: true
|
experimental: true
|
||||||
}))
|
}))
|
||||||
@ -114,54 +117,30 @@ gulp.task('testbuild', function () {
|
|||||||
.pipe(gulp.dest('build'))
|
.pipe(gulp.dest('build'))
|
||||||
})
|
})
|
||||||
|
|
||||||
gulp.task('build_jasmine_browser', function () {
|
gulp.task('dev:node', ['test'], function () {
|
||||||
gulp.src(files.test)
|
gulp.watch('src/**/*.js', ['test'])
|
||||||
.pipe(sourcemaps.init())
|
|
||||||
.pipe(concat('jasmine_browser.js'))
|
|
||||||
.pipe(babel({
|
|
||||||
loose: 'all',
|
|
||||||
modules: 'ignore',
|
|
||||||
// optional: ['es7.asyncFunctions'],
|
|
||||||
blacklist: 'regenerator'
|
|
||||||
// experimental: true
|
|
||||||
}))
|
|
||||||
.pipe(sourcemaps.write())
|
|
||||||
.pipe(gulp.dest('build'))
|
|
||||||
})
|
})
|
||||||
var testy = [
|
|
||||||
"build/Helper.spec.js",
|
|
||||||
"build/y.js",
|
|
||||||
"build/Connector.js",
|
|
||||||
"build/OperationStore.js",
|
|
||||||
"build/Struct.js",
|
|
||||||
"build/Utils.js",
|
|
||||||
"build/OperationStores/RedBlackTree.js",
|
|
||||||
"build/OperationStores/Memory.js",
|
|
||||||
"build/OperationStores/IndexedDB.js",
|
|
||||||
"build/Connectors/Test.js",
|
|
||||||
"build/Connectors/WebRTC.js",
|
|
||||||
"build/Types/Array.js",
|
|
||||||
"build/Types/Map.js",
|
|
||||||
"build/Types/TextBind.js",
|
|
||||||
"build/**/*.spec.js"
|
|
||||||
]
|
|
||||||
gulp.task('develop', ['testbuild'], function () {
|
|
||||||
//gulp.watch(files.test, ['build_jasmine_browser'])
|
|
||||||
// gulp.watch(files.test, ["test"])
|
|
||||||
gulp.watch('src/**/*.js', ['testbuild'])
|
|
||||||
|
|
||||||
return gulp.src(testy)
|
gulp.task('dev:browser', ['build:test'], function () {
|
||||||
|
gulp.watch('src/**/*.js', ['build:test'])
|
||||||
|
|
||||||
|
gulp.src(files.test)
|
||||||
.pipe(watch('build/**/*.js'))
|
.pipe(watch('build/**/*.js'))
|
||||||
.pipe(jasmineBrowser.specRunner())
|
.pipe(jasmineBrowser.specRunner())
|
||||||
.pipe(jasmineBrowser.server({port: options.testport}))
|
.pipe(jasmineBrowser.server({port: options.testport}))
|
||||||
})
|
})
|
||||||
|
|
||||||
gulp.task('test', ['testbuild'], function () {
|
gulp.task('dev', ['build:test'], function () {
|
||||||
return gulp.src(testy)
|
gulp.start('dev:browser')
|
||||||
|
gulp.start('dev:node')
|
||||||
|
})
|
||||||
|
|
||||||
|
gulp.task('test', ['build:test'], function () {
|
||||||
|
return gulp.src(files.test)
|
||||||
.pipe(jasmine({
|
.pipe(jasmine({
|
||||||
verbose: true,
|
verbose: true,
|
||||||
includeStuckTrace: true
|
includeStuckTrace: true
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
||||||
gulp.task('default', ['build', 'test'])
|
gulp.task('default', ['test'])
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
},
|
},
|
||||||
"pre-commit": [
|
"pre-commit": [
|
||||||
"lint",
|
"lint",
|
||||||
"build"
|
"test"
|
||||||
],
|
],
|
||||||
"standard": {
|
"standard": {
|
||||||
"parser": "babel-eslint",
|
"parser": "babel-eslint",
|
||||||
@ -41,11 +41,10 @@
|
|||||||
},
|
},
|
||||||
"homepage": "http://y-js.org",
|
"homepage": "http://y-js.org",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-eslint": "^3.1.23",
|
"babel-eslint": "^4.1.1",
|
||||||
"gulp": "^3.9.0",
|
"gulp": "^3.9.0",
|
||||||
"gulp-babel": "^5.1.0",
|
"gulp-babel": "^5.1.0",
|
||||||
"gulp-concat": "^2.5.2",
|
"gulp-concat": "^2.5.2",
|
||||||
"gulp-ignore": "^1.2.1",
|
|
||||||
"gulp-jasmine": "^2.0.1",
|
"gulp-jasmine": "^2.0.1",
|
||||||
"gulp-jasmine-browser": "^0.1.3",
|
"gulp-jasmine-browser": "^0.1.3",
|
||||||
"gulp-sourcemaps": "^1.5.2",
|
"gulp-sourcemaps": "^1.5.2",
|
||||||
@ -54,6 +53,6 @@
|
|||||||
"gulp-watch": "^4.2.4",
|
"gulp-watch": "^4.2.4",
|
||||||
"minimist": "^1.1.1",
|
"minimist": "^1.1.1",
|
||||||
"pre-commit": "^1.0.10",
|
"pre-commit": "^1.0.10",
|
||||||
"standard": "^5.0.0-2"
|
"standard": "^5.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
q.js
12
q.js
@ -1,12 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
|
|
||||||
var x = new Promise(function(r){r(true)})
|
|
||||||
|
|
||||||
x.then(function(q){console.log("yay",q)})
|
|
||||||
|
|
||||||
var ff = function * (){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("dtrn")
|
|
@ -1,5 +1,5 @@
|
|||||||
/* global Y */
|
/* global Y */
|
||||||
/* eslint-env browser,jasmine */
|
/* eslint-env browser, jasmine */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This is just a compilation of functions that help to test this library!
|
This is just a compilation of functions that help to test this library!
|
||||||
@ -15,9 +15,6 @@ if (typeof global !== 'undefined') {
|
|||||||
}
|
}
|
||||||
g.g = g
|
g.g = g
|
||||||
|
|
||||||
//var co = require('co')
|
|
||||||
// g.co = co
|
|
||||||
|
|
||||||
function wait (t) {
|
function wait (t) {
|
||||||
if (t == null) {
|
if (t == null) {
|
||||||
t = 10
|
t = 10
|
||||||
@ -194,7 +191,6 @@ function async (makeGenerator) {
|
|||||||
return Promise.resolve(result.value).then(function (res) {
|
return Promise.resolve(result.value).then(function (res) {
|
||||||
return handle(generator.next(res))
|
return handle(generator.next(res))
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
debugger
|
|
||||||
return handle(generator.throw(err))
|
return handle(generator.throw(err))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -207,10 +203,3 @@ function async (makeGenerator) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.wrapCo = async
|
g.wrapCo = async
|
||||||
|
|
||||||
/*function wrapCo (gen) {
|
|
||||||
return function (done) {
|
|
||||||
return co.wrap(gen)(done)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g.wrapCo = wrapCo*/
|
|
||||||
|
@ -79,10 +79,25 @@ class AbstractOperationStore { // eslint-disable-line no-unused-vars
|
|||||||
if (o.left != null) {
|
if (o.left != null) {
|
||||||
var left = yield* this.getOperation(o.left)
|
var left = yield* this.getOperation(o.left)
|
||||||
left.right = o.right
|
left.right = o.right
|
||||||
|
yield* this.setOperation(left)
|
||||||
}
|
}
|
||||||
if (o.right != null) {
|
if (o.right != null) {
|
||||||
var right = yield* this.getOperation(o.right)
|
var right = yield* this.getOperation(o.right)
|
||||||
right.left = o.left
|
right.left = o.left
|
||||||
|
yield* this.setOperation(right)
|
||||||
|
}
|
||||||
|
var parent = yield* this.getOperation(o.parent)
|
||||||
|
var setParent = false
|
||||||
|
if (Y.utils.compareIds(parent.start, o.id)) {
|
||||||
|
setParent = true
|
||||||
|
parent.start = o.right
|
||||||
|
}
|
||||||
|
if (Y.utils.compareIds(parent.end, o.id)) {
|
||||||
|
setParent = true
|
||||||
|
parent.end = o.left
|
||||||
|
}
|
||||||
|
if (setParent) {
|
||||||
|
yield* this.setOperation(parent)
|
||||||
}
|
}
|
||||||
yield* this.removeOperation(o.id)
|
yield* this.removeOperation(o.id)
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,12 @@ class DeleteStore extends Y.utils.RBTree {
|
|||||||
}
|
}
|
||||||
isDeleted (id) {
|
isDeleted (id) {
|
||||||
var n = this.findNodeWithUpperBound(id)
|
var n = this.findNodeWithUpperBound(id)
|
||||||
return n !== null && n.val.id[0] === id[0] && id[0] < n.val.id[0] + n.val.len
|
return n !== null && n.val.id[0] === id[0] && id[1] < n.val.id[1] + n.val.len
|
||||||
}
|
}
|
||||||
delete (id) {
|
delete (id) {
|
||||||
var n = this.findNodeWithUpperBound(id)
|
var n = this.findNodeWithUpperBound(id)
|
||||||
if (n != null && n.val.id[0] === id[0]) {
|
if (n != null && n.val.id[0] === id[0]) {
|
||||||
if (n.val.id[1] === id[1]) {
|
if (n.val.id[1] <= id[1] && id[1] < n.val.id[1] + n.val.len) {
|
||||||
// already deleted
|
// already deleted
|
||||||
return
|
return
|
||||||
} else if (n.val.id[1] + n.val.len === id[1]) {
|
} else if (n.val.id[1] + n.val.len === id[1]) {
|
||||||
|
@ -10,14 +10,20 @@ describe('Memory', function () {
|
|||||||
it('Deleted operation is deleted', function () {
|
it('Deleted operation is deleted', function () {
|
||||||
ds.delete(['u1', 10])
|
ds.delete(['u1', 10])
|
||||||
expect(ds.isDeleted(['u1', 10])).toBeTruthy()
|
expect(ds.isDeleted(['u1', 10])).toBeTruthy()
|
||||||
expect(ds.toDeleteSet()).toBeTruthy({'u1': [10, 1]})
|
expect(ds.toDeleteSet()).toEqual({'u1': [[10, 1]]})
|
||||||
})
|
})
|
||||||
it('Deleted operation extends other deleted operation', function () {
|
it('Deleted operation extends other deleted operation', function () {
|
||||||
ds.delete(['u1', 10])
|
ds.delete(['u1', 10])
|
||||||
ds.delete(['u1', 11])
|
ds.delete(['u1', 11])
|
||||||
expect(ds.isDeleted(['u1', 10])).toBeTruthy()
|
expect(ds.isDeleted(['u1', 10])).toBeTruthy()
|
||||||
expect(ds.isDeleted(['u1', 11])).toBeTruthy()
|
expect(ds.isDeleted(['u1', 11])).toBeTruthy()
|
||||||
expect(ds.toDeleteSet()).toBeTruthy({'u1': [10, 2]})
|
expect(ds.toDeleteSet()).toEqual({'u1': [[10, 2]]})
|
||||||
|
})
|
||||||
|
it('Deleted operation extends other deleted operation', function () {
|
||||||
|
ds.delete(['0', 3])
|
||||||
|
ds.delete(['0', 4])
|
||||||
|
ds.delete(['0', 2])
|
||||||
|
expect(ds.toDeleteSet()).toEqual({'0': [[2, 3]]})
|
||||||
})
|
})
|
||||||
it('Creates operations', function () {
|
it('Creates operations', function () {
|
||||||
var dels = ds.getDeletions({5: [[4, 1]]})
|
var dels = ds.getDeletions({5: [[4, 1]]})
|
||||||
|
@ -34,7 +34,7 @@ var Struct = {
|
|||||||
var target = yield* this.getOperation(op.target)
|
var target = yield* this.getOperation(op.target)
|
||||||
if (target != null && !target.deleted) {
|
if (target != null && !target.deleted) {
|
||||||
target.deleted = true
|
target.deleted = true
|
||||||
if (target.left !== null && (yield* this.getOperation(target.left)).deleted) {
|
if (target.left === null || (yield* this.getOperation(target.left)).deleted) {
|
||||||
this.store.addToGarbageCollector(target.id)
|
this.store.addToGarbageCollector(target.id)
|
||||||
target.gc = true
|
target.gc = true
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ var numberOfYArrayTests = 5
|
|||||||
describe('Array Type', function () {
|
describe('Array Type', function () {
|
||||||
var y1, y2, y3, yconfig1, yconfig2, yconfig3, flushAll
|
var y1, y2, y3, yconfig1, yconfig2, yconfig3, flushAll
|
||||||
|
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100
|
||||||
beforeEach(wrapCo(function * (done) {
|
beforeEach(wrapCo(function * (done) {
|
||||||
yield createUsers(this, 3)
|
yield createUsers(this, 3)
|
||||||
y1 = (yconfig1 = this.users[0]).root
|
y1 = (yconfig1 = this.users[0]).root
|
||||||
@ -23,7 +23,6 @@ describe('Array Type', function () {
|
|||||||
|
|
||||||
describe('Basic tests', function () {
|
describe('Basic tests', function () {
|
||||||
it('insert three elements, try re-get property', wrapCo(function * (done) {
|
it('insert three elements, try re-get property', wrapCo(function * (done) {
|
||||||
console.log("blahhhhhhhhhhhhhhhhh ")
|
|
||||||
var array = yield y1.set('Array', Y.Array)
|
var array = yield y1.set('Array', Y.Array)
|
||||||
array.insert(0, [1, 2, 3])
|
array.insert(0, [1, 2, 3])
|
||||||
array = yield y1.get('Array') // re-get property
|
array = yield y1.get('Array') // re-get property
|
||||||
@ -104,9 +103,9 @@ describe('Array Type', function () {
|
|||||||
l2 = yield y2.get('Array')
|
l2 = yield y2.get('Array')
|
||||||
l1.insert(0, ['x', 'y'])
|
l1.insert(0, ['x', 'y'])
|
||||||
l1.delete(0, 2)
|
l1.delete(0, 2)
|
||||||
yield wait(500)
|
yield wait()
|
||||||
yield flushAll()
|
yield flushAll()
|
||||||
yield wait(500)
|
yield wait()
|
||||||
expect(l1.toArray()).toEqual(l2.toArray())
|
expect(l1.toArray()).toEqual(l2.toArray())
|
||||||
yield compareAllUsers(this.users)
|
yield compareAllUsers(this.users)
|
||||||
done()
|
done()
|
||||||
|
2
src/y.js
2
src/y.js
@ -57,6 +57,6 @@ class YConfig { // eslint-disable-line no-unused-vars
|
|||||||
|
|
||||||
if (g) { // eslint-disable-line
|
if (g) { // eslint-disable-line
|
||||||
g.Y = Y //eslint-disable-line
|
g.Y = Y //eslint-disable-line
|
||||||
debugger //eslint-disable-line
|
// debugger //eslint-disable-line
|
||||||
}
|
}
|
||||||
Y.utils = {}
|
Y.utils = {}
|
||||||
|
34
test.js
34
test.js
@ -1,34 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
function * aaa (){}
|
|
||||||
|
|
||||||
class Y {
|
|
||||||
constructor () {
|
|
||||||
this.y = 4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class X extends Y {
|
|
||||||
constructor (a) {
|
|
||||||
this.x = 'true'
|
|
||||||
}
|
|
||||||
stuff () {
|
|
||||||
console.log("yay")
|
|
||||||
var r = function * () {
|
|
||||||
yield "dtrn"
|
|
||||||
}
|
|
||||||
var test = r()
|
|
||||||
console.dir(r())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var Q = {}
|
|
||||||
Q["X"] = X
|
|
||||||
|
|
||||||
var P = Q['X']
|
|
||||||
var x = new P( 44 )
|
|
||||||
|
|
||||||
(new Promise(function(resolve){
|
|
||||||
resolve(true)
|
|
||||||
})).then(function(arg){
|
|
||||||
console.log("yay", arg)
|
|
||||||
})
|
|
Loading…
x
Reference in New Issue
Block a user