gulpfile.js 49 KB

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