Просмотр исходного кода

修改gulp打包版本号获取

huqi 5 лет назад
Родитель
Сommit
9cdb8c3f0a
4 измененных файлов с 130 добавлено и 73 удалено
  1. 47 13
      gulpfile.js
  2. 80 58
      o2web/gulpfile.js
  3. 1 1
      o2web/package.json
  4. 2 1
      package.json

+ 47 - 13
gulpfile.js

@@ -23,6 +23,8 @@ var through2 = require('through2');
 var path = require('path');
 var sourceMap = require('gulp-sourcemaps');
 
+var git = require('gulp-git');
+
 //var downloadHost = "download.o2oa.net";
 // var downloadHost = "release.o2oa.net";
 // var protocol = "http";
@@ -798,14 +800,31 @@ exports.build_concat = gulp.parallel(
     gulp.series(build_concat_baseportal_style, build_concat_baseportal_action, build_concat_baseportal_body,build_concat_baseportal_clean)
 );
 
+function getGitV(){
+    var tagPromise = new Promise(function(s){
+        git.exec({args : 'describe --tag'}, function (err, stdout) {
+            var v = stdout.substring(0, stdout.indexOf("-"));
+            s(v);
+        });
+    });
+    var revPromise = new Promise(function(s){
+        git.exec({args : 'rev-parse --short HEAD'}, function (err, hash) {
+            s(hash.trim());
+        });
+    });
+    return Promise.all([tagPromise,revPromise])
+}
 
 function build_web_v_html() {
     var src = 'o2web/source/x_desktop/*.html';
     var dest = 'target/o2server/servers/webServer/x_desktop/';
-    return gulp.src(src)
-        .pipe(assetRev())
-        .pipe(gulp.dest(dest))
-        .pipe(gutil.noop());
+
+    return getGitV().then(function(arr){
+        return gulp.src(src)
+            .pipe(assetRev({"verConnecter": arr[0], "md5": arr[1]}))
+            .pipe(gulp.dest(dest))
+            .pipe(gutil.noop());
+    });
 }
 function build_web_api() {
     var src = 'o2web/api/**/*';
@@ -813,16 +832,31 @@ function build_web_api() {
     return gulp.src(src)
         .pipe(gulp.dest(dest))
 }
+
+function build_doc(){
+    return getGitV().then(function(arr){
+        return (shell.task('jsdoc -c o2web/jsdoc.conf.json -q version='+arr[0]+'-'+arr[1]))();
+    });
+}
+exports.build_api = gulp.series(build_doc, build_web_api);
+
+
 function build_web_v_o2() {
-    var src = 'target/o2server/servers/webServer/o2_core//o2.js';
+    var src = [
+        'target/o2server/servers/webServer/o2_core/o2.js',
+        'target/o2server/servers/webServer/o2_core/o2.min.js'
+    ];
     var dest = 'target/o2server/servers/webServer/o2_core/';
-    return gulp.src(src)
-        .pipe(assetRev())
-        .pipe(gulp.dest(dest))
-        .pipe(uglify())
-        .pipe(rename({ extname: '.min.js' }))
-        .pipe(gulp.dest(dest))
-        .pipe(gutil.noop());
+
+    return getGitV().then(function(arr){
+        return gulp.src(src)
+            .pipe(assetRev({"verConnecter": arr[0], "md5": arr[1], "replace": true}))
+            //.pipe(gulp.dest(dest))
+            // .pipe(uglify())
+            // .pipe(rename({ extname: '.min.js' }))
+            // .pipe(gulp.dest(dest))
+            .pipe(gutil.noop());
+    });
 }
 
 
@@ -907,7 +941,7 @@ exports.build_web = gulp.series(
         build_bundle
     ),
     build_web_v_html,
-    build_web_api,
+    build_api,
     build_web_v_o2);
 
 if (os.platform().indexOf("win")==-1){

+ 80 - 58
o2web/gulpfile.js

@@ -17,7 +17,7 @@ concat = require('gulp-concat');
 var through2 = require('through2');
 var path = require('path');
 var sourceMap = require('gulp-sourcemaps');
-
+var git = require('gulp-git');
 
 var assetRev = require('gulp-tm-asset-rev');
 var apps = require('./gulpapps.js');
@@ -936,72 +936,94 @@ gulp.task("index", function () {
 });
 gulp.task("cleanAll", getCleanTask('/'));
 
+function getGitV(){
+    var tagPromise = new Promise(function(s){
+        git.exec({args : 'describe --tag'}, function (err, stdout) {
+            var v = stdout.substring(0, stdout.indexOf("-"));
+            s(v);
+        });
+    });
+    var revPromise = new Promise(function(s){
+        git.exec({args : 'rev-parse --short HEAD'}, function (err, hash) {
+            s(hash.trim());
+        });
+    });
+    return Promise.all([tagPromise,revPromise])
+}
+
 gulp.task("o2:new-v:html", function () {
     var path = "x_desktop";
-    var src = '/source/x_desktop/*.html';
+    var src = 'source/x_desktop/*.html';
     var dest = options.dest + '/x_desktop/';
-    return gulp.src(src)
-        .pipe(assetRev())
-        .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
-        .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
-            host: options.host,
-            user: options.user || 'anonymous',
-            pass: options.pass || '@anonymous',
-            port: options.port || 21,
-            remotePath: (options.remotePath || '/') + path
-        })))
-        .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
-            host: options.host,
-            user: options.user || 'anonymous',
-            pass: options.pass || null,
-            port: options.port || 22,
-            remotePath: (options.remotePath || '/') + path
-        })))
-        .pipe(gulp.dest(dest))
-        .pipe(gutil.noop());
 
+    return getGitV().then(function(arr) {
+        return gulp.src(src)
+            .pipe(assetRev({"verConnecter": arr[0], "md5": arr[1]}))
+            .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
+            .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
+                host: options.host,
+                user: options.user || 'anonymous',
+                pass: options.pass || '@anonymous',
+                port: options.port || 21,
+                remotePath: (options.remotePath || '/') + path
+            })))
+            .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
+                host: options.host,
+                user: options.user || 'anonymous',
+                pass: options.pass || null,
+                port: options.port || 22,
+                remotePath: (options.remotePath || '/') + path
+            })))
+            .pipe(gulp.dest(dest))
+            .pipe(gutil.noop());
+    });
 });
+
 gulp.task("o2:new-v:o2", function () {
     var path = "o2_core";
     var src = options.dest +'/o2_core/o2.js';
     var dest = options.dest +'/o2_core/';
-    return gulp.src(src)
-        .pipe(assetRev())
-        .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
-        .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
-            host: options.host,
-            user: options.user || 'anonymous',
-            pass: options.pass || '@anonymous',
-            port: options.port || 21,
-            remotePath: (options.remotePath || '/') + path
-        })))
-        .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
-            host: options.host,
-            user: options.user || 'anonymous',
-            pass: options.pass || null,
-            port: options.port || 22,
-            remotePath: (options.remotePath || '/') + path
-        })))
-        .pipe(gulp.dest(dest))
-        .pipe(uglify())
-        .pipe(rename({ extname: '.min.js' }))
-        .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
-        .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
-            host: options.host,
-            user: options.user || 'anonymous',
-            pass: options.pass || '@anonymous',
-            port: options.port || 21,
-            remotePath: (options.remotePath || '/') + path
-        })))
-        .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
-            host: options.host,
-            user: options.user || 'anonymous',
-            pass: options.pass || null,
-            port: options.port || 22,
-            remotePath: (options.remotePath || '/') + path
-        })))
-        .pipe(gulp.dest(dest))
-        .pipe(gutil.noop());
+
+    return getGitV().then(function(arr){
+        var v = arr[0]+"-"+arr[1];
+        return gulp.src(src)
+            .pipe(assetRev({"verConnecter": arr[0], "md5": arr[1], "replace": true}))
+            .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
+            .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
+                host: options.host,
+                user: options.user || 'anonymous',
+                pass: options.pass || '@anonymous',
+                port: options.port || 21,
+                remotePath: (options.remotePath || '/') + path
+            })))
+            .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
+                host: options.host,
+                user: options.user || 'anonymous',
+                pass: options.pass || null,
+                port: options.port || 22,
+                remotePath: (options.remotePath || '/') + path
+            })))
+            .pipe(gulp.dest(dest))
+            .pipe(uglify())
+            .pipe(rename({ extname: '.min.js' }))
+            .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
+            .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
+                host: options.host,
+                user: options.user || 'anonymous',
+                pass: options.pass || '@anonymous',
+                port: options.port || 21,
+                remotePath: (options.remotePath || '/') + path
+            })))
+            .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
+                host: options.host,
+                user: options.user || 'anonymous',
+                pass: options.pass || null,
+                port: options.port || 22,
+                remotePath: (options.remotePath || '/') + path
+            })))
+            .pipe(gulp.dest(dest))
+            .pipe(gutil.noop());
+    });
 });
 gulp.task("o2:new-v", gulp.parallel("o2:new-v:o2", "o2:new-v:html"));
 

+ 1 - 1
o2web/package.json

@@ -36,7 +36,7 @@
     "gulp-rename": "^1.4.0",
     "gulp-sftp-up4": "^0.1.8",
     "gulp-sourcemaps": "^3.0.0",
-    "gulp-tm-asset-rev": "0.0.16",
+    "gulp-tm-asset-rev": "^0.0.18",
     "gulp-tm-uglify": "3.0.1",
     "gulp-uglify-es": "^2.0.0",
     "jasmine-core": "^3.6.0",

+ 2 - 1
package.json

@@ -61,12 +61,13 @@
                 "gulp-changed": "^3.2.0",
                 "gulp-concat": "^2.6.1",
                 "gulp-deleted": "^1.0.0",
+                "gulp-git": "^2.10.1",
                 "gulp-if": "^2.0.2",
                 "gulp-logger": "0.0.2",
                 "gulp-rename": "^1.4.0",
                 "gulp-shell": "^0.8.0",
                 "gulp-sourcemaps": "^3.0.0",
-                "gulp-tm-asset-rev": "0.0.16",
+                "gulp-tm-asset-rev": "^0.0.18",
                 "gulp-tm-uglify": "3.0.1",
                 "gulp-uglify-es": "^2.0.0",
                 "gulp-util": "^3.0.8",