From 78f4f6f5b9637d9e2dd11e888245b74031e6520c Mon Sep 17 00:00:00 2001
From: Kevin Jahns <kevin.jahns@rwth-aachen.de>
Date: Thu, 5 Nov 2015 15:53:26 +0100
Subject: [PATCH] implemented gulpfile.helper

---
 gulpfile.js              | 174 ++++++---------------------------------
 package.json             |   3 +-
 src/Connectors/WebRTC.js |  94 ---------------------
 src/Helper.spec.js       |   2 +-
 src/Types/Array.spec.js  |   2 +-
 src/Types/Map.spec.js    |   4 +-
 6 files changed, 32 insertions(+), 247 deletions(-)
 delete mode 100644 src/Connectors/WebRTC.js

diff --git a/gulpfile.js b/gulpfile.js
index 26538847..3d95236c 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -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'
-  }
+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'
 })
 
-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('default', ['test'])
 
-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('copy:dist', function () {
+  return gulp.src(['../y-*/dist/*.js', '../y-*/dist/*.js.map'])
+    .pipe(gulp.dest('./dist/Examples/bower_components/'))
 })
 
-gulp.task('dev:examples', ['copy:dist'], function () {
+gulp.task('dev:examples', ['dist', '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
-    }))
+  return $.serve('dist/Examples')()
 })
-
-gulp.task('default', ['test'])
diff --git a/package.json b/package.json
index 7afdd9d3..cfc70e42 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/src/Connectors/WebRTC.js b/src/Connectors/WebRTC.js
deleted file mode 100644
index 91e5ca26..00000000
--- a/src/Connectors/WebRTC.js
+++ /dev/null
@@ -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
diff --git a/src/Helper.spec.js b/src/Helper.spec.js
index bcb80b41..6ac70ec7 100644
--- a/src/Helper.spec.js
+++ b/src/Helper.spec.js
@@ -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 () {
diff --git a/src/Types/Array.spec.js b/src/Types/Array.spec.js
index bdb3d4fb..e81952b3 100644
--- a/src/Types/Array.spec.js
+++ b/src/Types/Array.spec.js
@@ -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) {
diff --git a/src/Types/Map.spec.js b/src/Types/Map.spec.js
index a338fbf9..4f8e8d39 100644
--- a/src/Types/Map.spec.js
+++ b/src/Types/Map.spec.js
@@ -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 () {
-- 
GitLab