gulpfile.js 49 KB

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