cms/gulpfile.js
author ymh <ymh.work@gmail.com>
Thu, 23 Feb 2017 18:59:04 +0100
changeset 525 c06db7aa1b10
parent 346 4cd0f8c936ed
child 541 e756a8c72c3d
permissions -rw-r--r--
Added tag 0.0.17 for changeset 85e8382852e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
346
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
     1
const gulp = require('gulp');
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
     2
const del = require('del');
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
     3
const zip = require('gulp-zip');
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
     4
const merge = require('merge-stream');
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
     5
const seq = require('run-sequence');
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
     6
const exec = require('child_process').execSync;
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
     7
const minimist = require('minimist');
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
     8
const template = require('gulp-template');
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
     9
const rename = require('gulp-rename');
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    10
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    11
const appBuildFolder = 'app-client/dist';
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    12
const moduleFolder = 'corpus_module';
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    13
const moduleBuildFolder = 'dist'
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    14
const buildDestFolder = '../build/root/var/www/corpusdelaparole/drupal/sites/all/modules/' + moduleFolder;
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    15
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    16
const options = minimist(process.argv.slice(2), {string: "version"});
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    17
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    18
if(!options.version) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    19
    return process.exit(2);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    20
}
14
10f67f0281e1 move the gulpfile in the cms folder instead of the app - add readme for module and cms
nowmad@23.1.168.192.in-addr.arpa
parents:
diff changeset
    21
346
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    22
var buildOption = "--prod";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    23
var environment = "production";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    24
var corpusBackUrl = "corpus-back";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    25
if(options.prod) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    26
    buildOption = "--prod";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    27
    environment = "production";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    28
    corpusBackUrl = "corpus-back";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    29
} else if(options.dev) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    30
    buildOption = "--dev";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    31
    environment = "development";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    32
    corpusBackUrl = "corpus-app";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    33
}
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    34
14
10f67f0281e1 move the gulpfile in the cms folder instead of the app - add readme for module and cms
nowmad@23.1.168.192.in-addr.arpa
parents:
diff changeset
    35
346
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    36
gulp.task('build-ember', function(cb) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    37
    exec('npm install', {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    38
        cwd: '../app-client',
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    39
        stdio:[0,1,2]
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    40
    });
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    41
    exec('node_modules/.bin/bower install', {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    42
        cwd: '../app-client',
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    43
        stdio:[0,1,2]
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    44
    });
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    45
    exec('node_modules/.bin/ember build '+buildOption, {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    46
        cwd: '../app-client',
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    47
        stdio:[0,1,2]
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    48
    });
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    49
});
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    50
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    51
gulp.task('clean', function() {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    52
    return del([
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    53
        moduleBuildFolder+'/'+moduleFolder+'/**/*',
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    54
        moduleBuildFolder+'/**/*',
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    55
    ]);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    56
});
14
10f67f0281e1 move the gulpfile in the cms folder instead of the app - add readme for module and cms
nowmad@23.1.168.192.in-addr.arpa
parents:
diff changeset
    57
gulp.task('copy-module', function () {
346
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    58
    var moduleFiles = gulp.src([moduleFolder+'/*', '!'+moduleFolder+'/*.tmpl'])
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    59
        .pipe(gulp.dest(moduleBuildFolder+'/'+moduleFolder));
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    60
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    61
    var templateValues = {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    62
        corpus_back_url: corpusBackUrl,
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    63
        version: options.version,
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    64
        environment: environment
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    65
    };
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    66
    var tmplModuleFile = gulp.src(moduleFolder+'/corpus.module.tmpl')
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    67
        .pipe(template(templateValues))
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    68
        .pipe(rename("corpus.module"))
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    69
        .pipe(gulp.dest(moduleBuildFolder+'/'+moduleFolder));
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    70
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    71
    var assetsFiles = gulp.src(appBuildFolder+'/assets/**/*')
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    72
        .pipe(gulp.dest(moduleBuildFolder+'/'+moduleFolder+'/app-client/assets'));
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    73
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    74
    var fontsFiles = gulp.src(appBuildFolder+'/fonts/**/*')
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    75
        .pipe(gulp.dest(moduleBuildFolder+'/'+moduleFolder+'/app-client/fonts'));
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    76
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    77
    return merge(moduleFiles, tmplModuleFile, assetsFiles, fontsFiles);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    78
14
10f67f0281e1 move the gulpfile in the cms folder instead of the app - add readme for module and cms
nowmad@23.1.168.192.in-addr.arpa
parents:
diff changeset
    79
});
346
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    80
gulp.task('zip-module', function() {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    81
    return gulp.src(moduleBuildFolder+'/'+moduleFolder+'/**/*')
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    82
        .pipe(zip(moduleFolder+'.zip'))
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    83
        .pipe(gulp.dest(moduleBuildFolder));
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    84
})
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    85
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    86
gulp.task('default', function(cb) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    87
    seq('clean', 'copy-module', function (err) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    88
      //if any error happened in the previous tasks, exit with a code > 0
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    89
      if (err) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    90
        var exitCode = 2;
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    91
        console.log('[ERROR] gulp build task failed', err);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    92
        console.log('[FAIL] gulp build task failed - exiting with code ' + exitCode);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    93
        return process.exit(exitCode);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    94
      }
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    95
      else {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    96
        return cb();
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    97
      }
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    98
    });
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    99
});
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   100
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   101
gulp.task('zip', function(cb) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   102
    seq('clean', 'copy-module', 'zip-module', function (err) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   103
      //if any error happened in the previous tasks, exit with a code > 0
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   104
      if (err) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   105
        var exitCode = 2;
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   106
        console.log('[ERROR] gulp build task failed', err);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   107
        console.log('[FAIL] gulp build task failed - exiting with code ' + exitCode);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   108
        return process.exit(exitCode);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   109
      }
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   110
      else {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   111
        return cb();
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   112
      }
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   113
    });
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   114
});
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   115
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   116
gulp.task('do-copy-build', function(cb) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   117
    return gulp.src(moduleBuildFolder+'/'+moduleFolder+'/**/*')
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   118
        .pipe(gulp.dest(buildDestFolder));
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   119
});
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   120
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   121
gulp.task('copy-build', function(cb) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   122
    seq('clean', 'copy-module', 'do-copy-build', function (err) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   123
      //if any error happened in the previous tasks, exit with a code > 0
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   124
      if (err) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   125
        var exitCode = 2;
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   126
        console.log('[ERROR] gulp build task failed', err);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   127
        console.log('[FAIL] gulp build task failed - exiting with code ' + exitCode);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   128
        return process.exit(exitCode);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   129
      }
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   130
      else {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   131
        return cb();
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   132
      }
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   133
    });
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   134
});