gulpfile.js 50 KB

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