gulpfile.js 56 KB

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