gulpfile.js 49 KB

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