Skip to content
Snippets Groups Projects
gulpfile.js 2.93 KiB
Newer Older
  • Learn to ignore specific revisions
  • /* eslint-env node */
    
    Kevin Jahns's avatar
    Kevin Jahns committed
    
    
    Kevin Jahns's avatar
    Kevin Jahns committed
    /** Gulp Commands
    
    
      gulp command*
        [--export ModuleType]
        [--name ModuleName]
        [--testport TestPort]
        [--testfiles TestFiles]
    
    Kevin Jahns's avatar
    Kevin Jahns committed
    
      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):
    
    Kevin Jahns's avatar
    Kevin Jahns committed
        Serve the specs on port 8888 (default)
    
    Kevin Jahns's avatar
    Kevin Jahns committed
    
    
      Test files (TestFiles):
        Specify which specs to use!
    
    
    Kevin Jahns's avatar
    Kevin Jahns committed
      Commands:
    
        - build:deploy
            Build this library for deployment (es6->es5, minified)
    
        - dev:browser
    
    Kevin Jahns's avatar
    Kevin Jahns committed
            Watch the ./src directory.
    
            Builds the library on changes.
    
    Kevin Jahns's avatar
    Kevin Jahns committed
            Starts an http-server and serves the test suite on http://127.0.0.1:8888.
    
        - dev:node
            Watch the ./src directory.
            Builds and specs the library on changes.
            Usefull to run with node-inspector.
            `node-debug $(which gulp) dev:node
    
    Kevin Jahns's avatar
    Kevin Jahns committed
        - test:
            Test this library
    */
    
    
    var gulp = require('gulp')
    
    Kevin Jahns's avatar
    Kevin Jahns committed
    var $ = require('gulp-load-plugins')()
    var runSequence = require('run-sequence').use(gulp)
    
    require('./gulpfile.helper.js')(gulp, {
    
    Kevin Jahns's avatar
    Kevin Jahns committed
      polyfills: [],
    
      entry: './src/y.js',
    
      targetName: 'y.js',
    
      moduleName: 'yjs',
    
      includeRuntime: true,
    
      specs: [
    
        './src/Database.spec.js',
    
        '../y-array/src/Array.spec.js',
    
        '../y-map/src/Map.spec.js'
    
    Kevin Jahns's avatar
    Kevin Jahns committed
    gulp.task('dev:examples', ['watch:dist'], function () {
    
    Kevin Jahns's avatar
    Kevin Jahns committed
      // watch all distfiles and copy them to bower_components
    
    Kevin Jahns's avatar
    Kevin Jahns committed
      var distfiles = ['./dist/*.{js,es6}', './dist/*.{js,es6}.map', '../y-*/dist/*.{js,es6}', '../y-*/dist/*.{js,es6}.map']
    
    Kevin Jahns's avatar
    Kevin Jahns committed
      gulp.src(distfiles)
        .pipe($.watch(distfiles))
        .pipe($.rename(function (path) {
    
          var dir = path.dirname.split(/[\\\/]/)[0]
    
    Kevin Jahns's avatar
    Kevin Jahns committed
          console.log(JSON.stringify(path))
          path.dirname = dir === '.' ? 'yjs' : dir
        }))
    
        .pipe(gulp.dest('./dist/Examples/bower_components/'))
    
    Kevin Jahns's avatar
    Kevin Jahns committed
    
    
    Kevin Jahns's avatar
    Kevin Jahns committed
      return $.serve('dist/Examples/')()
    })
    
    Kevin Jahns's avatar
    Kevin Jahns committed
    
    
    gulp.task('default', ['updateSubmodule'], function (cb) {
    
    Kevin Jahns's avatar
    Kevin Jahns committed
      gulp.src('package.json')
        .pipe($.prompt.prompt({
          type: 'checkbox',
          name: 'tasks',
          message: 'Which tasks would you like to run?',
          choices: [
            'test                    Test this project',
            'dev:examples            Serve the examples directory in ./dist/',
            'dev:browser             Watch files & serve the testsuite for the browser',
            'dev:nodejs              Watch filse & test this project with nodejs',
            'bump                    Bump the current state of the project',
            'publish                 Publish this project. Creates a github tag',
            'dist                    Build the distribution files'
          ]
        }, function (res) {
          var tasks = res.tasks.map(function (task) {
            return task.split(' ')[0]
          })
          if (tasks.length > 0) {
            console.info('gulp ' + tasks.join(' '))
            runSequence(tasks, cb)
          } else {
            console.info('Ok, .. goodbye')
          }
        }))
    
    Kevin Jahns's avatar
    Kevin Jahns committed
    })