gulpfile.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. var gulp = require('gulp'),
  2. gutil = require('gulp-util'),
  3. del = require('del'),
  4. fs = require("fs"),
  5. minimist = require('minimist'),
  6. targz = require('targz'),
  7. slog = require('single-line-log').stdout,
  8. dateFormat = require('dateformat'),
  9. progress = require('progress-stream'),
  10. request = require("request"),
  11. //uglify = require('gulp-tm-uglify'),
  12. uglify = require('gulp-uglify-es').default,
  13. rename = require('gulp-rename'),
  14. changed = require('gulp-changed'),
  15. gulpif = require('gulp-if'),
  16. http = require('http');
  17. concat = require('gulp-concat');
  18. var fg = require('fast-glob');
  19. var logger = require('gulp-logger');
  20. var assetRev = require('gulp-tm-asset-rev');
  21. const os = require('os');
  22. var through2 = require('through2');
  23. var path = require('path');
  24. var sourceMap = require('gulp-sourcemaps');
  25. //var downloadHost = "download.o2oa.net";
  26. // var downloadHost = "release.o2oa.net";
  27. // var protocol = "http";
  28. // var commonUrl = "/build/commons.tar.gz";
  29. // var jvmUrls = {
  30. // "all": "/build/jvm.tar.gz",
  31. // "linux": "/build/linux.tar.gz",
  32. // "aix": "/build/aix.tar.gz",
  33. // "arm": "/build/arm.tar.gz",
  34. // "macos": "/build/macos.tar.gz",
  35. // "risc": "/build/risc.tar.gz",
  36. // "raspberrypi": "/build/raspberrypi.tar.gz",
  37. // "windows": "/build/windows.tar.gz"
  38. // };
  39. var downloadHost = "git.o2oa.net";
  40. var protocol = "https";
  41. var commonUrl = "/o2oa/evn-o2server-commons/-/archive/master/evn-o2server-commons-master.tar.gz?path=commons";
  42. var jvmUrls = {
  43. "all": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm",
  44. "linux": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/linux",
  45. "aix": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/aix",
  46. "arm": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/arm",
  47. "macos": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/macos",
  48. "risc": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/risc",
  49. "raspi": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/raspi",
  50. "windows": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/windows"
  51. };
  52. var scripts = {
  53. "all": ["o2server/*.sh", "o2server/*.jar", "o2server/*.html", "o2server/*.bat", "o2server/version.o2"],
  54. "linux": ["o2server/*linux*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"],
  55. "aix": ["o2server/*aix*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"],
  56. "arm": ["o2server/*arm*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"],
  57. "macos": ["o2server/*macos*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"],
  58. "risc": ["o2server/*risc*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"],
  59. "raspi": ["o2server/*raspi*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"],
  60. "windows": ["o2server/*windows*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"]
  61. };
  62. var o_options = minimist(process.argv.slice(2), {//upload: local ftp or sftp
  63. string: ["e", "lp"]
  64. });
  65. var options = {};
  66. options.ev = o_options.e || "all";
  67. options.lp = o_options.lp || "zh-cn";
  68. var jvmUrl = jvmUrls[options.ev];
  69. var scriptSource = scripts[options.ev];
  70. function ProgressBar(description, bar_length){
  71. this.description = description || 'Progress';
  72. this.length = bar_length || 50;
  73. this.render = function (opts){
  74. var percent = (opts.completed / opts.total).toFixed(4);
  75. var cell_num = Math.floor(percent * this.length);
  76. var speed = "";
  77. if (opts.time){
  78. speed = (opts.completed/1024/1024)/(opts.time/1000);
  79. speed = speed.toFixed(2);
  80. speed = speed+"M/S";
  81. }
  82. var count = "";
  83. if (opts.count){
  84. count = "["+opts.count+"/"+opts.total+"]"
  85. }
  86. var cell = '';
  87. for (var i=0;i<cell_num;i++) { cell += '>'; }
  88. var empty = '';
  89. for (var i=0;i<this.length-cell_num;i++) { empty += '='; }
  90. if (opts.completed <= opts.total){
  91. var d = new Date();
  92. var cmdText = "["+dateFormat(d, "HH:MM:ss")+"]"+" "+this.description + ': ' + cell + empty + ' ' + (100*percent).toFixed(2) + '% '+speed+count;
  93. slog(cmdText);
  94. }
  95. };
  96. }
  97. function downloadFile_progress(path, filename, headcb, progresscb, cb){
  98. var dest = `o2server/${filename}`;
  99. // fs.exists(dest, function(exists) {
  100. // if (exists){
  101. // headcb(1);
  102. // progresscb({transferred:1});
  103. // cb();
  104. // }else{
  105. let stream = fs.createWriteStream(dest);
  106. var options = { url:protocol+"://"+downloadHost+path };
  107. var fileHost = downloadHost;
  108. var filePath = path;
  109. stream.on('finish', () => {
  110. //gutil.log("download", ":", gutil.colors.green(filename), " completed!");
  111. cb();
  112. });
  113. stream.on('error', (err) => {
  114. gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), err);
  115. });
  116. var req = http.request({
  117. host:fileHost,
  118. path:filePath,
  119. method:'HEAD'
  120. },function (res){
  121. if (res.statusCode == 200) {
  122. res.setEncoding(null);
  123. var time = 0;
  124. var l = res.headers['content-length'];
  125. var str = progress({
  126. length: l,
  127. time: 100 /* ms */
  128. });
  129. headcb(l);
  130. str.on('progress', function(progress) {
  131. if (pb){
  132. progresscb(progress);
  133. pb.render({ completed: currentLength, total: totalLength, time: time+=100 });
  134. }
  135. });
  136. request.get(options).pipe(str).pipe(stream);
  137. } else {
  138. gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+res.statusCode);
  139. }
  140. })
  141. req.on('error', (e) => {
  142. gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), e);
  143. });
  144. req.end();
  145. // }
  146. //});
  147. }
  148. function downloadFile(path, filename, headcb, progresscb, cb){
  149. var dest = `o2server/${filename}`;
  150. // fs.exists(dest, function(exists) {
  151. // if (exists){
  152. // headcb(1);
  153. // progresscb({transferred:1});
  154. // cb();
  155. // }else{
  156. let stream = fs.createWriteStream(dest);
  157. var options = { url:protocol+"://"+downloadHost+path };
  158. var fileHost = downloadHost;
  159. var filePath = path;
  160. stream.on('finish', () => {
  161. //gutil.log("download", ":", gutil.colors.green(filename), " completed!");
  162. cb();
  163. });
  164. stream.on('error', (err) => {
  165. gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), err);
  166. });
  167. // var req = http.request({
  168. // host:fileHost,
  169. // path:filePath,
  170. // method:'HEAD'
  171. // },function (res){
  172. // if (res.statusCode == 200) {
  173. // res.setEncoding(null);
  174. // var time = 0;
  175. // var l = res.headers['content-length'];
  176. // var str = progress({
  177. // length: l,
  178. // time: 100 /* ms */
  179. // });
  180. // headcb(l);
  181. //
  182. // str.on('progress', function(progress) {
  183. // if (pb){
  184. // progresscb(progress);
  185. // pb.render({ completed: currentLength, total: totalLength, time: time+=100 });
  186. // }
  187. //
  188. // });
  189. request.get(options).pipe(stream);
  190. // } else {
  191. // gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+res.statusCode);
  192. // }
  193. // })
  194. // req.on('error', (e) => {
  195. // gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), e);
  196. // });
  197. // req.end();
  198. // }
  199. //});
  200. }
  201. var commonsLength = 0;
  202. var jvmLenght = 0;
  203. var totalLength = 0;
  204. var currentLength = 0;
  205. var commonsCurrentLength = 0;
  206. var jvmCurrentLength = 0;
  207. var pb = null;
  208. function initProgress(){
  209. if (commonsLength && jvmLenght){
  210. totalLength = +commonsLength + jvmLenght;
  211. var t = (totalLength/1024/1024).toFixed(2);
  212. pb = new ProgressBar('total: '+t+"M", 50);
  213. }
  214. }
  215. function download_commons_and_jvm(cb){
  216. gutil.log(gutil.colors.green("begin download commons and jvm"));
  217. console.log(`---------------------------------------------------------------------
  218. . Start to download the dependencies needed for compilation ...
  219. ---------------------------------------------------------------------`);
  220. var downloader = new Promise((resolve, reject) => {
  221. var commonLoaded = false;
  222. var jvmLoaded = false;
  223. downloadFile(commonUrl, "commons_git.tar.gz", (length)=>{
  224. commonsLength = +length;
  225. initProgress();
  226. }, (progress)=>{
  227. commonsCurrentLength = progress.transferred;
  228. currentLength = +commonsCurrentLength+jvmCurrentLength;
  229. }, ()=>{
  230. commonLoaded = true;
  231. if (jvmLoaded && commonLoaded) resolve();
  232. });
  233. // var jvmName = jvmUrl.substr(jvmUrl.lastIndexOf("/"+1, jvmUrl.length));
  234. // console.log(jvmName);
  235. // console.log(jvmUrl);
  236. downloadFile(jvmUrl, "jvm_git.tar.gz", (length)=>{
  237. jvmLenght = +length;
  238. initProgress();
  239. }, (progress)=>{
  240. jvmCurrentLength = progress.transferred;
  241. currentLength = +commonsCurrentLength+jvmCurrentLength;
  242. }, ()=>{
  243. jvmLoaded = true;
  244. if (jvmLoaded && commonLoaded) resolve();
  245. });
  246. });
  247. downloader.then(()=>{
  248. //console.log();
  249. gutil.log(gutil.colors.green("download commons and jvm completed"));
  250. cb();
  251. });
  252. }
  253. function decompress_commons_and_jvm(cb){
  254. console.log(`---------------------------------------------------------------------
  255. . Start to decompress the dependencies needed for compilation ...
  256. ---------------------------------------------------------------------`);
  257. gutil.log(gutil.colors.green("begin decompress commons and jvm"));
  258. var count =0;
  259. var decompressor = new Promise((resolve, reject) => {
  260. var commonUnziped = false;
  261. var jvmUnziped = false;
  262. targz.decompress({
  263. src: 'o2server/commons_git.tar.gz',
  264. dest: 'o2server',
  265. tar: {map: function(header){
  266. count++;
  267. var d = new Date();
  268. slog("["+dateFormat(d, "HH:MM:ss")+"] " + count +" "+ header.name+" ...");
  269. //gutil.log(gutil.colors.cyan(header.name), gutil.colors.yellow("..."));
  270. }}
  271. }, function(err){
  272. if(err) {
  273. gutil.log(gutil.colors.red("decompress error"), ":", gutil.colors.red("common.tar.gz "), err);
  274. } else {
  275. commonUnziped = true;
  276. if (jvmUnziped && commonUnziped) resolve();
  277. }
  278. });
  279. targz.decompress({
  280. src: 'o2server/jvm_git.tar.gz',
  281. dest: 'o2server',
  282. tar: {map: function(header){
  283. count++;
  284. var d = new Date();
  285. slog("["+dateFormat(d, "HH:MM:ss")+"] " + count +" "+ header.name+" ...");
  286. //slog(count +" "+ header.name+" ...");
  287. //gutil.log(gutil.colors.cyan(header.name), gutil.colors.yellow("..."));
  288. }}
  289. }, function(err){
  290. if(err) {
  291. gutil.log(gutil.colors.red("decompress error"), ":", gutil.colors.red("jvm.tar.gz "), err);
  292. } else {
  293. jvmUnziped = true;
  294. if (jvmUnziped && commonUnziped) resolve();
  295. }
  296. });
  297. });
  298. decompressor.then(()=>{
  299. gutil.log(gutil.colors.green("decompress commons and jvm completed. " + count+" files"));
  300. cb();
  301. });
  302. }
  303. function move_commons(){
  304. console.log(`---------------------------------------------------------------------
  305. . move commons files to o2server/commons ...
  306. ---------------------------------------------------------------------`);
  307. return gulp.src("o2server/evn-o2server-commons-master-commons/commons/**/*")
  308. .pipe(gulp.dest("o2server/commons/"));
  309. }
  310. function move_jvm(){
  311. console.log(`---------------------------------------------------------------------
  312. . move jvm files to o2server/jvm ...
  313. ---------------------------------------------------------------------`);
  314. var path;
  315. if (options.ev=="all"){
  316. path = "o2server/evn-o2server-jvm-master-jvm/jvm/**/*"
  317. }else{
  318. path = "o2server/evn-o2server-jvm-master-jvm-"+options.ev+"/jvm/**/*"
  319. }
  320. return gulp.src(path)
  321. .pipe(gulp.dest("o2server/jvm/"));
  322. }
  323. function clear_commons_git(cb){
  324. var dest = ['o2server/evn-o2server-commons-master-commons/', 'o2server/commons_git.tar.gz'];
  325. del(dest, { force: true });
  326. cb();
  327. }
  328. function clear_jvm_git(cb){
  329. var path;
  330. if (options.ev=="all"){
  331. path = "o2server/evn-o2server-jvm-master-jvm/"
  332. }else{
  333. path = "o2server/evn-o2server-jvm-master-jvm-"+options.ev+"/"
  334. }
  335. del([path, 'o2server/jvm_git.tar.gz'], { force: true });
  336. cb();
  337. }
  338. function build_web_minimize(cb) {
  339. console.log(`---------------------------------------------------------------------
  340. . Start compiling the web ...
  341. ---------------------------------------------------------------------`);
  342. var dest = 'target/o2server/servers/webServer/';
  343. var src_min = ['o2web/source/**/*.js', '!o2web/source/o2_core/o2.js', '!**/*.spec.js', '!**/test/**', '!o2web/source/o2_lib/**/*'];
  344. var entries = fg.sync(src_min, { dot: false});
  345. var size = entries.length;
  346. var pb = new ProgressBar('', 50);
  347. var doCount = 0;
  348. var stream = gulp.src(src_min);
  349. stream.on("end", ()=>{console.log();});
  350. return stream.pipe(uglify())
  351. .pipe(rename({ extname: '.min.js' }))
  352. .pipe(gulp.dest(dest))
  353. .pipe(logger(function(){
  354. doCount++;
  355. if (doCount <= size){pb.render({ completed: doCount, total: size, count: doCount})};
  356. }))
  357. .pipe(gutil.noop());
  358. }
  359. function build_web_move() {
  360. var dest = 'target/o2server/servers/webServer/';
  361. var src_move = ['o2web/source/**/*', '!o2web/source/o2_core/o2.js', '!**/*.spec.js', '!**/test/**'];
  362. var entries = fg.sync(src_move, { dot: false});
  363. var size = entries.length;
  364. var pb = new ProgressBar('', 50);
  365. var doCount = 0;
  366. var stream = gulp.src(src_move);
  367. stream.on("end", ()=>{console.log();});
  368. return stream.pipe(gulp.dest(dest))
  369. .pipe(logger(function(){
  370. doCount++;
  371. if (doCount <= size) {pb.render({ completed: doCount, total: size, count: doCount})};
  372. }))
  373. .pipe(gutil.noop());
  374. }
  375. exports.build_web_move = build_web_move;
  376. function build_concat_o2(){
  377. var src = [
  378. 'o2web/source/o2_lib/mootools/mootools-1.6.0_all.js',
  379. 'o2web/source/o2_lib/mootools/plugin/mBox.js',
  380. 'o2web/source/o2_core/o2.js'
  381. ];
  382. var dest = 'target/o2server/servers/webServer/o2_core/';
  383. return gulp.src(src)
  384. .pipe(sourceMap.init())
  385. .pipe(concat('o2.js'))
  386. .pipe(gulp.dest(dest))
  387. .pipe(concat('o2.min.js'))
  388. .pipe(uglify())
  389. //.pipe(rename({ extname: '.min.js' }))
  390. .pipe(sourceMap.write(""))
  391. .pipe(gulp.dest(dest))
  392. }
  393. function build_concat_desktop(){
  394. let path = "o2_core";
  395. var src = [
  396. 'o2web/source/'+path+'/o2/widget/Common.js',
  397. 'o2web/source/'+path+'/o2/widget/Dialog.js',
  398. 'o2web/source/'+path+'/o2/widget/UUID.js',
  399. 'o2web/source/'+path+'/o2/xDesktop/Common.js',
  400. 'o2web/source/'+path+'/o2/xDesktop/Actions/RestActions.js',
  401. 'o2web/source/'+path+'/o2/xAction/RestActions.js',
  402. 'o2web/source/'+path+'/o2/xDesktop/Access.js',
  403. 'o2web/source/'+path+'/o2/xDesktop/Dialog.js',
  404. 'o2web/source/'+path+'/o2/xDesktop/Menu.js',
  405. 'o2web/source/'+path+'/o2/xDesktop/UserData.js',
  406. 'o2web/source/x_component_Template/MPopupForm.js',
  407. 'o2web/source/'+path+'/o2/xDesktop/Authentication.js',
  408. 'o2web/source/'+path+'/o2/xDesktop/Dialog.js',
  409. 'o2web/source/'+path+'/o2/xDesktop/Window.js',
  410. 'o2web/source/x_component_Common/Main.js'
  411. ];
  412. var dest = 'target/o2server/servers/webServer/o2_core/o2/xDesktop/';
  413. return gulp.src(src)
  414. .pipe(sourceMap.init())
  415. .pipe(concat('$all.js'))
  416. .pipe(gulp.dest(dest))
  417. .pipe(concat('$all.min.js'))
  418. .pipe(uglify())
  419. //.pipe(rename({ extname: '.min.js' }))
  420. .pipe(sourceMap.write(""))
  421. .pipe(gulp.dest(dest))
  422. }
  423. function build_concat_xform(){
  424. let path = "x_component_process_Xform";
  425. var src = [
  426. 'o2web/source/o2_core/o2/widget/AttachmentController.js',
  427. 'o2web/source/o2_core/o2/xScript/Macro.js',
  428. 'o2web/source/o2_core/o2/widget/Tab.js',
  429. 'o2web/source/o2_core/o2/widget/O2Identity.js',
  430. 'o2web/source/' + path + '/Form.js',
  431. 'o2web/source/' + path + '/$Module.js',
  432. 'o2web/source/' + path + '/$Input.js',
  433. 'o2web/source/' + path + '/Div.js',
  434. 'o2web/source/' + path + '/Combox.js',
  435. 'o2web/source/' + path + '/DatagridMobile.js',
  436. 'o2web/source/' + path + '/DatagridPC.js',
  437. 'o2web/source/' + path + '/Textfield.js',
  438. 'o2web/source/' + path + '/Personfield.js',
  439. 'o2web/source/' + path + '/Button.js',
  440. 'o2web/source/' + path + '/ViewSelector.js',
  441. 'o2web/source/' + path + '/*.js',
  442. 'o2web/source/x_component_process_Work/Processor.js',
  443. '!o2web/source/' + path + '/Office.js'
  444. ];
  445. var dest = 'target/o2server/servers/webServer/'+path+'/';
  446. return gulp.src(src)
  447. .pipe(sourceMap.init())
  448. .pipe(concat('$all.js'))
  449. .pipe(gulp.dest(dest))
  450. .pipe(concat('$all.min.js'))
  451. .pipe(uglify())
  452. //.pipe(rename({ extname: '.min.js' }))
  453. .pipe(sourceMap.write(""))
  454. .pipe(gulp.dest(dest))
  455. }
  456. function build_bundle(){
  457. let path = "o2_core";
  458. var src = [
  459. 'o2web/source/o2_lib/mootools/mootools-1.6.0_all.js',
  460. 'o2web/source/o2_lib/mootools/plugin/mBox.js',
  461. 'o2web/source/o2_core/o2.js',
  462. 'o2web/source/x_desktop/js/base.js',
  463. "o2web/source/o2_core/o2/framework.js"
  464. ];
  465. var dest = 'target/o2server/servers/webServer/'+path+'/';
  466. return gulp.src(src)
  467. .pipe(sourceMap.init())
  468. .pipe(concat('bundle.js'))
  469. .pipe(gulp.dest(dest))
  470. .pipe(concat('bundle.min.js'))
  471. .pipe(uglify())
  472. //.pipe(rename({ extname: '.min.js' }))
  473. .pipe(sourceMap.write(""))
  474. .pipe(gulp.dest(dest))
  475. }
  476. function concat_Actions(){
  477. return through2.obj(function (file, enc, cb) {
  478. if (file.isNull()) {
  479. this.push(file);
  480. return cb();
  481. }
  482. if (file.isStream()) {
  483. this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
  484. return cb();
  485. }
  486. var content = file.contents.toString();
  487. var o = path.parse(file.path);
  488. var name = o.name;
  489. content = "var actionJson = "+content;
  490. content = content+"\nif (!o2.xAction.RestActions.Action[\""+name+"\"]) o2.xAction.RestActions.Action[\""+name+"\"] = new Class({Extends: o2.xAction.RestActions.Action});";
  491. content = content+"\no2.Actions.actions[\""+name+"\"] = new o2.xAction.RestActions.Action[\""+name+"\"](\""+name+"\", actionJson);";
  492. file.contents = new Buffer.from(content);
  493. this.push(file);
  494. cb();
  495. });
  496. }
  497. function concat_Style(){
  498. return through2.obj(function (file, enc, cb) {
  499. if (file.isNull()) {
  500. this.push(file);
  501. return cb();
  502. }
  503. if (file.isStream()) {
  504. this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
  505. return cb();
  506. }
  507. var content = file.contents.toString();
  508. var name = file.path.replace(process.cwd(), "").replace(/\\/g, "/")
  509. name = ".."+name.substring(name.indexOf("/source")+7);
  510. content = "var csskey = encodeURIComponent(\""+name+"\");\no2.widget.css[csskey]="+content;
  511. file.contents = new Buffer.from(content);
  512. this.push(file);
  513. cb();
  514. });
  515. }
  516. function build_concat_basework_style(){
  517. return gulp.src([
  518. "o2web/source/x_component_process_Work/$Main/default/css.wcss",
  519. "o2web/source/x_component_process_Xform/$Form/default/css.wcss",
  520. "o2web/source/o2_core/o2/widget/$Tab/mobileForm/css.wcss",
  521. "o2web/source/o2_core/o2/widget/$Menu/tab/css.wcss",
  522. "o2web/source/o2_core/o2/widget/$Tab/form/css.wcss",
  523. "o2web/source/x_component_process_Xform/$Form/default/doc.wcss",
  524. "o2web/source/o2_core/o2/widget/$Toolbar/documentEdit/css.wcss",
  525. "o2web/source/o2_core/o2/widget/$Toolbar/documentEdit_side/css.wcss",
  526. "o2web/source/x_component_process_Xform/$Form/default/css.wcss"
  527. ])
  528. .pipe(concat_Style())
  529. .pipe(concat('js/base_work_style_temp.js'))
  530. .pipe(gulp.dest('o2web/source/x_desktop/'));
  531. }
  532. function build_concat_basework_action(){
  533. return gulp.src([
  534. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  535. "o2web/source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.json",
  536. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  537. "o2web/source/o2_core/o2/xAction/services/x_query_assemble_surface.json",
  538. "o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  539. "o2web/source/o2_core/o2/xAction/services/x_program_center.json",
  540. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.json"
  541. ])
  542. .pipe(concat_Actions())
  543. .pipe(concat('js/base_work_actions_temp.js'))
  544. .pipe(gulp.dest('o2web/source/x_desktop/'));
  545. }
  546. function build_concat_basework_clean(cb) {
  547. var dest = [
  548. 'o2web/source/x_desktop/js/base_work_actions_temp.js',
  549. 'o2web/source/x_desktop/js/base_work_style_temp.js'
  550. ];
  551. return del(dest, cb);
  552. }
  553. function build_concat_basework_body() {
  554. var src = [
  555. 'o2web/source/x_desktop/js/base_concat_head.js',
  556. 'o2web/source/o2_core/o2/lp/'+(options.lp || 'zh-cn')+'.js',
  557. 'o2web/source/x_desktop/js/base_work_style_temp.js',
  558. 'o2web/source/o2_core/o2/widget/Common.js',
  559. 'o2web/source/o2_core/o2/widget/Dialog.js',
  560. 'o2web/source/o2_core/o2/widget/UUID.js',
  561. 'o2web/source/o2_core/o2/widget/Menu.js',
  562. 'o2web/source/o2_core/o2/widget/Toolbar.js',
  563. 'o2web/source/o2_core/o2/xDesktop/Common.js',
  564. 'o2web/source/o2_core/o2/xDesktop/Actions/RestActions.js',
  565. 'o2web/source/o2_core/o2/xAction/RestActions.js',
  566. 'o2web/source/o2_core/o2/xDesktop/Access.js',
  567. 'o2web/source/o2_core/o2/xDesktop/Dialog.js',
  568. 'o2web/source/o2_core/o2/xDesktop/Menu.js',
  569. 'o2web/source/o2_core/o2/xDesktop/UserData.js',
  570. 'o2web/source/x_component_Template/MPopupForm.js',
  571. 'o2web/source/o2_core/o2/xDesktop/Authentication.js',
  572. 'o2web/source/o2_core/o2/xDesktop/Dialog.js',
  573. 'o2web/source/o2_core/o2/xDesktop/Window.js',
  574. 'o2web/source/x_component_Common/Main.js',
  575. 'o2web/source/o2_core/o2/lp/'+(options.lp || 'zh-cn')+'.js',
  576. 'o2web/source/x_component_process_Work/lp/'+(options.lp || 'zh-cn')+'.js',
  577. 'o2web/source/x_component_process_Xform/lp/'+(options.lp || 'zh-cn')+'.js',
  578. 'o2web/source/x_component_Selector/lp/'+(options.lp || 'zh-cn')+'.js',
  579. 'o2web/source/x_component_process_Work/Main.js',
  580. 'o2web/source/x_component_Selector/package.js',
  581. 'o2web/source/x_component_Selector/Person.js',
  582. 'o2web/source/x_component_Selector/Identity.js',
  583. 'o2web/source/x_component_Selector/Unit.js',
  584. 'o2web/source/x_component_Selector/IdentityWidthDuty.js',
  585. 'o2web/source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js',
  586. 'o2web/source/x_component_Selector/UnitWithType.js',
  587. 'o2web/source/o2_core/o2/xScript/Actions/UnitActions.js',
  588. 'o2web/source/o2_core/o2/xScript/Actions/ScriptActions.js',
  589. 'o2web/source/o2_core/o2/xScript/Actions/CMSScriptActions.js',
  590. 'o2web/source/o2_core/o2/xScript/Actions/PortalScriptActions.js',
  591. 'o2web/source/o2_core/o2/xScript/Environment.js',
  592. 'o2web/source/x_component_Template/MTooltips.js',
  593. 'o2web/source/x_component_Template/MSelector.js',
  594. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js',
  595. 'o2web/source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.js',
  596. 'o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.js',
  597. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.js',
  598. 'o2web/source/o2_core/o2/xAction/services/x_query_assemble_surface.js',
  599. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.js',
  600. 'o2web/source/x_desktop/js/base_work_actions_temp.js',
  601. 'o2web/source/x_desktop/js/base.js'
  602. ];
  603. var dest = 'target/o2server/servers/webServer/x_desktop/js/';
  604. return gulp.src(src)
  605. .pipe(sourceMap.init())
  606. .pipe(concat('base_work.js'))
  607. .pipe(gulp.dest(dest))
  608. .pipe(concat('base_work.min.js'))
  609. .pipe(uglify())
  610. //.pipe(rename({ extname: '.min.js' }))
  611. .pipe(sourceMap.write(""))
  612. .pipe(gulp.dest(dest));
  613. }
  614. function build_concat_baseportal_style(){
  615. return gulp.src([
  616. "o2web/source/x_component_process_Work/$Main/default/css.wcss",
  617. "o2web/source/x_component_portal_Portal/$Main/default/css.wcss",
  618. "o2web/source/x_component_process_Xform/$Form/default/css.wcss",
  619. "o2web/source/o2_core/o2/widget/$Tab/mobileForm/css.wcss",
  620. "o2web/source/o2_core/o2/widget/$Menu/tab/css.wcss",
  621. ])
  622. .pipe(concat_Style())
  623. .pipe(concat('js/base_portal_style_temp.js'))
  624. .pipe(gulp.dest('o2web/source/x_desktop/'));
  625. }
  626. function build_concat_baseportal_action(){
  627. return gulp.src([
  628. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  629. "o2web/source/o2_core/o2/xAction/services/x_portal_assemble_surface.json",
  630. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  631. "o2web/source/o2_core/o2/xAction/services/x_query_assemble_surface.json",
  632. "o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  633. "o2web/source/o2_core/o2/xAction/services/x_program_center.json",
  634. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.json"
  635. ])
  636. .pipe(concat_Actions())
  637. .pipe(concat('js/base_portal_actions_temp.js'))
  638. .pipe(gulp.dest('o2web/source/x_desktop/'));
  639. }
  640. function build_concat_baseportal_clean(cb) {
  641. var dest = [
  642. 'o2web/source/x_desktop/js/base_portal_actions_temp.js',
  643. 'o2web/source/x_desktop/js/base_portal_style_temp.js'
  644. ];
  645. return del(dest, cb);
  646. }
  647. function build_concat_baseportal_body() {
  648. var src = [
  649. 'o2web/source/x_desktop/js/base_concat_head.js',
  650. 'o2web/source/o2_core/o2/lp/'+(options.lp || 'zh-cn')+'.js',
  651. 'o2web/source/x_desktop/js/base_portal_style_temp.js',
  652. 'o2web/source/o2_core/o2/widget/Common.js',
  653. 'o2web/source/o2_core/o2/widget/Dialog.js',
  654. 'o2web/source/o2_core/o2/widget/UUID.js',
  655. 'o2web/source/o2_core/o2/widget/Menu.js',
  656. 'o2web/source/o2_core/o2/widget/Toolbar.js',
  657. 'o2web/source/o2_core/o2/xDesktop/Common.js',
  658. 'o2web/source/o2_core/o2/xDesktop/Actions/RestActions.js',
  659. 'o2web/source/o2_core/o2/xAction/RestActions.js',
  660. 'o2web/source/o2_core/o2/xDesktop/Access.js',
  661. 'o2web/source/o2_core/o2/xDesktop/Dialog.js',
  662. 'o2web/source/o2_core/o2/xDesktop/Menu.js',
  663. 'o2web/source/o2_core/o2/xDesktop/UserData.js',
  664. 'o2web/source/x_component_Template/MPopupForm.js',
  665. 'o2web/source/o2_core/o2/xDesktop/Authentication.js',
  666. 'o2web/source/o2_core/o2/xDesktop/Window.js',
  667. 'o2web/source/x_component_Common/Main.js',
  668. 'o2web/source/x_component_process_Work/lp/'+(options.lp || 'zh-cn')+'.js',
  669. 'o2web/source/x_component_portal_Portal/lp/'+(options.lp || 'zh-cn')+'.js',
  670. 'o2web/source/x_component_process_Xform/lp/'+(options.lp || 'zh-cn')+'.js',
  671. 'o2web/source/x_component_Selector/lp/'+(options.lp || 'zh-cn')+'.js',
  672. 'o2web/source/x_component_portal_Portal/Main.js',
  673. 'o2web/source/x_component_Selector/package.js',
  674. 'o2web/source/x_component_Selector/Person.js',
  675. 'o2web/source/x_component_Selector/Identity.js',
  676. 'o2web/source/x_component_Selector/Unit.js',
  677. 'o2web/source/x_component_Selector/IdentityWidthDuty.js',
  678. 'o2web/source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js',
  679. 'o2web/source/x_component_Selector/UnitWithType.js',
  680. 'o2web/source/o2_core/o2/xScript/Actions/UnitActions.js',
  681. 'o2web/source/o2_core/o2/xScript/Actions/ScriptActions.js',
  682. 'o2web/source/o2_core/o2/xScript/Actions/CMSScriptActions.js',
  683. 'o2web/source/o2_core/o2/xScript/Actions/PortalScriptActions.js',
  684. 'o2web/source/o2_core/o2/xScript/PageEnvironment.js',
  685. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js',
  686. 'o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.js',
  687. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.js',
  688. 'o2web/source/o2_core/o2/xAction/services/x_query_assemble_surface.js',
  689. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.js',
  690. 'o2web/source/x_desktop/js/base_portal_actions_temp.js',
  691. 'o2web/source/x_desktop/js/base.js'
  692. ];
  693. var dest = 'target/o2server/servers/webServer/x_desktop/js/';
  694. return gulp.src(src)
  695. .pipe(sourceMap.init())
  696. .pipe(concat('base_portal.js'))
  697. .pipe(gulp.dest(dest))
  698. .pipe(concat('base_portal.min.js'))
  699. .pipe(uglify())
  700. //.pipe(rename({ extname: '.min.js' }))
  701. .pipe(sourceMap.write(""))
  702. .pipe(gulp.dest(dest));
  703. }
  704. exports.build_concat = gulp.parallel(
  705. build_concat_o2,
  706. build_concat_desktop,
  707. build_concat_xform,
  708. build_bundle,
  709. gulp.series(build_concat_basework_style, build_concat_basework_action, build_concat_basework_body,build_concat_basework_clean),
  710. gulp.series(build_concat_baseportal_style, build_concat_baseportal_action, build_concat_baseportal_body,build_concat_baseportal_clean)
  711. );
  712. function build_web_v_html() {
  713. var src = 'o2web/source/x_desktop/*.html';
  714. var dest = 'target/o2server/servers/webServer/x_desktop/';
  715. return gulp.src(src)
  716. .pipe(assetRev())
  717. .pipe(gulp.dest(dest))
  718. .pipe(gutil.noop());
  719. }
  720. function build_web_v_o2() {
  721. var src = 'target/o2server/servers/webServer/o2_core//o2.js';
  722. var dest = 'target/o2server/servers/webServer/o2_core/';
  723. return gulp.src(src)
  724. .pipe(assetRev())
  725. .pipe(gulp.dest(dest))
  726. .pipe(uglify())
  727. .pipe(rename({ extname: '.min.js' }))
  728. .pipe(gulp.dest(dest))
  729. .pipe(gutil.noop());
  730. }
  731. function clear_build(cb){
  732. console.log(`---------------------------------------------------------------------
  733. . clear old build ...
  734. ---------------------------------------------------------------------`);
  735. var dest = 'target';
  736. del(dest, { force: true });
  737. cb();
  738. }
  739. function clear_deploy(cb){
  740. console.log(`---------------------------------------------------------------------
  741. . clear old deploy ...
  742. ---------------------------------------------------------------------`);
  743. var dest = ["target/o2server/store/", "target/o2server/commons/", "target/o2server/jvm/", "target/o2server/configSample/", "target/o2server/localSample/", "target/o2server/servers/"];
  744. dest = dest.concat(["target/o2server/*.sh", "target/o2server/*.jar", "target/o2server/*.html", "target/o2server/*.bat", "target/o2server/version.o2"]);
  745. del(dest, { force: true });
  746. cb();
  747. }
  748. exports.clear_build = clear_build;
  749. exports.clear_deploy = clear_deploy;
  750. function deploy_server(){
  751. console.log(`---------------------------------------------------------------------
  752. . deploy to target ...
  753. ---------------------------------------------------------------------`);
  754. var source = ["o2server/*store/**/*", "o2server/*commons/**/*", "o2server/*jvm/**/*", "o2server/*configSample/**/*", "o2server/*localSample/**/*"];
  755. source = source.concat(scriptSource);
  756. console.log(source)
  757. var dest = "target/o2server/"
  758. var entries = fg.sync(source, { dot: false});
  759. var size = entries.length;
  760. var pb = new ProgressBar('', 50);
  761. var doCount = 0;
  762. var stream = gulp.src(source);
  763. stream.on("end", ()=>{console.log();});
  764. return stream.pipe(gulp.dest(dest))
  765. .pipe(logger(function(){
  766. doCount++;
  767. if (doCount <= size) {pb.render({ completed: doCount, total: size, count: doCount})};
  768. }));
  769. }
  770. exports.preperation = gulp.series(download_commons_and_jvm, decompress_commons_and_jvm, move_commons, move_jvm, clear_commons_git, clear_jvm_git);
  771. var shell = require('gulp-shell')
  772. exports.build_server = function(){
  773. console.log(`---------------------------------------------------------------------
  774. . Start compiling the server ...
  775. ---------------------------------------------------------------------`);
  776. return (shell.task('npm run build_server_script'))();
  777. };
  778. function chmod_jvm(){
  779. return (shell.task('chmod 777 -R target/o2server/jvm'))();
  780. }
  781. function chmod_commons(){
  782. return (shell.task('chmod 777 -R target/o2server/commons'))();
  783. }
  784. function chmod_sh(){
  785. return (shell.task('chmod 777 target/o2server/*.sh'))();
  786. }
  787. function chmod_servers(){
  788. return (shell.task('chmod 777 -R target/o2server/servers'))();
  789. }
  790. exports.build_web = gulp.series(
  791. build_web_minimize,
  792. build_web_move,
  793. gulp.parallel(
  794. build_concat_o2,
  795. build_concat_desktop,
  796. build_concat_xform,
  797. gulp.series(build_concat_basework_style, build_concat_basework_action, build_concat_basework_body,build_concat_basework_clean),
  798. gulp.series(build_concat_baseportal_style, build_concat_baseportal_action, build_concat_baseportal_body,build_concat_baseportal_clean),
  799. build_bundle
  800. ),
  801. build_web_v_html,
  802. build_web_v_o2);
  803. if (os.platform().indexOf("win")==-1){
  804. exports.deploy = gulp.series(deploy_server, chmod_jvm, chmod_commons, chmod_sh, chmod_servers);
  805. }else{
  806. exports.deploy = gulp.series(deploy_server);
  807. }