From 9cdb8c3f0a9d7db6ba25eaf61a3d0a74ac9b0527 Mon Sep 17 00:00:00 2001 From: huqi Date: Tue, 19 Jan 2021 18:16:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9gulp=E6=89=93=E5=8C=85?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gulpfile.js | 60 +++++++++++++++----- o2web/gulpfile.js | 138 ++++++++++++++++++++++++++------------------- o2web/package.json | 2 +- package.json | 3 +- 4 files changed, 130 insertions(+), 73 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index dde5083862..19cd4a36a5 100644 --- a/gulpfile.js +++ b/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){ diff --git a/o2web/gulpfile.js b/o2web/gulpfile.js index 14ff9afcdd..d63516dec7 100644 --- a/o2web/gulpfile.js +++ b/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")); diff --git a/o2web/package.json b/o2web/package.json index 244e4a1e93..0d77b4efb6 100644 --- a/o2web/package.json +++ b/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", diff --git a/package.json b/package.json index e1643992f2..1f7cb8b299 100644 --- a/package.json +++ b/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", -- GitLab