gulpfile.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. var gulp = require('gulp'),
  2. //var deleted = require('gulp-deleted');
  3. del = require('del'),
  4. //uglify = require('gulp-tm-uglify'),
  5. uglify = require('gulp-uglify-es').default,
  6. rename = require('gulp-rename'),
  7. changed = require('gulp-changed'),
  8. gulpif = require('gulp-if'),
  9. minimist = require('minimist'),
  10. ftp = require('gulp-ftp'),
  11. sftp = require('gulp-sftp-up4'),
  12. JSFtp = require('jsftp'),
  13. gutil = require('gulp-util'),
  14. fs = require("fs");
  15. concat = require('gulp-concat');
  16. //let uglify = require('gulp-uglify-es').default;
  17. var through2 = require('through2');
  18. var path = require('path');
  19. var sourceMap = require('gulp-sourcemaps');
  20. var assetRev = require('gulp-tm-asset-rev');
  21. var apps = require('./gulpapps.js');
  22. var ftpconfig = require('./gulpconfig.js');
  23. var o_options = minimist(process.argv.slice(2), {//upload: local ftp or sftp
  24. string: ["ev", "upload", "location", "host", "user", "pass", "port", "remotePath", "dest", "src", "lp"]
  25. });
  26. function getEvOptions(ev){
  27. options.ev = ev;
  28. return (ftpconfig[ev]) || {
  29. 'location': '',
  30. 'host': '',
  31. 'user': '',
  32. 'pass': '',
  33. "port": null,
  34. "remotePath": "",
  35. "dest": "dest",
  36. "upload": ""
  37. }
  38. }
  39. function setOptions(op1, op2){
  40. if (!op2) op2 = {};
  41. options.upload = op1.upload || op2.upload || "";
  42. options.location = op1.location || op2.location || "";
  43. options.host = op1.host || op2.host || "";
  44. options.user = op1.user || op2.user || "";
  45. options.pass = op1.pass || op2.pass || "";
  46. options.port = op1.port || op2.port || "";
  47. options.remotePath = op1.remotePath || op2.remotePath || "";
  48. options.dest = op1.dest || op2.dest || "dest";
  49. options.lp = op1.lp || op2.lp || "zh-cn";
  50. }
  51. var options = {};
  52. setOptions(o_options, getEvOptions(o_options.ev));
  53. var appTasks = [];
  54. function createDefaultTask(path, isMin, thisOptions) {
  55. gulp.task(path, function (cb) {
  56. //var srcFile = 'source/' + path + '/**/*';
  57. var option = thisOptions || options;
  58. var src;
  59. var dest = option.dest+'/' + path + '/';
  60. let ev = option.ev
  61. var evList = Object.keys(ftpconfig).map((i)=>{ return (i==ev) ? "*"+i : i; });
  62. if (isMin){
  63. var src_min = ['source/' + path + '/**/*.js', '!**/*.spec.js', '!**/test/**'];
  64. var src_move = ['source/' + path + '/**/*', '!**/*.spec.js', '!**/test/**'];
  65. gutil.log("Move-Uglify", ":", gutil.colors.green(gutil.colors.blue(path), gutil.colors.white('->'), dest));
  66. return gulp.src(src_min)
  67. .pipe(changed(dest))
  68. .pipe(uglify())
  69. .pipe(rename({ extname: '.min.js' }))
  70. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  71. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  72. host: option.host,
  73. user: option.user || 'anonymous',
  74. pass: option.pass || '@anonymous',
  75. port: option.port || 21,
  76. remotePath: (option.remotePath || '/') + path
  77. })))
  78. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  79. host: option.host,
  80. user: option.user || 'anonymous',
  81. pass: option.pass || null,
  82. port: option.port || 22,
  83. remotePath: (option.remotePath || '/') + path
  84. })))
  85. .pipe(gulpif((option.ev == "dev" || option.ev == "pro") ,gulp.dest(dest)))
  86. .pipe(gulp.src(src_move))
  87. .pipe(changed(dest))
  88. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  89. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  90. host: option.host,
  91. user: option.user || 'anonymous',
  92. pass: option.pass || '@anonymous',
  93. port: option.port || 21,
  94. remotePath: (option.remotePath || '/') + path
  95. })))
  96. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  97. host: option.host,
  98. user: option.user || 'anonymous',
  99. pass: option.pass || null,
  100. port: option.port || 22,
  101. remotePath: (option.remotePath || '/') + path
  102. })))
  103. .pipe(gulp.dest(dest))
  104. .pipe(gutil.noop());
  105. }else{
  106. src = ['source/' + path + '/**/*', '!**/*.spec.js', '!**/test/**'];
  107. gutil.log("Move", ":", gutil.colors.green(gutil.colors.blue(path), gutil.colors.white('->'), dest));
  108. return gulp.src(src)
  109. .pipe(changed(dest))
  110. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  111. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  112. host: option.host,
  113. user: option.user || 'anonymous',
  114. pass: option.pass || '@anonymous',
  115. port: option.port || 21,
  116. remotePath: (option.remotePath || '/') + path
  117. })))
  118. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  119. host: option.host,
  120. user: option.user || 'anonymous',
  121. pass: option.pass || null,
  122. port: option.port || 22,
  123. remotePath: (option.remotePath || '/') + path
  124. })))
  125. .pipe(gulp.dest(dest))
  126. .pipe(gutil.noop());
  127. }
  128. });
  129. }
  130. function createXFormConcatTask(path, isMin, thisOptions) {
  131. gulp.task(path+" : concat", function(){
  132. var option = thisOptions || options;
  133. var src = [
  134. 'source/o2_core/o2/widget/AttachmentController.js',
  135. 'source/o2_core/o2/xScript/Macro.js',
  136. 'source/o2_core/o2/widget/Tab.js',
  137. 'source/o2_core/o2/widget/O2Identity.js',
  138. 'source/' + path + '/Form.js',
  139. 'source/' + path + '/$Module.js',
  140. 'source/' + path + '/$Input.js',
  141. 'source/' + path + '/Div.js',
  142. 'source/' + path + '/Combox.js',
  143. 'source/' + path + '/DatagridMobile.js',
  144. 'source/' + path + '/DatagridPC.js',
  145. 'source/' + path + '/Textfield.js',
  146. 'source/' + path + '/Personfield.js',
  147. 'source/' + path + '/Button.js',
  148. 'source/' + path + '/ViewSelector.js',
  149. 'source/' + path + '/*.js',
  150. 'source/x_component_process_Work/Processor.js',
  151. '!source/' + path + '/Office.js'
  152. ];
  153. var dest = option.dest+'/' + path + '/';
  154. return gulp.src(src)
  155. .pipe(sourceMap.init())
  156. .pipe(concat('$all.js'))
  157. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  158. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  159. host: option.host,
  160. user: option.user || 'anonymous',
  161. pass: option.pass || '@anonymous',
  162. port: option.port || 21,
  163. remotePath: (option.remotePath || '/') + path
  164. })))
  165. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  166. host: option.host,
  167. user: option.user || 'anonymous',
  168. pass: option.pass || null,
  169. port: option.port || 22,
  170. remotePath: (option.remotePath || '/') + path
  171. })))
  172. .pipe(gulp.dest(dest))
  173. .pipe(concat('$all.min.js'))
  174. .pipe(uglify())
  175. .pipe(sourceMap.write(""))
  176. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  177. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  178. host: option.host,
  179. user: option.user || 'anonymous',
  180. pass: option.pass || '@anonymous',
  181. port: option.port || 21,
  182. remotePath: (option.remotePath || '/') + path
  183. })))
  184. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  185. host: option.host,
  186. user: option.user || 'anonymous',
  187. pass: option.pass || null,
  188. port: option.port || 22,
  189. remotePath: (option.remotePath || '/') + path
  190. })))
  191. .pipe(gulp.dest(dest))
  192. });
  193. }
  194. function createO2ConcatTask(path, isMin, thisOptions) {
  195. gulp.task(path+" : concat", function(){
  196. var option = thisOptions || options;
  197. var src = [
  198. 'source/o2_lib/mootools/mootools-1.6.0_all.js',
  199. 'source/o2_lib/mootools/plugin/mBox.js',
  200. 'source/' + path + '/o2.js'
  201. ];
  202. var dest = option.dest+'/' + path + '/';
  203. return gulp.src(src)
  204. .pipe(sourceMap.init())
  205. .pipe(concat('o2.js'))
  206. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  207. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  208. host: option.host,
  209. user: option.user || 'anonymous',
  210. pass: option.pass || '@anonymous',
  211. port: option.port || 21,
  212. remotePath: (option.remotePath || '/') + path
  213. })))
  214. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  215. host: option.host,
  216. user: option.user || 'anonymous',
  217. pass: option.pass || null,
  218. port: option.port || 22,
  219. remotePath: (option.remotePath || '/') + path
  220. })))
  221. .pipe(gulp.dest(dest))
  222. .pipe(concat('o2.min.js'))
  223. .pipe(uglify())
  224. //.pipe(rename({ extname: '.min.js' }))
  225. .pipe(sourceMap.write(""))
  226. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  227. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  228. host: option.host,
  229. user: option.user || 'anonymous',
  230. pass: option.pass || '@anonymous',
  231. port: option.port || 21,
  232. remotePath: (option.remotePath || '/') + path
  233. })))
  234. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  235. host: option.host,
  236. user: option.user || 'anonymous',
  237. pass: option.pass || null,
  238. port: option.port || 22,
  239. remotePath: (option.remotePath || '/') + path
  240. })))
  241. .pipe(gulp.dest(dest))
  242. });
  243. gulp.task(path+".xDesktop : concat", function(){
  244. var option = thisOptions || options;
  245. var src = [
  246. 'source/'+path+'/o2/widget/Common.js',
  247. 'source/'+path+'/o2/widget/Dialog.js',
  248. 'source/'+path+'/o2/widget/UUID.js',
  249. 'source/'+path+'/o2/xDesktop/Common.js',
  250. 'source/'+path+'/o2/xDesktop/Actions/RestActions.js',
  251. 'source/'+path+'/o2/xAction/RestActions.js',
  252. 'source/'+path+'/o2/xDesktop/Access.js',
  253. 'source/'+path+'/o2/xDesktop/Dialog.js',
  254. 'source/'+path+'/o2/xDesktop/Menu.js',
  255. 'source/'+path+'/o2/xDesktop/UserData.js',
  256. 'source/x_component_Template/MPopupForm.js',
  257. 'source/'+path+'/o2/xDesktop/Authentication.js',
  258. 'source/'+path+'/o2/xDesktop/Dialog.js',
  259. 'source/'+path+'/o2/xDesktop/Window.js',
  260. 'source/x_component_Common/Main.js'
  261. ];
  262. var dest = option.dest+'/' + path + '/o2/xDesktop/';
  263. return gulp.src(src)
  264. .pipe(sourceMap.init())
  265. .pipe(concat('$all.js'))
  266. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/o2/xDesktop/')))
  267. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  268. host: option.host,
  269. user: option.user || 'anonymous',
  270. pass: option.pass || '@anonymous',
  271. port: option.port || 21,
  272. remotePath: (option.remotePath || '/') + path+"/o2/xDesktop/"
  273. })))
  274. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  275. host: option.host,
  276. user: option.user || 'anonymous',
  277. pass: option.pass || null,
  278. port: option.port || 22,
  279. remotePath: (option.remotePath || '/') + path+"/o2/xDesktop/"
  280. })))
  281. .pipe(gulp.dest(dest))
  282. .pipe(concat('$all.min.js'))
  283. .pipe(uglify())
  284. //.pipe(rename({ extname: '.min.js' }))
  285. .pipe(sourceMap.write(""))
  286. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/o2/xDesktop/')))
  287. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  288. host: option.host,
  289. user: option.user || 'anonymous',
  290. pass: option.pass || '@anonymous',
  291. port: option.port || 21,
  292. remotePath: (option.remotePath || '/') + path+"/o2/xDesktop/"
  293. })))
  294. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  295. host: option.host,
  296. user: option.user || 'anonymous',
  297. pass: option.pass || null,
  298. port: option.port || 22,
  299. remotePath: (option.remotePath || '/') + path+"/o2/xDesktop/"
  300. })))
  301. .pipe(gulp.dest(dest))
  302. });
  303. gulp.task(path+" : bundle", function(){
  304. var option = thisOptions || options;
  305. var src = [
  306. 'source/o2_lib/mootools/mootools-1.6.0_all.js',
  307. 'source/o2_lib/mootools/plugin/mBox.js',
  308. 'source/' + path + '/o2.js',
  309. 'source/x_desktop/js/base.js',
  310. "source/o2_core/o2/framework.js"
  311. ];
  312. var dest = option.dest+'/' + path + '/';
  313. return gulp.src(src)
  314. .pipe(sourceMap.init())
  315. .pipe(concat('bundle.js'))
  316. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  317. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  318. host: option.host,
  319. user: option.user || 'anonymous',
  320. pass: option.pass || '@anonymous',
  321. port: option.port || 21,
  322. remotePath: (option.remotePath || '/') + path
  323. })))
  324. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  325. host: option.host,
  326. user: option.user || 'anonymous',
  327. pass: option.pass || null,
  328. port: option.port || 22,
  329. remotePath: (option.remotePath || '/') + path
  330. })))
  331. .pipe(gulp.dest(dest))
  332. .pipe(concat('bundle.min.js'))
  333. .pipe(uglify())
  334. //.pipe(rename({ extname: '.min.js' }))
  335. .pipe(sourceMap.write(""))
  336. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  337. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  338. host: option.host,
  339. user: option.user || 'anonymous',
  340. pass: option.pass || '@anonymous',
  341. port: option.port || 21,
  342. remotePath: (option.remotePath || '/') + path
  343. })))
  344. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  345. host: option.host,
  346. user: option.user || 'anonymous',
  347. pass: option.pass || null,
  348. port: option.port || 22,
  349. remotePath: (option.remotePath || '/') + path
  350. })))
  351. .pipe(gulp.dest(dest))
  352. });
  353. }
  354. function concat_Actions(){
  355. return through2.obj(function (file, enc, cb) {
  356. debugger;
  357. if (file.isNull()) {
  358. this.push(file);
  359. return cb();
  360. }
  361. if (file.isStream()) {
  362. this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
  363. return cb();
  364. }
  365. var content = file.contents.toString();
  366. var o = path.parse(file.path);
  367. var name = o.name;
  368. content = "var actionJson = "+content;
  369. content = content+"\nif (!o2.xAction.RestActions.Action[\""+name+"\"]) o2.xAction.RestActions.Action[\""+name+"\"] = new Class({Extends: o2.xAction.RestActions.Action});";
  370. content = content+"\no2.Actions.actions[\""+name+"\"] = new o2.xAction.RestActions.Action[\""+name+"\"](\""+name+"\", actionJson);";
  371. file.contents = new Buffer.from(content);
  372. this.push(file);
  373. cb();
  374. });
  375. }
  376. function concat_Style(){
  377. return through2.obj(function (file, enc, cb) {
  378. if (file.isNull()) {
  379. this.push(file);
  380. return cb();
  381. }
  382. if (file.isStream()) {
  383. this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
  384. return cb();
  385. }
  386. var content = file.contents.toString();
  387. //name = ".."+file.path.replace(process.cwd(), "").replace(/\\/g, "/").substring("/source".length);
  388. var name = file.path.replace(process.cwd(), "").replace(/\\/g, "/")
  389. name = ".."+name.substring(name.indexOf("/source")+7);
  390. content = "var csskey = encodeURIComponent(\""+name+"\");\no2.widget.css[csskey]="+content;
  391. file.contents = new Buffer.from(content);
  392. this.push(file);
  393. cb();
  394. });
  395. }
  396. function createBaseWorkConcatStyleTask(path){
  397. gulp.task(path+".base_work : style", function(){
  398. return gulp.src([
  399. "source/x_component_process_Work/$Main/default/css.wcss",
  400. "source/x_component_process_Xform/$Form/default/css.wcss",
  401. "source/o2_core/o2/widget/$Tab/mobileForm/css.wcss",
  402. "source/o2_core/o2/widget/$Menu/tab/css.wcss",
  403. "source/o2_core/o2/widget/$Tab/form/css.wcss",
  404. "source/x_component_process_Xform/$Form/default/doc.wcss",
  405. "source/o2_core/o2/widget/$Toolbar/documentEdit/css.wcss",
  406. "source/o2_core/o2/widget/$Toolbar/documentEdit_side/css.wcss"
  407. ])
  408. .pipe(concat_Style())
  409. .pipe(concat('js/base_work_style_temp.js'))
  410. .pipe(gulp.dest('source/x_desktop/'))
  411. })
  412. }
  413. function createBaseWorkConcatActionTask(path){
  414. gulp.task(path+".base_work : action", function(){
  415. return gulp.src([
  416. "source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  417. "source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.json",
  418. "source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  419. "source/o2_core/o2/xAction/services/x_query_assemble_surface.json",
  420. "source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  421. "source/o2_core/o2/xAction/services/x_program_center.json",
  422. "source/o2_core/o2/xAction/services/x_organization_assemble_personal.json"
  423. ])
  424. .pipe(concat_Actions())
  425. .pipe(concat('js/base_work_actions_temp.js'))
  426. .pipe(gulp.dest('source/x_desktop/'))
  427. })
  428. }
  429. function createBaseWorkConcatDelTempTask(path) {
  430. gulp.task(path+".base_work : clean", function(cb){
  431. var dest = [
  432. 'source/'+path+'/js/base_work_actions_temp.js',
  433. 'source/'+path+'/js/base_work_style_temp.js'
  434. ];
  435. return del(dest, cb);
  436. });
  437. }
  438. function createBaseWorkConcatBodyTask(path, isMin, thisOptions) {
  439. gulp.task(path+".base_work : concat", function(){
  440. var option = thisOptions || options;
  441. var src = [
  442. 'source/' + path + '/js/base_concat_head.js',
  443. 'source/o2_core/o2/lp/'+(option.lp || 'zh-cn')+'.js',
  444. 'source/x_component_process_Work/lp/'+(option.lp || 'zh-cn')+'.js',
  445. 'source/x_component_process_Xform/lp/'+(option.lp || 'zh-cn')+'.js',
  446. 'source/x_component_Selector/lp/'+(option.lp || 'zh-cn')+'.js',
  447. 'source/' + path + '/js/base_work_style_temp.js',
  448. 'source/o2_core/o2/widget/Common.js',
  449. 'source/o2_core/o2/widget/Dialog.js',
  450. 'source/o2_core/o2/widget/UUID.js',
  451. 'source/o2_core/o2/widget/Menu.js',
  452. 'source/o2_core/o2/widget/Toolbar.js',
  453. 'source/o2_core/o2/xDesktop/Common.js',
  454. 'source/o2_core/o2/xDesktop/Actions/RestActions.js',
  455. 'source/o2_core/o2/xAction/RestActions.js',
  456. 'source/o2_core/o2/xDesktop/Access.js',
  457. 'source/o2_core/o2/xDesktop/Dialog.js',
  458. 'source/o2_core/o2/xDesktop/Menu.js',
  459. 'source/o2_core/o2/xDesktop/UserData.js',
  460. 'source/x_component_Template/MPopupForm.js',
  461. 'source/o2_core/o2/xDesktop/Authentication.js',
  462. 'source/o2_core/o2/xDesktop/Window.js',
  463. 'source/x_component_Common/Main.js',
  464. 'source/x_component_process_Work/Main.js',
  465. 'source/x_component_Selector/package.js',
  466. 'source/x_component_Selector/Person.js',
  467. 'source/x_component_Selector/Identity.js',
  468. 'source/x_component_Selector/Unit.js',
  469. 'source/x_component_Selector/IdentityWidthDuty.js',
  470. 'source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js',
  471. 'source/x_component_Selector/UnitWithType.js',
  472. 'source/o2_core/o2/xScript/Actions/UnitActions.js',
  473. 'source/o2_core/o2/xScript/Actions/ScriptActions.js',
  474. 'source/o2_core/o2/xScript/Actions/CMSScriptActions.js',
  475. 'source/o2_core/o2/xScript/Actions/PortalScriptActions.js',
  476. 'source/o2_core/o2/xScript/Environment.js',
  477. 'source/x_component_Template/MTooltips.js',
  478. 'source/x_component_Template/MSelector.js',
  479. 'source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js',
  480. 'source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.js',
  481. 'source/o2_core/o2/xAction/services/x_cms_assemble_control.js',
  482. 'source/o2_core/o2/xAction/services/x_organization_assemble_control.js',
  483. 'source/o2_core/o2/xAction/services/x_query_assemble_surface.js',
  484. 'source/o2_core/o2/xAction/services/x_organization_assemble_personal.js',
  485. 'source/' + path + '/js/base_work_actions_temp.js',
  486. 'source/' + path + '/js/base.js'
  487. ];
  488. var dest = option.dest+'/' + path + '/';
  489. return gulp.src(src)
  490. .pipe(sourceMap.init())
  491. .pipe(concat('js/base_work.js'))
  492. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  493. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  494. host: option.host,
  495. user: option.user || 'anonymous',
  496. pass: option.pass || '@anonymous',
  497. port: option.port || 21,
  498. remotePath: (option.remotePath || '/') + path
  499. })))
  500. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  501. host: option.host,
  502. user: option.user || 'anonymous',
  503. pass: option.pass || null,
  504. port: option.port || 22,
  505. remotePath: (option.remotePath || '/') + path
  506. })))
  507. .pipe(gulp.dest(dest))
  508. .pipe(uglify())
  509. .pipe(concat('js/base_work.min.js'))
  510. .pipe( sourceMap.write("") )
  511. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  512. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  513. host: option.host,
  514. user: option.user || 'anonymous',
  515. pass: option.pass || '@anonymous',
  516. port: option.port || 21,
  517. remotePath: (option.remotePath || '/') + path
  518. })))
  519. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  520. host: option.host,
  521. user: option.user || 'anonymous',
  522. pass: option.pass || null,
  523. port: option.port || 22,
  524. remotePath: (option.remotePath || '/') + path
  525. })))
  526. .pipe(gulp.dest(dest))
  527. });
  528. }
  529. function createBaseWorkConcatTask(path, isMin, thisOptions){
  530. createBaseWorkConcatActionTask(path);
  531. createBaseWorkConcatStyleTask(path);
  532. createBaseWorkConcatBodyTask(path, isMin, thisOptions);
  533. createBaseWorkConcatDelTempTask(path);
  534. gulp.task( path+".base_work", gulp.series(path+".base_work : action", path+".base_work : style", path+".base_work : concat", path+".base_work : clean"));
  535. }
  536. function createBasePortalConcatStyleTask(path){
  537. gulp.task(path+".base_portal : style", function(){
  538. return gulp.src([
  539. "source/x_component_process_Work/$Main/default/css.wcss",
  540. "source/x_component_portal_Portal/$Main/default/css.wcss",
  541. "source/x_component_process_Xform/$Form/default/css.wcss",
  542. "source/o2_core/o2/widget/$Tab/mobileForm/css.wcss",
  543. "source/o2_core/o2/widget/$Menu/tab/css.wcss"
  544. ])
  545. .pipe(concat_Style())
  546. .pipe(concat('js/base_portal_style_temp.js'))
  547. .pipe(gulp.dest('source/x_desktop/'))
  548. })
  549. }
  550. function createBasePortalConcatActionTask(path){
  551. gulp.task(path+".base_portal : action", function(){
  552. return gulp.src([
  553. "source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  554. "source/o2_core/o2/xAction/services/x_portal_assemble_surface.json",
  555. "source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  556. "source/o2_core/o2/xAction/services/x_query_assemble_surface.json",
  557. "source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  558. "source/o2_core/o2/xAction/services/x_program_center.json",
  559. "source/o2_core/o2/xAction/services/x_organization_assemble_personal.json"
  560. ])
  561. .pipe(concat_Actions())
  562. .pipe(concat('js/base_portal_actions_temp.js'))
  563. .pipe(gulp.dest('source/x_desktop/'))
  564. })
  565. }
  566. function createBasePortalConcatDelTempTask(path) {
  567. gulp.task(path+".base_portal : clean", function(cb){
  568. var dest = [
  569. 'source/'+path+'/js/base_portal_actions_temp.js',
  570. 'source/'+path+'/js/base_portal_style_temp.js'
  571. ];
  572. return del(dest, cb);
  573. });
  574. }
  575. function createBasePortalConcatBodyTask(path, isMin, thisOptions) {
  576. gulp.task(path+".base_portal : concat", function(){
  577. var option = thisOptions || options;
  578. var src = [
  579. 'source/' + path + '/js/base_concat_head.js',
  580. 'source/o2_core/o2/lp/'+(option.lp || 'zh-cn')+'.js',
  581. 'source/' + path + '/js/base_portal_style_temp.js',
  582. 'source/o2_core/o2/widget/Common.js',
  583. 'source/o2_core/o2/widget/Dialog.js',
  584. 'source/o2_core/o2/widget/UUID.js',
  585. 'source/o2_core/o2/widget/Menu.js',
  586. 'source/o2_core/o2/widget/Toolbar.js',
  587. 'source/o2_core/o2/xDesktop/Common.js',
  588. 'source/o2_core/o2/xDesktop/Actions/RestActions.js',
  589. 'source/o2_core/o2/xAction/RestActions.js',
  590. 'source/o2_core/o2/xDesktop/Access.js',
  591. 'source/o2_core/o2/xDesktop/Dialog.js',
  592. 'source/o2_core/o2/xDesktop/Menu.js',
  593. 'source/o2_core/o2/xDesktop/UserData.js',
  594. 'source/x_component_Template/MPopupForm.js',
  595. 'source/o2_core/o2/xDesktop/Authentication.js',
  596. 'source/o2_core/o2/xDesktop/Window.js',
  597. 'source/x_component_Common/Main.js',
  598. 'source/x_component_process_Work/lp/'+(option.lp || 'zh-cn')+'.js',
  599. 'source/x_component_portal_Portal/lp/'+(option.lp || 'zh-cn')+'.js',
  600. 'source/x_component_process_Xform/lp/'+(option.lp || 'zh-cn')+'.js',
  601. 'source/x_component_Selector/lp/'+(option.lp || 'zh-cn')+'.js',
  602. 'source/x_component_portal_Portal/Main.js',
  603. 'source/x_component_Selector/package.js',
  604. 'source/x_component_Selector/Person.js',
  605. 'source/x_component_Selector/Identity.js',
  606. 'source/x_component_Selector/Unit.js',
  607. 'source/x_component_Selector/IdentityWidthDuty.js',
  608. 'source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js',
  609. 'source/x_component_Selector/UnitWithType.js',
  610. 'source/o2_core/o2/xScript/Actions/UnitActions.js',
  611. 'source/o2_core/o2/xScript/Actions/ScriptActions.js',
  612. 'source/o2_core/o2/xScript/Actions/CMSScriptActions.js',
  613. 'source/o2_core/o2/xScript/Actions/PortalScriptActions.js',
  614. 'source/o2_core/o2/xScript/PageEnvironment.js',
  615. 'source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js',
  616. 'source/o2_core/o2/xAction/services/x_cms_assemble_control.js',
  617. 'source/o2_core/o2/xAction/services/x_organization_assemble_control.js',
  618. 'source/o2_core/o2/xAction/services/x_query_assemble_surface.js',
  619. 'source/o2_core/o2/xAction/services/x_organization_assemble_personal.js',
  620. 'source/' + path + '/js/base_portal_actions_temp.js',
  621. 'source/' + path + '/js/base.js'
  622. ];
  623. var dest = option.dest+'/' + path + '/';
  624. return gulp.src(src)
  625. .pipe(sourceMap.init())
  626. .pipe(concat('js/base_portal.js'))
  627. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  628. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  629. host: option.host,
  630. user: option.user || 'anonymous',
  631. pass: option.pass || '@anonymous',
  632. port: option.port || 21,
  633. remotePath: (option.remotePath || '/') + path
  634. })))
  635. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  636. host: option.host,
  637. user: option.user || 'anonymous',
  638. pass: option.pass || null,
  639. port: option.port || 22,
  640. remotePath: (option.remotePath || '/') + path
  641. })))
  642. .pipe(gulp.dest(dest))
  643. // .pipe(gulp.src(src))
  644. .pipe(concat('js/base_portal.min.js'))
  645. .pipe(uglify())
  646. .pipe( sourceMap.write("") )
  647. // .pipe(rename({ extname: '.min.js' }))
  648. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  649. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  650. host: option.host,
  651. user: option.user || 'anonymous',
  652. pass: option.pass || '@anonymous',
  653. port: option.port || 21,
  654. remotePath: (option.remotePath || '/') + path
  655. })))
  656. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  657. host: option.host,
  658. user: option.user || 'anonymous',
  659. pass: option.pass || null,
  660. port: option.port || 22,
  661. remotePath: (option.remotePath || '/') + path
  662. })))
  663. .pipe(gulp.dest(dest))
  664. });
  665. }
  666. function createBasePortalConcatTask(path, isMin, thisOptions){
  667. createBasePortalConcatActionTask(path);
  668. createBasePortalConcatStyleTask(path);
  669. createBasePortalConcatBodyTask(path, isMin, thisOptions);
  670. createBasePortalConcatDelTempTask(path);
  671. gulp.task( path+".base_portal", gulp.series(path+".base_portal : action", path+".base_portal : style", path+".base_portal : concat", path+".base_portal : clean"));
  672. }
  673. function createBaseConcatTask(path, isMin, thisOptions){
  674. gulp.task(path+".base", function(){
  675. var option = thisOptions || options;
  676. var src = [
  677. 'source/' + path + '/js/base.js'
  678. ];
  679. var dest = option.dest+'/' + path + '/';
  680. return gulp.src(src)
  681. .pipe(sourceMap.init())
  682. .pipe(concat('js/base.js'))
  683. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  684. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  685. host: option.host,
  686. user: option.user || 'anonymous',
  687. pass: option.pass || '@anonymous',
  688. port: option.port || 21,
  689. remotePath: (option.remotePath || '/') + path
  690. })))
  691. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  692. host: option.host,
  693. user: option.user || 'anonymous',
  694. pass: option.pass || null,
  695. port: option.port || 22,
  696. remotePath: (option.remotePath || '/') + path
  697. })))
  698. .pipe(gulp.dest(dest))
  699. // .pipe(gulp.src(src))
  700. .pipe(concat('js/base.min.js'))
  701. .pipe(uglify())
  702. .pipe( sourceMap.write("") )
  703. // .pipe(rename({ extname: '.min.js' }))
  704. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  705. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  706. host: option.host,
  707. user: option.user || 'anonymous',
  708. pass: option.pass || '@anonymous',
  709. port: option.port || 21,
  710. remotePath: (option.remotePath || '/') + path
  711. })))
  712. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  713. host: option.host,
  714. user: option.user || 'anonymous',
  715. pass: option.pass || null,
  716. port: option.port || 22,
  717. remotePath: (option.remotePath || '/') + path
  718. })))
  719. .pipe(gulp.dest(dest))
  720. });
  721. }
  722. function getAppTask(path, isMin, thisOptions) {
  723. if (path==="x_component_process_Xform"){
  724. createDefaultTask(path, isMin, thisOptions);
  725. createXFormConcatTask(path, isMin, thisOptions);
  726. return gulp.series(path, path+" : concat");
  727. }else if (path==="o2_core"){
  728. createDefaultTask(path, isMin, thisOptions);
  729. createO2ConcatTask(path, isMin, thisOptions);
  730. return gulp.series(path, path+" : concat", path+".xDesktop : concat", path+" : bundle");
  731. }else if (path==="x_desktop") {
  732. createDefaultTask(path, isMin, thisOptions);
  733. createBaseWorkConcatTask(path, isMin, thisOptions);
  734. createBasePortalConcatTask(path, isMin, thisOptions);
  735. createBaseConcatTask(path, isMin, thisOptions);
  736. return gulp.series(path, path+".base_work", path+".base_portal", path+".base");
  737. //return gulp.series(path, path+".base_work : concat");
  738. }else{
  739. createDefaultTask(path, isMin, thisOptions);
  740. return gulp.series(path);
  741. }
  742. }
  743. //var taskObj = {};
  744. apps.map(function (app) {
  745. var taskName;
  746. var isMin = (app.tasks.indexOf("min")!==-1);
  747. taskName = app.folder;
  748. appTasks.push(taskName);
  749. gulp.task(taskName, getAppTask(app.folder, isMin));
  750. // //var isMin = (app.tasks.indexOf("min")!==-1);
  751. // taskName = app.folder+"_release";
  752. // //appTasks.push(taskName);
  753. // gulp.task(taskName, getAppTask(app.folder, isMin, release_options));
  754. });
  755. // Object.keys(taskObj).map(function(k){
  756. // exports[k] = parallel(taskObj[k]);
  757. // });
  758. //exports[app.folder] = parallel(minTask, moveTask);
  759. function getCleanTask(path) {
  760. return function (cb) {
  761. if (path){
  762. var dest = (path=="/") ? options.dest+"/" : options.dest+'/' + path + '/';
  763. gutil.log("Clean", ":", gutil.colors.red(dest));
  764. del.sync(dest, cb);
  765. cb();
  766. }else{
  767. cb();
  768. }
  769. }
  770. }
  771. function cleanRemoteFtp(f, cb) {
  772. var file = options.remotePath + f;
  773. var ftp = new JSFtp({
  774. host: options.host,
  775. user: options.user || 'anonymous',
  776. pass: options.pass || null,
  777. port: options.port || 21
  778. });
  779. ftp.raw('dele ' + file, function (err) {
  780. if (err) { cb(); return; }
  781. if (file.substring(file.length - 3).toLowerCase() == ".js") {
  782. file = file.replace('.js', ".min.js");
  783. ftp.raw('dele ' + file, function (err) {
  784. if (err) { cb(); return; }
  785. if (file.indexOf("/") != -1) {
  786. var p = file.substring(0, file.lastIndexOf("/"));
  787. ftp.raw('rmd ' + p, function (err) {
  788. if (err) { cb(); return; }
  789. ftp.raw.quit();
  790. cb();
  791. });
  792. }
  793. });
  794. } else {
  795. if (file.indexOf("/") != -1) {
  796. var pPath = file.substring(0, file.lastIndexOf("/"));
  797. ftp.raw('rmd ' + pPath, function (err) {
  798. if (err) { cb(); return; }
  799. ftp.raw.quit();
  800. cb();
  801. });
  802. }
  803. }
  804. });
  805. }
  806. function cleanRemoteLocal(f, cb) {
  807. var file = options.location + f;
  808. del(file, { force: true, dryRun: true }, function () {
  809. if (file.substring(file.length - 3).toLowerCase() == ".js") {
  810. var minfile = file.replace('.js', ".min.js");
  811. del(minfile, { force: true, dryRun: true }, function () {
  812. var p = file.substring(0, file.lastIndexOf("/"));
  813. fs.rmdir(p, function (err) {
  814. if (err) { }
  815. cb();
  816. })
  817. });
  818. } else {
  819. var p = file.substring(0, file.lastIndexOf("/"));
  820. fs.rmdir(p, function (err) {
  821. if (err) { }
  822. cb();
  823. })
  824. }
  825. });
  826. }
  827. function getCleanRemoteTask(path) {
  828. return function (cb) {
  829. if (options.upload) {
  830. var file = path.replace(/\\/g, "/");
  831. file = file.substring(file.indexOf("source/") + 7);
  832. if (options.upload == 'local' && options.location != '') cleanRemoteLocal(file, cb);
  833. if (options.upload == 'ftp' && options.host != '') cleanRemoteFtp(file, cb);
  834. } else {
  835. if (cb) cb();
  836. }
  837. }
  838. }
  839. function getWatchTask(path) {
  840. return (path) ? function (cb) {
  841. gutil.log("watch", ":", gutil.colors.green(path, "is watching ..."));
  842. gulp.watch(['source/' + path + '/**/*', "!./**/test/**"], { "events": ['addDir', 'add', 'change'] }, gulp.parallel([path]));
  843. } : function(cb){cb();};
  844. }
  845. gulp.task("clean", getCleanTask(options.src))
  846. gulp.task("watch", getWatchTask(options.src));
  847. gulp.task("index", function () {
  848. var src = ['source/favicon.ico', 'source/index.html'];
  849. var dest = options.dest;
  850. return gulp.src(src)
  851. .pipe(changed(dest))
  852. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + '/')))
  853. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  854. host: options.host,
  855. user: options.user || 'anonymous',
  856. pass: options.pass || '@anonymous',
  857. port: options.port || 21,
  858. remotePath: (options.remotePath || '/')
  859. })))
  860. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), ftp({
  861. host: options.host,
  862. user: options.user || 'anonymous',
  863. pass: options.pass || null,
  864. port: options.port || 22,
  865. remotePath: (options.remotePath || '/')
  866. })))
  867. .pipe(gulp.dest(dest))
  868. .pipe(gutil.noop());
  869. });
  870. gulp.task("cleanAll", getCleanTask('/'));
  871. gulp.task("o2:new-v:html", function () {
  872. var path = "x_desktop";
  873. var src = '/source/x_desktop/*.html';
  874. var dest = options.dest + '/x_desktop/';
  875. return gulp.src(src)
  876. .pipe(assetRev())
  877. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
  878. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  879. host: options.host,
  880. user: options.user || 'anonymous',
  881. pass: options.pass || '@anonymous',
  882. port: options.port || 21,
  883. remotePath: (options.remotePath || '/') + path
  884. })))
  885. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
  886. host: options.host,
  887. user: options.user || 'anonymous',
  888. pass: options.pass || null,
  889. port: options.port || 22,
  890. remotePath: (options.remotePath || '/') + path
  891. })))
  892. .pipe(gulp.dest(dest))
  893. .pipe(gutil.noop());
  894. });
  895. gulp.task("o2:new-v:o2", function () {
  896. var path = "o2_core";
  897. var src = options.dest +'/o2_core/o2.js';
  898. var dest = options.dest +'/o2_core/';
  899. return gulp.src(src)
  900. .pipe(assetRev())
  901. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
  902. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  903. host: options.host,
  904. user: options.user || 'anonymous',
  905. pass: options.pass || '@anonymous',
  906. port: options.port || 21,
  907. remotePath: (options.remotePath || '/') + path
  908. })))
  909. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
  910. host: options.host,
  911. user: options.user || 'anonymous',
  912. pass: options.pass || null,
  913. port: options.port || 22,
  914. remotePath: (options.remotePath || '/') + path
  915. })))
  916. .pipe(gulp.dest(dest))
  917. .pipe(uglify())
  918. .pipe(rename({ extname: '.min.js' }))
  919. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
  920. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  921. host: options.host,
  922. user: options.user || 'anonymous',
  923. pass: options.pass || '@anonymous',
  924. port: options.port || 21,
  925. remotePath: (options.remotePath || '/') + path
  926. })))
  927. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
  928. host: options.host,
  929. user: options.user || 'anonymous',
  930. pass: options.pass || null,
  931. port: options.port || 22,
  932. remotePath: (options.remotePath || '/') + path
  933. })))
  934. .pipe(gulp.dest(dest))
  935. .pipe(gutil.noop());
  936. });
  937. gulp.task("o2:new-v", gulp.parallel("o2:new-v:o2", "o2:new-v:html"));
  938. gulp.task("git_clean", function (cb) {
  939. var dest = 'D:/O2/github/huqi1980/o2oa/o2web/source/';
  940. del(dest, { dryRun: true, force: true }, cb);
  941. });
  942. gulp.task("git_dest", function () {
  943. var dest = "D:/O2/github/huqi1980/o2oa/o2web/source";
  944. return gulp.src(["source/**/*", "!./**/test/**"])
  945. .pipe(changed(dest))
  946. .pipe(gulp.dest(dest))
  947. });
  948. gulp.task("git", gulp.series('git_clean', 'git_dest'));
  949. gulp.task("default", gulp.series(gulp.parallel(appTasks, 'index'), "o2:new-v"));
  950. function build(){
  951. options.ev = "p";
  952. options.upload = o_options.upload || "";
  953. options.location = o_options.location || uploadOptions.location;
  954. options.host = o_options.host || uploadOptions.host;
  955. options.user = o_options.user || uploadOptions.user;
  956. options.pass = o_options.pass || uploadOptions.pass;
  957. options.port = o_options.port || uploadOptions.port;
  958. options.remotePath = o_options.remotePath || uploadOptions.remotePath;
  959. options.dest = o_options.dest || uploadOptions.dest || "dest";
  960. };
  961. gulp.task("build", gulp.series("clean", gulp.parallel(appTasks, 'index'), "o2:new-v"))