cms/gulpfile.js
author ymh <ymh.work@gmail.com>
Tue, 26 Sep 2017 21:41:49 +0200
changeset 550 fbd1bfc9f963
parent 541 e756a8c72c3d
permissions -rw-r--r--
Improve label resolution in french for geonames.
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';
541
e756a8c72c3d integrate drupal and correct build process. update version
ymh <ymh.work@gmail.com>
parents: 346
diff changeset
    13
const moduleBuildFolder = 'dist';
e756a8c72c3d integrate drupal and correct build process. update version
ymh <ymh.work@gmail.com>
parents: 346
diff changeset
    14
const drupalSrcFolder = 'drupal';
e756a8c72c3d integrate drupal and correct build process. update version
ymh <ymh.work@gmail.com>
parents: 346
diff changeset
    15
const drupalDestFolder = '../build/root/var/www/corpusdelaparole/drupal';
e756a8c72c3d integrate drupal and correct build process. update version
ymh <ymh.work@gmail.com>
parents: 346
diff changeset
    16
const buildDestFolder = drupalDestFolder + '/sites/all/modules/' + moduleFolder;
346
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
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
    19
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    20
if(!options.version) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    21
    return process.exit(2);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    22
}
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
    23
346
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    24
var buildOption = "--prod";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    25
var environment = "production";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    26
var corpusBackUrl = "corpus-back";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    27
if(options.prod) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    28
    buildOption = "--prod";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    29
    environment = "production";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    30
    corpusBackUrl = "corpus-back";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    31
} else if(options.dev) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    32
    buildOption = "--dev";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    33
    environment = "development";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    34
    corpusBackUrl = "corpus-app";
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    35
}
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    36
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
    37
346
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    38
gulp.task('build-ember', function(cb) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    39
    exec('npm install', {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    40
        cwd: '../app-client',
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    41
        stdio:[0,1,2]
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    42
    });
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    43
    exec('node_modules/.bin/bower install', {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    44
        cwd: '../app-client',
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    45
        stdio:[0,1,2]
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    46
    });
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    47
    exec('node_modules/.bin/ember build '+buildOption, {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    48
        cwd: '../app-client',
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    49
        stdio:[0,1,2]
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
});
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    52
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    53
gulp.task('clean', function() {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    54
    return del([
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    55
        moduleBuildFolder+'/'+moduleFolder+'/**/*',
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    56
        moduleBuildFolder+'/**/*',
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    57
    ]);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    58
});
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
    59
gulp.task('copy-module', function () {
346
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    60
    var moduleFiles = gulp.src([moduleFolder+'/*', '!'+moduleFolder+'/*.tmpl'])
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    61
        .pipe(gulp.dest(moduleBuildFolder+'/'+moduleFolder));
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    62
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    63
    var templateValues = {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    64
        corpus_back_url: corpusBackUrl,
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    65
        version: options.version,
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    66
        environment: environment
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    67
    };
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    68
    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
    69
        .pipe(template(templateValues))
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    70
        .pipe(rename("corpus.module"))
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    71
        .pipe(gulp.dest(moduleBuildFolder+'/'+moduleFolder));
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    72
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    73
    var assetsFiles = gulp.src(appBuildFolder+'/assets/**/*')
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    74
        .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
    75
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    76
    var fontsFiles = gulp.src(appBuildFolder+'/fonts/**/*')
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    77
        .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
    78
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    79
    return merge(moduleFiles, tmplModuleFile, assetsFiles, fontsFiles);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    80
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
    81
});
346
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    82
gulp.task('zip-module', function() {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    83
    return gulp.src(moduleBuildFolder+'/'+moduleFolder+'/**/*')
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    84
        .pipe(zip(moduleFolder+'.zip'))
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    85
        .pipe(gulp.dest(moduleBuildFolder));
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    86
})
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    87
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    88
gulp.task('default', function(cb) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    89
    seq('clean', 'copy-module', function (err) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    90
      //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
    91
      if (err) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    92
        var exitCode = 2;
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    93
        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
    94
        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
    95
        return process.exit(exitCode);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    96
      }
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    97
      else {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
    98
        return cb();
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
});
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   102
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   103
gulp.task('zip', function(cb) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   104
    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
   105
      //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
   106
      if (err) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   107
        var exitCode = 2;
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   108
        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
   109
        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
   110
        return process.exit(exitCode);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   111
      }
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   112
      else {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   113
        return cb();
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
});
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   117
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   118
gulp.task('do-copy-build', function(cb) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   119
    return gulp.src(moduleBuildFolder+'/'+moduleFolder+'/**/*')
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   120
        .pipe(gulp.dest(buildDestFolder));
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   121
});
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   122
541
e756a8c72c3d integrate drupal and correct build process. update version
ymh <ymh.work@gmail.com>
parents: 346
diff changeset
   123
gulp.task('copy-drupal', function(cb) {
e756a8c72c3d integrate drupal and correct build process. update version
ymh <ymh.work@gmail.com>
parents: 346
diff changeset
   124
    return gulp.src([drupalSrcFolder+'/**/*', drupalSrcFolder+'/**/.*'])
e756a8c72c3d integrate drupal and correct build process. update version
ymh <ymh.work@gmail.com>
parents: 346
diff changeset
   125
        .pipe(gulp.dest(drupalDestFolder));
e756a8c72c3d integrate drupal and correct build process. update version
ymh <ymh.work@gmail.com>
parents: 346
diff changeset
   126
});
e756a8c72c3d integrate drupal and correct build process. update version
ymh <ymh.work@gmail.com>
parents: 346
diff changeset
   127
346
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   128
gulp.task('copy-build', function(cb) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   129
    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
   130
      //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
   131
      if (err) {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   132
        var exitCode = 2;
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   133
        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
   134
        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
   135
        return process.exit(exitCode);
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   136
      }
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   137
      else {
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   138
        return cb();
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   139
      }
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   140
    });
4cd0f8c936ed upgrade build and delivery process for integration
ymh <ymh.work@gmail.com>
parents: 14
diff changeset
   141
});