gulpfile.js 57 KB

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