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:
|
||||
- build:
|
||||
Build this library
|
||||
- develop:
|
||||
- dev:
|
||||
Watch the ./src directory.
|
||||
Builds and specs the library on changes.
|
||||
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 concat = require('gulp-concat')
|
||||
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), {
|
||||
string: ['export', 'name', 'testport', 'testfiles'],
|
||||
@ -64,49 +59,57 @@ var options = minimist(process.argv.slice(2), {
|
||||
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 = {
|
||||
y: yfiles.concat(['!src/**/*.spec.js']),
|
||||
test: yfiles.concat([options.testfiles]),
|
||||
build_test: ['build_test/y.js']
|
||||
production: polyfills.concat(concatOrder.map(function (f) {
|
||||
return 'src/' + f
|
||||
})),
|
||||
test: concatOrder.map(function (f) {
|
||||
return 'build/' + f
|
||||
}).concat(['build/**/*.spec.js'])
|
||||
}
|
||||
|
||||
gulp.task('build', function () {
|
||||
/*
|
||||
return gulp.src(files.y)
|
||||
gulp.task('build:deploy', function () {
|
||||
gulp.src('src/**/*.js')
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(concat(options.name))
|
||||
.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(concat('y.js'))
|
||||
.pipe(babel({
|
||||
loose: 'all',
|
||||
modules: 'ignore',
|
||||
optional: ['es7.asyncFunctions'],
|
||||
blacklist: ['regenerator'],
|
||||
experimental: true
|
||||
}))
|
||||
.pipe(sourcemaps.write('.'))
|
||||
.pipe(uglify())
|
||||
.pipe(sourcemaps.write())
|
||||
.pipe(gulp.dest('.'))
|
||||
})
|
||||
|
||||
gulp.task('testbuild', function () {
|
||||
gulp.task('build:test', function () {
|
||||
gulp.src('src/**/*.js')
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(babel({
|
||||
loose: 'all',
|
||||
modules: 'ignore',
|
||||
// optional: ['es7.asyncFunctions'],
|
||||
blacklist: 'regenerator',
|
||||
experimental: true
|
||||
}))
|
||||
@ -114,54 +117,30 @@ gulp.task('testbuild', function () {
|
||||
.pipe(gulp.dest('build'))
|
||||
})
|
||||
|
||||
gulp.task('build_jasmine_browser', function () {
|
||||
gulp.src(files.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'))
|
||||
gulp.task('dev:node', ['test'], function () {
|
||||
gulp.watch('src/**/*.js', ['test'])
|
||||
})
|
||||
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(jasmineBrowser.specRunner())
|
||||
.pipe(jasmineBrowser.server({port: options.testport}))
|
||||
})
|
||||
|
||||
gulp.task('test', ['testbuild'], function () {
|
||||
return gulp.src(testy)
|
||||
gulp.task('dev', ['build:test'], function () {
|
||||
gulp.start('dev:browser')
|
||||
gulp.start('dev:node')
|
||||
})
|
||||
|
||||
gulp.task('test', ['build:test'], function () {
|
||||
return gulp.src(files.test)
|
||||
.pipe(jasmine({
|
||||
verbose: true,
|
||||
includeStuckTrace: true
|
||||
}))
|
||||
})
|
||||
|
||||
gulp.task('default', ['build', 'test'])
|
||||
gulp.task('default', ['test'])
|
||||
|
@ -10,7 +10,7 @@
|
||||
},
|
||||
"pre-commit": [
|
||||
"lint",
|
||||
"build"
|
||||
"test"
|
||||
],
|
||||
"standard": {
|
||||
"parser": "babel-eslint",
|
||||
@ -41,11 +41,10 @@
|
||||
},
|
||||
"homepage": "http://y-js.org",
|
||||
"devDependencies": {
|
||||
"babel-eslint": "^3.1.23",
|
||||
"babel-eslint": "^4.1.1",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-babel": "^5.1.0",
|
||||
"gulp-concat": "^2.5.2",
|
||||
"gulp-ignore": "^1.2.1",
|
||||
"gulp-jasmine": "^2.0.1",
|
||||
"gulp-jasmine-browser": "^0.1.3",
|
||||
"gulp-sourcemaps": "^1.5.2",
|
||||
@ -54,6 +53,6 @@
|
||||
"gulp-watch": "^4.2.4",
|
||||
"minimist": "^1.1.1",
|
||||
"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 */
|
||||
/* eslint-env browser,jasmine */
|
||||
/* eslint-env browser, jasmine */
|
||||
|
||||
/*
|
||||
This is just a compilation of functions that help to test this library!
|
||||
@ -15,9 +15,6 @@ if (typeof global !== 'undefined') {
|
||||
}
|
||||
g.g = g
|
||||
|
||||
//var co = require('co')
|
||||
// g.co = co
|
||||
|
||||
function wait (t) {
|
||||
if (t == null) {
|
||||
t = 10
|
||||
@ -194,7 +191,6 @@ function async (makeGenerator) {
|
||||
return Promise.resolve(result.value).then(function (res) {
|
||||
return handle(generator.next(res))
|
||||
}, function (err) {
|
||||
debugger
|
||||
return handle(generator.throw(err))
|
||||
})
|
||||
}
|
||||
@ -207,10 +203,3 @@ function async (makeGenerator) {
|
||||
}
|
||||
}
|
||||
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) {
|
||||
var left = yield* this.getOperation(o.left)
|
||||
left.right = o.right
|
||||
yield* this.setOperation(left)
|
||||
}
|
||||
if (o.right != null) {
|
||||
var right = yield* this.getOperation(o.right)
|
||||
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)
|
||||
}
|
||||
|
@ -16,12 +16,12 @@ class DeleteStore extends Y.utils.RBTree {
|
||||
}
|
||||
isDeleted (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) {
|
||||
var n = this.findNodeWithUpperBound(id)
|
||||
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
|
||||
return
|
||||
} else if (n.val.id[1] + n.val.len === id[1]) {
|
||||
|
@ -10,14 +10,20 @@ describe('Memory', function () {
|
||||
it('Deleted operation is deleted', function () {
|
||||
ds.delete(['u1', 10])
|
||||
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 () {
|
||||
ds.delete(['u1', 10])
|
||||
ds.delete(['u1', 11])
|
||||
expect(ds.isDeleted(['u1', 10])).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 () {
|
||||
var dels = ds.getDeletions({5: [[4, 1]]})
|
||||
|
@ -34,7 +34,7 @@ var Struct = {
|
||||
var target = yield* this.getOperation(op.target)
|
||||
if (target != null && !target.deleted) {
|
||||
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)
|
||||
target.gc = true
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ var numberOfYArrayTests = 5
|
||||
describe('Array Type', function () {
|
||||
var y1, y2, y3, yconfig1, yconfig2, yconfig3, flushAll
|
||||
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100
|
||||
beforeEach(wrapCo(function * (done) {
|
||||
yield createUsers(this, 3)
|
||||
y1 = (yconfig1 = this.users[0]).root
|
||||
@ -23,7 +23,6 @@ describe('Array Type', function () {
|
||||
|
||||
describe('Basic tests', function () {
|
||||
it('insert three elements, try re-get property', wrapCo(function * (done) {
|
||||
console.log("blahhhhhhhhhhhhhhhhh ")
|
||||
var array = yield y1.set('Array', Y.Array)
|
||||
array.insert(0, [1, 2, 3])
|
||||
array = yield y1.get('Array') // re-get property
|
||||
@ -104,9 +103,9 @@ describe('Array Type', function () {
|
||||
l2 = yield y2.get('Array')
|
||||
l1.insert(0, ['x', 'y'])
|
||||
l1.delete(0, 2)
|
||||
yield wait(500)
|
||||
yield wait()
|
||||
yield flushAll()
|
||||
yield wait(500)
|
||||
yield wait()
|
||||
expect(l1.toArray()).toEqual(l2.toArray())
|
||||
yield compareAllUsers(this.users)
|
||||
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
|
||||
g.Y = Y //eslint-disable-line
|
||||
debugger //eslint-disable-line
|
||||
// debugger //eslint-disable-line
|
||||
}
|
||||
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