gulpfile.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  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 createCMSXFormConcatTask(path, isMin, thisOptions) {
  195. var processPath = "x_component_process_Xform";
  196. gulp.task(path+" : concat", function(){
  197. var option = thisOptions || options;
  198. var src = [
  199. 'source/o2_core/o2/widget/AttachmentController.js',
  200. // 'source/o2_core/o2/xScript/CMSEnvironment.js',
  201. 'source/o2_core/o2/xScript/CMSMacro.js',
  202. 'source/o2_core/o2/widget/Tab.js',
  203. 'source/o2_core/o2/widget/O2Identity.js',
  204. 'source/' + processPath + '/Form.js',
  205. 'source/' + processPath + '/$Module.js',
  206. 'source/' + processPath + '/$Input.js',
  207. 'source/' + processPath + '/Div.js',
  208. //'source/' + processPath + '/Combox.js',
  209. 'source/' + processPath + '/DatagridMobile.js',
  210. 'source/' + processPath + '/DatagridPC.js',
  211. 'source/' + processPath + '/Textfield.js',
  212. //'source/' + processPath + '/Personfield.js',
  213. 'source/' + processPath + '/Button.js',
  214. //'source/' + processPath + '/ViewSelector.js',
  215. 'source/' + processPath + '/Org.js',
  216. // 'source/' + processPath + '/*.js',
  217. 'source/' + processPath + '/Actionbar.js',
  218. //'source/' + processPath + '/Address.js',
  219. 'source/' + processPath + '/Attachment.js',
  220. 'source/' + processPath + '/Calendar.js',
  221. 'source/' + processPath + '/Checkbox.js',
  222. 'source/' + processPath + '/Datagrid.js',
  223. 'source/' + processPath + '/Htmleditor.js',
  224. //'source/' + processPath + '/Iframe.js',
  225. 'source/' + processPath + '/Label.js',
  226. 'source/' + processPath + '/Number.js',
  227. 'source/' + processPath + '/Common.js',
  228. 'source/' + processPath + '/Image.js',
  229. 'source/' + processPath + '/ImageClipper.js',
  230. 'source/' + processPath + '/Html.js',
  231. 'source/' + processPath + '/Radio.js',
  232. 'source/' + processPath + '/Select.js',
  233. //'source/' + processPath + '/Stat.js',
  234. //'source/' + processPath + '/Statement.js',
  235. //'source/' + processPath + '/StatementSelector.js',
  236. //'source/' + processPath + '/Subform.js',
  237. 'source/' + processPath + '/Tab.js',
  238. 'source/' + processPath + '/Table.js',
  239. 'source/' + processPath + '/Textarea.js',
  240. //'source/' + processPath + '/Tree.js',
  241. //'source/' + processPath + '/View.js',
  242. // 'source/x_component_process_Work/Processor.js',
  243. // '!source/' + processPath + '/Office.js'
  244. 'source/o2_core/o2/widget/SimpleToolbar.js',
  245. 'source/' + path + '/ModuleImplements.js',
  246. 'source/' + path + '/Package.js',
  247. 'source/' + path + '/Form.js',
  248. //'source/' + path + '/widget/Comment.js',
  249. 'source/' + path + '/widget/Log.js',
  250. 'source/' + path + '/Org.js',
  251. 'source/' + path + '/Author.js',
  252. 'source/' + path + '/Reader.js',
  253. 'source/' + path + '/Textfield.js',
  254. 'source/' + path + '/Actionbar.js',
  255. 'source/' + path + '/Attachment.js',
  256. 'source/' + path + '/Button.js',
  257. 'source/' + path + '/Calendar.js',
  258. 'source/' + path + '/Checkbox.js',
  259. 'source/' + path + '/Datagrid.js',
  260. 'source/' + path + '/Htmleditor.js',
  261. 'source/' + path + '/ImageClipper.js',
  262. 'source/' + path + '/Label.js',
  263. 'source/' + path + '/Number.js',
  264. 'source/' + path + '/Radio.js',
  265. 'source/' + path + '/Select.js',
  266. 'source/' + path + '/Tab.js',
  267. 'source/' + path + '/Table.js',
  268. 'source/' + path + '/Textarea.js'
  269. //'source/' + path + '/Personfield.js',
  270. //'source/' + path + '/Readerfield.js',
  271. //'source/' + path + '/Authorfield.js',
  272. //'source/' + path + '/Orgfield.js',
  273. // 'source/' + path + '/*.js',
  274. // '!source/' + path + '/Office.js'
  275. ];
  276. var dest = option.dest+'/' + path + '/';
  277. return gulp.src(src)
  278. .pipe(sourceMap.init())
  279. .pipe(concat('$all.js'))
  280. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  281. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  282. host: option.host,
  283. user: option.user || 'anonymous',
  284. pass: option.pass || '@anonymous',
  285. port: option.port || 21,
  286. remotePath: (option.remotePath || '/') + path
  287. })))
  288. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  289. host: option.host,
  290. user: option.user || 'anonymous',
  291. pass: option.pass || null,
  292. port: option.port || 22,
  293. remotePath: (option.remotePath || '/') + path
  294. })))
  295. .pipe(gulp.dest(dest))
  296. .pipe(concat('$all.min.js'))
  297. .pipe(uglify())
  298. .pipe(sourceMap.write(""))
  299. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  300. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  301. host: option.host,
  302. user: option.user || 'anonymous',
  303. pass: option.pass || '@anonymous',
  304. port: option.port || 21,
  305. remotePath: (option.remotePath || '/') + path
  306. })))
  307. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  308. host: option.host,
  309. user: option.user || 'anonymous',
  310. pass: option.pass || null,
  311. port: option.port || 22,
  312. remotePath: (option.remotePath || '/') + path
  313. })))
  314. .pipe(gulp.dest(dest))
  315. });
  316. }
  317. function createO2ConcatTask(path, isMin, thisOptions) {
  318. gulp.task(path+" : concat", function(){
  319. var option = thisOptions || options;
  320. var src = [
  321. 'source/o2_lib/mootools/mootools-1.6.0_all.js',
  322. 'source/o2_lib/mootools/plugin/mBox.js',
  323. 'source/' + path + '/o2.js'
  324. ];
  325. var dest = option.dest+'/' + path + '/';
  326. return gulp.src(src)
  327. .pipe(sourceMap.init())
  328. .pipe(concat('o2.js'))
  329. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  330. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  331. host: option.host,
  332. user: option.user || 'anonymous',
  333. pass: option.pass || '@anonymous',
  334. port: option.port || 21,
  335. remotePath: (option.remotePath || '/') + path
  336. })))
  337. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  338. host: option.host,
  339. user: option.user || 'anonymous',
  340. pass: option.pass || null,
  341. port: option.port || 22,
  342. remotePath: (option.remotePath || '/') + path
  343. })))
  344. .pipe(gulp.dest(dest))
  345. .pipe(concat('o2.min.js'))
  346. .pipe(uglify())
  347. //.pipe(rename({ extname: '.min.js' }))
  348. .pipe(sourceMap.write(""))
  349. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  350. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  351. host: option.host,
  352. user: option.user || 'anonymous',
  353. pass: option.pass || '@anonymous',
  354. port: option.port || 21,
  355. remotePath: (option.remotePath || '/') + path
  356. })))
  357. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  358. host: option.host,
  359. user: option.user || 'anonymous',
  360. pass: option.pass || null,
  361. port: option.port || 22,
  362. remotePath: (option.remotePath || '/') + path
  363. })))
  364. .pipe(gulp.dest(dest))
  365. });
  366. gulp.task(path+".xDesktop : concat", function(){
  367. var option = thisOptions || options;
  368. var src = [
  369. 'source/'+path+'/o2/widget/Common.js',
  370. 'source/'+path+'/o2/widget/Dialog.js',
  371. 'source/'+path+'/o2/widget/UUID.js',
  372. 'source/'+path+'/o2/xDesktop/Common.js',
  373. 'source/'+path+'/o2/xDesktop/Actions/RestActions.js',
  374. 'source/'+path+'/o2/xAction/RestActions.js',
  375. 'source/'+path+'/o2/xDesktop/Access.js',
  376. 'source/'+path+'/o2/xDesktop/Dialog.js',
  377. 'source/'+path+'/o2/xDesktop/Menu.js',
  378. 'source/'+path+'/o2/xDesktop/UserData.js',
  379. 'source/x_component_Template/MPopupForm.js',
  380. 'source/'+path+'/o2/xDesktop/Authentication.js',
  381. 'source/'+path+'/o2/xDesktop/Dialog.js',
  382. 'source/'+path+'/o2/xDesktop/Window.js',
  383. 'source/x_component_Common/Main.js'
  384. ];
  385. var dest = option.dest+'/' + path + '/o2/xDesktop/';
  386. return gulp.src(src)
  387. .pipe(sourceMap.init())
  388. .pipe(concat('$all.js'))
  389. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/o2/xDesktop/')))
  390. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  391. host: option.host,
  392. user: option.user || 'anonymous',
  393. pass: option.pass || '@anonymous',
  394. port: option.port || 21,
  395. remotePath: (option.remotePath || '/') + path+"/o2/xDesktop/"
  396. })))
  397. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  398. host: option.host,
  399. user: option.user || 'anonymous',
  400. pass: option.pass || null,
  401. port: option.port || 22,
  402. remotePath: (option.remotePath || '/') + path+"/o2/xDesktop/"
  403. })))
  404. .pipe(gulp.dest(dest))
  405. .pipe(concat('$all.min.js'))
  406. .pipe(uglify())
  407. //.pipe(rename({ extname: '.min.js' }))
  408. .pipe(sourceMap.write(""))
  409. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/o2/xDesktop/')))
  410. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  411. host: option.host,
  412. user: option.user || 'anonymous',
  413. pass: option.pass || '@anonymous',
  414. port: option.port || 21,
  415. remotePath: (option.remotePath || '/') + path+"/o2/xDesktop/"
  416. })))
  417. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  418. host: option.host,
  419. user: option.user || 'anonymous',
  420. pass: option.pass || null,
  421. port: option.port || 22,
  422. remotePath: (option.remotePath || '/') + path+"/o2/xDesktop/"
  423. })))
  424. .pipe(gulp.dest(dest))
  425. });
  426. gulp.task(path+" : bundle", function(){
  427. var option = thisOptions || options;
  428. var src = [
  429. 'source/o2_lib/mootools/mootools-1.6.0_all.js',
  430. 'source/o2_lib/mootools/plugin/mBox.js',
  431. 'source/' + path + '/o2.js',
  432. 'source/x_desktop/js/base.js',
  433. "source/o2_core/o2/framework.js"
  434. ];
  435. var dest = option.dest+'/' + path + '/';
  436. return gulp.src(src)
  437. .pipe(sourceMap.init())
  438. .pipe(concat('bundle.js'))
  439. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  440. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  441. host: option.host,
  442. user: option.user || 'anonymous',
  443. pass: option.pass || '@anonymous',
  444. port: option.port || 21,
  445. remotePath: (option.remotePath || '/') + path
  446. })))
  447. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  448. host: option.host,
  449. user: option.user || 'anonymous',
  450. pass: option.pass || null,
  451. port: option.port || 22,
  452. remotePath: (option.remotePath || '/') + path
  453. })))
  454. .pipe(gulp.dest(dest))
  455. .pipe(concat('bundle.min.js'))
  456. .pipe(uglify())
  457. //.pipe(rename({ extname: '.min.js' }))
  458. .pipe(sourceMap.write(""))
  459. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  460. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  461. host: option.host,
  462. user: option.user || 'anonymous',
  463. pass: option.pass || '@anonymous',
  464. port: option.port || 21,
  465. remotePath: (option.remotePath || '/') + path
  466. })))
  467. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  468. host: option.host,
  469. user: option.user || 'anonymous',
  470. pass: option.pass || null,
  471. port: option.port || 22,
  472. remotePath: (option.remotePath || '/') + path
  473. })))
  474. .pipe(gulp.dest(dest))
  475. });
  476. }
  477. function concat_Actions(){
  478. return through2.obj(function (file, enc, cb) {
  479. debugger;
  480. if (file.isNull()) {
  481. this.push(file);
  482. return cb();
  483. }
  484. if (file.isStream()) {
  485. this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
  486. return cb();
  487. }
  488. var content = file.contents.toString();
  489. var o = path.parse(file.path);
  490. var name = o.name;
  491. content = "var actionJson = "+content;
  492. content = content+"\nif (!o2.xAction.RestActions.Action[\""+name+"\"]) o2.xAction.RestActions.Action[\""+name+"\"] = new Class({Extends: o2.xAction.RestActions.Action});";
  493. content = content+"\no2.Actions.actions[\""+name+"\"] = new o2.xAction.RestActions.Action[\""+name+"\"](\""+name+"\", actionJson);";
  494. file.contents = new Buffer.from(content);
  495. this.push(file);
  496. cb();
  497. });
  498. }
  499. function concat_Style(){
  500. return through2.obj(function (file, enc, cb) {
  501. if (file.isNull()) {
  502. this.push(file);
  503. return cb();
  504. }
  505. if (file.isStream()) {
  506. this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
  507. return cb();
  508. }
  509. var content = file.contents.toString();
  510. //name = ".."+file.path.replace(process.cwd(), "").replace(/\\/g, "/").substring("/source".length);
  511. var name = file.path.replace(process.cwd(), "").replace(/\\/g, "/")
  512. name = ".."+name.substring(name.indexOf("/source")+7);
  513. content = "var csskey = encodeURIComponent(\""+name+"\");\no2.widget.css[csskey]="+content;
  514. file.contents = new Buffer.from(content);
  515. this.push(file);
  516. cb();
  517. });
  518. }
  519. function createBaseWorkConcatStyleTask(path){
  520. gulp.task(path+".base_work : style", function(){
  521. return gulp.src([
  522. "source/x_component_process_Work/$Main/default/css.wcss",
  523. "source/x_component_process_Xform/$Form/default/css.wcss",
  524. "source/o2_core/o2/widget/$Tab/mobileForm/css.wcss",
  525. "source/o2_core/o2/widget/$Menu/tab/css.wcss",
  526. "source/o2_core/o2/widget/$Tab/form/css.wcss",
  527. "source/x_component_process_Xform/$Form/default/doc.wcss",
  528. "source/o2_core/o2/widget/$Toolbar/documentEdit/css.wcss",
  529. "source/o2_core/o2/widget/$Toolbar/documentEdit_side/css.wcss"
  530. ])
  531. .pipe(concat_Style())
  532. .pipe(concat('js/base_work_style_temp.js'))
  533. .pipe(gulp.dest('source/x_desktop/'))
  534. })
  535. }
  536. function createBaseWorkConcatActionTask(path){
  537. gulp.task(path+".base_work : action", function(){
  538. return gulp.src([
  539. "source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  540. "source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.json",
  541. "source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  542. "source/o2_core/o2/xAction/services/x_query_assemble_surface.json",
  543. "source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  544. "source/o2_core/o2/xAction/services/x_program_center.json",
  545. "source/o2_core/o2/xAction/services/x_organization_assemble_personal.json"
  546. ])
  547. .pipe(concat_Actions())
  548. .pipe(concat('js/base_work_actions_temp.js'))
  549. .pipe(gulp.dest('source/x_desktop/'))
  550. })
  551. }
  552. function createBaseWorkConcatDelTempTask(path) {
  553. gulp.task(path+".base_work : clean", function(cb){
  554. var dest = [
  555. 'source/'+path+'/js/base_work_actions_temp.js',
  556. 'source/'+path+'/js/base_work_style_temp.js'
  557. ];
  558. return del(dest, cb);
  559. });
  560. }
  561. function createBaseWorkConcatBodyTask(path, isMin, thisOptions) {
  562. gulp.task(path+".base_work : concat", function(){
  563. var option = thisOptions || options;
  564. var src = [
  565. 'source/' + path + '/js/base_concat_head.js',
  566. 'source/o2_core/o2/lp/'+(option.lp || 'zh-cn')+'.js',
  567. 'source/x_component_process_Work/lp/'+(option.lp || 'zh-cn')+'.js',
  568. 'source/x_component_process_Xform/lp/'+(option.lp || 'zh-cn')+'.js',
  569. 'source/x_component_Selector/lp/'+(option.lp || 'zh-cn')+'.js',
  570. 'source/' + path + '/js/base_work_style_temp.js',
  571. 'source/o2_core/o2/widget/Common.js',
  572. 'source/o2_core/o2/widget/Dialog.js',
  573. 'source/o2_core/o2/widget/UUID.js',
  574. 'source/o2_core/o2/widget/Menu.js',
  575. 'source/o2_core/o2/widget/Toolbar.js',
  576. 'source/o2_core/o2/xDesktop/Common.js',
  577. 'source/o2_core/o2/xDesktop/Actions/RestActions.js',
  578. 'source/o2_core/o2/xAction/RestActions.js',
  579. 'source/o2_core/o2/xDesktop/Access.js',
  580. 'source/o2_core/o2/xDesktop/Dialog.js',
  581. 'source/o2_core/o2/xDesktop/Menu.js',
  582. 'source/o2_core/o2/xDesktop/UserData.js',
  583. 'source/x_component_Template/MPopupForm.js',
  584. 'source/o2_core/o2/xDesktop/Authentication.js',
  585. 'source/o2_core/o2/xDesktop/Window.js',
  586. 'source/x_component_Common/Main.js',
  587. 'source/x_component_process_Work/Main.js',
  588. 'source/x_component_Selector/package.js',
  589. 'source/x_component_Selector/Person.js',
  590. 'source/x_component_Selector/Identity.js',
  591. 'source/x_component_Selector/Unit.js',
  592. 'source/x_component_Selector/IdentityWidthDuty.js',
  593. 'source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js',
  594. 'source/x_component_Selector/UnitWithType.js',
  595. 'source/o2_core/o2/xScript/Actions/UnitActions.js',
  596. 'source/o2_core/o2/xScript/Actions/ScriptActions.js',
  597. 'source/o2_core/o2/xScript/Actions/CMSScriptActions.js',
  598. 'source/o2_core/o2/xScript/Actions/PortalScriptActions.js',
  599. 'source/o2_core/o2/xScript/Environment.js',
  600. 'source/x_component_Template/MTooltips.js',
  601. 'source/x_component_Template/MSelector.js',
  602. 'source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js',
  603. 'source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.js',
  604. 'source/o2_core/o2/xAction/services/x_cms_assemble_control.js',
  605. 'source/o2_core/o2/xAction/services/x_organization_assemble_control.js',
  606. 'source/o2_core/o2/xAction/services/x_query_assemble_surface.js',
  607. 'source/o2_core/o2/xAction/services/x_organization_assemble_personal.js',
  608. 'source/' + path + '/js/base_work_actions_temp.js',
  609. 'source/' + path + '/js/base.js'
  610. ];
  611. var dest = option.dest+'/' + path + '/';
  612. return gulp.src(src)
  613. .pipe(sourceMap.init())
  614. .pipe(concat('js/base_work.js'))
  615. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  616. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  617. host: option.host,
  618. user: option.user || 'anonymous',
  619. pass: option.pass || '@anonymous',
  620. port: option.port || 21,
  621. remotePath: (option.remotePath || '/') + path
  622. })))
  623. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  624. host: option.host,
  625. user: option.user || 'anonymous',
  626. pass: option.pass || null,
  627. port: option.port || 22,
  628. remotePath: (option.remotePath || '/') + path
  629. })))
  630. .pipe(gulp.dest(dest))
  631. .pipe(uglify())
  632. .pipe(concat('js/base_work.min.js'))
  633. .pipe( sourceMap.write("") )
  634. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  635. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  636. host: option.host,
  637. user: option.user || 'anonymous',
  638. pass: option.pass || '@anonymous',
  639. port: option.port || 21,
  640. remotePath: (option.remotePath || '/') + path
  641. })))
  642. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  643. host: option.host,
  644. user: option.user || 'anonymous',
  645. pass: option.pass || null,
  646. port: option.port || 22,
  647. remotePath: (option.remotePath || '/') + path
  648. })))
  649. .pipe(gulp.dest(dest))
  650. });
  651. }
  652. function createBaseWorkConcatTask(path, isMin, thisOptions){
  653. createBaseWorkConcatActionTask(path);
  654. createBaseWorkConcatStyleTask(path);
  655. createBaseWorkConcatBodyTask(path, isMin, thisOptions);
  656. createBaseWorkConcatDelTempTask(path);
  657. gulp.task( path+".base_work", gulp.series(path+".base_work : action", path+".base_work : style", path+".base_work : concat", path+".base_work : clean"));
  658. }
  659. function createBasePortalConcatStyleTask(path){
  660. gulp.task(path+".base_portal : style", function(){
  661. return gulp.src([
  662. "source/x_component_process_Work/$Main/default/css.wcss",
  663. "source/x_component_portal_Portal/$Main/default/css.wcss",
  664. "source/x_component_process_Xform/$Form/default/css.wcss",
  665. "source/o2_core/o2/widget/$Tab/mobileForm/css.wcss",
  666. "source/o2_core/o2/widget/$Menu/tab/css.wcss"
  667. ])
  668. .pipe(concat_Style())
  669. .pipe(concat('js/base_portal_style_temp.js'))
  670. .pipe(gulp.dest('source/x_desktop/'))
  671. })
  672. }
  673. function createBasePortalConcatActionTask(path){
  674. gulp.task(path+".base_portal : action", function(){
  675. return gulp.src([
  676. "source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  677. "source/o2_core/o2/xAction/services/x_portal_assemble_surface.json",
  678. "source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  679. "source/o2_core/o2/xAction/services/x_query_assemble_surface.json",
  680. "source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  681. "source/o2_core/o2/xAction/services/x_program_center.json",
  682. "source/o2_core/o2/xAction/services/x_organization_assemble_personal.json"
  683. ])
  684. .pipe(concat_Actions())
  685. .pipe(concat('js/base_portal_actions_temp.js'))
  686. .pipe(gulp.dest('source/x_desktop/'))
  687. })
  688. }
  689. function createBasePortalConcatDelTempTask(path) {
  690. gulp.task(path+".base_portal : clean", function(cb){
  691. var dest = [
  692. 'source/'+path+'/js/base_portal_actions_temp.js',
  693. 'source/'+path+'/js/base_portal_style_temp.js'
  694. ];
  695. return del(dest, cb);
  696. });
  697. }
  698. function createBasePortalConcatBodyTask(path, isMin, thisOptions) {
  699. gulp.task(path+".base_portal : concat", function(){
  700. var option = thisOptions || options;
  701. var src = [
  702. 'source/' + path + '/js/base_concat_head.js',
  703. 'source/o2_core/o2/lp/'+(option.lp || 'zh-cn')+'.js',
  704. 'source/' + path + '/js/base_portal_style_temp.js',
  705. 'source/o2_core/o2/widget/Common.js',
  706. 'source/o2_core/o2/widget/Dialog.js',
  707. 'source/o2_core/o2/widget/UUID.js',
  708. 'source/o2_core/o2/widget/Menu.js',
  709. 'source/o2_core/o2/widget/Toolbar.js',
  710. 'source/o2_core/o2/xDesktop/Common.js',
  711. 'source/o2_core/o2/xDesktop/Actions/RestActions.js',
  712. 'source/o2_core/o2/xAction/RestActions.js',
  713. 'source/o2_core/o2/xDesktop/Access.js',
  714. 'source/o2_core/o2/xDesktop/Dialog.js',
  715. 'source/o2_core/o2/xDesktop/Menu.js',
  716. 'source/o2_core/o2/xDesktop/UserData.js',
  717. 'source/x_component_Template/MPopupForm.js',
  718. 'source/o2_core/o2/xDesktop/Authentication.js',
  719. 'source/o2_core/o2/xDesktop/Window.js',
  720. 'source/x_component_Common/Main.js',
  721. 'source/x_component_process_Work/lp/'+(option.lp || 'zh-cn')+'.js',
  722. 'source/x_component_portal_Portal/lp/'+(option.lp || 'zh-cn')+'.js',
  723. 'source/x_component_process_Xform/lp/'+(option.lp || 'zh-cn')+'.js',
  724. 'source/x_component_Selector/lp/'+(option.lp || 'zh-cn')+'.js',
  725. 'source/x_component_portal_Portal/Main.js',
  726. 'source/x_component_Selector/package.js',
  727. 'source/x_component_Selector/Person.js',
  728. 'source/x_component_Selector/Identity.js',
  729. 'source/x_component_Selector/Unit.js',
  730. 'source/x_component_Selector/IdentityWidthDuty.js',
  731. 'source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js',
  732. 'source/x_component_Selector/UnitWithType.js',
  733. 'source/o2_core/o2/xScript/Actions/UnitActions.js',
  734. 'source/o2_core/o2/xScript/Actions/ScriptActions.js',
  735. 'source/o2_core/o2/xScript/Actions/CMSScriptActions.js',
  736. 'source/o2_core/o2/xScript/Actions/PortalScriptActions.js',
  737. 'source/o2_core/o2/xScript/PageEnvironment.js',
  738. 'source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js',
  739. 'source/o2_core/o2/xAction/services/x_cms_assemble_control.js',
  740. 'source/o2_core/o2/xAction/services/x_organization_assemble_control.js',
  741. 'source/o2_core/o2/xAction/services/x_query_assemble_surface.js',
  742. 'source/o2_core/o2/xAction/services/x_organization_assemble_personal.js',
  743. 'source/' + path + '/js/base_portal_actions_temp.js',
  744. 'source/' + path + '/js/base.js'
  745. ];
  746. var dest = option.dest+'/' + path + '/';
  747. return gulp.src(src)
  748. .pipe(sourceMap.init())
  749. .pipe(concat('js/base_portal.js'))
  750. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  751. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  752. host: option.host,
  753. user: option.user || 'anonymous',
  754. pass: option.pass || '@anonymous',
  755. port: option.port || 21,
  756. remotePath: (option.remotePath || '/') + path
  757. })))
  758. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  759. host: option.host,
  760. user: option.user || 'anonymous',
  761. pass: option.pass || null,
  762. port: option.port || 22,
  763. remotePath: (option.remotePath || '/') + path
  764. })))
  765. .pipe(gulp.dest(dest))
  766. // .pipe(gulp.src(src))
  767. .pipe(concat('js/base_portal.min.js'))
  768. .pipe(uglify())
  769. .pipe( sourceMap.write("") )
  770. // .pipe(rename({ extname: '.min.js' }))
  771. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  772. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  773. host: option.host,
  774. user: option.user || 'anonymous',
  775. pass: option.pass || '@anonymous',
  776. port: option.port || 21,
  777. remotePath: (option.remotePath || '/') + path
  778. })))
  779. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  780. host: option.host,
  781. user: option.user || 'anonymous',
  782. pass: option.pass || null,
  783. port: option.port || 22,
  784. remotePath: (option.remotePath || '/') + path
  785. })))
  786. .pipe(gulp.dest(dest))
  787. });
  788. }
  789. function createBasePortalConcatTask(path, isMin, thisOptions){
  790. createBasePortalConcatActionTask(path);
  791. createBasePortalConcatStyleTask(path);
  792. createBasePortalConcatBodyTask(path, isMin, thisOptions);
  793. createBasePortalConcatDelTempTask(path);
  794. gulp.task( path+".base_portal", gulp.series(path+".base_portal : action", path+".base_portal : style", path+".base_portal : concat", path+".base_portal : clean"));
  795. }
  796. function createBaseDocumentConcatActionTask(path){
  797. gulp.task(path+".base_document : action", function(){
  798. return gulp.src([
  799. "source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  800. "source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  801. "source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  802. "source/o2_core/o2/xAction/services/x_program_center.json",
  803. "source/o2_core/o2/xAction/services/x_organization_assemble_personal.json"
  804. ])
  805. .pipe(concat_Actions())
  806. .pipe(concat('js/base_document_actions_temp.js'))
  807. .pipe(gulp.dest('source/x_desktop/'))
  808. })
  809. }
  810. function createBaseDocumentConcatStyleTask(path){
  811. gulp.task(path+".base_document : style", function(){
  812. return gulp.src([
  813. "source/x_component_cms_Document/$Main/default/css.wcss",
  814. "source/x_component_cms_Xform/$Form/default/css.wcss",
  815. "source/o2_core/o2/widget/$AttachmentController/default/css.wcss"
  816. ])
  817. .pipe(concat_Style())
  818. .pipe(concat('js/base_document_style_temp.js'))
  819. .pipe(gulp.dest('source/x_desktop/'))
  820. })
  821. }
  822. function createBaseDocumentConcatBodyTask(path, isMin, thisOptions) {
  823. gulp.task(path+".base_document : concat", function(){
  824. var option = thisOptions || options;
  825. var src = [
  826. 'source/' + path + '/js/base_concat_head.js',
  827. 'source/o2_core/o2/lp/'+(option.lp || 'zh-cn')+'.js',
  828. 'source/' + path + '/js/base_document_style_temp.js',
  829. 'source/o2_core/o2/widget/Common.js',
  830. 'source/o2_core/o2/widget/UUID.js',
  831. 'source/o2_core/o2/widget/Menu.js',
  832. 'source/o2_core/o2/widget/Mask.js',
  833. 'source/o2_core/o2/xDesktop/Common.js',
  834. 'source/o2_core/o2/xDesktop/Actions/RestActions.js',
  835. 'source/o2_core/o2/xAction/RestActions.js',
  836. 'source/o2_core/o2/xDesktop/Access.js',
  837. 'source/o2_core/o2/xDesktop/Dialog.js',
  838. 'source/o2_core/o2/xDesktop/Menu.js',
  839. 'source/o2_core/o2/xDesktop/UserData.js',
  840. 'source/o2_core/o2/xDesktop/Authentication.js',
  841. 'source/o2_core/o2/xDesktop/Window.js',
  842. 'source/x_component_Common/Main.js',
  843. 'source/x_component_cms_Document/lp/'+(option.lp || 'zh-cn')+'.js',
  844. 'source/x_component_process_Xform/lp/'+(option.lp || 'zh-cn')+'.js',
  845. 'source/x_component_Selector/lp/'+(option.lp || 'zh-cn')+'.js',
  846. 'source/x_component_cms_xform/lp/'+(option.lp || 'zh-cn')+'.js',
  847. 'source/x_component_cms_Document/Main.js',
  848. 'source/x_component_Selector/package.js',
  849. 'source/o2_core/o2/xScript/Actions/UnitActions.js',
  850. 'source/o2_core/o2/xScript/Actions/CMSScriptActions.js',
  851. 'source/o2_core/o2/xScript/CMSEnvironment.js',
  852. 'source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js',
  853. 'source/o2_core/o2/xAction/services/x_cms_assemble_control.js',
  854. 'source/o2_core/o2/xAction/services/x_organization_assemble_control.js',
  855. 'source/o2_core/o2/xAction/services/x_organization_assemble_personal.js',
  856. 'source/' + path + '/js/base_document_actions_temp.js',
  857. 'source/' + path + '/js/base.js'
  858. ];
  859. var dest = option.dest+'/' + path + '/';
  860. return gulp.src(src)
  861. .pipe(sourceMap.init())
  862. .pipe(concat('js/base_document.js'))
  863. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  864. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  865. host: option.host,
  866. user: option.user || 'anonymous',
  867. pass: option.pass || '@anonymous',
  868. port: option.port || 21,
  869. remotePath: (option.remotePath || '/') + path
  870. })))
  871. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  872. host: option.host,
  873. user: option.user || 'anonymous',
  874. pass: option.pass || null,
  875. port: option.port || 22,
  876. remotePath: (option.remotePath || '/') + path
  877. })))
  878. .pipe(gulp.dest(dest))
  879. // .pipe(gulp.src(src))
  880. .pipe(concat('js/base_document.min.js'))
  881. .pipe(uglify())
  882. .pipe( sourceMap.write("") )
  883. // .pipe(rename({ extname: '.min.js' }))
  884. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  885. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  886. host: option.host,
  887. user: option.user || 'anonymous',
  888. pass: option.pass || '@anonymous',
  889. port: option.port || 21,
  890. remotePath: (option.remotePath || '/') + path
  891. })))
  892. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  893. host: option.host,
  894. user: option.user || 'anonymous',
  895. pass: option.pass || null,
  896. port: option.port || 22,
  897. remotePath: (option.remotePath || '/') + path
  898. })))
  899. .pipe(gulp.dest(dest))
  900. });
  901. }
  902. function createBaseDocumentConcatDelTempTask(path) {
  903. gulp.task(path+".base_document : clean", function(cb){
  904. var dest = [
  905. 'source/'+path+'/js/base_document_actions_temp.js',
  906. 'source/'+path+'/js/base_document_style_temp.js'
  907. ];
  908. return del(dest, cb);
  909. });
  910. }
  911. function createBaseDocumentConcatTask(path, isMin, thisOptions){
  912. createBaseDocumentConcatActionTask(path);
  913. createBaseDocumentConcatStyleTask(path);
  914. createBaseDocumentConcatBodyTask(path, isMin, thisOptions);
  915. createBaseDocumentConcatDelTempTask(path);
  916. gulp.task( path+".base_document", gulp.series(path+".base_document : action", path+".base_document : style", path+".base_document : concat", path+".base_document : clean"));
  917. }
  918. function createBaseConcatTask(path, isMin, thisOptions){
  919. gulp.task(path+".base", function(){
  920. var option = thisOptions || options;
  921. var src = [
  922. 'source/' + path + '/js/base.js'
  923. ];
  924. var dest = option.dest+'/' + path + '/';
  925. return gulp.src(src)
  926. .pipe(sourceMap.init())
  927. .pipe(concat('js/base.js'))
  928. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  929. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  930. host: option.host,
  931. user: option.user || 'anonymous',
  932. pass: option.pass || '@anonymous',
  933. port: option.port || 21,
  934. remotePath: (option.remotePath || '/') + path
  935. })))
  936. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  937. host: option.host,
  938. user: option.user || 'anonymous',
  939. pass: option.pass || null,
  940. port: option.port || 22,
  941. remotePath: (option.remotePath || '/') + path
  942. })))
  943. .pipe(gulp.dest(dest))
  944. // .pipe(gulp.src(src))
  945. .pipe(concat('js/base.min.js'))
  946. .pipe(uglify())
  947. .pipe( sourceMap.write("") )
  948. // .pipe(rename({ extname: '.min.js' }))
  949. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  950. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  951. host: option.host,
  952. user: option.user || 'anonymous',
  953. pass: option.pass || '@anonymous',
  954. port: option.port || 21,
  955. remotePath: (option.remotePath || '/') + path
  956. })))
  957. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  958. host: option.host,
  959. user: option.user || 'anonymous',
  960. pass: option.pass || null,
  961. port: option.port || 22,
  962. remotePath: (option.remotePath || '/') + path
  963. })))
  964. .pipe(gulp.dest(dest))
  965. });
  966. }
  967. function getAppTask(path, isMin, thisOptions) {
  968. if (path==="x_component_process_Xform") {
  969. createDefaultTask(path, isMin, thisOptions);
  970. createXFormConcatTask(path, isMin, thisOptions);
  971. return gulp.series(path, path + " : concat");
  972. }else if (path==="x_component_cms_Xform"){
  973. createDefaultTask(path, isMin, thisOptions);
  974. createCMSXFormConcatTask(path, isMin, thisOptions);
  975. return gulp.series(path, path+" : concat");
  976. }else if (path==="o2_core"){
  977. createDefaultTask(path, isMin, thisOptions);
  978. createO2ConcatTask(path, isMin, thisOptions);
  979. return gulp.series(path, path+" : concat", path+".xDesktop : concat", path+" : bundle");
  980. }else if (path==="x_desktop") {
  981. createDefaultTask(path, isMin, thisOptions);
  982. createBaseWorkConcatTask(path, isMin, thisOptions);
  983. createBasePortalConcatTask(path, isMin, thisOptions);
  984. createBaseDocumentConcatTask(path, isMin, thisOptions);
  985. createBaseConcatTask(path, isMin, thisOptions);
  986. return gulp.series(path, path+".base_work", path+".base_portal", path+".base");
  987. //return gulp.series(path, path+".base_work : concat");
  988. }else{
  989. createDefaultTask(path, isMin, thisOptions);
  990. return gulp.series(path);
  991. }
  992. }
  993. //var taskObj = {};
  994. apps.map(function (app) {
  995. var taskName;
  996. var isMin = (app.tasks.indexOf("min")!==-1);
  997. taskName = app.folder;
  998. appTasks.push(taskName);
  999. gulp.task(taskName, getAppTask(app.folder, isMin));
  1000. // //var isMin = (app.tasks.indexOf("min")!==-1);
  1001. // taskName = app.folder+"_release";
  1002. // //appTasks.push(taskName);
  1003. // gulp.task(taskName, getAppTask(app.folder, isMin, release_options));
  1004. });
  1005. // Object.keys(taskObj).map(function(k){
  1006. // exports[k] = parallel(taskObj[k]);
  1007. // });
  1008. //exports[app.folder] = parallel(minTask, moveTask);
  1009. function getCleanTask(path) {
  1010. return function (cb) {
  1011. if (path){
  1012. var dest = (path=="/") ? options.dest+"/" : options.dest+'/' + path + '/';
  1013. gutil.log("Clean", ":", gutil.colors.red(dest));
  1014. del.sync(dest, cb);
  1015. cb();
  1016. }else{
  1017. cb();
  1018. }
  1019. }
  1020. }
  1021. function cleanRemoteFtp(f, cb) {
  1022. var file = options.remotePath + f;
  1023. var ftp = new JSFtp({
  1024. host: options.host,
  1025. user: options.user || 'anonymous',
  1026. pass: options.pass || null,
  1027. port: options.port || 21
  1028. });
  1029. ftp.raw('dele ' + file, function (err) {
  1030. if (err) { cb(); return; }
  1031. if (file.substring(file.length - 3).toLowerCase() == ".js") {
  1032. file = file.replace('.js', ".min.js");
  1033. ftp.raw('dele ' + file, function (err) {
  1034. if (err) { cb(); return; }
  1035. if (file.indexOf("/") != -1) {
  1036. var p = file.substring(0, file.lastIndexOf("/"));
  1037. ftp.raw('rmd ' + p, function (err) {
  1038. if (err) { cb(); return; }
  1039. ftp.raw.quit();
  1040. cb();
  1041. });
  1042. }
  1043. });
  1044. } else {
  1045. if (file.indexOf("/") != -1) {
  1046. var pPath = file.substring(0, file.lastIndexOf("/"));
  1047. ftp.raw('rmd ' + pPath, function (err) {
  1048. if (err) { cb(); return; }
  1049. ftp.raw.quit();
  1050. cb();
  1051. });
  1052. }
  1053. }
  1054. });
  1055. }
  1056. function cleanRemoteLocal(f, cb) {
  1057. var file = options.location + f;
  1058. del(file, { force: true, dryRun: true }, function () {
  1059. if (file.substring(file.length - 3).toLowerCase() == ".js") {
  1060. var minfile = file.replace('.js', ".min.js");
  1061. del(minfile, { force: true, dryRun: true }, function () {
  1062. var p = file.substring(0, file.lastIndexOf("/"));
  1063. fs.rmdir(p, function (err) {
  1064. if (err) { }
  1065. cb();
  1066. })
  1067. });
  1068. } else {
  1069. var p = file.substring(0, file.lastIndexOf("/"));
  1070. fs.rmdir(p, function (err) {
  1071. if (err) { }
  1072. cb();
  1073. })
  1074. }
  1075. });
  1076. }
  1077. function getCleanRemoteTask(path) {
  1078. return function (cb) {
  1079. if (options.upload) {
  1080. var file = path.replace(/\\/g, "/");
  1081. file = file.substring(file.indexOf("source/") + 7);
  1082. if (options.upload == 'local' && options.location != '') cleanRemoteLocal(file, cb);
  1083. if (options.upload == 'ftp' && options.host != '') cleanRemoteFtp(file, cb);
  1084. } else {
  1085. if (cb) cb();
  1086. }
  1087. }
  1088. }
  1089. function getWatchTask(path) {
  1090. return (path) ? function (cb) {
  1091. gutil.log("watch", ":", gutil.colors.green(path, "is watching ..."));
  1092. gulp.watch(['source/' + path + '/**/*', "!./**/test/**"], { "events": ['addDir', 'add', 'change'] }, gulp.parallel([path]));
  1093. } : function(cb){cb();};
  1094. }
  1095. gulp.task("clean", getCleanTask(options.src))
  1096. gulp.task("watch", getWatchTask(options.src));
  1097. gulp.task("index", function () {
  1098. var src = ['source/favicon.ico', 'source/index.html'];
  1099. var dest = options.dest;
  1100. return gulp.src(src)
  1101. .pipe(changed(dest))
  1102. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + '/')))
  1103. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  1104. host: options.host,
  1105. user: options.user || 'anonymous',
  1106. pass: options.pass || '@anonymous',
  1107. port: options.port || 21,
  1108. remotePath: (options.remotePath || '/')
  1109. })))
  1110. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), ftp({
  1111. host: options.host,
  1112. user: options.user || 'anonymous',
  1113. pass: options.pass || null,
  1114. port: options.port || 22,
  1115. remotePath: (options.remotePath || '/')
  1116. })))
  1117. .pipe(gulp.dest(dest))
  1118. .pipe(gutil.noop());
  1119. });
  1120. gulp.task("cleanAll", getCleanTask('/'));
  1121. gulp.task("o2:new-v:html", function () {
  1122. var path = "x_desktop";
  1123. var src = '/source/x_desktop/*.html';
  1124. var dest = options.dest + '/x_desktop/';
  1125. return gulp.src(src)
  1126. .pipe(assetRev())
  1127. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
  1128. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  1129. host: options.host,
  1130. user: options.user || 'anonymous',
  1131. pass: options.pass || '@anonymous',
  1132. port: options.port || 21,
  1133. remotePath: (options.remotePath || '/') + path
  1134. })))
  1135. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
  1136. host: options.host,
  1137. user: options.user || 'anonymous',
  1138. pass: options.pass || null,
  1139. port: options.port || 22,
  1140. remotePath: (options.remotePath || '/') + path
  1141. })))
  1142. .pipe(gulp.dest(dest))
  1143. .pipe(gutil.noop());
  1144. });
  1145. gulp.task("o2:new-v:o2", function () {
  1146. var path = "o2_core";
  1147. var src = options.dest +'/o2_core/o2.js';
  1148. var dest = options.dest +'/o2_core/';
  1149. return gulp.src(src)
  1150. .pipe(assetRev())
  1151. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
  1152. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  1153. host: options.host,
  1154. user: options.user || 'anonymous',
  1155. pass: options.pass || '@anonymous',
  1156. port: options.port || 21,
  1157. remotePath: (options.remotePath || '/') + path
  1158. })))
  1159. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
  1160. host: options.host,
  1161. user: options.user || 'anonymous',
  1162. pass: options.pass || null,
  1163. port: options.port || 22,
  1164. remotePath: (options.remotePath || '/') + path
  1165. })))
  1166. .pipe(gulp.dest(dest))
  1167. .pipe(uglify())
  1168. .pipe(rename({ extname: '.min.js' }))
  1169. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
  1170. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  1171. host: options.host,
  1172. user: options.user || 'anonymous',
  1173. pass: options.pass || '@anonymous',
  1174. port: options.port || 21,
  1175. remotePath: (options.remotePath || '/') + path
  1176. })))
  1177. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
  1178. host: options.host,
  1179. user: options.user || 'anonymous',
  1180. pass: options.pass || null,
  1181. port: options.port || 22,
  1182. remotePath: (options.remotePath || '/') + path
  1183. })))
  1184. .pipe(gulp.dest(dest))
  1185. .pipe(gutil.noop());
  1186. });
  1187. gulp.task("o2:new-v", gulp.parallel("o2:new-v:o2", "o2:new-v:html"));
  1188. gulp.task("git_clean", function (cb) {
  1189. var dest = 'D:/O2/github/huqi1980/o2oa/o2web/source/';
  1190. del(dest, { dryRun: true, force: true }, cb);
  1191. });
  1192. gulp.task("git_dest", function () {
  1193. var dest = "D:/O2/github/huqi1980/o2oa/o2web/source";
  1194. return gulp.src(["source/**/*", "!./**/test/**"])
  1195. .pipe(changed(dest))
  1196. .pipe(gulp.dest(dest))
  1197. });
  1198. gulp.task("git", gulp.series('git_clean', 'git_dest'));
  1199. gulp.task("default", gulp.series(gulp.parallel(appTasks, 'index'), "o2:new-v"));
  1200. function build(){
  1201. options.ev = "p";
  1202. options.upload = o_options.upload || "";
  1203. options.location = o_options.location || uploadOptions.location;
  1204. options.host = o_options.host || uploadOptions.host;
  1205. options.user = o_options.user || uploadOptions.user;
  1206. options.pass = o_options.pass || uploadOptions.pass;
  1207. options.port = o_options.port || uploadOptions.port;
  1208. options.remotePath = o_options.remotePath || uploadOptions.remotePath;
  1209. options.dest = o_options.dest || uploadOptions.dest || "dest";
  1210. };
  1211. gulp.task("build", gulp.series("clean", gulp.parallel(appTasks, 'index'), "o2:new-v"))