implemented gulpfile.helper

This commit is contained in:
Kevin Jahns 2015-11-05 15:53:26 +01:00
parent 317f7f19bb
commit 78f4f6f5b9
6 changed files with 37 additions and 252 deletions

View File

@ -44,160 +44,38 @@
*/
var gulp = require('gulp')
var minimist = require('minimist')
var concat = require('gulp-concat')
var $ = require('gulp-load-plugins')()
var options = minimist(process.argv.slice(2), {
string: ['export', 'name', 'testport', 'testfiles', 'regenerator'],
default: {
export: 'ignore',
name: 'y.js',
testport: '8888',
testfiles: 'src/**/*.js',
regenerator: process.version < 'v0.12'
}
})
var polyfills = [
'./node_modules/gulp-babel/node_modules/babel-core/node_modules/regenerator/runtime.js'
]
var concatOrder = [
'y.js',
'Connector.js',
'Database.js',
'Transaction.js',
'Struct.js',
'Utils.js',
'Databases/RedBlackTree.js',
'Databases/Memory.js',
'Databases/IndexedDB.js',
'Connectors/Test.js',
'Connectors/WebRTC.js',
'Types/Array.js',
'Types/Map.js',
'Types/TextBind.js'
]
var files = {
src: polyfills.concat(concatOrder.map(function (f) {
return 'src/' + f
})),
test: ['build/Helper.spec.js'].concat(concatOrder.map(function (f) {
return 'build/' + f
}).concat(['build/**/*.spec.js']))
}
if (options.regenerator) {
files.test = polyfills.concat(files.test)
}
gulp.task('deploy:updateSubmodule', function () {
return $.git.updateSubmodule({ args: '--init' })
})
gulp.task('deploy:copy', function () {
return gulp.src(['README.md'], {base: '.'})
.pipe(gulp.dest('dist/'))
})
gulp.task('deploy:bump', function () {
return gulp.src(['./package.json', './dist/package.json'], {base: '.'})
.pipe($.bump({type: 'patch'}))
.pipe(gulp.dest('./'))
})
gulp.task('deploy', ['test', 'deploy:updateSubmodule', 'deploy:bump', 'build:dist', 'deploy:copy'], function () {
return gulp.src('./package.json', {read: false})
.pipe($.shell([
'standard',
'echo "Deploying version <%= getVersion(file.path) %>"',
'git pull',
'cd ./dist/ && git add -A',
'cd ./dist/ && git commit -am "Deploy <%= getVersion(file.path) %>" -n',
'cd ./dist/ && git push',
'cd ./dist/ && git tag -a v<%= getVersion(file.path) %> -m "Release <%= getVersion(file.path) %>"',
'cd ./dist/ && git push origin --tags',
'git commit -am "Release <%= getVersion(file.path) %>" -n',
'git push'
], {
templateData: {
getVersion: function (s) {
return require(s).version
}
}
}))
})
gulp.task('build:dist', function () {
return gulp.src(files.src)
.pipe($.sourcemaps.init())
.pipe(concat('y.js'))
.pipe($.babel({
loose: 'all',
modules: 'ignore',
experimental: true
}))
.pipe($.uglify())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('./dist/'))
})
gulp.task('build:test', function () {
var babelOptions = {
loose: 'all',
modules: 'ignore',
experimental: true
}
if (!options.regenerator) {
babelOptions.blacklist = 'regenerator'
}
return gulp.src('src/**/*.js')
.pipe($.sourcemaps.init())
.pipe($.babel(babelOptions))
.pipe($.sourcemaps.write())
.pipe(gulp.dest('build'))
})
gulp.task('dev:node', ['test'], function () {
gulp.watch('src/**/*.js', ['test'])
})
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('dev', ['build:test'], function () {
gulp.start('dev:browser')
gulp.start('dev:node')
})
gulp.task('copy:dist', ['build:dist'], function () {
return gulp.src(['./dist/y.js', './dist/y.js.map'])
.pipe(gulp.dest('./dist/Examples/bower_components/yjs/'))
})
gulp.task('dev:examples', ['copy:dist'], function () {
gulp.watch('src/**/*.js', ['copy:dist'])
return $.serve('dist/Examples')()
})
gulp.task('test', ['build:test'], function () {
var testfiles = files.test
if (typeof Promise === 'undefined') {
testfiles.concat(['src/polyfills.js'])
}
return gulp.src(testfiles)
.pipe($.jasmine({
verbose: true,
includeStuckTrace: true
}))
require('./gulpfile.helper.js')(gulp, {
polyfills: ['./node_modules/gulp-babel/node_modules/babel-core/node_modules/regenerator/runtime.js'],
concatOrder: [
'y.js',
'Connector.js',
'Database.js',
'Transaction.js',
'Struct.js',
'Utils.js',
'Databases/RedBlackTree.js',
'Databases/Memory.js',
'Databases/IndexedDB.js',
'Connectors/Test.js',
'Connectors/WebRTC.js',
'Types/Array.js',
'Types/Map.js',
'Types/TextBind.js'
],
targetName: 'y.js',
moduleName: 'yjs'
})
gulp.task('default', ['test'])
gulp.task('copy:dist', function () {
return gulp.src(['../y-*/dist/*.js', '../y-*/dist/*.js.map'])
.pipe(gulp.dest('./dist/Examples/bower_components/'))
})
gulp.task('dev:examples', ['dist', 'copy:dist'], function () {
gulp.watch('src/**/*.js', ['copy:dist'])
return $.serve('dist/Examples')()
})

View File

@ -1,6 +1,6 @@
{
"name": "yjs",
"version": "0.6.26",
"version": "0.6.31",
"description": "A framework for real-time p2p shared editing on arbitrary complex data types",
"main": "y.js",
"scripts": {
@ -52,6 +52,7 @@
"gulp-jasmine": "^2.0.1",
"gulp-jasmine-browser": "^0.2.3",
"gulp-load-plugins": "^1.0.0",
"gulp-prompt": "^0.1.2",
"gulp-serve": "^1.2.0",
"gulp-shell": "^0.5.1",
"gulp-sourcemaps": "^1.5.2",

View File

@ -1,94 +0,0 @@
/* global Y, SimpleWebRTC */
'use strict'
class WebRTC extends Y.AbstractConnector {
constructor (y, options) {
if (options === undefined) {
throw new Error('Options must not be undefined!')
}
if (options.room == null) {
throw new Error('You must define a room name!')
}
options.role = 'slave'
super(y, options)
this.webrtcOptions = {
url: options.url || 'https://yatta.ninja:8888',
room: options.room
}
var swr = new SimpleWebRTC(this.webrtcOptions)
this.swr = swr
var self = this
swr.once('connectionReady', function (userId) {
// SimpleWebRTC (swr) is initialized
swr.joinRoom(self.webrtcOptions.room)
swr.once('joinedRoom', function () {
self.setUserId(userId)
/*
var i
// notify the connector class about all the users that already
// joined the session
for(i in self.swr.webrtc.peers){
self.userJoined(self.swr.webrtc.peers[i].id, "master")
}*/
swr.on('channelMessage', function (peer, room_, message) {
// The client received a message
// Check if the connector is already initialized,
// only then forward the message to the connector class
if (message.type != null) {
self.receiveMessage(peer.id, message.payload)
}
})
})
swr.on('createdPeer', function (peer) {
// a new peer/client joined the session.
// Notify the connector class, if the connector
// is already initialized
self.userJoined(peer.id, 'master')
})
swr.on('peerStreamRemoved', function (peer) {
// a client left the session.
// Notify the connector class, if the connector
// is already initialized
self.userLeft(peer.id)
})
})
}
disconnect () {
this.swr.leaveRoom()
super.disconnect()
}
reconnect () {
this.swr.joinRoom(this.webrtcOptions.room)
super.reconnect()
}
send (uid, message) {
var self = this
// we have to make sure that the message is sent under all circumstances
var send = function () {
// check if the clients still exists
var peer = self.swr.webrtc.getPeers(uid)[0]
var success
if (peer) {
// success is true, if the message is successfully sent
success = peer.sendDirectly('simplewebrtc', 'yjs', message)
}
if (!success) {
// resend the message if it didn't work
setTimeout(send, 500)
}
}
// try to send the message
send()
}
broadcast (message) {
this.swr.sendDirectlyToAll('simplewebrtc', 'yjs', message)
}
isDisconnected () {
return false
}
}
Y.WebRTC = WebRTC

View File

@ -31,7 +31,7 @@ g.describeManyTimes = function describeManyTimes (times, name, f) {
*/
function wait (t) {
if (t == null) {
t = 80
t = 5
}
return new Promise(function (resolve) {
setTimeout(function () {

View File

@ -1,7 +1,7 @@
/* global createUsers, databases, wait, Y, compareAllUsers, getRandomNumber, applyRandomTransactionsAllRejoinNoGC, applyRandomTransactionsWithGC, async, garbageCollectAllUsers, describeManyTimes */
/* eslint-env browser,jasmine */
var numberOfYArrayTests = 50
var numberOfYArrayTests = 10
var repeatArrayTests = 2
for (let database of databases) {

View File

@ -1,8 +1,8 @@
/* global createUsers, Y, databases, compareAllUsers, getRandomNumber, applyRandomTransactionsAllRejoinNoGC, applyRandomTransactionsWithGC, async, describeManyTimes */
/* eslint-env browser,jasmine */
var numberOfYMapTests = 40
var repeatMapTeasts = 2
var numberOfYMapTests = 10
var repeatMapTeasts = 1
for (let database of databases) {
describe(`Map Type (DB: ${database})`, function () {