From 77df43b15e16c9b71162a17a66925091a9b83134 Mon Sep 17 00:00:00 2001 From: huqi Date: Sat, 21 Mar 2020 14:38:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=93=E5=8C=85=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 36 +------- gulpfile.js | 227 ++++++++++++++++++---------------------------- o2web/gulpapps.js | 4 +- o2web/gulpfile.js | 15 ++- package.json | 129 +++++++++++++------------- 5 files changed, 172 insertions(+), 239 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5397c42914..072f03baf1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,6 +8,7 @@ pipeline { } sh 'npm install' sh 'npm run preperation:linux' + sh 'npm run clear' } } stage('build') { @@ -26,38 +27,9 @@ pipeline { } } stage('deploy') { - parallel { - stage('deploy sotre') { - steps { - sh 'npm run deploy:sotre' - } - } - stage('deploy commons') { - steps { - sh 'npm run deploy:commons' - } - } - stage('deploy jvm') { - steps { - sh 'npm run deploy:jvm' - } - } - stage('deploy config') { - steps { - sh 'npm run deploy:config' - } - } - stage('deploy local') { - steps { - sh 'npm run deploy:local' - } - } - stage('deploy script') { - steps { - sh 'deploy_script:linux' - sh 'chmod 777 target/o2server/*.sh' - } - } + steps { + sh 'deploy_script:linux' + sh 'chmod 777 target/o2server/*.sh' } } stage('run') { diff --git a/gulpfile.js b/gulpfile.js index 987a938244..d5bea67052 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,5 +1,6 @@ var gulp = require('gulp'), gutil = require('gulp-util'), + del = require('del'), fs = require("fs"), minimist = require('minimist'), targz = require('targz'), @@ -7,7 +8,13 @@ var gulp = require('gulp'), dateFormat = require('dateformat'), progress = require('progress-stream'), request = require("request"), + uglify = require('gulp-tm-uglify'), + rename = require('gulp-rename'), + changed = require('gulp-changed'), + gulpif = require('gulp-if'), http = require('http'); +var fg = require('fast-glob'); +var logger = require('gulp-logger'); //var downloadHost = "download.o2oa.net"; var downloadHost = "release.o2oa.net"; @@ -231,7 +238,7 @@ function decompress_commons_and_jvm(cb){ }); } -function getFileCount(p){ +function getJsFileCount(p){ var fileCount = 0; function readFile(path,filesList, ){ files = fs.readdirSync(path); @@ -252,160 +259,100 @@ function getFileCount(p){ } -function deploy_web(){ - var path = "o2server/servers/" - var fileCount = getFileCount(path); +function build_web_minimize(cb) { + var dest = 'target/o2server/webServer/'; + var src_min = ['o2web/source/**/*.js', '!**/*.spec.js', '!**/test/**', '!o2web/source/o2_lib/**/*']; + //var src_min = ['o2web/source/o2_core/**/*.js', '!**/*.spec.js', '!**/test/**', '!o2web/source/o2_lib/**/*']; - //console.log(fileCount); - var pb = new ProgressBar('', 50); - var progressStream = progress({ - length: fileCount, - time: 100, - objectMode: true - }); - progressStream.on('progress', function (stats) { - var n = (fileCount*stats.percentage/100).toFixed(0); - if (n>fileCount) n = fileCount; - pb.render({ completed: n, total: fileCount, count: n}); - }); + var entries = fg.sync(src_min, { dot: true}); + var size = entries.length; - var source = "o2server/servers/**/*"; - var dest = "target/o2server/servers/" - return gulp.src(source) - .pipe(progressStream) + var pb = new ProgressBar('total: '+size, 50); + var doCount = 0; + return gulp.src(src_min) + .pipe(uglify()) + .pipe(rename({ extname: '.min.js' })) .pipe(gulp.dest(dest)) + .pipe(logger(function(){ + doCount++; + pb.render({ completed: doCount, total: size, count: doCount}); + if (doCount == size) console.log(); + })) .pipe(gutil.noop()); } -function deploy_server_store(){ - var path = "o2server/store/" - var fileCount = getFileCount(path); - - var pb = new ProgressBar('total: '+fileCount, 50); - var progressStream = progress({ - length: fileCount, - time: 100, - objectMode: true - }); - progressStream.on('progress', function (stats) { - var n = (fileCount*stats.percentage/100).toFixed(0); - if (n>fileCount) n = fileCount; - pb.render({ completed: n, total: fileCount, count: n}); - }); - var source = "o2server/store/**/*"; - var dest = "target/o2server/store/"; - return gulp.src(source) - .pipe(progressStream) - .pipe(gulp.dest(dest)) - .pipe(gutil.noop()); -} -function deploy_server_commons(){ - var path = "o2server/commons/"; - var fileCount = getFileCount(path); - - var pb = new ProgressBar('total: '+fileCount, 50); - var progressStream = progress({ - length: fileCount, - time: 100, - objectMode: true - }); - progressStream.on('progress', function (stats) { - var n = (fileCount*stats.percentage/100).toFixed(0); - if (n>fileCount) n = fileCount; - pb.render({ completed: n, total: fileCount, count: n}); - }); +function build_web_move() { + var dest = 'target/o2server/webServer/'; + var src_move = ['o2web/source/**/*', '!**/*.spec.js', '!**/test/**']; - var source = "o2server/commons/**/*"; - var dest = "target/o2server/commons/"; - return gulp.src(source) - .pipe(progressStream) - .pipe(gulp.dest(dest)) - .pipe(gutil.noop()); -} -function deploy_server_jvm(){ - var path = "o2server/jvm/"; - var fileCount = getFileCount(path); - - var pb = new ProgressBar('total: '+fileCount, 50); - var progressStream = progress({ - length: fileCount, - time: 100, - objectMode: true - }); - progressStream.on('progress', function (stats) { - var n = (fileCount*stats.percentage/100).toFixed(0); - if (n>fileCount) n = fileCount; - pb.render({ completed: n, total: fileCount, count: n}); - }); + var entries = fg.sync(src_move, { dot: true}); + var size = entries.length; + var pb = new ProgressBar('total: '+size, 50); + var doCount = 0; - var source = "o2server/jvm/**/*"; - var dest = "target/o2server/jvm/"; - return gulp.src(source) - .pipe(progressStream) + return gulp.src(src_move) .pipe(gulp.dest(dest)) + .pipe(logger(function(){ + doCount++; + pb.render({ completed: doCount, total: size, count: doCount}); + if (doCount == size) console.log(); + })) .pipe(gutil.noop()); } -function deploy_server_config(){ - var path = "o2server/configSample/"; - var fileCount = getFileCount(path); - - var pb = new ProgressBar('total: '+fileCount, 50); - var progressStream = progress({ - length: fileCount, - time: 100, - objectMode: true - }); - progressStream.on('progress', function (stats) { - var n = (fileCount*stats.percentage/100).toFixed(0); - if (n>fileCount) n = fileCount; - pb.render({ completed: n, total: fileCount, count: n}); - }); - - var source = "o2server/configSample/**/*"; - var dest = "target/o2server/configSample/"; - return gulp.src(source) - .pipe(progressStream) - .pipe(gulp.dest(dest)) - .pipe(gutil.noop()); +exports.build_web_move = build_web_move; + +function clear_build(cb){ + console.log(`------------------------------------------------------------- + . clear old build ... +-------------------------------------------------------------`); + var dest = 'target'; + del(dest, { dryRun: true, force: true }); + cb(); } -function deploy_server_local(){ - var path = "o2server/localSample/"; - var fileCount = getFileCount(path); - - var pb = new ProgressBar('total: '+fileCount, 50); - var progressStream = progress({ - length: fileCount, - time: 100, - objectMode: true - }); - progressStream.on('progress', function (stats) { - var n = (fileCount*stats.percentage/100).toFixed(0); - if (n>fileCount) n = fileCount; - pb.render({ completed: n, total: fileCount, count: n}); - }); +exports.clear_build = clear_build; + + +function deploy_server(){ + console.log(`------------------------------------------------------------- + . deploy to target ... +-------------------------------------------------------------`); + var source1 = ["o2server/store/**/*", "o2server/commons/**/*", "o2server/jvm/**/*", "o2server/configSample/**/*", "o2server/localSample/**/*"]; + source = source1.concat(scriptSource); + var dest = "target/o2server/servers/" + + var entries = fg.sync(source, { dot: true}); + var size = entries.length; + var pb = new ProgressBar('total: '+size, 50); + var doCount = 0; - var source = "o2server/localSample/**/*"; - var dest = "target/o2server/localSample/"; return gulp.src(source) - .pipe(progressStream) .pipe(gulp.dest(dest)) - .pipe(gutil.noop()); -} -function deploy_server_script(){ - var dest = "target/o2server/"; - return gulp.src(scriptSource) - .pipe(gulp.dest(dest)) - .pipe(gutil.noop()); + .pipe(logger(function(){ + doCount++; + if (doCount <= size) pb.render({ completed: doCount, total: size, count: doCount}); + if (doCount > size) {console.log();} + })); + //.pipe(gutil.noop()); } +exports.preperation = function(){ + console.log(`--------------------------------------------------------------------- + . Start to download the dependencies needed for compilation ... +---------------------------------------------------------------------`); + return (gulp.series(download_commons_and_jvm, decompress_commons_and_jvm))(); +} -exports.preperation = gulp.series(download_commons_and_jvm, decompress_commons_and_jvm); -//exports.deploy_web = deploy_web; -exports.deploy_server_store = deploy_server_store; -exports.deploy_server_commons = deploy_server_commons; -exports.deploy_server_jvm = deploy_server_jvm; -exports.deploy_server_config = deploy_server_config; -exports.deploy_server_local = deploy_server_local; -exports.deploy_server_script = deploy_server_script; -exports.deploy_server = gulp.series(deploy_server_store, deploy_server_commons, deploy_server_jvm, deploy_server_config, deploy_server_local, deploy_server_script); -exports.deploy = gulp.series(deploy_server_store, deploy_server_commons, deploy_server_jvm, deploy_server_config, deploy_server_local, deploy_server_script); +var shell = require('gulp-shell') +exports.build_server = function(){ + console.log(`------------------------------------------------------------- + . Start compiling the server ... +-------------------------------------------------------------`); + return (shell.task('npm run build_server_script'))(); +}; +exports.build_web = function(){ + console.log(`------------------------------------------------------------- + . Start compiling the web ... +-------------------------------------------------------------`); + return (gulp.series(build_web_minimize, build_web_move))(); +} +exports.deploy = deploy_server; diff --git a/o2web/gulpapps.js b/o2web/gulpapps.js index 667edf31c6..5441587c99 100644 --- a/o2web/gulpapps.js +++ b/o2web/gulpapps.js @@ -1,4 +1,4 @@ -var dev = [ +var apps = [ { "folder": "o2_lib", "tasks": ["move"] }, { "folder": "o2_core", "tasks": ["move", "min"] }, { "folder": "x_component_ANN", "tasks": ["move", "min"] }, @@ -86,4 +86,4 @@ var dev = [ { "folder": "x_desktop", "tasks": ["move", "min"] }, ]; -module.exports = dev; +module.exports = apps; diff --git a/o2web/gulpfile.js b/o2web/gulpfile.js index d6ec8ead23..631194562b 100644 --- a/o2web/gulpfile.js +++ b/o2web/gulpfile.js @@ -90,7 +90,7 @@ function getAppTask(path, isMin, thisOptions) { port: option.port || 22, remotePath: (option.remotePath || '/') + path }))) - .pipe(gulpif((option.ev == "dev") ,gulp.dest(dest))) + .pipe(gulpif((option.ev == "dev" || option.ev == "pro") ,gulp.dest(dest))) .pipe(gulp.src(src_move)) .pipe(changed(dest)) @@ -367,3 +367,16 @@ gulp.task("git_dest", function () { gulp.task("git", gulp.series('git_clean', 'git_dest')); gulp.task("default", gulp.series(gulp.parallel(appTasks, 'index'), "o2:new-v")); + +function build(){ + options.ev = "p"; + options.upload = o_options.upload || ""; + options.location = o_options.location || uploadOptions.location; + options.host = o_options.host || uploadOptions.host; + options.user = o_options.user || uploadOptions.user; + options.pass = o_options.pass || uploadOptions.pass; + options.port = o_options.port || uploadOptions.port; + options.remotePath = o_options.remotePath || uploadOptions.remotePath; + options.dest = o_options.dest || uploadOptions.dest || "dest"; +}; +gulp.task("build", gulp.series("clean", gulp.parallel(appTasks, 'index'), "o2:new-v")) diff --git a/package.json b/package.json index 82013a536e..dbd982c4f1 100644 --- a/package.json +++ b/package.json @@ -1,70 +1,71 @@ { - "name": "o2oa", - "version": "4.0.3763", - "description": "o2oa", - "main": "", - "scripts": { - "preperation": "gulp preperation", - "preperation:win": "gulp preperation --e windows", - "preperation:linux": "gulp preperation --e linux", - "preperation:aix": "gulp preperation --e aix", - "preperation:kylinos": "gulp preperation --e kylinos", - "preperation:macos": "gulp preperation --e macos", - "preperation:neokylin": "gulp preperation --e neokylin", - "preperation:rpi": "gulp preperation --e raspberrypi", + "name": "o2oa", + "version": "4.0.3763", + "description": "o2oa", + "main": "", + "scripts": { + "preperation": "gulp preperation", + "preperation:win": "gulp preperation --e windows", + "preperation:linux": "gulp preperation --e linux", + "preperation:aix": "gulp preperation --e aix", + "preperation:kylinos": "gulp preperation --e kylinos", + "preperation:macos": "gulp preperation --e macos", + "preperation:neokylin": "gulp preperation --e neokylin", + "preperation:rpi": "gulp preperation --e raspberrypi", - "build_server": "cd o2server && mvn clean && mvn install", - "build_web": "cd o2server && npm install && gulp", - "build_parallel": "npm run build_server & npm run build_web", + "build_server": "gulp build_server", + "build_server_script": "cd o2server && mvn clean && mvn install", + "build_web": "gulp build_web", + "build_parallel": "npm run build_server & npm run build_web", - "deploy": "gulp deploy", - "deploy:win": "gulp deploy --e windows", - "deploy:linux": "gulp deploy --e linux", - "deploy:aix": "gulp deploy --e aix", - "deploy:kylinos": "gulp deploy --e kylinos", - "deploy:macos": "gulp deploy --e macos", - "deploy:neokylin": "gulp deploy --e neokylin", - "deploy:rpi": "gulp deploy --e raspberrypi", + "deploy": "gulp deploy", + "deploy:win": "gulp deploy --e windows", + "deploy:linux": "gulp deploy --e linux", + "deploy:aix": "gulp deploy --e aix", + "deploy:kylinos": "gulp deploy --e kylinos", + "deploy:macos": "gulp deploy --e macos", + "deploy:neokylin": "gulp deploy --e neokylin", + "deploy:rpi": "gulp deploy --e raspberrypi", - "deploy:sotre": "gulp deploy_server_store", - "deploy:commons": "gulp deploy_server_commons", - "deploy:jvm": "gulp deploy_server_jvm", - "deploy:config": "gulp deploy_server_config", - "deploy:local": "gulp deploy_server_local", - "deploy_script:win": "gulp deploy_server_script --e windows", - "deploy_script:linux": "gulp deploy_server_script --e linux", - "deploy_script:aix": "gulp deploy_server_script --e aix", - "deploy_script:kylinos": "gulp deploy_server_script --e kylinos", - "deploy_script:macos": "gulp deploy_server_script --e macos", - "deploy_script:neokylin": "gulp deploy_server_script --e neokylin", - "deploy_script:rpi": "gulp deploy_server_script --e raspberrypi", + "typeInfor": "type welcome && echo Your server is build success: target/o2server/", + "clear": "gulp clear_build", - "typeInfor": "type welcome && echo Your server is build success: target/o2server/", - - "build": "npm run preperation && npm run build_parallel && npm run deploy && npm run typeInfor", - "build:win": "npm run preperation:win && npm run build_parallel && npm run deploy:win && npm run typeInfor", - "build:linux": "npm run preperation:linux && npm run build_parallel && npm run deploy:linux && npm run typeInfor", - "build:aix": "npm run preperation:aix && npm run build_parallel && npm run deploy:aix && npm run typeInfor", - "build:kylinos": "npm run preperation:kylinos && npm run build_parallel && npm run deploy:kylinos && npm run typeInfor", - "build:macos": "npm run preperation:macos && npm run build_parallel && npm run deploy:macos && npm run typeInfor", - "build:neokylin": "npm run preperation:neokylin && npm run build_parallel && npm run deploy:neokylin && npm run typeInfor", - "build:rpi": "npm run preperation:rpi && npm run build_parallel && npm run deploy:rpi && npm run typeInfor", - - "test": "type welcome" - }, - "repository": { - "type": "git", - "url": "https://github.com/o2oa/o2oa.git" - }, - "author": "", - "license": "ISC", - "dependencies": { - "dateformat": "^3.0.3", - "gulp": "^4.0.2", - "gulp-util": "^3.0.8", - "progress-stream": "^2.0.0", - "request": "^2.88.2", - "single-line-log": "^1.1.2", - "targz": "^1.0.1" - } + "build": "npm run clear && npm run preperation && npm run build_parallel && npm run deploy && npm run typeInfor", + "build:win": "npm run clear && npm run preperation:win && npm run build_parallel && npm run deploy:win && npm run typeInfor", + "build:linux": "npm run clear && npm run preperation:linux && npm run build_parallel && npm run deploy:linux && npm run typeInfor", + "build:aix": "npm run clear && npm run preperation:aix && npm run build_parallel && npm run deploy:aix && npm run typeInfor", + "build:kylinos": "npm run clear && npm run preperation:kylinos && npm run build_parallel && npm run deploy:kylinos && npm run typeInfor", + "build:macos": "npm run clear && npm run preperation:macos && npm run build_parallel && npm run deploy:macos && npm run typeInfor", + "build:neokylin": "npm run clear && npm run preperation:neokylin && npm run build_parallel && npm run deploy:neokylin && npm run typeInfor", + "build:rpi": "npm run clear && npm run preperation:rpi && npm run build_parallel && npm run deploy:rpi && npm run typeInfor", + "test": "type welcome" + }, + "repository": { + "type": "git", + "url": "https://github.com/o2oa/o2oa.git" + }, + "author": "", + "license": "ISC", + "dependencies": { + "dateformat": "^3.0.3", + "fast-glob": "^3.2.2", + "glob": "^7.1.6", + "gulp": "^4.0.2", + "gulp-changed": "^3.2.0", + "gulp-deleted": "^1.0.0", + "gulp-if": "^2.0.2", + "gulp-logger": "0.0.2", + "gulp-progress": "^1.0.0", + "gulp-rename": "^1.4.0", + "gulp-shell": "^0.8.0", + "gulp-tm-asset-rev": "0.0.16", + "gulp-tm-uglify": "3.0.1", + "gulp-util": "^3.0.8", + "merge-stream": "^1.0.1", + "minimist": "^1.2.0", + "progress-stream": "^2.0.0", + "request": "^2.88.2", + "single-line-log": "^1.1.2", + "targz": "^1.0.1" + } } -- GitLab