gulpfile.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564
  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 git = require("gulp-git");
  26. //var downloadHost = "download.o2oa.net";
  27. // var downloadHost = "release.o2oa.net";
  28. // var protocol = "http";
  29. // var commonUrl = "/build/commons.tar.gz";
  30. // var jvmUrls = {
  31. // "all": "/build/jvm.tar.gz",
  32. // "linux": "/build/linux.tar.gz",
  33. // "aix": "/build/aix.tar.gz",
  34. // "arm": "/build/arm.tar.gz",
  35. // "macos": "/build/macos.tar.gz",
  36. // "risc": "/build/risc.tar.gz",
  37. // "raspberrypi": "/build/raspberrypi.tar.gz",
  38. // "windows": "/build/windows.tar.gz"
  39. // };
  40. var downloadHost = "git.o2oa.net";
  41. var protocol = "https";
  42. var commonUrl =
  43. "/o2oa/evn-o2server-commons/-/archive/master/evn-o2server-commons-master.tar.gz?path=commons";
  44. var jvmUrls = {
  45. all:
  46. "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm",
  47. linux:
  48. "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/linux",
  49. aix:
  50. "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/aix",
  51. arm:
  52. "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/arm",
  53. macos:
  54. "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/macos",
  55. risc:
  56. "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/risc",
  57. raspi:
  58. "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/raspi",
  59. windows:
  60. "/o2oa/evn-o2server-jvm/-/archive/master/evn-o2server-jvm-master.tar.gz?path=jvm/windows",
  61. };
  62. var scripts = {
  63. all: [
  64. "o2server/*.sh",
  65. "o2server/*.jar",
  66. "o2server/*.html",
  67. "o2server/*.bat",
  68. "o2server/version.o2",
  69. ],
  70. linux: [
  71. "o2server/*linux*",
  72. "o2server/*.jar",
  73. "o2server/*.html",
  74. "o2server/version.o2",
  75. ],
  76. aix: [
  77. "o2server/*aix*",
  78. "o2server/*.jar",
  79. "o2server/*.html",
  80. "o2server/version.o2",
  81. ],
  82. arm: [
  83. "o2server/*arm*",
  84. "o2server/*.jar",
  85. "o2server/*.html",
  86. "o2server/version.o2",
  87. ],
  88. macos: [
  89. "o2server/*macos*",
  90. "o2server/*.jar",
  91. "o2server/*.html",
  92. "o2server/version.o2",
  93. ],
  94. risc: [
  95. "o2server/*risc*",
  96. "o2server/*.jar",
  97. "o2server/*.html",
  98. "o2server/version.o2",
  99. ],
  100. raspi: [
  101. "o2server/*raspi*",
  102. "o2server/*.jar",
  103. "o2server/*.html",
  104. "o2server/version.o2",
  105. ],
  106. windows: [
  107. "o2server/*windows*",
  108. "o2server/*.jar",
  109. "o2server/*.html",
  110. "o2server/version.o2",
  111. ],
  112. };
  113. var o_options = minimist(process.argv.slice(2), {
  114. //upload: local ftp or sftp
  115. string: ["e", "lp"],
  116. });
  117. var options = {};
  118. options.ev = o_options.e || "all";
  119. options.lp = o_options.lp || "zh-cn";
  120. var jvmUrl = jvmUrls[options.ev];
  121. var scriptSource = scripts[options.ev];
  122. function ProgressBar(description, bar_length) {
  123. this.description = description || "Progress";
  124. this.length = bar_length || 50;
  125. this.render = function (opts) {
  126. var percent = (opts.completed / opts.total).toFixed(4);
  127. var cell_num = Math.floor(percent * this.length);
  128. var speed = "";
  129. if (opts.time) {
  130. speed = opts.completed / 1024 / 1024 / (opts.time / 1000);
  131. speed = speed.toFixed(2);
  132. speed = speed + "M/S";
  133. }
  134. var count = "";
  135. if (opts.count) {
  136. count = "[" + opts.count + "/" + opts.total + "]";
  137. }
  138. var cell = "";
  139. for (var i = 0; i < cell_num; i++) {
  140. cell += ">";
  141. }
  142. var empty = "";
  143. for (var i = 0; i < this.length - cell_num; i++) {
  144. empty += "=";
  145. }
  146. if (opts.completed <= opts.total) {
  147. var d = new Date();
  148. var cmdText =
  149. "[" +
  150. dateFormat(d, "HH:MM:ss") +
  151. "]" +
  152. " " +
  153. this.description +
  154. ": " +
  155. cell +
  156. empty +
  157. " " +
  158. (100 * percent).toFixed(2) +
  159. "% " +
  160. speed +
  161. count;
  162. slog(cmdText);
  163. }
  164. };
  165. }
  166. function downloadFile_progress(path, filename, headcb, progresscb, cb) {
  167. var dest = `o2server/${filename}`;
  168. // fs.exists(dest, function(exists) {
  169. // if (exists){
  170. // headcb(1);
  171. // progresscb({transferred:1});
  172. // cb();
  173. // }else{
  174. let stream = fs.createWriteStream(dest);
  175. var options = { url: protocol + "://" + downloadHost + path };
  176. var fileHost = downloadHost;
  177. var filePath = path;
  178. stream.on("finish", () => {
  179. //gutil.log("download", ":", gutil.colors.green(filename), " completed!");
  180. cb();
  181. });
  182. stream.on("error", (err) => {
  183. gutil.log(
  184. gutil.colors.red("download error"),
  185. ":",
  186. gutil.colors.red(filename),
  187. err
  188. );
  189. });
  190. var req = http.request(
  191. {
  192. host: fileHost,
  193. path: filePath,
  194. method: "HEAD",
  195. },
  196. function (res) {
  197. if (res.statusCode == 200) {
  198. res.setEncoding(null);
  199. var time = 0;
  200. var l = res.headers["content-length"];
  201. var str = progress({
  202. length: l,
  203. time: 100 /* ms */,
  204. });
  205. headcb(l);
  206. str.on("progress", function (progress) {
  207. if (pb) {
  208. progresscb(progress);
  209. pb.render({
  210. completed: currentLength,
  211. total: totalLength,
  212. time: (time += 100),
  213. });
  214. }
  215. });
  216. request.get(options).pipe(str).pipe(stream);
  217. } else {
  218. gutil.log(
  219. gutil.colors.red("download error"),
  220. ":",
  221. gutil.colors.red(filename),
  222. "statusCode:" + res.statusCode
  223. );
  224. }
  225. }
  226. );
  227. req.on("error", (e) => {
  228. gutil.log(
  229. gutil.colors.red("download error"),
  230. ":",
  231. gutil.colors.red(filename),
  232. e
  233. );
  234. });
  235. req.end();
  236. // }
  237. //});
  238. }
  239. function downloadFile(path, filename, headcb, progresscb, cb) {
  240. var dest = `o2server/${filename}`;
  241. // fs.exists(dest, function(exists) {
  242. // if (exists){
  243. // headcb(1);
  244. // progresscb({transferred:1});
  245. // cb();
  246. // }else{
  247. let stream = fs.createWriteStream(dest);
  248. var options = { url: protocol + "://" + downloadHost + path };
  249. var fileHost = downloadHost;
  250. var filePath = path;
  251. stream.on("finish", () => {
  252. //gutil.log("download", ":", gutil.colors.green(filename), " completed!");
  253. cb();
  254. });
  255. stream.on("error", (err) => {
  256. gutil.log(
  257. gutil.colors.red("download error"),
  258. ":",
  259. gutil.colors.red(filename),
  260. err
  261. );
  262. });
  263. // var req = http.request({
  264. // host:fileHost,
  265. // path:filePath,
  266. // method:'HEAD'
  267. // },function (res){
  268. // if (res.statusCode == 200) {
  269. // res.setEncoding(null);
  270. // var time = 0;
  271. // var l = res.headers['content-length'];
  272. // var str = progress({
  273. // length: l,
  274. // time: 100 /* ms */
  275. // });
  276. // headcb(l);
  277. //
  278. // str.on('progress', function(progress) {
  279. // if (pb){
  280. // progresscb(progress);
  281. // pb.render({ completed: currentLength, total: totalLength, time: time+=100 });
  282. // }
  283. //
  284. // });
  285. request.get(options).pipe(stream);
  286. // } else {
  287. // gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+res.statusCode);
  288. // }
  289. // })
  290. // req.on('error', (e) => {
  291. // gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), e);
  292. // });
  293. // req.end();
  294. // }
  295. //});
  296. }
  297. var commonsLength = 0;
  298. var jvmLenght = 0;
  299. var totalLength = 0;
  300. var currentLength = 0;
  301. var commonsCurrentLength = 0;
  302. var jvmCurrentLength = 0;
  303. var pb = null;
  304. function initProgress() {
  305. if (commonsLength && jvmLenght) {
  306. totalLength = +commonsLength + jvmLenght;
  307. var t = (totalLength / 1024 / 1024).toFixed(2);
  308. pb = new ProgressBar("total: " + t + "M", 50);
  309. }
  310. }
  311. function download_commons_and_jvm(cb) {
  312. gutil.log(gutil.colors.green("begin download commons and jvm"));
  313. console.log(`---------------------------------------------------------------------
  314. . Start to download the dependencies needed for compilation ...
  315. ---------------------------------------------------------------------`);
  316. var downloader = new Promise((resolve, reject) => {
  317. var commonLoaded = false;
  318. var jvmLoaded = false;
  319. downloadFile(
  320. commonUrl,
  321. "commons_git.tar.gz",
  322. (length) => {
  323. commonsLength = +length;
  324. initProgress();
  325. },
  326. (progress) => {
  327. commonsCurrentLength = progress.transferred;
  328. currentLength = +commonsCurrentLength + jvmCurrentLength;
  329. },
  330. () => {
  331. commonLoaded = true;
  332. if (jvmLoaded && commonLoaded) resolve();
  333. }
  334. );
  335. // var jvmName = jvmUrl.substr(jvmUrl.lastIndexOf("/"+1, jvmUrl.length));
  336. // console.log(jvmName);
  337. // console.log(jvmUrl);
  338. downloadFile(
  339. jvmUrl,
  340. "jvm_git.tar.gz",
  341. (length) => {
  342. jvmLenght = +length;
  343. initProgress();
  344. },
  345. (progress) => {
  346. jvmCurrentLength = progress.transferred;
  347. currentLength = +commonsCurrentLength + jvmCurrentLength;
  348. },
  349. () => {
  350. jvmLoaded = true;
  351. if (jvmLoaded && commonLoaded) resolve();
  352. }
  353. );
  354. });
  355. downloader.then(() => {
  356. //console.log();
  357. gutil.log(gutil.colors.green("download commons and jvm completed"));
  358. cb();
  359. });
  360. }
  361. function decompress_commons_and_jvm(cb) {
  362. console.log(`---------------------------------------------------------------------
  363. . Start to decompress the dependencies needed for compilation ...
  364. ---------------------------------------------------------------------`);
  365. gutil.log(gutil.colors.green("begin decompress commons and jvm"));
  366. var count = 0;
  367. var decompressor = new Promise((resolve, reject) => {
  368. var commonUnziped = false;
  369. var jvmUnziped = false;
  370. targz.decompress(
  371. {
  372. src: "o2server/commons_git.tar.gz",
  373. dest: "o2server",
  374. tar: {
  375. map: function (header) {
  376. count++;
  377. var d = new Date();
  378. slog(
  379. "[" +
  380. dateFormat(d, "HH:MM:ss") +
  381. "] " +
  382. count +
  383. " " +
  384. header.name +
  385. " ..."
  386. );
  387. //gutil.log(gutil.colors.cyan(header.name), gutil.colors.yellow("..."));
  388. },
  389. },
  390. },
  391. function (err) {
  392. if (err) {
  393. gutil.log(
  394. gutil.colors.red("decompress error"),
  395. ":",
  396. gutil.colors.red("common.tar.gz "),
  397. err
  398. );
  399. } else {
  400. commonUnziped = true;
  401. if (jvmUnziped && commonUnziped) resolve();
  402. }
  403. }
  404. );
  405. targz.decompress(
  406. {
  407. src: "o2server/jvm_git.tar.gz",
  408. dest: "o2server",
  409. tar: {
  410. map: function (header) {
  411. count++;
  412. var d = new Date();
  413. slog(
  414. "[" +
  415. dateFormat(d, "HH:MM:ss") +
  416. "] " +
  417. count +
  418. " " +
  419. header.name +
  420. " ..."
  421. );
  422. //slog(count +" "+ header.name+" ...");
  423. //gutil.log(gutil.colors.cyan(header.name), gutil.colors.yellow("..."));
  424. },
  425. },
  426. },
  427. function (err) {
  428. if (err) {
  429. gutil.log(
  430. gutil.colors.red("decompress error"),
  431. ":",
  432. gutil.colors.red("jvm.tar.gz "),
  433. err
  434. );
  435. } else {
  436. jvmUnziped = true;
  437. if (jvmUnziped && commonUnziped) resolve();
  438. }
  439. }
  440. );
  441. });
  442. decompressor.then(() => {
  443. gutil.log(
  444. gutil.colors.green(
  445. "decompress commons and jvm completed. " + count + " files"
  446. )
  447. );
  448. cb();
  449. });
  450. }
  451. function move_commons() {
  452. console.log(`---------------------------------------------------------------------
  453. . move commons files to o2server/commons ...
  454. ---------------------------------------------------------------------`);
  455. return gulp
  456. .src("o2server/evn-o2server-commons-master-commons/commons/**/*")
  457. .pipe(gulp.dest("o2server/commons/"));
  458. }
  459. function move_jvm() {
  460. console.log(`---------------------------------------------------------------------
  461. . move jvm files to o2server/jvm ...
  462. ---------------------------------------------------------------------`);
  463. var path;
  464. if (options.ev == "all") {
  465. path = "o2server/evn-o2server-jvm-master-jvm/jvm/**/*";
  466. } else {
  467. path =
  468. "o2server/evn-o2server-jvm-master-jvm-" + options.ev + "/jvm/**/*";
  469. }
  470. return gulp.src(path).pipe(gulp.dest("o2server/jvm/"));
  471. }
  472. function clear_commons_git(cb) {
  473. var dest = [
  474. "o2server/evn-o2server-commons-master-commons/",
  475. "o2server/commons_git.tar.gz",
  476. ];
  477. del(dest, { force: true });
  478. cb();
  479. }
  480. function clear_jvm_git(cb) {
  481. var path;
  482. if (options.ev == "all") {
  483. path = "o2server/evn-o2server-jvm-master-jvm/";
  484. } else {
  485. path = "o2server/evn-o2server-jvm-master-jvm-" + options.ev + "/";
  486. }
  487. del([path, "o2server/jvm_git.tar.gz"], { force: true });
  488. cb();
  489. }
  490. function build_web_minimize(cb) {
  491. console.log(`---------------------------------------------------------------------
  492. . Start compiling the web ...
  493. ---------------------------------------------------------------------`);
  494. var dest = "target/o2server/servers/webServer/";
  495. var src_min = [
  496. "o2web/source/**/*.js",
  497. "!o2web/source/o2_core/o2.js",
  498. "!**/*.spec.js",
  499. "!**/test/**",
  500. "!o2web/source/o2_lib/**/*",
  501. ];
  502. var entries = fg.sync(src_min, { dot: false });
  503. var size = entries.length;
  504. var pb = new ProgressBar("", 50);
  505. var doCount = 0;
  506. var stream = gulp.src(src_min);
  507. stream.on("end", () => {
  508. console.log();
  509. });
  510. return stream
  511. .pipe(uglify())
  512. .pipe(rename({ extname: ".min.js" }))
  513. .pipe(gulp.dest(dest))
  514. .pipe(
  515. logger(function () {
  516. doCount++;
  517. if (doCount <= size) {
  518. pb.render({
  519. completed: doCount,
  520. total: size,
  521. count: doCount,
  522. });
  523. }
  524. })
  525. )
  526. .pipe(gutil.noop());
  527. }
  528. function build_web_move() {
  529. var dest = "target/o2server/servers/webServer/";
  530. var src_move = [
  531. "o2web/source/**/*",
  532. "!o2web/source/o2_core/o2.js",
  533. "!**/*.spec.js",
  534. "!**/test/**",
  535. ];
  536. var entries = fg.sync(src_move, { dot: false });
  537. var size = entries.length;
  538. var pb = new ProgressBar("", 50);
  539. var doCount = 0;
  540. var stream = gulp.src(src_move);
  541. stream.on("end", () => {
  542. console.log();
  543. });
  544. return stream
  545. .pipe(gulp.dest(dest))
  546. .pipe(
  547. logger(function () {
  548. doCount++;
  549. if (doCount <= size) {
  550. pb.render({
  551. completed: doCount,
  552. total: size,
  553. count: doCount,
  554. });
  555. }
  556. })
  557. )
  558. .pipe(gutil.noop());
  559. }
  560. exports.build_web_move = build_web_move;
  561. function build_concat_o2() {
  562. var src = [
  563. "o2web/source/o2_lib/mootools/mootools-1.6.0_all.js",
  564. "o2web/source/o2_lib/mootools/plugin/mBox.js",
  565. "o2web/source/o2_core/o2.js",
  566. ];
  567. var dest = "target/o2server/servers/webServer/o2_core/";
  568. return (
  569. gulp
  570. .src(src)
  571. .pipe(sourceMap.init())
  572. .pipe(concat("o2.js"))
  573. .pipe(gulp.dest(dest))
  574. .pipe(concat("o2.min.js"))
  575. .pipe(uglify())
  576. //.pipe(rename({ extname: '.min.js' }))
  577. .pipe(sourceMap.write(""))
  578. .pipe(gulp.dest(dest))
  579. );
  580. }
  581. function build_concat_base() {
  582. var src = [
  583. "o2web/source/x_desktop/js/base.js",
  584. "o2web/source/x_desktop/js/base_loader.js",
  585. ];
  586. var dest = "target/o2server/servers/webServer/x_desktop/js/";
  587. return (
  588. gulp
  589. .src(src)
  590. .pipe(sourceMap.init())
  591. //.pipe(concat('o2.js'))
  592. .pipe(gulp.dest(dest))
  593. .pipe(concat("base.min.js"))
  594. .pipe(uglify())
  595. //.pipe(rename({ extname: '.min.js' }))
  596. .pipe(sourceMap.write(""))
  597. .pipe(gulp.dest(dest))
  598. );
  599. }
  600. function build_concat_desktop() {
  601. let path = "o2_core";
  602. var src = [
  603. "o2web/source/" + path + "/o2/widget/Common.js",
  604. "o2web/source/" + path + "/o2/widget/Dialog.js",
  605. "o2web/source/" + path + "/o2/widget/UUID.js",
  606. "o2web/source/" + path + "/o2/xDesktop/Common.js",
  607. "o2web/source/" + path + "/o2/xDesktop/Actions/RestActions.js",
  608. "o2web/source/" + path + "/o2/xAction/RestActions.js",
  609. "o2web/source/" + path + "/o2/xDesktop/Access.js",
  610. "o2web/source/" + path + "/o2/xDesktop/Dialog.js",
  611. "o2web/source/" + path + "/o2/xDesktop/Menu.js",
  612. "o2web/source/" + path + "/o2/xDesktop/UserData.js",
  613. "o2web/source/x_component_Template/MPopupForm.js",
  614. "o2web/source/" + path + "/o2/xDesktop/Authentication.js",
  615. "o2web/source/" + path + "/o2/xDesktop/Dialog.js",
  616. "o2web/source/" + path + "/o2/xDesktop/Window.js",
  617. "o2web/source/x_component_Common/Main.js",
  618. ];
  619. var dest = "target/o2server/servers/webServer/o2_core/o2/xDesktop/";
  620. return (
  621. gulp
  622. .src(src)
  623. .pipe(sourceMap.init())
  624. .pipe(concat("$all.js"))
  625. .pipe(gulp.dest(dest))
  626. .pipe(concat("$all.min.js"))
  627. .pipe(uglify())
  628. //.pipe(rename({ extname: '.min.js' }))
  629. .pipe(sourceMap.write(""))
  630. .pipe(gulp.dest(dest))
  631. );
  632. }
  633. function build_concat_xform() {
  634. let path = "x_component_process_Xform";
  635. var src = [
  636. "o2web/source/o2_core/o2/widget/AttachmentController.js",
  637. "o2web/source/o2_core/o2/xScript/Macro.js",
  638. "o2web/source/o2_core/o2/widget/Tab.js",
  639. "o2web/source/o2_core/o2/widget/O2Identity.js",
  640. "o2web/source/" + path + "/Form.js",
  641. "o2web/source/" + path + "/$Module.js",
  642. "o2web/source/" + path + "/$Input.js",
  643. "o2web/source/" + path + "/Div.js",
  644. "o2web/source/" + path + "/Combox.js",
  645. "o2web/source/" + path + "/DatagridMobile.js",
  646. "o2web/source/" + path + "/DatagridPC.js",
  647. "o2web/source/" + path + "/Textfield.js",
  648. "o2web/source/" + path + "/Personfield.js",
  649. "o2web/source/" + path + "/Button.js",
  650. "o2web/source/" + path + "/ViewSelector.js",
  651. "o2web/source/" + path + "/*.js",
  652. "o2web/source/x_component_process_Work/Processor.js",
  653. "!o2web/source/" + path + "/Office.js",
  654. ];
  655. var dest = "target/o2server/servers/webServer/" + path + "/";
  656. return (
  657. gulp
  658. .src(src)
  659. .pipe(sourceMap.init())
  660. .pipe(concat("$all.js"))
  661. .pipe(gulp.dest(dest))
  662. .pipe(concat("$all.min.js"))
  663. .pipe(uglify())
  664. //.pipe(rename({ extname: '.min.js' }))
  665. .pipe(sourceMap.write(""))
  666. .pipe(gulp.dest(dest))
  667. );
  668. }
  669. function build_concat_cms_xform() {
  670. let processPath = "x_component_process_Xform";
  671. let path = "x_component_cms_Xform";
  672. var src = [
  673. "o2web/source/o2_core/o2/widget/AttachmentController.js",
  674. // 'source/o2_core/o2/xScript/CMSEnvironment.js',
  675. "o2web/source/o2_core/o2/xScript/CMSMacro.js",
  676. "o2web/source/o2_core/o2/widget/Tab.js",
  677. "o2web/source/o2_core/o2/widget/O2Identity.js",
  678. "o2web/source/" + processPath + "/Form.js",
  679. "o2web/source/" + processPath + "/$Module.js",
  680. "o2web/source/" + processPath + "/$Input.js",
  681. "o2web/source/" + processPath + "/Div.js",
  682. //'source/' + processPath + '/Combox.js',
  683. "o2web/source/" + processPath + "/DatagridMobile.js",
  684. "o2web/source/" + processPath + "/DatagridPC.js",
  685. "o2web/source/" + processPath + "/Textfield.js",
  686. //'source/' + processPath + '/Personfield.js',
  687. "o2web/source/" + processPath + "/Button.js",
  688. //'source/' + processPath + '/ViewSelector.js',
  689. "o2web/source/" + processPath + "/Org.js",
  690. // 'source/' + processPath + '/*.js',
  691. "o2web/source/" + processPath + "/Actionbar.js",
  692. //'source/' + processPath + '/Address.js',
  693. "o2web/source/" + processPath + "/Attachment.js",
  694. "o2web/source/" + processPath + "/Calendar.js",
  695. "o2web/source/" + processPath + "/Checkbox.js",
  696. "o2web/source/" + processPath + "/Datagrid.js",
  697. "o2web/source/" + processPath + "/Htmleditor.js",
  698. //'source/' + processPath + '/Iframe.js',
  699. "o2web/source/" + processPath + "/Label.js",
  700. "o2web/source/" + processPath + "/Number.js",
  701. "o2web/source/" + processPath + "/Common.js",
  702. "o2web/source/" + processPath + "/Image.js",
  703. "o2web/source/" + processPath + "/ImageClipper.js",
  704. "o2web/source/" + processPath + "/Html.js",
  705. "o2web/source/" + processPath + "/Radio.js",
  706. "o2web/source/" + processPath + "/Select.js",
  707. //'source/' + processPath + '/Stat.js',
  708. //'source/' + processPath + '/Statement.js',
  709. //'source/' + processPath + '/StatementSelector.js',
  710. //'source/' + processPath + '/Subform.js',
  711. "o2web/source/" + processPath + "/Tab.js",
  712. "o2web/source/" + processPath + "/Table.js",
  713. "o2web/source/" + processPath + "/Textarea.js",
  714. //'source/' + processPath + '/Tree.js',
  715. //'source/' + processPath + '/View.js',
  716. // 'source/x_component_process_Work/Processor.js',
  717. // '!source/' + processPath + '/Office.js'
  718. "o2web/source/o2_core/o2/widget/SimpleToolbar.js",
  719. "o2web/source/" + path + "/ModuleImplements.js",
  720. "o2web/source/" + path + "/Package.js",
  721. "o2web/source/" + path + "/Form.js",
  722. //'source/' + path + '/widget/Comment.js',
  723. "o2web/source/" + path + "/widget/Log.js",
  724. "o2web/source/" + path + "/Org.js",
  725. "o2web/source/" + path + "/Author.js",
  726. "o2web/source/" + path + "/Reader.js",
  727. "o2web/source/" + path + "/Textfield.js",
  728. "o2web/source/" + path + "/Actionbar.js",
  729. "o2web/source/" + path + "/Attachment.js",
  730. "o2web/source/" + path + "/Button.js",
  731. "o2web/source/" + path + "/Calendar.js",
  732. "o2web/source/" + path + "/Checkbox.js",
  733. "o2web/source/" + path + "/Datagrid.js",
  734. "o2web/source/" + path + "/Htmleditor.js",
  735. "o2web/source/" + path + "/ImageClipper.js",
  736. "o2web/source/" + path + "/Label.js",
  737. "o2web/source/" + path + "/Number.js",
  738. "o2web/source/" + path + "/Radio.js",
  739. "o2web/source/" + path + "/Select.js",
  740. "o2web/source/" + path + "/Tab.js",
  741. "o2web/source/" + path + "/Table.js",
  742. "o2web/source/" + path + "/Textarea.js",
  743. //'source/' + path + '/Personfield.js',
  744. //'source/' + path + '/Readerfield.js',
  745. //'source/' + path + '/Authorfield.js',
  746. //'source/' + path + '/Orgfield.js',
  747. // 'source/' + path + '/*.js',
  748. // '!source/' + path + '/Office.js'
  749. ];
  750. var dest = "target/o2server/servers/webServer/" + path + "/";
  751. return (
  752. gulp
  753. .src(src)
  754. .pipe(sourceMap.init())
  755. .pipe(concat("$all.js"))
  756. .pipe(gulp.dest(dest))
  757. .pipe(concat("$all.min.js"))
  758. .pipe(uglify())
  759. //.pipe(rename({ extname: '.min.js' }))
  760. .pipe(sourceMap.write(""))
  761. .pipe(gulp.dest(dest))
  762. );
  763. }
  764. function build_bundle() {
  765. let path = "o2_core";
  766. var src = [
  767. "o2web/source/o2_lib/mootools/mootools-1.6.0_all.js",
  768. "o2web/source/o2_lib/mootools/plugin/mBox.js",
  769. "o2web/source/o2_core/o2.js",
  770. "o2web/source/x_desktop/js/base.js",
  771. "o2web/source/x_desktop/js/base_loader.js",
  772. "o2web/source/o2_core/o2/framework.js",
  773. ];
  774. var dest = "target/o2server/servers/webServer/" + path + "/";
  775. return (
  776. gulp
  777. .src(src)
  778. .pipe(sourceMap.init())
  779. .pipe(concat("bundle.js"))
  780. .pipe(gulp.dest(dest))
  781. .pipe(concat("bundle.min.js"))
  782. .pipe(uglify())
  783. //.pipe(rename({ extname: '.min.js' }))
  784. .pipe(sourceMap.write(""))
  785. .pipe(gulp.dest(dest))
  786. );
  787. }
  788. function concat_Actions() {
  789. return through2.obj(function (file, enc, cb) {
  790. if (file.isNull()) {
  791. this.push(file);
  792. return cb();
  793. }
  794. if (file.isStream()) {
  795. this.emit(
  796. "error",
  797. new gutil.PluginError(PLUGIN_NAME, "Streaming not supported")
  798. );
  799. return cb();
  800. }
  801. var content = file.contents.toString();
  802. var o = path.parse(file.path);
  803. var name = o.name;
  804. content = "var actionJson = " + content;
  805. content =
  806. content +
  807. '\nif (!o2.xAction.RestActions.Action["' +
  808. name +
  809. '"]) o2.xAction.RestActions.Action["' +
  810. name +
  811. '"] = new Class({Extends: o2.xAction.RestActions.Action});';
  812. content =
  813. content +
  814. '\no2.Actions.actions["' +
  815. name +
  816. '"] = new o2.xAction.RestActions.Action["' +
  817. name +
  818. '"]("' +
  819. name +
  820. '", actionJson);';
  821. file.contents = new Buffer.from(content);
  822. this.push(file);
  823. cb();
  824. });
  825. }
  826. function concat_Style() {
  827. return through2.obj(function (file, enc, cb) {
  828. if (file.isNull()) {
  829. this.push(file);
  830. return cb();
  831. }
  832. if (file.isStream()) {
  833. this.emit(
  834. "error",
  835. new gutil.PluginError(PLUGIN_NAME, "Streaming not supported")
  836. );
  837. return cb();
  838. }
  839. var content = file.contents.toString();
  840. var name = file.path.replace(process.cwd(), "").replace(/\\/g, "/");
  841. name = ".." + name.substring(name.indexOf("/source") + 7);
  842. content =
  843. 'var csskey = encodeURIComponent("' +
  844. name +
  845. '");\no2.widget.css[csskey]=' +
  846. content;
  847. file.contents = new Buffer.from(content);
  848. this.push(file);
  849. cb();
  850. });
  851. }
  852. function build_concat_basework_style() {
  853. return gulp
  854. .src([
  855. "o2web/source/x_component_process_Work/$Main/default/css.wcss",
  856. "o2web/source/x_component_process_Xform/$Form/default/css.wcss",
  857. "o2web/source/o2_core/o2/widget/$Tab/mobileForm/css.wcss",
  858. "o2web/source/o2_core/o2/widget/$Menu/tab/css.wcss",
  859. "o2web/source/o2_core/o2/widget/$Tab/form/css.wcss",
  860. "o2web/source/x_component_process_Xform/$Form/default/doc.wcss",
  861. "o2web/source/o2_core/o2/widget/$Toolbar/documentEdit/css.wcss",
  862. "o2web/source/o2_core/o2/widget/$Toolbar/documentEdit_side/css.wcss",
  863. "o2web/source/x_component_process_Xform/$Form/default/css.wcss",
  864. ])
  865. .pipe(concat_Style())
  866. .pipe(concat("js/base_work_style_temp.js"))
  867. .pipe(gulp.dest("o2web/source/x_desktop/"));
  868. }
  869. function build_concat_basework_action() {
  870. return gulp
  871. .src([
  872. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  873. "o2web/source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.json",
  874. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  875. "o2web/source/o2_core/o2/xAction/services/x_query_assemble_surface.json",
  876. "o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  877. "o2web/source/o2_core/o2/xAction/services/x_program_center.json",
  878. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.json",
  879. ])
  880. .pipe(concat_Actions())
  881. .pipe(concat("js/base_work_actions_temp.js"))
  882. .pipe(gulp.dest("o2web/source/x_desktop/"));
  883. }
  884. function build_concat_basework_clean(cb) {
  885. var dest = [
  886. "o2web/source/x_desktop/js/base_work_actions_temp.js",
  887. "o2web/source/x_desktop/js/base_work_style_temp.js",
  888. ];
  889. return del(dest, cb);
  890. }
  891. function build_concat_basework_body() {
  892. var src = [
  893. "o2web/source/x_desktop/js/base_concat_head.js",
  894. "o2web/source/o2_core/o2/lp/" + (options.lp || "zh-cn") + ".js",
  895. "o2web/source/x_desktop/js/base_work_style_temp.js",
  896. "o2web/source/o2_core/o2/widget/Common.js",
  897. "o2web/source/o2_core/o2/widget/Dialog.js",
  898. "o2web/source/o2_core/o2/widget/UUID.js",
  899. "o2web/source/o2_core/o2/widget/Menu.js",
  900. "o2web/source/o2_core/o2/widget/Toolbar.js",
  901. "o2web/source/o2_core/o2/xDesktop/Common.js",
  902. "o2web/source/o2_core/o2/xDesktop/Actions/RestActions.js",
  903. "o2web/source/o2_core/o2/xAction/RestActions.js",
  904. "o2web/source/o2_core/o2/xDesktop/Access.js",
  905. "o2web/source/o2_core/o2/xDesktop/Dialog.js",
  906. "o2web/source/o2_core/o2/xDesktop/Menu.js",
  907. "o2web/source/o2_core/o2/xDesktop/UserData.js",
  908. "o2web/source/x_component_Template/MPopupForm.js",
  909. "o2web/source/o2_core/o2/xDesktop/Authentication.js",
  910. "o2web/source/o2_core/o2/xDesktop/Dialog.js",
  911. "o2web/source/o2_core/o2/xDesktop/Window.js",
  912. "o2web/source/x_component_Common/Main.js",
  913. "o2web/source/o2_core/o2/lp/" + (options.lp || "zh-cn") + ".js",
  914. "o2web/source/x_component_process_Work/lp/" +
  915. (options.lp || "zh-cn") +
  916. ".js",
  917. "o2web/source/x_component_process_Xform/lp/" +
  918. (options.lp || "zh-cn") +
  919. ".js",
  920. "o2web/source/x_component_Selector/lp/" +
  921. (options.lp || "zh-cn") +
  922. ".js",
  923. "o2web/source/x_component_process_Work/Main.js",
  924. "o2web/source/x_component_Selector/package.js",
  925. "o2web/source/x_component_Selector/Person.js",
  926. "o2web/source/x_component_Selector/Identity.js",
  927. "o2web/source/x_component_Selector/Unit.js",
  928. "o2web/source/x_component_Selector/IdentityWidthDuty.js",
  929. "o2web/source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js",
  930. "o2web/source/x_component_Selector/UnitWithType.js",
  931. "o2web/source/o2_core/o2/xScript/Actions/UnitActions.js",
  932. "o2web/source/o2_core/o2/xScript/Actions/ScriptActions.js",
  933. "o2web/source/o2_core/o2/xScript/Actions/CMSScriptActions.js",
  934. "o2web/source/o2_core/o2/xScript/Actions/PortalScriptActions.js",
  935. "o2web/source/o2_core/o2/xScript/Environment.js",
  936. "o2web/source/x_component_Template/MTooltips.js",
  937. "o2web/source/x_component_Template/MSelector.js",
  938. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js",
  939. "o2web/source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.js",
  940. "o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.js",
  941. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.js",
  942. "o2web/source/o2_core/o2/xAction/services/x_query_assemble_surface.js",
  943. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.js",
  944. "o2web/source/x_desktop/js/base_work_actions_temp.js",
  945. "o2web/source/x_desktop/js/base.js",
  946. "o2web/source/x_desktop/js/base_loader.js",
  947. ];
  948. var dest = "target/o2server/servers/webServer/x_desktop/js/";
  949. return (
  950. gulp
  951. .src(src)
  952. .pipe(sourceMap.init())
  953. .pipe(concat("base_work.js"))
  954. .pipe(gulp.dest(dest))
  955. .pipe(concat("base_work.min.js"))
  956. .pipe(uglify())
  957. //.pipe(rename({ extname: '.min.js' }))
  958. .pipe(sourceMap.write(""))
  959. .pipe(gulp.dest(dest))
  960. );
  961. }
  962. function build_concat_baseportal_style() {
  963. return gulp
  964. .src([
  965. "o2web/source/x_component_process_Work/$Main/default/css.wcss",
  966. "o2web/source/x_component_portal_Portal/$Main/default/css.wcss",
  967. "o2web/source/x_component_process_Xform/$Form/default/css.wcss",
  968. "o2web/source/o2_core/o2/widget/$Tab/mobileForm/css.wcss",
  969. "o2web/source/o2_core/o2/widget/$Menu/tab/css.wcss",
  970. ])
  971. .pipe(concat_Style())
  972. .pipe(concat("js/base_portal_style_temp.js"))
  973. .pipe(gulp.dest("o2web/source/x_desktop/"));
  974. }
  975. function build_concat_baseportal_action() {
  976. return gulp
  977. .src([
  978. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  979. "o2web/source/o2_core/o2/xAction/services/x_portal_assemble_surface.json",
  980. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  981. "o2web/source/o2_core/o2/xAction/services/x_query_assemble_surface.json",
  982. "o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  983. "o2web/source/o2_core/o2/xAction/services/x_program_center.json",
  984. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.json",
  985. ])
  986. .pipe(concat_Actions())
  987. .pipe(concat("js/base_portal_actions_temp.js"))
  988. .pipe(gulp.dest("o2web/source/x_desktop/"));
  989. }
  990. function build_concat_baseportal_clean(cb) {
  991. var dest = [
  992. "o2web/source/x_desktop/js/base_portal_actions_temp.js",
  993. "o2web/source/x_desktop/js/base_portal_style_temp.js",
  994. ];
  995. return del(dest, cb);
  996. }
  997. function build_concat_baseportal_body() {
  998. var src = [
  999. "o2web/source/x_desktop/js/base_concat_head.js",
  1000. "o2web/source/o2_core/o2/lp/" + (options.lp || "zh-cn") + ".js",
  1001. "o2web/source/x_desktop/js/base_portal_style_temp.js",
  1002. "o2web/source/o2_core/o2/widget/Common.js",
  1003. "o2web/source/o2_core/o2/widget/Dialog.js",
  1004. "o2web/source/o2_core/o2/widget/UUID.js",
  1005. "o2web/source/o2_core/o2/widget/Menu.js",
  1006. "o2web/source/o2_core/o2/widget/Toolbar.js",
  1007. "o2web/source/o2_core/o2/xDesktop/Common.js",
  1008. "o2web/source/o2_core/o2/xDesktop/Actions/RestActions.js",
  1009. "o2web/source/o2_core/o2/xAction/RestActions.js",
  1010. "o2web/source/o2_core/o2/xDesktop/Access.js",
  1011. "o2web/source/o2_core/o2/xDesktop/Dialog.js",
  1012. "o2web/source/o2_core/o2/xDesktop/Menu.js",
  1013. "o2web/source/o2_core/o2/xDesktop/UserData.js",
  1014. "o2web/source/x_component_Template/MPopupForm.js",
  1015. "o2web/source/o2_core/o2/xDesktop/Authentication.js",
  1016. "o2web/source/o2_core/o2/xDesktop/Window.js",
  1017. "o2web/source/x_component_Common/Main.js",
  1018. "o2web/source/x_component_process_Work/lp/" +
  1019. (options.lp || "zh-cn") +
  1020. ".js",
  1021. "o2web/source/x_component_portal_Portal/lp/" +
  1022. (options.lp || "zh-cn") +
  1023. ".js",
  1024. "o2web/source/x_component_process_Xform/lp/" +
  1025. (options.lp || "zh-cn") +
  1026. ".js",
  1027. "o2web/source/x_component_Selector/lp/" +
  1028. (options.lp || "zh-cn") +
  1029. ".js",
  1030. "o2web/source/x_component_portal_Portal/Main.js",
  1031. "o2web/source/x_component_Selector/package.js",
  1032. "o2web/source/x_component_Selector/Person.js",
  1033. "o2web/source/x_component_Selector/Identity.js",
  1034. "o2web/source/x_component_Selector/Unit.js",
  1035. "o2web/source/x_component_Selector/IdentityWidthDuty.js",
  1036. "o2web/source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js",
  1037. "o2web/source/x_component_Selector/UnitWithType.js",
  1038. "o2web/source/o2_core/o2/xScript/Actions/UnitActions.js",
  1039. "o2web/source/o2_core/o2/xScript/Actions/ScriptActions.js",
  1040. "o2web/source/o2_core/o2/xScript/Actions/CMSScriptActions.js",
  1041. "o2web/source/o2_core/o2/xScript/Actions/PortalScriptActions.js",
  1042. "o2web/source/o2_core/o2/xScript/PageEnvironment.js",
  1043. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js",
  1044. "o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.js",
  1045. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.js",
  1046. "o2web/source/o2_core/o2/xAction/services/x_query_assemble_surface.js",
  1047. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.js",
  1048. "o2web/source/x_desktop/js/base_portal_actions_temp.js",
  1049. "o2web/source/x_desktop/js/base.js",
  1050. "o2web/source/x_desktop/js/base_loader.js",
  1051. ];
  1052. var dest = "target/o2server/servers/webServer/x_desktop/js/";
  1053. return (
  1054. gulp
  1055. .src(src)
  1056. .pipe(sourceMap.init())
  1057. .pipe(concat("base_portal.js"))
  1058. .pipe(gulp.dest(dest))
  1059. .pipe(concat("base_portal.min.js"))
  1060. .pipe(uglify())
  1061. //.pipe(rename({ extname: '.min.js' }))
  1062. .pipe(sourceMap.write(""))
  1063. .pipe(gulp.dest(dest))
  1064. );
  1065. }
  1066. function build_concat_basedocument_style() {
  1067. return gulp
  1068. .src([
  1069. "o2web/source/x_component_cms_Document/$Main/default/css.wcss",
  1070. "o2web/source/x_component_cms_Xform/$Form/default/css.wcss",
  1071. "o2web/source/o2_core/o2/widget/$AttachmentController/default/css.wcss",
  1072. ])
  1073. .pipe(concat_Style())
  1074. .pipe(concat("js/base_document_style_temp.js"))
  1075. .pipe(gulp.dest("o2web/source/x_desktop/"));
  1076. }
  1077. function build_concat_basedocument_action() {
  1078. return gulp
  1079. .src([
  1080. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  1081. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  1082. "o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  1083. "o2web/source/o2_core/o2/xAction/services/x_program_center.json",
  1084. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.json",
  1085. ])
  1086. .pipe(concat_Actions())
  1087. .pipe(concat("js/base_document_actions_temp.js"))
  1088. .pipe(gulp.dest("o2web/source/x_desktop/"));
  1089. }
  1090. function build_concat_basedocument_clean(cb) {
  1091. var dest = [
  1092. "o2web/source/x_desktop/js/base_document_actions_temp.js",
  1093. "o2web/source/x_desktop/js/base_document_style_temp.js",
  1094. ];
  1095. return del(dest, cb);
  1096. }
  1097. function build_concat_basedocument_body() {
  1098. var src = [
  1099. "o2web/source/x_desktop/js/base_concat_head.js",
  1100. "o2web/source/o2_core/o2/lp/" + (options.lp || "zh-cn") + ".js",
  1101. "o2web/source/x_desktop/js/base_document_style_temp.js",
  1102. "o2web/source/o2_core/o2/widget/Common.js",
  1103. "o2web/source/o2_core/o2/widget/Dialog.js",
  1104. "o2web/source/o2_core/o2/widget/UUID.js",
  1105. "o2web/source/o2_core/o2/widget/Menu.js",
  1106. "o2web/source/o2_core/o2/widget/Mask.js",
  1107. "o2web/source/o2_core/o2/xDesktop/Common.js",
  1108. "o2web/source/o2_core/o2/xDesktop/Actions/RestActions.js",
  1109. "o2web/source/o2_core/o2/xAction/RestActions.js",
  1110. "o2web/source/o2_core/o2/xDesktop/Access.js",
  1111. "o2web/source/o2_core/o2/xDesktop/Dialog.js",
  1112. "o2web/source/o2_core/o2/xDesktop/Menu.js",
  1113. "o2web/source/o2_core/o2/xDesktop/UserData.js",
  1114. "o2web/source/x_component_Template/MPopupForm.js",
  1115. "o2web/source/o2_core/o2/xDesktop/Authentication.js",
  1116. "o2web/source/o2_core/o2/xDesktop/Window.js",
  1117. "o2web/source/x_component_Common/Main.js",
  1118. "o2web/source/x_component_cms_Document/lp/" +
  1119. (options.lp || "zh-cn") +
  1120. ".js",
  1121. "o2web/source/x_component_process_Xform/lp/" +
  1122. (options.lp || "zh-cn") +
  1123. ".js",
  1124. "o2web/source/x_component_Selector/lp/" +
  1125. (options.lp || "zh-cn") +
  1126. ".js",
  1127. "o2web/source/x_component_cms_Xform/lp/" +
  1128. (options.lp || "zh-cn") +
  1129. ".js",
  1130. "o2web/source/x_component_cms_Document/Main.js",
  1131. "o2web/source/x_component_Selector/package.js",
  1132. "o2web/source/o2_core/o2/xScript/Actions/UnitActions.js",
  1133. "o2web/source/o2_core/o2/xScript/Actions/CMSScriptActions.js",
  1134. "o2web/source/o2_core/o2/xScript/CMSEnvironment.js",
  1135. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js",
  1136. "o2web/source/o2_core/o2/xAction/services/x_cms_assemble_control.js",
  1137. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_control.js",
  1138. "o2web/source/o2_core/o2/xAction/services/x_organization_assemble_personal.js",
  1139. "o2web/source/x_desktop/js/base_document_actions_temp.js",
  1140. "o2web/source/x_desktop/js/base.js",
  1141. "o2web/source/x_desktop/js/base_loader.js",
  1142. ];
  1143. var dest = "target/o2server/servers/webServer/x_desktop/js/";
  1144. return (
  1145. gulp
  1146. .src(src)
  1147. .pipe(sourceMap.init())
  1148. .pipe(concat("base_document.js"))
  1149. .pipe(gulp.dest(dest))
  1150. .pipe(concat("base_document.min.js"))
  1151. .pipe(uglify())
  1152. //.pipe(rename({ extname: '.min.js' }))
  1153. .pipe(sourceMap.write(""))
  1154. .pipe(gulp.dest(dest))
  1155. );
  1156. }
  1157. exports.build_concat = gulp.parallel(
  1158. build_concat_o2,
  1159. build_concat_base,
  1160. build_concat_desktop,
  1161. build_concat_xform,
  1162. build_concat_cms_xform,
  1163. build_bundle,
  1164. gulp.series(
  1165. build_concat_basework_style,
  1166. build_concat_basework_action,
  1167. build_concat_basework_body,
  1168. build_concat_basework_clean
  1169. ),
  1170. gulp.series(
  1171. build_concat_baseportal_style,
  1172. build_concat_baseportal_action,
  1173. build_concat_baseportal_body,
  1174. build_concat_baseportal_clean
  1175. ),
  1176. gulp.series(
  1177. build_concat_basedocument_style,
  1178. build_concat_basedocument_action,
  1179. build_concat_basedocument_body,
  1180. build_concat_basedocument_clean
  1181. )
  1182. );
  1183. function getGitV() {
  1184. var tagPromise = new Promise(function (s, f) {
  1185. git.exec({ args: "describe --tag" }, function (err, stdout) {
  1186. if (err) {
  1187. f(err);
  1188. }
  1189. var v = stdout.substring(0, stdout.indexOf("-"));
  1190. s(v);
  1191. });
  1192. });
  1193. var revPromise = new Promise(function (s, f) {
  1194. git.exec({ args: "rev-parse --short HEAD" }, function (err, hash) {
  1195. if (err) {
  1196. f(err);
  1197. }
  1198. s(hash.trim());
  1199. });
  1200. });
  1201. return Promise.all([tagPromise, revPromise]);
  1202. }
  1203. function build_web_v_html() {
  1204. var src = "o2web/source/x_desktop/*.html";
  1205. var dest = "target/o2server/servers/webServer/x_desktop/";
  1206. return getGitV().then(
  1207. function (arr) {
  1208. return gulp
  1209. .src(src)
  1210. .pipe(assetRev({ verConnecter: arr[0], md5: arr[1] }))
  1211. .pipe(gulp.dest(dest))
  1212. .pipe(gutil.noop());
  1213. },
  1214. function () {
  1215. return gulp
  1216. .src(src)
  1217. .pipe(assetRev())
  1218. .pipe(gulp.dest(dest))
  1219. .pipe(gutil.noop());
  1220. }
  1221. );
  1222. }
  1223. function build_web_api() {
  1224. var src = "o2web/api/**/*";
  1225. var dest = "target/o2server/servers/webServer/api/";
  1226. return gulp.src(src).pipe(gulp.dest(dest));
  1227. }
  1228. function build_doc() {
  1229. return getGitV().then(
  1230. function (arr) {
  1231. return shell.task(
  1232. "jsdoc -c o2web/jsdoc.conf.json -q version=" +
  1233. arr[0] +
  1234. "-" +
  1235. arr[1] +
  1236. ""
  1237. )();
  1238. },
  1239. function () {
  1240. return shell.task("jsdoc -c o2web/jsdoc.conf.json -q version=")();
  1241. }
  1242. );
  1243. }
  1244. exports.build_api = gulp.series(build_doc, build_web_api);
  1245. function build_web_v_o2() {
  1246. var src = [
  1247. "target/o2server/servers/webServer/o2_core/o2.js",
  1248. "target/o2server/servers/webServer/o2_core/o2.min.js",
  1249. ];
  1250. var dest = "target/o2server/servers/webServer/o2_core/";
  1251. return getGitV().then(
  1252. function (arr) {
  1253. return (
  1254. gulp
  1255. .src(src)
  1256. .pipe(
  1257. assetRev({
  1258. verConnecter: arr[0],
  1259. md5: arr[1],
  1260. replace: true,
  1261. })
  1262. )
  1263. //.pipe(gulp.dest(dest))
  1264. // .pipe(uglify())
  1265. // .pipe(rename({ extname: '.min.js' }))
  1266. // .pipe(gulp.dest(dest))
  1267. .pipe(gutil.noop())
  1268. );
  1269. },
  1270. function () {
  1271. return gulp.src(src).pipe(assetRev()).pipe(gutil.noop());
  1272. }
  1273. );
  1274. }
  1275. function clear_build(cb) {
  1276. console.log(`---------------------------------------------------------------------
  1277. . clear old build ...
  1278. ---------------------------------------------------------------------`);
  1279. var dest = "target";
  1280. del(dest, { force: true });
  1281. cb();
  1282. }
  1283. function clear_deploy(cb) {
  1284. console.log(`---------------------------------------------------------------------
  1285. . clear old deploy ...
  1286. ---------------------------------------------------------------------`);
  1287. var dest = [
  1288. "target/o2server/store/",
  1289. "target/o2server/commons/",
  1290. "target/o2server/jvm/",
  1291. "target/o2server/configSample/",
  1292. "target/o2server/localSample/",
  1293. "target/o2server/servers/",
  1294. ];
  1295. dest = dest.concat([
  1296. "target/o2server/*.sh",
  1297. "target/o2server/*.jar",
  1298. "target/o2server/*.html",
  1299. "target/o2server/*.bat",
  1300. "target/o2server/version.o2",
  1301. ]);
  1302. del(dest, { force: true });
  1303. cb();
  1304. }
  1305. exports.clear_build = clear_build;
  1306. exports.clear_deploy = clear_deploy;
  1307. function deploy_server() {
  1308. console.log(`---------------------------------------------------------------------
  1309. . deploy to target ...
  1310. ---------------------------------------------------------------------`);
  1311. var source = [
  1312. "o2server/*store/**/*",
  1313. "o2server/*commons/**/*",
  1314. "o2server/*jvm/**/*",
  1315. "o2server/*configSample/**/*",
  1316. "o2server/*localSample/**/*",
  1317. ];
  1318. source = source.concat(scriptSource);
  1319. console.log(source);
  1320. var dest = "target/o2server/";
  1321. var entries = fg.sync(source, { dot: false });
  1322. var size = entries.length;
  1323. var pb = new ProgressBar("", 50);
  1324. var doCount = 0;
  1325. var stream = gulp.src(source);
  1326. stream.on("end", () => {
  1327. console.log();
  1328. });
  1329. return stream.pipe(gulp.dest(dest)).pipe(
  1330. logger(function () {
  1331. doCount++;
  1332. if (doCount <= size) {
  1333. pb.render({ completed: doCount, total: size, count: doCount });
  1334. }
  1335. })
  1336. );
  1337. }
  1338. exports.preperation = gulp.series(
  1339. download_commons_and_jvm,
  1340. decompress_commons_and_jvm,
  1341. move_commons,
  1342. move_jvm,
  1343. clear_commons_git,
  1344. clear_jvm_git
  1345. );
  1346. var shell = require("gulp-shell");
  1347. const { dir } = require("console");
  1348. exports.build_server = function () {
  1349. console.log(`---------------------------------------------------------------------
  1350. . Start compiling the server ...
  1351. ---------------------------------------------------------------------`);
  1352. return shell.task("npm run build_server_script")();
  1353. };
  1354. function chmod_jvm() {
  1355. return shell.task("chmod 777 -R target/o2server/jvm")();
  1356. }
  1357. function chmod_commons() {
  1358. return shell.task("chmod 777 -R target/o2server/commons")();
  1359. }
  1360. function chmod_sh() {
  1361. return shell.task("chmod 777 target/o2server/*.sh")();
  1362. }
  1363. function chmod_servers() {
  1364. return shell.task("chmod 777 -R target/o2server/servers")();
  1365. }
  1366. exports.build_web = gulp.series(
  1367. build_web_minimize,
  1368. build_web_move,
  1369. gulp.parallel(
  1370. build_concat_o2,
  1371. build_concat_base,
  1372. build_concat_desktop,
  1373. build_concat_xform,
  1374. build_concat_cms_xform,
  1375. gulp.series(
  1376. build_concat_basework_style,
  1377. build_concat_basework_action,
  1378. build_concat_basework_body,
  1379. build_concat_basework_clean
  1380. ),
  1381. gulp.series(
  1382. build_concat_baseportal_style,
  1383. build_concat_baseportal_action,
  1384. build_concat_baseportal_body,
  1385. build_concat_baseportal_clean
  1386. ),
  1387. gulp.series(
  1388. build_concat_basedocument_style,
  1389. build_concat_basedocument_action,
  1390. build_concat_basedocument_body,
  1391. build_concat_basedocument_clean
  1392. ),
  1393. build_bundle
  1394. ),
  1395. build_web_v_html,
  1396. build_web_v_o2,
  1397. gulp.series(build_doc, build_web_api)
  1398. );
  1399. if (os.platform().indexOf("win") == -1) {
  1400. exports.deploy = gulp.series(
  1401. deploy_server,
  1402. chmod_jvm,
  1403. chmod_commons,
  1404. chmod_sh,
  1405. chmod_servers
  1406. );
  1407. } else {
  1408. exports.deploy = gulp.series(deploy_server);
  1409. }
  1410. function make_def_config(cb) {
  1411. let configDir = path.resolve(__dirname, "target", "o2server", "config");
  1412. if (!fs.existsSync(configDir)) {
  1413. fs.mkdirSync(configDir);
  1414. }
  1415. let serverConfig = require("./serverConfig.json");
  1416. let nodeConfig = JSON.parse(
  1417. fs.readFileSync(
  1418. path.resolve(
  1419. __dirname,
  1420. "target",
  1421. "o2server",
  1422. "configSample",
  1423. "node_127.0.0.1.json"
  1424. )
  1425. )
  1426. );
  1427. nodeConfig.data.enable = false;
  1428. nodeConfig.web.port = serverConfig.port;
  1429. fs.writeFileSync(
  1430. path.resolve(
  1431. __dirname,
  1432. "target",
  1433. "o2server",
  1434. "config",
  1435. "node_127.0.0.1.json"
  1436. ),
  1437. JSON.stringify(nodeConfig, null, 4)
  1438. );
  1439. let externalDataSources = JSON.parse(
  1440. fs.readFileSync(
  1441. path.resolve(
  1442. __dirname,
  1443. "target",
  1444. "o2server",
  1445. "configSample",
  1446. "externalDataSources.json"
  1447. )
  1448. )
  1449. );
  1450. externalDataSources.url = serverConfig.dataSource.url;
  1451. externalDataSources.username = serverConfig.dataSource.username;
  1452. externalDataSources.password = serverConfig.dataSource.password;
  1453. fs.writeFileSync(
  1454. path.resolve(
  1455. __dirname,
  1456. "target",
  1457. "o2server",
  1458. "config",
  1459. "externalDataSources.json"
  1460. ),
  1461. JSON.stringify(externalDataSources, null, 4)
  1462. );
  1463. cb();
  1464. }
  1465. exports.make_def_config = gulp.series(make_def_config);