gulpfile.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  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. const ora = require('ora');
  18. concat = require('gulp-concat');
  19. var fg = require('fast-glob');
  20. var logger = require('gulp-logger');
  21. var assetRev = require('gulp-tm-asset-rev');
  22. const os = require('os');
  23. var through2 = require('through2');
  24. var path = require('path');
  25. //var sourceMap = require('gulp-sourcemaps');
  26. var git = require('gulp-git');
  27. //var downloadHost = "download.o2oa.net";
  28. // var downloadHost = "release.o2oa.net";
  29. // var protocol = "http";
  30. // var commonUrl = "/build/commons.tar.gz";
  31. // var jvmUrls = {
  32. // "all": "/build/jvm.tar.gz",
  33. // "linux": "/build/linux.tar.gz",
  34. // "aix": "/build/aix.tar.gz",
  35. // "arm": "/build/arm.tar.gz",
  36. // "macos": "/build/macos.tar.gz",
  37. // "risc": "/build/risc.tar.gz",
  38. // "raspberrypi": "/build/raspberrypi.tar.gz",
  39. // "windows": "/build/windows.tar.gz"
  40. // };
  41. var supportedLanguage = ["zh-cn", "en"];
  42. var downloadHost = "git.o2oa.net";
  43. var protocol = "https";
  44. var commonUrl = "/o2oa/evn-o2server-commons/-/archive/7.3/evn-o2server-commons-7.3.tar.gz?path=commons";
  45. var jvmUrls = {
  46. "all": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm",
  47. "linux_java11": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/linux_java11",
  48. "aix_java11": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/aix_java11",
  49. "arm_java11": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/arm_java11",
  50. "macos_java11": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/macos_java11",
  51. "risc_java11": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/risc_java11",
  52. "mips_java11": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/mips_java11",
  53. "raspi_java11": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/raspi_java11",
  54. "windows_java11": "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/windows_java11"
  55. };
  56. var scripts = {
  57. "all": ["o2server/*.sh", "o2server/*.jar", "o2server/*.html", "o2server/*.bat", "o2server/version.o2"],
  58. "linux": ["o2server/*linux*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"],
  59. "aix": ["o2server/*aix*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"],
  60. "arm": ["o2server/*arm*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"],
  61. "macos": ["o2server/*macos*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"],
  62. "risc": ["o2server/*risc*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"],
  63. "mips": ["o2server/*mips*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"],
  64. "raspi": ["o2server/*raspi*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"],
  65. "windows": ["o2server/*windows*", "o2server/*.jar", "o2server/*.html", "o2server/version.o2"]
  66. };
  67. var o_options = minimist(process.argv.slice(2), {//upload: local ftp or sftp
  68. string: ["e", "lp", "w", "m", "d"]
  69. });
  70. var options = {};
  71. options.ev = o_options.e || "all";
  72. options.lp = o_options.lp || "zh-cn";
  73. options.webSite = o_options.w || "https://www.o2oa.net";
  74. options.mirrorSite = o_options.m || "http://mirror1.o2oa.net";
  75. options.downloadSite = o_options.d || "https://download.o2oa.net";
  76. var jvmUrl = jvmUrls[options.ev];
  77. var scriptSource = scripts[options.ev];
  78. function ProgressBar(description, bar_length){
  79. this.description = description || 'Progress';
  80. this.length = bar_length || 50;
  81. this.render = function (opts){
  82. var percent = (opts.completed / opts.total).toFixed(4);
  83. var cell_num = Math.floor(percent * this.length);
  84. var speed = "";
  85. if (opts.time){
  86. speed = (opts.completed/1024/1024)/(opts.time/1000);
  87. speed = speed.toFixed(2);
  88. speed = speed+"M/S";
  89. }
  90. var count = "";
  91. if (opts.count){
  92. count = "["+opts.count+"/"+opts.total+"]"
  93. }
  94. var cell = '';
  95. for (var i=0;i<cell_num;i++) { cell += '>'; }
  96. var empty = '';
  97. for (var i=0;i<this.length-cell_num;i++) { empty += '='; }
  98. if (opts.completed <= opts.total){
  99. var d = new Date();
  100. var cmdText = "["+dateFormat(d, "HH:MM:ss")+"]"+" "+this.description + ': ' + cell + empty + ' ' + (100*percent).toFixed(2) + '% '+speed+count;
  101. slog(cmdText);
  102. }
  103. };
  104. }
  105. function downloadFile_progress(path, filename, headcb, progresscb, cb){
  106. var dest = `o2server/${filename}`;
  107. let stream = fs.createWriteStream(dest);
  108. var options = { url:protocol+"://"+downloadHost+path };
  109. var fileHost = downloadHost;
  110. var filePath = path;
  111. stream.on('finish', () => {
  112. //gutil.log("download", ":", gutil.colors.green(filename), " completed!");
  113. cb();
  114. });
  115. stream.on('error', (err) => {
  116. gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), err);
  117. });
  118. var req = http.request({
  119. host:fileHost,
  120. path:filePath,
  121. method:'HEAD'
  122. },function (res){
  123. if (res.statusCode == 200) {
  124. res.setEncoding(null);
  125. var time = 0;
  126. var l = res.headers['content-length'];
  127. var str = progress({
  128. length: l,
  129. time: 100 /* ms */
  130. });
  131. headcb(l);
  132. str.on('progress', function(progress) {
  133. if (pb){
  134. progresscb(progress);
  135. pb.render({ completed: currentLength, total: totalLength, time: time+=100 });
  136. }
  137. });
  138. request.get(options).pipe(str).pipe(stream);
  139. } else {
  140. downloadFile(path, filename, headcb, progresscb, cb)
  141. //gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+res.statusCode);
  142. }
  143. })
  144. req.on('error', (e) => {
  145. downloadFile(path, filename, headcb, progresscb, cb)
  146. //gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), e);
  147. });
  148. req.end();
  149. // }
  150. //});
  151. }
  152. function downloadFile(path, filename, headcb, progresscb, cb){
  153. var dest = `o2server/${filename}`;
  154. const spinner = ora({
  155. 'prefixText': 'Downloading '+filename+' ...',
  156. 'spinner': {
  157. interval: 80, // Optional
  158. frames: ['⠋','⠙','⠹','⠸','⠼','⠴','⠦','⠧','⠇','⠏']
  159. }
  160. }).start();
  161. let stream = fs.createWriteStream(dest);
  162. var options = { url:protocol+"://"+downloadHost+path };
  163. var fileHost = downloadHost;
  164. var filePath = path;
  165. stream.on('finish', () => {
  166. //gutil.log("download", ":", gutil.colors.green(filename), " completed!");
  167. spinner.stop();
  168. spinner.succeed(filename + ' Downloaded!');
  169. cb();
  170. });
  171. stream.on('error', (err) => {
  172. gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), err);
  173. });
  174. request.get(options).pipe(stream);
  175. }
  176. var commonsLength = 0;
  177. var jvmLenght = 0;
  178. var totalLength = 0;
  179. var currentLength = 0;
  180. var commonsCurrentLength = 0;
  181. var jvmCurrentLength = 0;
  182. var pb = null;
  183. function initProgress(){
  184. if (commonsLength && jvmLenght){
  185. totalLength = +commonsLength + jvmLenght;
  186. var t = (totalLength/1024/1024).toFixed(2);
  187. pb = new ProgressBar('total: '+t+"M", 50);
  188. }
  189. }
  190. function download_commons_and_jvm(cb){
  191. gutil.log(gutil.colors.green("begin download commons and jvm"));
  192. console.log(`---------------------------------------------------------------------
  193. . Start to download the dependencies needed for compilation ...
  194. ---------------------------------------------------------------------`);
  195. var downloader = new Promise((resolve, reject) => {
  196. var commonLoaded = false;
  197. var jvmLoaded = false;
  198. downloadFile_progress(commonUrl, "commons_git.tar.gz", (length)=>{
  199. commonsLength = +length;
  200. initProgress();
  201. }, (progress)=>{
  202. commonsCurrentLength = progress.transferred;
  203. currentLength = +commonsCurrentLength+jvmCurrentLength;
  204. }, ()=>{
  205. commonLoaded = true;
  206. if (jvmLoaded && commonLoaded) resolve();
  207. });
  208. // var jvmName = jvmUrl.substr(jvmUrl.lastIndexOf("/"+1, jvmUrl.length));
  209. // console.log(jvmName);
  210. // console.log(jvmUrl);
  211. downloadFile_progress(jvmUrl, "jvm_git.tar.gz", (length)=>{
  212. jvmLenght = +length;
  213. initProgress();
  214. }, (progress)=>{
  215. jvmCurrentLength = progress.transferred;
  216. currentLength = +commonsCurrentLength+jvmCurrentLength;
  217. }, ()=>{
  218. jvmLoaded = true;
  219. if (jvmLoaded && commonLoaded) resolve();
  220. });
  221. });
  222. downloader.then(()=>{
  223. //console.log();
  224. gutil.log(gutil.colors.green("download commons and jvm completed"));
  225. cb();
  226. });
  227. }
  228. function decompress_commons_and_jvm(cb){
  229. console.log(`---------------------------------------------------------------------
  230. . Start to decompress the dependencies needed for compilation ...
  231. ---------------------------------------------------------------------`);
  232. gutil.log(gutil.colors.green("begin decompress commons and jvm"));
  233. var count =0;
  234. var decompressor = new Promise((resolve, reject) => {
  235. var commonUnziped = false;
  236. var jvmUnziped = false;
  237. targz.decompress({
  238. src: 'o2server/commons_git.tar.gz',
  239. dest: 'o2server/tmp',
  240. tar: {map: function(header){
  241. count++;
  242. var d = new Date();
  243. slog("["+dateFormat(d, "HH:MM:ss")+"] " + count +" "+ header.name+" ...");
  244. //gutil.log(gutil.colors.cyan(header.name), gutil.colors.yellow("..."));
  245. }}
  246. }, function(err){
  247. if(err) {
  248. gutil.log(gutil.colors.red("decompress error"), ":", gutil.colors.red("common.tar.gz "), err);
  249. } else {
  250. commonUnziped = true;
  251. if (jvmUnziped && commonUnziped) resolve();
  252. }
  253. });
  254. targz.decompress({
  255. src: 'o2server/jvm_git.tar.gz',
  256. dest: 'o2server/tmp',
  257. tar: {map: function(header){
  258. count++;
  259. var d = new Date();
  260. slog("["+dateFormat(d, "HH:MM:ss")+"] " + count +" "+ header.name+" ...");
  261. //slog(count +" "+ header.name+" ...");
  262. //gutil.log(gutil.colors.cyan(header.name), gutil.colors.yellow("..."));
  263. }}
  264. }, function(err){
  265. if(err) {
  266. gutil.log(gutil.colors.red("decompress error"), ":", gutil.colors.red("jvm.tar.gz "), err);
  267. } else {
  268. jvmUnziped = true;
  269. if (jvmUnziped && commonUnziped) resolve();
  270. }
  271. });
  272. });
  273. decompressor.then(()=>{
  274. gutil.log(gutil.colors.green("decompress commons and jvm completed. " + count+" files"));
  275. cb();
  276. });
  277. }
  278. function move_commons(){
  279. console.log(`---------------------------------------------------------------------
  280. . move commons files to o2server/commons ...
  281. ---------------------------------------------------------------------`);
  282. return gulp.src("o2server/tmp/evn-o2server-commons-7.3-commons/commons/**/*")
  283. .pipe(gulp.dest("o2server/commons/"));
  284. }
  285. function move_jvm(){
  286. console.log(`---------------------------------------------------------------------
  287. . move jvm files to o2server/jvm ...
  288. ---------------------------------------------------------------------`);
  289. var path;
  290. if (options.ev=="all"){
  291. path = "o2server/tmp/evn-o2server-jvm-master-jvm/jvm/**/*"
  292. }else{
  293. path = "o2server/tmp/evn-o2server-jvm-master-jvm-"+options.ev+"/jvm/**/*"
  294. }
  295. return gulp.src(path)
  296. .pipe(gulp.dest("o2server/jvm/"));
  297. }
  298. async function clear_commons_git(cb) {
  299. var dest = ['o2server/tmp/evn-o2server-commons-7.3-commons/', 'o2server/commons_git.tar.gz'];
  300. await del(dest, {force: true});
  301. cb();
  302. }
  303. async function clear_jvm_git(cb){
  304. //var path;
  305. // if (options.ev=="all"){
  306. // path = "o2server/tmp/evn-o2server-jvm-master-jvm/"
  307. // }else{
  308. // path = "o2server/tmp/evn-o2server-jvm-master-jvm-"+options.ev+"/"
  309. // }
  310. await del(['o2server/tmp/', 'o2server/jvm_git.tar.gz'], { force: true });
  311. cb();
  312. }
  313. var moduleFolder = [];
  314. async function build_web_module() {
  315. var dest = 'target/o2server/servers/webServer/';
  316. var srcPath = 'o2web/source';
  317. const fp = fs.promises;
  318. return fp.readdir(srcPath).then((files)=>{
  319. let statP = [];
  320. files.forEach((file) => {
  321. let p = path.resolve(srcPath, file)
  322. statP.push(fp.stat(p).then((s)=>{
  323. if (s.isDirectory()){
  324. var pkgPath = path.resolve(srcPath, p, 'package.json');
  325. if (fs.existsSync(pkgPath)){
  326. var pkg = require(pkgPath);
  327. if (pkg.scripts['o2-build']){
  328. moduleFolder.push(file);
  329. }
  330. }
  331. }
  332. }));
  333. });
  334. const shelljs = require('shelljs');
  335. return Promise.all(statP).then(()=>{
  336. // var tasks = [];
  337. moduleFolder.forEach((f)=>{
  338. shelljs.config.verbose = true;
  339. shelljs.exec('npm install && npm run o2-build', {cwd: path.resolve(srcPath, f)});
  340. });
  341. });
  342. });
  343. }
  344. function build_web_minimize(cb) {
  345. console.log(`---------------------------------------------------------------------
  346. . Start compiling the web ...
  347. ---------------------------------------------------------------------`);
  348. var dest = 'target/o2server/servers/webServer/';
  349. var src_min = ['o2web/source/**/*.js', '!o2web/source/o2_core/o2.js', '!**/*.spec.js', '!**/test/**', '!o2web/source/o2_lib/**/*'];
  350. moduleFolder.forEach((f)=>{
  351. src_min.push('!o2web/source/'+f+'/**/*');
  352. })
  353. var entries = fg.sync(src_min, { dot: false});
  354. var size = entries.length;
  355. var pb = new ProgressBar('', 50);
  356. var doCount = 0;
  357. var stream = gulp.src(src_min);
  358. stream.on("end", ()=>{console.log();});
  359. return stream.pipe(uglify())
  360. .pipe(rename({ extname: '.min.js' }))
  361. .pipe(gulp.dest(dest))
  362. .pipe(logger(function(){
  363. doCount++;
  364. if (doCount <= size){pb.render({ completed: doCount, total: size, count: doCount})};
  365. }))
  366. .pipe(gutil.noop());
  367. }
  368. function build_web_move() {
  369. var dest = 'target/o2server/servers/webServer/';
  370. var src_move = ['o2web/source/**/*', '!o2web/source/o2_core/o2.js', '!**/*.spec.js', '!**/test/**'];
  371. moduleFolder.forEach((f)=>{
  372. src_move.push('!o2web/source/'+f+'/**/*');
  373. })
  374. var entries = fg.sync(src_move, { dot: false});
  375. var size = entries.length;
  376. var pb = new ProgressBar('', 50);
  377. var doCount = 0;
  378. var stream = gulp.src(src_move);
  379. stream.on("end", ()=>{console.log();});
  380. return stream.pipe(gulp.dest(dest))
  381. .pipe(logger(function(){
  382. doCount++;
  383. if (doCount <= size) {pb.render({ completed: doCount, total: size, count: doCount})};
  384. }))
  385. .pipe(gutil.noop());
  386. }
  387. exports.build_web_move = build_web_move;
  388. function build_concat_o2(){
  389. var src = [
  390. 'o2web/source/o2_core/polyfill.js',
  391. 'o2web/source/o2_lib/mootools/mootools-1.6.0_all.js',
  392. 'o2web/source/o2_lib/mootools/plugin/mBox.js',
  393. 'o2web/source/o2_core/o2.js'
  394. ];
  395. var dest = 'target/o2server/servers/webServer/o2_core/';
  396. return gulp.src(src, {sourcemaps: true})
  397. //.pipe(sourceMap.init())
  398. .pipe(concat('o2.js'))
  399. .pipe(gulp.dest(dest))
  400. .pipe(concat('o2.min.js'))
  401. .pipe(uglify())
  402. //.pipe(rename({ extname: '.min.js' }))
  403. //.pipe(sourceMap.write(""))
  404. .pipe(gulp.dest(dest, {sourcemaps: '.'}))
  405. }
  406. function build_concat_base(){
  407. var src = [
  408. 'o2web/source/x_desktop/js/base.js',
  409. 'o2web/source/o2_core/o2/xScript/PageEnvironment.js',
  410. 'o2web/source/o2_core/o2/framework.js',
  411. 'o2web/source/x_desktop/js/base_loader.js'
  412. ];
  413. var dest = 'target/o2server/servers/webServer/x_desktop/js/';
  414. return gulp.src(src, {sourcemaps: true})
  415. //.pipe(sourceMap.init())
  416. .pipe(concat('base.js'))
  417. .pipe(gulp.dest(dest))
  418. .pipe(concat('base.min.js'))
  419. .pipe(uglify())
  420. //.pipe(rename({ extname: '.min.js' }))
  421. //.pipe(sourceMap.write(""))
  422. .pipe(gulp.dest(dest, {sourcemaps: '.'}));
  423. }
  424. function build_concat_desktop(){
  425. let path = "o2_core";
  426. var src = [
  427. 'o2web/source/'+path+'/o2/widget/Common.js',
  428. 'o2web/source/'+path+'/o2/widget/Dialog.js',
  429. 'o2web/source/'+path+'/o2/widget/UUID.js',
  430. 'o2web/source/'+path+'/o2/xDesktop/Common.js',
  431. 'o2web/source/'+path+'/o2/xDesktop/Actions/RestActions.js',
  432. 'o2web/source/'+path+'/o2/xAction/RestActions.js',
  433. 'o2web/source/'+path+'/o2/xDesktop/Access.js',
  434. 'o2web/source/'+path+'/o2/xDesktop/Dialog.js',
  435. 'o2web/source/'+path+'/o2/xDesktop/Menu.js',
  436. 'o2web/source/'+path+'/o2/xDesktop/UserData.js',
  437. 'o2web/source/x_component_Template/MPopupForm.js',
  438. 'o2web/source/'+path+'/o2/xDesktop/Authentication.js',
  439. 'o2web/source/'+path+'/o2/xDesktop/Dialog.js',
  440. 'o2web/source/'+path+'/o2/xDesktop/Window.js',
  441. 'o2web/source/x_component_Common/Main.js'
  442. ];
  443. var dest = 'target/o2server/servers/webServer/o2_core/o2/xDesktop/';
  444. return gulp.src(src, {sourcemaps: true})
  445. //.pipe(sourceMap.init())
  446. .pipe(concat('$all.js'))
  447. .pipe(gulp.dest(dest))
  448. .pipe(concat('$all.min.js'))
  449. .pipe(uglify())
  450. //.pipe(rename({ extname: '.min.js' }))
  451. //.pipe(sourceMap.write(""))
  452. .pipe(gulp.dest(dest, {sourcemaps: '.'}))
  453. }
  454. function build_concat_xform(){
  455. let path = "x_component_process_Xform";
  456. var src = [
  457. 'o2web/source/o2_core/o2/widget/AttachmentController.js',
  458. 'o2web/source/o2_core/o2/xScript/Macro.js',
  459. 'o2web/source/o2_core/o2/widget/Tab.js',
  460. 'o2web/source/o2_core/o2/widget/O2Identity.js',
  461. 'o2web/source/' + path + '/Form.js',
  462. 'o2web/source/' + path + '/$Module.js',
  463. 'o2web/source/' + path + '/$Input.js',
  464. 'o2web/source/' + path + '/Div.js',
  465. 'o2web/source/' + path + '/Combox.js',
  466. 'o2web/source/' + path + '/DatagridMobile.js',
  467. 'o2web/source/' + path + '/DatagridPC.js',
  468. 'o2web/source/' + path + '/Textfield.js',
  469. 'o2web/source/' + path + '/Personfield.js',
  470. 'o2web/source/' + path + '/Button.js',
  471. 'o2web/source/' + path + '/ViewSelector.js',
  472. 'o2web/source/' + path + '/*.js',
  473. 'o2web/source/x_component_process_Work/Processor.js',
  474. '!o2web/source/' + path + '/Documenteditor.js ',
  475. '!o2web/source/' + path + '/Office.js',
  476. '!o2web/source/' + path + '/WpsOffice.js',
  477. '!o2web/source/' + path + '/WpsOffice2.js',
  478. '!o2web/source/' + path + '/YozoOffice.js',
  479. '!o2web/source/' + path + '/IWebOffice.js',
  480. '!o2web/source/' + path + '/OnlyOffice.js',
  481. '!o2web/source/' + path + '/TinyMCEEditor.js'
  482. ];
  483. var dest = 'target/o2server/servers/webServer/'+path+'/';
  484. return gulp.src(src, {sourcemaps: true})
  485. //.pipe(sourceMap.init())
  486. .pipe(concat('$all.js'))
  487. .pipe(gulp.dest(dest))
  488. .pipe(concat('$all.min.js'))
  489. .pipe(uglify())
  490. //.pipe(rename({ extname: '.min.js' }))
  491. //.pipe(sourceMap.write(""))
  492. .pipe(gulp.dest(dest, {sourcemaps: '.'}))
  493. }
  494. function build_concat_cms_xform(){
  495. let processPath = "x_component_process_Xform";
  496. let path = "x_component_cms_Xform";
  497. var src = [
  498. 'o2web/source/o2_core/o2/widget/AttachmentController.js',
  499. // 'source/o2_core/o2/xScript/CMSEnvironment.js',
  500. 'o2web/source/o2_core/o2/xScript/CMSMacro.js',
  501. 'o2web/source/o2_core/o2/widget/Tab.js',
  502. 'o2web/source/o2_core/o2/widget/O2Identity.js',
  503. 'o2web/source/' + processPath + '/Form.js',
  504. 'o2web/source/' + processPath + '/$Module.js',
  505. 'o2web/source/' + processPath + '/$Input.js',
  506. 'o2web/source/' + processPath + '/Div.js',
  507. //'source/' + processPath + '/Combox.js',
  508. 'o2web/source/' + processPath + '/DatagridMobile.js',
  509. 'o2web/source/' + processPath + '/DatagridPC.js',
  510. 'o2web/source/' + processPath + '/Textfield.js',
  511. //'source/' + processPath + '/Personfield.js',
  512. 'o2web/source/' + processPath + '/Button.js',
  513. //'source/' + processPath + '/ViewSelector.js',
  514. 'o2web/source/' + processPath + '/Org.js',
  515. // 'source/' + processPath + '/*.js',
  516. 'o2web/source/' + processPath + '/Actionbar.js',
  517. //'source/' + processPath + '/Address.js',
  518. 'o2web/source/' + processPath + '/Attachment.js',
  519. 'o2web/source/' + processPath + '/Calendar.js',
  520. 'o2web/source/' + processPath + '/Checkbox.js',
  521. 'o2web/source/' + processPath + '/Datagrid.js',
  522. 'o2web/source/' + processPath + '/Htmleditor.js',
  523. //'source/' + processPath + '/Iframe.js',
  524. 'o2web/source/' + processPath + '/Label.js',
  525. 'o2web/source/' + processPath + '/Number.js',
  526. 'o2web/source/' + processPath + '/Common.js',
  527. 'o2web/source/' + processPath + '/Image.js',
  528. 'o2web/source/' + processPath + '/ImageClipper.js',
  529. 'o2web/source/' + processPath + '/Html.js',
  530. 'o2web/source/' + processPath + '/Radio.js',
  531. 'o2web/source/' + processPath + '/Select.js',
  532. //'source/' + processPath + '/Stat.js',
  533. //'source/' + processPath + '/Statement.js',
  534. //'source/' + processPath + '/StatementSelector.js',
  535. //'source/' + processPath + '/Subform.js',
  536. 'o2web/source/' + processPath + '/Tab.js',
  537. 'o2web/source/' + processPath + '/Table.js',
  538. 'o2web/source/' + processPath + '/Textarea.js',
  539. //'source/' + processPath + '/Tree.js',
  540. //'source/' + processPath + '/View.js',
  541. // 'source/x_component_process_Work/Processor.js',
  542. // '!source/' + processPath + '/Office.js'
  543. 'o2web/source/o2_core/o2/widget/SimpleToolbar.js',
  544. 'o2web/source/' + path + '/ModuleImplements.js',
  545. 'o2web/source/' + path + '/Package.js',
  546. 'o2web/source/' + path + '/Form.js',
  547. //'source/' + path + '/widget/Comment.js',
  548. 'o2web/source/' + path + '/widget/Log.js',
  549. 'o2web/source/' + path + '/Org.js',
  550. 'o2web/source/' + path + '/Author.js',
  551. 'o2web/source/' + path + '/Reader.js',
  552. 'o2web/source/' + path + '/Textfield.js',
  553. 'o2web/source/' + path + '/Actionbar.js',
  554. 'o2web/source/' + path + '/Attachment.js',
  555. 'o2web/source/' + path + '/Button.js',
  556. 'o2web/source/' + path + '/Calendar.js',
  557. 'o2web/source/' + path + '/Checkbox.js',
  558. 'o2web/source/' + path + '/Datagrid.js',
  559. 'o2web/source/' + path + '/Htmleditor.js',
  560. 'o2web/source/' + path + '/ImageClipper.js',
  561. 'o2web/source/' + path + '/Label.js',
  562. 'o2web/source/' + path + '/Number.js',
  563. 'o2web/source/' + path + '/Radio.js',
  564. 'o2web/source/' + path + '/Select.js',
  565. 'o2web/source/' + path + '/Tab.js',
  566. 'o2web/source/' + path + '/Table.js',
  567. 'o2web/source/' + path + '/Textarea.js'
  568. //'source/' + path + '/Personfield.js',
  569. //'source/' + path + '/Readerfield.js',
  570. //'source/' + path + '/Authorfield.js',
  571. //'source/' + path + '/Orgfield.js',
  572. // 'source/' + path + '/*.js',
  573. // '!source/' + path + '/Office.js'
  574. ];
  575. var dest = 'target/o2server/servers/webServer/'+path+'/';
  576. return gulp.src(src, {sourcemaps: true})
  577. //.pipe(sourceMap.init())
  578. .pipe(concat('$all.js'))
  579. .pipe(gulp.dest(dest))
  580. .pipe(concat('$all.min.js'))
  581. .pipe(uglify())
  582. //.pipe(rename({ extname: '.min.js' }))
  583. //.pipe(sourceMap.write(""))
  584. .pipe(gulp.dest(dest, {sourcemaps: '.'}))
  585. }
  586. function build_bundle(){
  587. let path = "o2_core";
  588. var src = [
  589. 'o2web/source/o2_core/polyfill.js',
  590. 'o2web/source/o2_lib/mootools/mootools-1.6.0_all.js',
  591. 'o2web/source/o2_lib/mootools/plugin/mBox.js',
  592. 'o2web/source/o2_core/o2.js',
  593. 'o2web/source/x_desktop/js/base.js',
  594. 'o2web/source/x_desktop/js/base_loader.js',
  595. 'o2web/source/o2_core/o2/xScript/PageEnvironment.js',
  596. "o2web/source/o2_core/o2/framework.js"
  597. ];
  598. var dest = 'target/o2server/servers/webServer/'+path+'/';
  599. return gulp.src(src, {sourcemaps: true})
  600. //.pipe(sourceMap.init())
  601. .pipe(concat('bundle.js'))
  602. .pipe(gulp.dest(dest))
  603. .pipe(concat('bundle.min.js'))
  604. .pipe(uglify())
  605. //.pipe(rename({ extname: '.min.js' }))
  606. //.pipe(sourceMap.write(""))
  607. .pipe(gulp.dest(dest, {sourcemaps: '.'}))
  608. }
  609. function concat_Actions(){
  610. return through2.obj(function (file, enc, cb) {
  611. if (file.isNull()) {
  612. this.push(file);
  613. return cb();
  614. }
  615. if (file.isStream()) {
  616. this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
  617. return cb();
  618. }
  619. var content = file.contents.toString();
  620. var o = path.parse(file.path);
  621. var name = o.name;
  622. content = "var actionJson = "+content;
  623. content = content+"\nif (!o2.xAction.RestActions.Action[\""+name+"\"]) o2.xAction.RestActions.Action[\""+name+"\"] = new Class({Extends: o2.xAction.RestActions.Action});";
  624. content = content+"\no2.Actions.actions[\""+name+"\"] = new o2.xAction.RestActions.Action[\""+name+"\"](\""+name+"\", actionJson);";
  625. file.contents = new Buffer.from(content);
  626. this.push(file);
  627. cb();
  628. });
  629. }
  630. function concat_Style(){
  631. return through2.obj(function (file, enc, cb) {
  632. if (file.isNull()) {
  633. this.push(file);
  634. return cb();
  635. }
  636. if (file.isStream()) {
  637. this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
  638. return cb();
  639. }
  640. var content = file.contents.toString();
  641. var name = file.path.replace(process.cwd(), "").replace(/\\/g, "/")
  642. name = ".."+name.substring(name.indexOf("/source")+7);
  643. content = "var csskey = encodeURIComponent(\""+name+"\");\no2.widget.css[csskey]="+content;
  644. file.contents = new Buffer.from(content);
  645. this.push(file);
  646. cb();
  647. });
  648. }
  649. function build_concat_basework_style(){
  650. return gulp.src([
  651. "o2web/source/x_component_process_Work/$Main/default/css.wcss",
  652. "o2web/source/x_component_process_Xform/$Form/default/css.wcss",
  653. "o2web/source/o2_core/o2/widget/$Tab/mobileForm/css.wcss",
  654. "o2web/source/o2_core/o2/widget/$Menu/tab/css.wcss",
  655. "o2web/source/o2_core/o2/widget/$Tab/form/css.wcss",
  656. "o2web/source/x_component_process_Xform/$Form/default/doc.wcss",
  657. "o2web/source/o2_core/o2/widget/$Toolbar/documentEdit/css.wcss",
  658. "o2web/source/o2_core/o2/widget/$Toolbar/documentEdit_side/css.wcss",
  659. "o2web/source/x_component_process_Xform/$Form/default/css.wcss"
  660. ])
  661. .pipe(concat_Style())
  662. .pipe(concat('js/base_work_style_temp.js'))
  663. .pipe(gulp.dest('o2web/source/x_desktop/'));
  664. }
  665. function build_concat_basework_action(){
  666. return gulp.src([
  667. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  668. "o2web/source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.json",
  669. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  670. "o2web/source/o2_core/o2/xAction/services/x_query_assemble_surface.json",
  671. "o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  672. "o2web/source/o2_core/o2/xAction/services/x_program_center.json",
  673. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.json"
  674. ])
  675. .pipe(concat_Actions())
  676. .pipe(concat('js/base_work_actions_temp.js'))
  677. .pipe(gulp.dest('o2web/source/x_desktop/'));
  678. }
  679. function build_concat_basework_clean(cb) {
  680. var dest = [
  681. 'o2web/source/x_desktop/js/base_work_actions_temp.js',
  682. 'o2web/source/x_desktop/js/base_work_style_temp.js'
  683. ];
  684. return del(dest, cb);
  685. }
  686. function build_concat_lp(cb) {
  687. var lpTasks = [];
  688. supportedLanguage.forEach(function(lp){
  689. var src = [
  690. 'o2web/source/o2_core/o2/lp/'+(lp)+'.js',
  691. 'o2web/source/x_component_process_Work/lp/'+(lp)+'.js',
  692. 'o2web/source/x_component_process_Xform/lp/'+(lp)+'.js',
  693. 'o2web/source/x_component_Selector/lp/'+(lp)+'.js',
  694. 'o2web/source/x_component_Template/lp/'+(lp)+'.js',
  695. 'o2web/source/x_component_portal_Portal/lp/'+(lp)+'.js',
  696. 'o2web/source/x_component_cms_Document/lp/'+(lp)+'.js',
  697. 'o2web/source/x_component_cms_Xform/lp/'+(lp)+'.js',
  698. ];
  699. var dest = 'target/o2server/servers/webServer/x_desktop/js/';
  700. // lpTasks["build_concat_lp_"+lp] = function(){
  701. // return
  702. // };
  703. var stream = gulp.src(src, {"allowEmpty": true, sourcemaps: true});
  704. lpTasks.push(new Promise((resolve)=>{
  705. stream.on("end", ()=>{ resolve(); });
  706. }));
  707. //.pipe(sourceMap.init())
  708. stream.pipe(concat('base_lp_' + lp + '.js'))
  709. .pipe(gulp.dest(dest))
  710. .pipe(concat('base_lp_' + lp + '.min.js'))
  711. .pipe(uglify())
  712. //.pipe(rename({ extname: '.min.js' }))
  713. // .pipe(sourceMap.write(""))
  714. .pipe(gulp.dest(dest, {sourcemaps: '.' }));
  715. });
  716. return Promise.all(lpTasks);
  717. //var build_concat_lp = gulp.parallel( Object.values(lpTasks) );
  718. // return gulp.parallel(lpTasks);
  719. }
  720. function build_concat_basework_body() {
  721. var src = [
  722. 'o2web/source/x_desktop/js/base_concat_head.js',
  723. //'o2web/source/o2_core/o2/lp/'+(options.lp || 'zh-cn')+'.js',
  724. 'o2web/source/x_desktop/js/base_work_style_temp.js',
  725. 'o2web/source/o2_core/o2/widget/Common.js',
  726. 'o2web/source/o2_core/o2/widget/Dialog.js',
  727. 'o2web/source/o2_core/o2/widget/UUID.js',
  728. 'o2web/source/o2_core/o2/widget/Menu.js',
  729. 'o2web/source/o2_core/o2/widget/Toolbar.js',
  730. 'o2web/source/o2_core/o2/xDesktop/Common.js',
  731. 'o2web/source/o2_core/o2/xDesktop/Actions/RestActions.js',
  732. 'o2web/source/o2_core/o2/xAction/RestActions.js',
  733. 'o2web/source/o2_core/o2/xDesktop/Access.js',
  734. 'o2web/source/o2_core/o2/xDesktop/Dialog.js',
  735. 'o2web/source/o2_core/o2/xDesktop/Menu.js',
  736. 'o2web/source/o2_core/o2/xDesktop/UserData.js',
  737. 'o2web/source/x_component_Template/MPopupForm.js',
  738. 'o2web/source/o2_core/o2/xDesktop/Authentication.js',
  739. 'o2web/source/o2_core/o2/xDesktop/Dialog.js',
  740. 'o2web/source/o2_core/o2/xDesktop/Window.js',
  741. 'o2web/source/x_component_Common/Main.js',
  742. // 'o2web/source/o2_core/o2/lp/'+(options.lp || 'zh-cn')+'.js',
  743. // 'o2web/source/x_component_process_Work/lp/'+(options.lp || 'zh-cn')+'.js',
  744. // 'o2web/source/x_component_process_Xform/lp/'+(options.lp || 'zh-cn')+'.js',
  745. // 'o2web/source/x_component_Selector/lp/'+(options.lp || 'zh-cn')+'.js',
  746. 'o2web/source/x_component_process_Work/Main.js',
  747. 'o2web/source/x_component_Selector/package.js',
  748. 'o2web/source/x_component_Selector/Person.js',
  749. 'o2web/source/x_component_Selector/Identity.js',
  750. 'o2web/source/x_component_Selector/Unit.js',
  751. 'o2web/source/x_component_Selector/IdentityWidthDuty.js',
  752. 'o2web/source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js',
  753. 'o2web/source/x_component_Selector/UnitWithType.js',
  754. 'o2web/source/o2_core/o2/xScript/Actions/UnitActions.js',
  755. 'o2web/source/o2_core/o2/xScript/Actions/ScriptActions.js',
  756. 'o2web/source/o2_core/o2/xScript/Actions/CMSScriptActions.js',
  757. 'o2web/source/o2_core/o2/xScript/Actions/PortalScriptActions.js',
  758. 'o2web/source/o2_core/o2/xScript/Environment.js',
  759. 'o2web/source/x_component_Template/MTooltips.js',
  760. 'o2web/source/x_component_Template/MSelector.js',
  761. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js',
  762. 'o2web/source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.js',
  763. 'o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.js',
  764. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.js',
  765. 'o2web/source/o2_core/o2/xAction/services/x_query_assemble_surface.js',
  766. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.js',
  767. 'o2web/source/x_desktop/js/base_work_actions_temp.js',
  768. 'o2web/source/x_desktop/js/base.js',
  769. 'o2web/source/x_desktop/js/base_loader.js'
  770. ];
  771. var dest = 'target/o2server/servers/webServer/x_desktop/js/';
  772. return gulp.src(src, {sourcemaps: true})
  773. //.pipe(sourceMap.init())
  774. .pipe(concat('base_work.js'))
  775. .pipe(gulp.dest(dest))
  776. .pipe(concat('base_work.min.js'))
  777. .pipe(uglify())
  778. //.pipe(rename({ extname: '.min.js' }))
  779. //.pipe(sourceMap.write(""))
  780. .pipe(gulp.dest(dest, {sourcemaps: '.'}));
  781. }
  782. function build_concat_baseportal_style(){
  783. return gulp.src([
  784. "o2web/source/x_component_process_Work/$Main/default/css.wcss",
  785. "o2web/source/x_component_portal_Portal/$Main/default/css.wcss",
  786. "o2web/source/x_component_process_Xform/$Form/default/css.wcss",
  787. "o2web/source/o2_core/o2/widget/$Tab/mobileForm/css.wcss",
  788. "o2web/source/o2_core/o2/widget/$Menu/tab/css.wcss",
  789. ])
  790. .pipe(concat_Style())
  791. .pipe(concat('js/base_portal_style_temp.js'))
  792. .pipe(gulp.dest('o2web/source/x_desktop/'));
  793. }
  794. function build_concat_baseportal_action(){
  795. return gulp.src([
  796. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  797. "o2web/source/o2_core/o2/xAction/services/x_portal_assemble_surface.json",
  798. "o2web/source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.json",
  799. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  800. "o2web/source/o2_core/o2/xAction/services/x_query_assemble_surface.json",
  801. "o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  802. "o2web/source/o2_core/o2/xAction/services/x_program_center.json",
  803. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.json"
  804. ])
  805. .pipe(concat_Actions())
  806. .pipe(concat('js/base_portal_actions_temp.js'))
  807. .pipe(gulp.dest('o2web/source/x_desktop/'));
  808. }
  809. function build_concat_baseportal_clean(cb) {
  810. var dest = [
  811. 'o2web/source/x_desktop/js/base_portal_actions_temp.js',
  812. 'o2web/source/x_desktop/js/base_portal_style_temp.js'
  813. ];
  814. return del(dest, cb);
  815. }
  816. function build_concat_baseportal_body() {
  817. var src = [
  818. 'o2web/source/x_desktop/js/base_concat_head.js',
  819. //'o2web/source/o2_core/o2/lp/'+(options.lp || 'zh-cn')+'.js',
  820. 'o2web/source/x_desktop/js/base_portal_style_temp.js',
  821. 'o2web/source/o2_core/o2/widget/Common.js',
  822. 'o2web/source/o2_core/o2/widget/Dialog.js',
  823. 'o2web/source/o2_core/o2/widget/UUID.js',
  824. 'o2web/source/o2_core/o2/widget/Menu.js',
  825. 'o2web/source/o2_core/o2/widget/Toolbar.js',
  826. 'o2web/source/o2_core/o2/xDesktop/Common.js',
  827. 'o2web/source/o2_core/o2/xDesktop/Actions/RestActions.js',
  828. 'o2web/source/o2_core/o2/xAction/RestActions.js',
  829. 'o2web/source/o2_core/o2/xDesktop/Access.js',
  830. 'o2web/source/o2_core/o2/xDesktop/Dialog.js',
  831. 'o2web/source/o2_core/o2/xDesktop/Menu.js',
  832. 'o2web/source/o2_core/o2/xDesktop/UserData.js',
  833. 'o2web/source/x_component_Template/MPopupForm.js',
  834. 'o2web/source/o2_core/o2/xDesktop/Authentication.js',
  835. 'o2web/source/o2_core/o2/xDesktop/Window.js',
  836. 'o2web/source/x_component_Common/Main.js',
  837. // 'o2web/source/x_component_process_Work/lp/'+(options.lp || 'zh-cn')+'.js',
  838. // 'o2web/source/x_component_portal_Portal/lp/'+(options.lp || 'zh-cn')+'.js',
  839. // 'o2web/source/x_component_process_Xform/lp/'+(options.lp || 'zh-cn')+'.js',
  840. // 'o2web/source/x_component_Selector/lp/'+(options.lp || 'zh-cn')+'.js',
  841. 'o2web/source/x_component_portal_Portal/Main.js',
  842. 'o2web/source/x_component_Selector/package.js',
  843. 'o2web/source/x_component_Selector/Person.js',
  844. 'o2web/source/x_component_Selector/Identity.js',
  845. 'o2web/source/x_component_Selector/Unit.js',
  846. 'o2web/source/x_component_Selector/IdentityWidthDuty.js',
  847. 'o2web/source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js',
  848. 'o2web/source/x_component_Selector/UnitWithType.js',
  849. 'o2web/source/o2_core/o2/xScript/Actions/UnitActions.js',
  850. 'o2web/source/o2_core/o2/xScript/Actions/ScriptActions.js',
  851. 'o2web/source/o2_core/o2/xScript/Actions/CMSScriptActions.js',
  852. 'o2web/source/o2_core/o2/xScript/Actions/PortalScriptActions.js',
  853. 'o2web/source/o2_core/o2/xScript/PageEnvironment.js',
  854. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js',
  855. 'o2web/source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.js',
  856. 'o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.js',
  857. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.js',
  858. 'o2web/source/o2_core/o2/xAction/services/x_query_assemble_surface.js',
  859. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.js',
  860. 'o2web/source/x_desktop/js/base_portal_actions_temp.js',
  861. 'o2web/source/x_desktop/js/base.js',
  862. 'o2web/source/x_desktop/js/base_loader.js'
  863. ];
  864. var dest = 'target/o2server/servers/webServer/x_desktop/js/';
  865. return gulp.src(src, {sourcemaps: true})
  866. //.pipe(sourceMap.init())
  867. .pipe(concat('base_portal.js'))
  868. .pipe(gulp.dest(dest))
  869. .pipe(concat('base_portal.min.js'))
  870. .pipe(uglify())
  871. //.pipe(rename({ extname: '.min.js' }))
  872. //.pipe(sourceMap.write(""))
  873. .pipe(gulp.dest(dest, {sourcemaps: '.'}));
  874. }
  875. function build_concat_basedocument_style(){
  876. return gulp.src([
  877. "o2web/source/x_component_cms_Document/$Main/default/css.wcss",
  878. "o2web/source/x_component_cms_Xform/$Form/default/css.wcss",
  879. "o2web/source/o2_core/o2/widget/$AttachmentController/default/css.wcss"
  880. ])
  881. .pipe(concat_Style())
  882. .pipe(concat('js/base_document_style_temp.js'))
  883. .pipe(gulp.dest('o2web/source/x_desktop/'));
  884. }
  885. function build_concat_basedocument_action(){
  886. return gulp.src([
  887. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  888. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  889. "o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  890. "o2web/source/o2_core/o2/xAction/services/x_program_center.json",
  891. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.json"
  892. ])
  893. .pipe(concat_Actions())
  894. .pipe(concat('js/base_document_actions_temp.js'))
  895. .pipe(gulp.dest('o2web/source/x_desktop/'));
  896. }
  897. function build_concat_basedocument_clean(cb) {
  898. var dest = [
  899. 'o2web/source/x_desktop/js/base_document_actions_temp.js',
  900. 'o2web/source/x_desktop/js/base_document_style_temp.js'
  901. ];
  902. return del(dest, cb);
  903. }
  904. function build_concat_basedocument_body() {
  905. var src = [
  906. 'o2web/source/x_desktop/js/base_concat_head.js',
  907. //'o2web/source/o2_core/o2/lp/'+(options.lp || 'zh-cn')+'.js',
  908. 'o2web/source/x_desktop/js/base_document_style_temp.js',
  909. 'o2web/source/o2_core/o2/widget/Common.js',
  910. 'o2web/source/o2_core/o2/widget/Dialog.js',
  911. 'o2web/source/o2_core/o2/widget/UUID.js',
  912. 'o2web/source/o2_core/o2/widget/Menu.js',
  913. 'o2web/source/o2_core/o2/widget/Mask.js',
  914. 'o2web/source/o2_core/o2/xDesktop/Common.js',
  915. 'o2web/source/o2_core/o2/xDesktop/Actions/RestActions.js',
  916. 'o2web/source/o2_core/o2/xAction/RestActions.js',
  917. 'o2web/source/o2_core/o2/xDesktop/Access.js',
  918. 'o2web/source/o2_core/o2/xDesktop/Dialog.js',
  919. 'o2web/source/o2_core/o2/xDesktop/Menu.js',
  920. 'o2web/source/o2_core/o2/xDesktop/UserData.js',
  921. 'o2web/source/x_component_Template/MPopupForm.js',
  922. 'o2web/source/o2_core/o2/xDesktop/Authentication.js',
  923. 'o2web/source/o2_core/o2/xDesktop/Window.js',
  924. 'o2web/source/x_component_Common/Main.js',
  925. // 'o2web/source/x_component_cms_Document/lp/'+(options.lp || 'zh-cn')+'.js',
  926. // 'o2web/source/x_component_process_Xform/lp/'+(options.lp || 'zh-cn')+'.js',
  927. // 'o2web/source/x_component_Selector/lp/'+(options.lp || 'zh-cn')+'.js',
  928. // 'o2web/source/x_component_cms_Xform/lp/'+(options.lp || 'zh-cn')+'.js',
  929. 'o2web/source/x_component_cms_Document/Main.js',
  930. 'o2web/source/x_component_Selector/package.js',
  931. 'o2web/source/o2_core/o2/xScript/Actions/UnitActions.js',
  932. 'o2web/source/o2_core/o2/xScript/Actions/CMSScriptActions.js',
  933. 'o2web/source/o2_core/o2/xScript/CMSEnvironment.js',
  934. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js',
  935. 'o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.js',
  936. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.js',
  937. 'o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.js',
  938. 'o2web/source/x_desktop/js/base_document_actions_temp.js',
  939. 'o2web/source/x_desktop/js/base.js',
  940. 'o2web/source/x_desktop/js/base_loader.js'
  941. ];
  942. var dest = 'target/o2server/servers/webServer/x_desktop/js/';
  943. return gulp.src(src, {sourcemaps: true})
  944. //.pipe(sourceMap.init())
  945. .pipe(concat('base_document.js'))
  946. .pipe(gulp.dest(dest))
  947. .pipe(concat('base_document.min.js'))
  948. .pipe(uglify())
  949. //.pipe(rename({ extname: '.min.js' }))
  950. //.pipe(sourceMap.write(""))
  951. .pipe(gulp.dest(dest, {sourcemaps: '.'}));
  952. }
  953. exports.build_concat = gulp.parallel(
  954. build_concat_o2,
  955. build_concat_base,
  956. build_concat_desktop,
  957. build_concat_xform,
  958. build_concat_cms_xform,
  959. build_bundle,
  960. build_concat_lp,
  961. gulp.series(build_concat_basework_style, build_concat_basework_action, build_concat_basework_body,build_concat_basework_clean),
  962. gulp.series(build_concat_baseportal_style, build_concat_baseportal_action, build_concat_baseportal_body,build_concat_baseportal_clean),
  963. gulp.series(build_concat_basedocument_style, build_concat_basedocument_action, build_concat_basedocument_body,build_concat_basedocument_clean)
  964. );
  965. function getGitV(){
  966. var tagPromise = new Promise(function(s, f){
  967. git.exec({args : 'describe --tag'}, function (err, stdout) {
  968. if (err){
  969. f(err);
  970. }
  971. var v = stdout.substring(0, stdout.lastIndexOf("-"));
  972. s(v);
  973. });
  974. });
  975. var revPromise = new Promise(function(s, f){
  976. git.exec({args : 'rev-parse --short HEAD'}, function (err, hash) {
  977. if (err){
  978. f(err);
  979. }
  980. s(hash.trim());
  981. });
  982. });
  983. return Promise.all([tagPromise,revPromise])
  984. }
  985. function build_web_v_html() {
  986. var src = 'o2web/source/x_desktop/*.html';
  987. var dest = 'target/o2server/servers/webServer/x_desktop/';
  988. return getGitV().then(function(arr){
  989. return gulp.src(src)
  990. .pipe(assetRev({"verConnecter": arr[0], "md5": arr[1]}))
  991. .pipe(gulp.dest(dest))
  992. .pipe(gutil.noop());
  993. }, function(){
  994. return gulp.src(src)
  995. .pipe(assetRev())
  996. .pipe(gulp.dest(dest))
  997. .pipe(gutil.noop());
  998. });
  999. }
  1000. function build_web_api() {
  1001. var src = 'o2web/api/**/*';
  1002. var dest = 'target/o2server/servers/webServer/api/';
  1003. return gulp.src(src)
  1004. .pipe(gulp.dest(dest))
  1005. }
  1006. function build_doc(){
  1007. return getGitV().then(function(arr){
  1008. return (shell.task('jsdoc -c o2web/jsdoc.conf.json -q version='+arr[0]+'-'+arr[1]+''))();
  1009. }, function(){
  1010. return (shell.task('jsdoc -c o2web/jsdoc.conf.json -q version='))();
  1011. });
  1012. }
  1013. exports.build_api = gulp.series(build_doc, build_web_api);
  1014. function build_web_v_o2() {
  1015. var src = [
  1016. 'target/o2server/servers/webServer/o2_core/o2.js',
  1017. 'target/o2server/servers/webServer/o2_core/o2.min.js'
  1018. ];
  1019. var dest = 'target/o2server/servers/webServer/o2_core/';
  1020. return getGitV().then(function(arr){
  1021. return gulp.src(src)
  1022. .pipe(assetRev({"verConnecter": arr[0], "md5": arr[1], "replace": true}))
  1023. //.pipe(gulp.dest(dest))
  1024. // .pipe(uglify())
  1025. // .pipe(rename({ extname: '.min.js' }))
  1026. .pipe(gulp.dest(dest))
  1027. .pipe(gutil.noop());
  1028. }, function(){
  1029. return gulp.src(src)
  1030. .pipe(assetRev())
  1031. .pipe(gutil.noop());
  1032. });
  1033. }
  1034. async function clear_build(cb) {
  1035. console.log(`---------------------------------------------------------------------
  1036. . clear old build ...
  1037. ---------------------------------------------------------------------`);
  1038. var dest = 'target';
  1039. await del(dest, {force: true});
  1040. cb();
  1041. }
  1042. async function clear_deploy(cb) {
  1043. console.log(`---------------------------------------------------------------------
  1044. . clear old deploy ...
  1045. ---------------------------------------------------------------------`);
  1046. var dest = ["target/o2server/store/", "target/o2server/commons/", "target/o2server/jvm/", "target/o2server/configSample/", "target/o2server/localSample/", "target/o2server/servers/"];
  1047. dest = dest.concat(["target/o2server/*.sh", "target/o2server/*.jar", "target/o2server/*.html", "target/o2server/*.bat", "target/o2server/version.o2"]);
  1048. await del(dest, {force: true});
  1049. cb();
  1050. }
  1051. exports.clear_build = clear_build;
  1052. exports.clear_deploy = clear_deploy;
  1053. function deploy_server(){
  1054. console.log(`---------------------------------------------------------------------
  1055. . deploy to target ...
  1056. ---------------------------------------------------------------------`);
  1057. var source = ["o2server/*store/**/*", "o2server/*commons/**/*", "o2server/*jvm/**/*", "o2server/*configSample/**/*", "o2server/*localSample/**/*"];
  1058. source = source.concat(scriptSource);
  1059. console.log(source)
  1060. var dest = "target/o2server/"
  1061. var entries = fg.sync(source, { dot: false});
  1062. var size = entries.length;
  1063. var pb = new ProgressBar('', 50);
  1064. var doCount = 0;
  1065. var stream = gulp.src(source);
  1066. stream.on("end", ()=>{console.log();});
  1067. return stream.pipe(gulp.dest(dest))
  1068. .pipe(logger(function(){
  1069. doCount++;
  1070. if (doCount <= size) {pb.render({ completed: doCount, total: size, count: doCount})};
  1071. }));
  1072. }
  1073. //exports.preperation = gulp.series(download_commons_and_jvm, decompress_commons_and_jvm, move_commons, move_jvm);
  1074. exports.preperation = gulp.series(download_commons_and_jvm, decompress_commons_and_jvm, move_commons, move_jvm, clear_commons_git, clear_jvm_git);
  1075. var shell = require('gulp-shell')
  1076. const shelljs = require("shelljs");
  1077. exports.build_server = function(){
  1078. console.log(`---------------------------------------------------------------------
  1079. . Start compiling the server ...
  1080. ---------------------------------------------------------------------`);
  1081. return (shell.task('npm run build_server_script'))();
  1082. };
  1083. function chmod_jvm(){
  1084. return (shell.task('chmod 777 -R target/o2server/jvm'))();
  1085. }
  1086. function chmod_commons(){
  1087. return (shell.task('chmod 777 -R target/o2server/commons'))();
  1088. }
  1089. function chmod_sh(){
  1090. return (shell.task('chmod 777 target/o2server/*.sh'))();
  1091. }
  1092. function chmod_servers(){
  1093. return (shell.task('chmod 777 -R target/o2server/servers'))();
  1094. }
  1095. exports.build_web = gulp.series(
  1096. build_web_module,
  1097. build_web_minimize,
  1098. build_web_move,
  1099. gulp.parallel(
  1100. build_concat_o2,
  1101. build_concat_base,
  1102. build_concat_desktop,
  1103. build_concat_xform,
  1104. build_concat_cms_xform,
  1105. build_concat_lp,
  1106. gulp.series(build_concat_basework_style, build_concat_basework_action, build_concat_basework_body,build_concat_basework_clean),
  1107. gulp.series(build_concat_baseportal_style, build_concat_baseportal_action, build_concat_baseportal_body,build_concat_baseportal_clean),
  1108. gulp.series(build_concat_basedocument_style, build_concat_basedocument_action, build_concat_basedocument_body,build_concat_basedocument_clean),
  1109. build_bundle
  1110. ),
  1111. build_web_v_html,
  1112. build_web_v_o2,
  1113. //gulp.series(build_doc, build_web_api)
  1114. );
  1115. if (os.platform().indexOf("win")==-1){
  1116. exports.deploy = gulp.series(deploy_server, chmod_jvm, chmod_commons, chmod_sh, chmod_servers);
  1117. }else{
  1118. exports.deploy = gulp.series(deploy_server);
  1119. }
  1120. function createHistoryJsonFile(url, fileName, host){
  1121. const fp = fs.promises;
  1122. return new Promise(function(resolve){
  1123. request.get({'url': url}, function(error, response, body) {
  1124. if (!error && response.statusCode == 200) {
  1125. const historyJsons = JSON.parse(body);
  1126. fp.readFile(path.resolve(process.cwd(), 'download-pro.json'), 'utf8').then(function(str){
  1127. const downloadJson = JSON.parse(str);
  1128. downloadJson.windows.url = host+downloadJson.windows.url;
  1129. downloadJson.linux.url = host+downloadJson.linux.url
  1130. downloadJson.macos.url = host+downloadJson.macos.url
  1131. downloadJson.aix.url = host+downloadJson.aix.url
  1132. downloadJson.raspi.url = host+downloadJson.raspi.url
  1133. downloadJson.mips.url = host+downloadJson.mips.url
  1134. downloadJson.arm.url = host+downloadJson.arm.url
  1135. let append = true;
  1136. for (var i=0; i<historyJsons.length; i++){
  1137. var o = historyJsons[i];
  1138. if (o.title == downloadJson.title){
  1139. historyJsons.splice(i, 1, downloadJson)
  1140. append = false;
  1141. break;
  1142. }
  1143. }
  1144. if (append){
  1145. historyJsons.unshift(downloadJson);
  1146. }
  1147. const jsonStr = JSON.stringify(historyJsons, null, '\t');
  1148. fp.writeFile(path.resolve(process.cwd(), fileName), jsonStr).then(()=>{resolve();});
  1149. });
  1150. }
  1151. });
  1152. });
  1153. }
  1154. async function createHistroyJson(cb) {
  1155. const host = options.webSite;
  1156. const mirrorHost = options.mirrorSite;
  1157. const downloadHost = options.downloadSite
  1158. if (host) {
  1159. const url = host + "/website/history.json?t=" + (new Date()).getTime();
  1160. const mirrorUrl = mirrorHost + "/download/download-history.json?t=" + (new Date()).getTime();
  1161. var doneWebSite = false;
  1162. var doneMirror = false;
  1163. var check = function () {
  1164. if (doneWebSite && doneMirror) cb();
  1165. };
  1166. await createHistoryJsonFile(url, 'history.json', downloadHost);
  1167. await createHistoryJsonFile(mirrorUrl, 'download-history.json', mirrorHost);
  1168. }
  1169. cb();
  1170. }
  1171. exports.build_historyJson = createHistroyJson;
  1172. // /exports.build_module = build_web_module;