gulpfile.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  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 assetRev = require('gulp-tm-asset-rev');
  20. var apps = require('./gulpapps.js');
  21. var ftpconfig = require('./gulpconfig.js');
  22. var o_options = minimist(process.argv.slice(2), {//upload: local ftp or sftp
  23. string: ["ev", "upload", "location", "host", "user", "pass", "port", "remotePath", "dest", "src", "lp"]
  24. });
  25. function getEvOptions(ev){
  26. options.ev = ev;
  27. return (ftpconfig[ev]) || {
  28. 'location': '',
  29. 'host': '',
  30. 'user': '',
  31. 'pass': '',
  32. "port": null,
  33. "remotePath": "",
  34. "dest": "dest",
  35. "upload": ""
  36. }
  37. }
  38. function setOptions(op1, op2){
  39. if (!op2) op2 = {};
  40. options.upload = op1.upload || op2.upload || "";
  41. options.location = op1.location || op2.location || "";
  42. options.host = op1.host || op2.host || "";
  43. options.user = op1.user || op2.user || "";
  44. options.pass = op1.pass || op2.pass || "";
  45. options.port = op1.port || op2.port || "";
  46. options.remotePath = op1.remotePath || op2.remotePath || "";
  47. options.dest = op1.dest || op2.dest || "dest";
  48. options.lp = op1.lp || op2.lp || "zh-cn";
  49. }
  50. var options = {};
  51. setOptions(o_options, getEvOptions(o_options.ev));
  52. var appTasks = [];
  53. function createDefaultTask(path, isMin, thisOptions) {
  54. gulp.task(path, function (cb) {
  55. //var srcFile = 'source/' + path + '/**/*';
  56. var option = thisOptions || options;
  57. var src;
  58. var dest = option.dest+'/' + path + '/';
  59. let ev = option.ev
  60. var evList = Object.keys(ftpconfig).map((i)=>{ return (i==ev) ? "*"+i : i; });
  61. if (isMin){
  62. var src_min = ['source/' + path + '/**/*.js', '!**/*.spec.js', '!**/test/**'];
  63. var src_move = ['source/' + path + '/**/*', '!**/*.spec.js', '!**/test/**'];
  64. gutil.log("Move-Uglify", ":", gutil.colors.green(gutil.colors.blue(path), gutil.colors.white('->'), dest));
  65. return gulp.src(src_min)
  66. .pipe(changed(dest))
  67. .pipe(uglify())
  68. .pipe(rename({ extname: '.min.js' }))
  69. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  70. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  71. host: option.host,
  72. user: option.user || 'anonymous',
  73. pass: option.pass || '@anonymous',
  74. port: option.port || 21,
  75. remotePath: (option.remotePath || '/') + path
  76. })))
  77. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  78. host: option.host,
  79. user: option.user || 'anonymous',
  80. pass: option.pass || null,
  81. port: option.port || 22,
  82. remotePath: (option.remotePath || '/') + path
  83. })))
  84. .pipe(gulpif((option.ev == "dev" || option.ev == "pro") ,gulp.dest(dest)))
  85. .pipe(gulp.src(src_move))
  86. .pipe(changed(dest))
  87. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  88. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  89. host: option.host,
  90. user: option.user || 'anonymous',
  91. pass: option.pass || '@anonymous',
  92. port: option.port || 21,
  93. remotePath: (option.remotePath || '/') + path
  94. })))
  95. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  96. host: option.host,
  97. user: option.user || 'anonymous',
  98. pass: option.pass || null,
  99. port: option.port || 22,
  100. remotePath: (option.remotePath || '/') + path
  101. })))
  102. .pipe(gulp.dest(dest))
  103. .pipe(gutil.noop());
  104. }else{
  105. src = ['source/' + path + '/**/*', '!**/*.spec.js', '!**/test/**'];
  106. gutil.log("Move", ":", gutil.colors.green(gutil.colors.blue(path), gutil.colors.white('->'), dest));
  107. return gulp.src(src)
  108. .pipe(changed(dest))
  109. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  110. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  111. host: option.host,
  112. user: option.user || 'anonymous',
  113. pass: option.pass || '@anonymous',
  114. port: option.port || 21,
  115. remotePath: (option.remotePath || '/') + path
  116. })))
  117. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  118. host: option.host,
  119. user: option.user || 'anonymous',
  120. pass: option.pass || null,
  121. port: option.port || 22,
  122. remotePath: (option.remotePath || '/') + path
  123. })))
  124. .pipe(gulp.dest(dest))
  125. .pipe(gutil.noop());
  126. }
  127. });
  128. }
  129. function createXFormConcatTask(path, isMin, thisOptions) {
  130. gulp.task(path+" : concat", function(){
  131. var option = thisOptions || options;
  132. var src = [
  133. 'source/o2_core/o2/widget/AttachmentController.js',
  134. 'source/o2_core/o2/xScript/Macro.js',
  135. 'source/o2_core/o2/widget/Tab.js',
  136. 'source/o2_core/o2/widget/O2Identity.js',
  137. 'source/' + path + '/Form.js',
  138. 'source/' + path + '/$Module.js',
  139. 'source/' + path + '/$Input.js',
  140. 'source/' + path + '/Div.js',
  141. 'source/' + path + '/Combox.js',
  142. 'source/' + path + '/DatagridMobile.js',
  143. 'source/' + path + '/DatagridPC.js',
  144. 'source/' + path + '/Textfield.js',
  145. 'source/' + path + '/Personfield.js',
  146. 'source/' + path + '/Button.js',
  147. 'source/' + path + '/ViewSelector.js',
  148. 'source/' + path + '/*.js',
  149. 'source/x_component_process_Work/Processor.js',
  150. '!source/' + path + '/Office.js'
  151. ];
  152. var dest = option.dest+'/' + path + '/';
  153. return gulp.src(src)
  154. .pipe(concat('$all.js'))
  155. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  156. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  157. host: option.host,
  158. user: option.user || 'anonymous',
  159. pass: option.pass || '@anonymous',
  160. port: option.port || 21,
  161. remotePath: (option.remotePath || '/') + path
  162. })))
  163. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  164. host: option.host,
  165. user: option.user || 'anonymous',
  166. pass: option.pass || null,
  167. port: option.port || 22,
  168. remotePath: (option.remotePath || '/') + path
  169. })))
  170. .pipe(gulp.dest(dest))
  171. .pipe(uglify())
  172. .pipe(rename({ extname: '.min.js' }))
  173. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  174. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  175. host: option.host,
  176. user: option.user || 'anonymous',
  177. pass: option.pass || '@anonymous',
  178. port: option.port || 21,
  179. remotePath: (option.remotePath || '/') + path
  180. })))
  181. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  182. host: option.host,
  183. user: option.user || 'anonymous',
  184. pass: option.pass || null,
  185. port: option.port || 22,
  186. remotePath: (option.remotePath || '/') + path
  187. })))
  188. .pipe(gulp.dest(dest))
  189. });
  190. }
  191. function createO2ConcatTask(path, isMin, thisOptions) {
  192. gulp.task(path+" : concat", function(){
  193. var option = thisOptions || options;
  194. var src = [
  195. 'source/o2_lib/mootools/mootools-1.6.0_all.js',
  196. 'source/o2_lib/mootools/plugin/mBox.js',
  197. 'source/' + path + '/o2.js'
  198. ];
  199. var dest = option.dest+'/' + path + '/';
  200. return gulp.src(src)
  201. .pipe(concat('o2.js'))
  202. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  203. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  204. host: option.host,
  205. user: option.user || 'anonymous',
  206. pass: option.pass || '@anonymous',
  207. port: option.port || 21,
  208. remotePath: (option.remotePath || '/') + path
  209. })))
  210. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  211. host: option.host,
  212. user: option.user || 'anonymous',
  213. pass: option.pass || null,
  214. port: option.port || 22,
  215. remotePath: (option.remotePath || '/') + path
  216. })))
  217. .pipe(gulp.dest(dest))
  218. .pipe(uglify())
  219. .pipe(rename({ extname: '.min.js' }))
  220. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  221. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  222. host: option.host,
  223. user: option.user || 'anonymous',
  224. pass: option.pass || '@anonymous',
  225. port: option.port || 21,
  226. remotePath: (option.remotePath || '/') + path
  227. })))
  228. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  229. host: option.host,
  230. user: option.user || 'anonymous',
  231. pass: option.pass || null,
  232. port: option.port || 22,
  233. remotePath: (option.remotePath || '/') + path
  234. })))
  235. .pipe(gulp.dest(dest))
  236. });
  237. gulp.task(path+".xDesktop : concat", function(){
  238. var option = thisOptions || options;
  239. var src = [
  240. 'source/'+path+'/o2/widget/Common.js',
  241. 'source/'+path+'/o2/widget/Dialog.js',
  242. 'source/'+path+'/o2/widget/UUID.js',
  243. 'source/'+path+'/o2/xDesktop/Common.js',
  244. 'source/'+path+'/o2/xDesktop/Actions/RestActions.js',
  245. 'source/'+path+'/o2/xAction/RestActions.js',
  246. 'source/'+path+'/o2/xDesktop/Access.js',
  247. 'source/'+path+'/o2/xDesktop/Dialog.js',
  248. 'source/'+path+'/o2/xDesktop/Menu.js',
  249. 'source/'+path+'/o2/xDesktop/UserData.js',
  250. 'source/x_component_Template/MPopupForm.js',
  251. 'source/'+path+'/o2/xDesktop/Authentication.js',
  252. 'source/'+path+'/o2/xDesktop/Dialog.js',
  253. 'source/'+path+'/o2/xDesktop/Window.js',
  254. 'source/x_component_Common/Main.js'
  255. ];
  256. var dest = option.dest+'/' + path + '/o2/xDesktop/';
  257. return gulp.src(src)
  258. .pipe(concat('$all.js'))
  259. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/o2/xDesktop/')))
  260. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  261. host: option.host,
  262. user: option.user || 'anonymous',
  263. pass: option.pass || '@anonymous',
  264. port: option.port || 21,
  265. remotePath: (option.remotePath || '/') + path+"/o2/xDesktop/"
  266. })))
  267. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  268. host: option.host,
  269. user: option.user || 'anonymous',
  270. pass: option.pass || null,
  271. port: option.port || 22,
  272. remotePath: (option.remotePath || '/') + path+"/o2/xDesktop/"
  273. })))
  274. .pipe(gulp.dest(dest))
  275. .pipe(uglify())
  276. .pipe(rename({ extname: '.min.js' }))
  277. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/o2/xDesktop/')))
  278. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  279. host: option.host,
  280. user: option.user || 'anonymous',
  281. pass: option.pass || '@anonymous',
  282. port: option.port || 21,
  283. remotePath: (option.remotePath || '/') + path+"/o2/xDesktop/"
  284. })))
  285. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  286. host: option.host,
  287. user: option.user || 'anonymous',
  288. pass: option.pass || null,
  289. port: option.port || 22,
  290. remotePath: (option.remotePath || '/') + path+"/o2/xDesktop/"
  291. })))
  292. .pipe(gulp.dest(dest))
  293. });
  294. gulp.task(path+" : bundle", function(){
  295. var option = thisOptions || options;
  296. var src = [
  297. 'source/o2_lib/mootools/mootools-1.6.0_all.js',
  298. 'source/o2_lib/mootools/plugin/mBox.js',
  299. 'source/' + path + '/o2.js',
  300. 'source/x_desktop/js/base.js',
  301. "source/o2_core/o2/framework.js"
  302. ];
  303. var dest = option.dest+'/' + path + '/';
  304. return gulp.src(src)
  305. .pipe(concat('bundle.js'))
  306. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  307. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  308. host: option.host,
  309. user: option.user || 'anonymous',
  310. pass: option.pass || '@anonymous',
  311. port: option.port || 21,
  312. remotePath: (option.remotePath || '/') + path
  313. })))
  314. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  315. host: option.host,
  316. user: option.user || 'anonymous',
  317. pass: option.pass || null,
  318. port: option.port || 22,
  319. remotePath: (option.remotePath || '/') + path
  320. })))
  321. .pipe(gulp.dest(dest))
  322. .pipe(uglify())
  323. .pipe(rename({ extname: '.min.js' }))
  324. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  325. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  326. host: option.host,
  327. user: option.user || 'anonymous',
  328. pass: option.pass || '@anonymous',
  329. port: option.port || 21,
  330. remotePath: (option.remotePath || '/') + path
  331. })))
  332. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  333. host: option.host,
  334. user: option.user || 'anonymous',
  335. pass: option.pass || null,
  336. port: option.port || 22,
  337. remotePath: (option.remotePath || '/') + path
  338. })))
  339. .pipe(gulp.dest(dest))
  340. });
  341. }
  342. function concat_Actions(){
  343. return through2.obj(function (file, enc, cb) {
  344. debugger;
  345. if (file.isNull()) {
  346. this.push(file);
  347. return cb();
  348. }
  349. if (file.isStream()) {
  350. this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
  351. return cb();
  352. }
  353. var content = file.contents.toString();
  354. var o = path.parse(file.path);
  355. var name = o.name;
  356. content = "var actionJson = "+content;
  357. content = content+"\nif (!o2.xAction.RestActions.Action[\""+name+"\"]) o2.xAction.RestActions.Action[\""+name+"\"] = new Class({Extends: o2.xAction.RestActions.Action});";
  358. content = content+"\no2.Actions.actions[\""+name+"\"] = new o2.xAction.RestActions.Action[\""+name+"\"](\""+name+"\", actionJson);";
  359. file.contents = new Buffer.from(content);
  360. this.push(file);
  361. cb();
  362. });
  363. }
  364. function concat_Style(){
  365. return through2.obj(function (file, enc, cb) {
  366. if (file.isNull()) {
  367. this.push(file);
  368. return cb();
  369. }
  370. if (file.isStream()) {
  371. this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
  372. return cb();
  373. }
  374. var content = file.contents.toString();
  375. name = ".."+file.path.replace(process.cwd(), "").replace(/\\/g, "/").substring("/source".length);
  376. content = "var csskey = encodeURIComponent(\""+name+"\");\no2.widget.css[csskey]="+content;
  377. file.contents = new Buffer.from(content);
  378. this.push(file);
  379. cb();
  380. });
  381. }
  382. function createBaseWorkConcatStyleTask(path){
  383. gulp.task(path+".base_work : style", function(){
  384. return gulp.src([
  385. "source/x_component_process_Work/$Main/default/css.wcss",
  386. "source/x_component_process_Xform/$Form/default/css.wcss",
  387. "source/o2_core/o2/widget/$Tab/mobileForm/css.wcss",
  388. "source/o2_core/o2/widget/$Menu/tab/css.wcss"
  389. ])
  390. .pipe(concat_Style())
  391. .pipe(concat('js/base_work_style_temp.js'))
  392. .pipe(gulp.dest('source/x_desktop/'))
  393. })
  394. }
  395. function createBaseWorkConcatActionTask(path){
  396. gulp.task(path+".base_work : action", function(){
  397. return gulp.src([
  398. "source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  399. "source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.json",
  400. "source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  401. "source/o2_core/o2/xAction/services/x_query_assemble_surface.json",
  402. "source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  403. "source/o2_core/o2/xAction/services/x_program_center.json",
  404. "source/o2_core/o2/xAction/services/x_organization_assemble_personal.json"
  405. ])
  406. .pipe(concat_Actions())
  407. .pipe(concat('js/base_work_actions_temp.js'))
  408. .pipe(gulp.dest('source/x_desktop/'))
  409. })
  410. }
  411. function createBaseWorkConcatDelTempTask(path) {
  412. gulp.task(path+".base_work : clean", function(cb){
  413. var dest = [
  414. 'source/'+path+'/js/base_work_actions_temp.js',
  415. 'source/'+path+'/js/base_work_style_temp.js'
  416. ];
  417. return del(dest, cb);
  418. });
  419. }
  420. function createBaseWorkConcatBodyTask(path, isMin, thisOptions) {
  421. gulp.task(path+".base_work : concat", function(){
  422. var option = thisOptions || options;
  423. var src = [
  424. 'source/' + path + '/js/base_concat_head.js',
  425. 'source/o2_core/o2/lp/'+(option.lp || 'zh-cn')+'.js',
  426. 'source/x_component_process_Work/lp/'+(option.lp || 'zh-cn')+'.js',
  427. 'source/x_component_process_Xform/lp/'+(option.lp || 'zh-cn')+'.js',
  428. 'source/x_component_Selector/lp/'+(option.lp || 'zh-cn')+'.js',
  429. 'source/' + path + '/js/base_work_style_temp.js',
  430. 'source/o2_core/o2/widget/Common.js',
  431. 'source/o2_core/o2/widget/Dialog.js',
  432. 'source/o2_core/o2/widget/UUID.js',
  433. 'source/o2_core/o2/widget/Menu.js',
  434. 'source/o2_core/o2/widget/Toolbar.js',
  435. 'source/o2_core/o2/xDesktop/Common.js',
  436. 'source/o2_core/o2/xDesktop/Actions/RestActions.js',
  437. 'source/o2_core/o2/xAction/RestActions.js',
  438. 'source/o2_core/o2/xDesktop/Access.js',
  439. 'source/o2_core/o2/xDesktop/Dialog.js',
  440. 'source/o2_core/o2/xDesktop/Menu.js',
  441. 'source/o2_core/o2/xDesktop/UserData.js',
  442. 'source/x_component_Template/MPopupForm.js',
  443. 'source/o2_core/o2/xDesktop/Authentication.js',
  444. 'source/o2_core/o2/xDesktop/Window.js',
  445. 'source/x_component_Common/Main.js',
  446. 'source/x_component_process_Work/Main.js',
  447. 'source/x_component_Selector/package.js',
  448. 'source/x_component_Selector/Person.js',
  449. 'source/x_component_Selector/Identity.js',
  450. 'source/x_component_Selector/Unit.js',
  451. 'source/x_component_Selector/IdentityWidthDuty.js',
  452. 'source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js',
  453. 'source/x_component_Selector/UnitWithType.js',
  454. 'source/o2_core/o2/xScript/Actions/UnitActions.js',
  455. 'source/o2_core/o2/xScript/Actions/ScriptActions.js',
  456. 'source/o2_core/o2/xScript/Actions/CMSScriptActions.js',
  457. 'source/o2_core/o2/xScript/Actions/PortalScriptActions.js',
  458. 'source/o2_core/o2/xScript/Environment.js',
  459. 'source/x_component_Template/MTooltips.js',
  460. 'source/x_component_Template/MSelector.js',
  461. 'source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js',
  462. 'source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.js',
  463. 'source/o2_core/o2/xAction/services/x_cms_assemble_control.js',
  464. 'source/o2_core/o2/xAction/services/x_organization_assemble_control.js',
  465. 'source/o2_core/o2/xAction/services/x_query_assemble_surface.js',
  466. 'source/o2_core/o2/xAction/services/x_organization_assemble_personal.js',
  467. 'source/' + path + '/js/base_work_actions_temp.js',
  468. 'source/' + path + '/js/base.js'
  469. ];
  470. var dest = option.dest+'/' + path + '/';
  471. return gulp.src(src)
  472. .pipe(concat('js/base_work.js'))
  473. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  474. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  475. host: option.host,
  476. user: option.user || 'anonymous',
  477. pass: option.pass || '@anonymous',
  478. port: option.port || 21,
  479. remotePath: (option.remotePath || '/') + path
  480. })))
  481. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  482. host: option.host,
  483. user: option.user || 'anonymous',
  484. pass: option.pass || null,
  485. port: option.port || 22,
  486. remotePath: (option.remotePath || '/') + path
  487. })))
  488. .pipe(gulp.dest(dest))
  489. .pipe(uglify())
  490. .pipe(rename({ extname: '.min.js' }))
  491. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  492. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  493. host: option.host,
  494. user: option.user || 'anonymous',
  495. pass: option.pass || '@anonymous',
  496. port: option.port || 21,
  497. remotePath: (option.remotePath || '/') + path
  498. })))
  499. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  500. host: option.host,
  501. user: option.user || 'anonymous',
  502. pass: option.pass || null,
  503. port: option.port || 22,
  504. remotePath: (option.remotePath || '/') + path
  505. })))
  506. .pipe(gulp.dest(dest))
  507. });
  508. }
  509. function createBaseWorkConcatTask(path, isMin, thisOptions){
  510. createBaseWorkConcatActionTask(path);
  511. createBaseWorkConcatStyleTask(path);
  512. createBaseWorkConcatBodyTask(path, isMin, thisOptions);
  513. createBaseWorkConcatDelTempTask(path);
  514. gulp.task( path+".base_work", gulp.series(path+".base_work : action", path+".base_work : style", path+".base_work : concat", path+".base_work : clean"));
  515. }
  516. function createBasePortalConcatStyleTask(path){
  517. gulp.task(path+".base_portal : style", function(){
  518. return gulp.src([
  519. "source/x_component_process_Work/$Main/default/css.wcss",
  520. "source/x_component_portal_Portal/$Main/default/css.wcss",
  521. "source/x_component_process_Xform/$Form/default/css.wcss",
  522. "source/o2_core/o2/widget/$Tab/mobileForm/css.wcss",
  523. "source/o2_core/o2/widget/$Menu/tab/css.wcss"
  524. ])
  525. .pipe(concat_Style())
  526. .pipe(concat('js/base_portal_style_temp.js'))
  527. .pipe(gulp.dest('source/x_desktop/'))
  528. })
  529. }
  530. function createBasePortalConcatActionTask(path){
  531. gulp.task(path+".base_portal : action", function(){
  532. return gulp.src([
  533. "source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  534. "source/o2_core/o2/xAction/services/x_portal_assemble_surface.json",
  535. "source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  536. "source/o2_core/o2/xAction/services/x_query_assemble_surface.json",
  537. "source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  538. "source/o2_core/o2/xAction/services/x_program_center.json",
  539. "source/o2_core/o2/xAction/services/x_organization_assemble_personal.json"
  540. ])
  541. .pipe(concat_Actions())
  542. .pipe(concat('js/base_portal_actions_temp.js'))
  543. .pipe(gulp.dest('source/x_desktop/'))
  544. })
  545. }
  546. function createBasePortalConcatDelTempTask(path) {
  547. gulp.task(path+".base_portal : clean", function(cb){
  548. var dest = [
  549. 'source/'+path+'/js/base_portal_actions_temp.js',
  550. 'source/'+path+'/js/base_portal_style_temp.js'
  551. ];
  552. return del(dest, cb);
  553. });
  554. }
  555. function createBasePortalConcatBodyTask(path, isMin, thisOptions) {
  556. gulp.task(path+".base_portal : concat", function(){
  557. var option = thisOptions || options;
  558. var src = [
  559. 'source/' + path + '/js/base_concat_head.js',
  560. 'source/o2_core/o2/lp/'+(option.lp || 'zh-cn')+'.js',
  561. 'source/' + path + '/js/base_portal_style_temp.js',
  562. 'source/o2_core/o2/widget/Common.js',
  563. 'source/o2_core/o2/widget/Dialog.js',
  564. 'source/o2_core/o2/widget/UUID.js',
  565. 'source/o2_core/o2/widget/Menu.js',
  566. 'source/o2_core/o2/widget/Toolbar.js',
  567. 'source/o2_core/o2/xDesktop/Common.js',
  568. 'source/o2_core/o2/xDesktop/Actions/RestActions.js',
  569. 'source/o2_core/o2/xAction/RestActions.js',
  570. 'source/o2_core/o2/xDesktop/Access.js',
  571. 'source/o2_core/o2/xDesktop/Dialog.js',
  572. 'source/o2_core/o2/xDesktop/Menu.js',
  573. 'source/o2_core/o2/xDesktop/UserData.js',
  574. 'source/x_component_Template/MPopupForm.js',
  575. 'source/o2_core/o2/xDesktop/Authentication.js',
  576. 'source/o2_core/o2/xDesktop/Window.js',
  577. 'source/x_component_Common/Main.js',
  578. 'source/x_component_process_Work/lp/'+(option.lp || 'zh-cn')+'.js',
  579. 'source/x_component_portal_Portal/lp/'+(option.lp || 'zh-cn')+'.js',
  580. 'source/x_component_process_Xform/lp/'+(option.lp || 'zh-cn')+'.js',
  581. 'source/x_component_Selector/lp/'+(option.lp || 'zh-cn')+'.js',
  582. 'source/x_component_portal_Portal/Main.js',
  583. 'source/x_component_Selector/package.js',
  584. 'source/x_component_Selector/Person.js',
  585. 'source/x_component_Selector/Identity.js',
  586. 'source/x_component_Selector/Unit.js',
  587. 'source/x_component_Selector/IdentityWidthDuty.js',
  588. 'source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js',
  589. 'source/x_component_Selector/UnitWithType.js',
  590. 'source/o2_core/o2/xScript/Actions/UnitActions.js',
  591. 'source/o2_core/o2/xScript/Actions/ScriptActions.js',
  592. 'source/o2_core/o2/xScript/Actions/CMSScriptActions.js',
  593. 'source/o2_core/o2/xScript/Actions/PortalScriptActions.js',
  594. 'source/o2_core/o2/xScript/PageEnvironment.js',
  595. 'source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js',
  596. 'source/o2_core/o2/xAction/services/x_cms_assemble_control.js',
  597. 'source/o2_core/o2/xAction/services/x_organization_assemble_control.js',
  598. 'source/o2_core/o2/xAction/services/x_query_assemble_surface.js',
  599. 'source/o2_core/o2/xAction/services/x_organization_assemble_personal.js',
  600. 'source/' + path + '/js/base_portal_actions_temp.js',
  601. 'source/' + path + '/js/base.js'
  602. ];
  603. var dest = option.dest+'/' + path + '/';
  604. return gulp.src(src)
  605. .pipe(concat('js/base_portal.js'))
  606. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  607. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  608. host: option.host,
  609. user: option.user || 'anonymous',
  610. pass: option.pass || '@anonymous',
  611. port: option.port || 21,
  612. remotePath: (option.remotePath || '/') + path
  613. })))
  614. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  615. host: option.host,
  616. user: option.user || 'anonymous',
  617. pass: option.pass || null,
  618. port: option.port || 22,
  619. remotePath: (option.remotePath || '/') + path
  620. })))
  621. .pipe(gulp.dest(dest))
  622. // .pipe(gulp.src(src))
  623. .pipe(concat('js/base_portal.min.js'))
  624. .pipe(uglify())
  625. // .pipe(rename({ extname: '.min.js' }))
  626. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  627. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  628. host: option.host,
  629. user: option.user || 'anonymous',
  630. pass: option.pass || '@anonymous',
  631. port: option.port || 21,
  632. remotePath: (option.remotePath || '/') + path
  633. })))
  634. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  635. host: option.host,
  636. user: option.user || 'anonymous',
  637. pass: option.pass || null,
  638. port: option.port || 22,
  639. remotePath: (option.remotePath || '/') + path
  640. })))
  641. .pipe(gulp.dest(dest))
  642. });
  643. }
  644. function createBasePortalConcatTask(path, isMin, thisOptions){
  645. createBasePortalConcatActionTask(path);
  646. createBasePortalConcatStyleTask(path);
  647. createBasePortalConcatBodyTask(path, isMin, thisOptions);
  648. createBasePortalConcatDelTempTask(path);
  649. gulp.task( path+".base_portal", gulp.series(path+".base_portal : action", path+".base_portal : style", path+".base_portal : concat", path+".base_portal : clean"));
  650. }
  651. function getAppTask(path, isMin, thisOptions) {
  652. if (path==="x_component_process_Xform"){
  653. createDefaultTask(path, isMin, thisOptions);
  654. createXFormConcatTask(path, isMin, thisOptions);
  655. return gulp.series(path, path+" : concat");
  656. }else if (path==="o2_core"){
  657. createDefaultTask(path, isMin, thisOptions);
  658. createO2ConcatTask(path, isMin, thisOptions);
  659. return gulp.series(path, path+" : concat", path+".xDesktop : concat", path+" : bundle");
  660. }else if (path==="x_desktop") {
  661. createDefaultTask(path, isMin, thisOptions);
  662. createBaseWorkConcatTask(path, isMin, thisOptions);
  663. createBasePortalConcatTask(path, isMin, thisOptions);
  664. return gulp.series(path, path+".base_work", path+".base_portal");
  665. //return gulp.series(path, path+".base_work : concat");
  666. }else{
  667. createDefaultTask(path, isMin, thisOptions);
  668. return gulp.series(path);
  669. }
  670. }
  671. //var taskObj = {};
  672. apps.map(function (app) {
  673. var taskName;
  674. var isMin = (app.tasks.indexOf("min")!==-1);
  675. taskName = app.folder;
  676. appTasks.push(taskName);
  677. gulp.task(taskName, getAppTask(app.folder, isMin));
  678. // //var isMin = (app.tasks.indexOf("min")!==-1);
  679. // taskName = app.folder+"_release";
  680. // //appTasks.push(taskName);
  681. // gulp.task(taskName, getAppTask(app.folder, isMin, release_options));
  682. });
  683. // Object.keys(taskObj).map(function(k){
  684. // exports[k] = parallel(taskObj[k]);
  685. // });
  686. //exports[app.folder] = parallel(minTask, moveTask);
  687. function getCleanTask(path) {
  688. return function (cb) {
  689. if (path){
  690. var dest = (path=="/") ? options.dest+"/" : options.dest+'/' + path + '/';
  691. gutil.log("Clean", ":", gutil.colors.red(dest));
  692. del.sync(dest, cb);
  693. cb();
  694. }else{
  695. cb();
  696. }
  697. }
  698. }
  699. function cleanRemoteFtp(f, cb) {
  700. var file = options.remotePath + f;
  701. var ftp = new JSFtp({
  702. host: options.host,
  703. user: options.user || 'anonymous',
  704. pass: options.pass || null,
  705. port: options.port || 21
  706. });
  707. ftp.raw('dele ' + file, function (err) {
  708. if (err) { cb(); return; }
  709. if (file.substring(file.length - 3).toLowerCase() == ".js") {
  710. file = file.replace('.js', ".min.js");
  711. ftp.raw('dele ' + file, function (err) {
  712. if (err) { cb(); return; }
  713. if (file.indexOf("/") != -1) {
  714. var p = file.substring(0, file.lastIndexOf("/"));
  715. ftp.raw('rmd ' + p, function (err) {
  716. if (err) { cb(); return; }
  717. ftp.raw.quit();
  718. cb();
  719. });
  720. }
  721. });
  722. } else {
  723. if (file.indexOf("/") != -1) {
  724. var pPath = file.substring(0, file.lastIndexOf("/"));
  725. ftp.raw('rmd ' + pPath, function (err) {
  726. if (err) { cb(); return; }
  727. ftp.raw.quit();
  728. cb();
  729. });
  730. }
  731. }
  732. });
  733. }
  734. function cleanRemoteLocal(f, cb) {
  735. var file = options.location + f;
  736. del(file, { force: true, dryRun: true }, function () {
  737. if (file.substring(file.length - 3).toLowerCase() == ".js") {
  738. var minfile = file.replace('.js', ".min.js");
  739. del(minfile, { force: true, dryRun: true }, function () {
  740. var p = file.substring(0, file.lastIndexOf("/"));
  741. fs.rmdir(p, function (err) {
  742. if (err) { }
  743. cb();
  744. })
  745. });
  746. } else {
  747. var p = file.substring(0, file.lastIndexOf("/"));
  748. fs.rmdir(p, function (err) {
  749. if (err) { }
  750. cb();
  751. })
  752. }
  753. });
  754. }
  755. function getCleanRemoteTask(path) {
  756. return function (cb) {
  757. if (options.upload) {
  758. var file = path.replace(/\\/g, "/");
  759. file = file.substring(file.indexOf("source/") + 7);
  760. if (options.upload == 'local' && options.location != '') cleanRemoteLocal(file, cb);
  761. if (options.upload == 'ftp' && options.host != '') cleanRemoteFtp(file, cb);
  762. } else {
  763. if (cb) cb();
  764. }
  765. }
  766. }
  767. function getWatchTask(path) {
  768. return (path) ? function (cb) {
  769. gutil.log("watch", ":", gutil.colors.green(path, "is watching ..."));
  770. gulp.watch(['source/' + path + '/**/*', "!./**/test/**"], { "events": ['addDir', 'add', 'change'] }, gulp.parallel([path]));
  771. } : function(cb){cb();};
  772. }
  773. gulp.task("clean", getCleanTask(options.src))
  774. gulp.task("watch", getWatchTask(options.src));
  775. gulp.task("index", function () {
  776. var src = ['source/favicon.ico', 'source/index.html'];
  777. var dest = options.dest;
  778. return gulp.src(src)
  779. .pipe(changed(dest))
  780. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + '/')))
  781. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  782. host: options.host,
  783. user: options.user || 'anonymous',
  784. pass: options.pass || '@anonymous',
  785. port: options.port || 21,
  786. remotePath: (options.remotePath || '/')
  787. })))
  788. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), ftp({
  789. host: options.host,
  790. user: options.user || 'anonymous',
  791. pass: options.pass || null,
  792. port: options.port || 22,
  793. remotePath: (options.remotePath || '/')
  794. })))
  795. .pipe(gulp.dest(dest))
  796. .pipe(gutil.noop());
  797. });
  798. gulp.task("cleanAll", getCleanTask('/'));
  799. gulp.task("o2:new-v:html", function () {
  800. var path = "x_desktop";
  801. var src = '/source/x_desktop/*.html';
  802. var dest = options.dest + '/x_desktop/';
  803. return gulp.src(src)
  804. .pipe(assetRev())
  805. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
  806. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  807. host: options.host,
  808. user: options.user || 'anonymous',
  809. pass: options.pass || '@anonymous',
  810. port: options.port || 21,
  811. remotePath: (options.remotePath || '/') + path
  812. })))
  813. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
  814. host: options.host,
  815. user: options.user || 'anonymous',
  816. pass: options.pass || null,
  817. port: options.port || 22,
  818. remotePath: (options.remotePath || '/') + path
  819. })))
  820. .pipe(gulp.dest(dest))
  821. .pipe(gutil.noop());
  822. });
  823. gulp.task("o2:new-v:o2", function () {
  824. var path = "o2_core";
  825. var src = options.dest +'/o2_core/o2.js';
  826. var dest = options.dest +'/o2_core/';
  827. return gulp.src(src)
  828. .pipe(assetRev())
  829. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
  830. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  831. host: options.host,
  832. user: options.user || 'anonymous',
  833. pass: options.pass || '@anonymous',
  834. port: options.port || 21,
  835. remotePath: (options.remotePath || '/') + path
  836. })))
  837. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
  838. host: options.host,
  839. user: options.user || 'anonymous',
  840. pass: options.pass || null,
  841. port: options.port || 22,
  842. remotePath: (options.remotePath || '/') + path
  843. })))
  844. .pipe(gulp.dest(dest))
  845. .pipe(uglify())
  846. .pipe(rename({ extname: '.min.js' }))
  847. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
  848. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  849. host: options.host,
  850. user: options.user || 'anonymous',
  851. pass: options.pass || '@anonymous',
  852. port: options.port || 21,
  853. remotePath: (options.remotePath || '/') + path
  854. })))
  855. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
  856. host: options.host,
  857. user: options.user || 'anonymous',
  858. pass: options.pass || null,
  859. port: options.port || 22,
  860. remotePath: (options.remotePath || '/') + path
  861. })))
  862. .pipe(gulp.dest(dest))
  863. .pipe(gutil.noop());
  864. });
  865. gulp.task("o2:new-v", gulp.parallel("o2:new-v:o2", "o2:new-v:html"));
  866. gulp.task("git_clean", function (cb) {
  867. var dest = 'D:/O2/github/huqi1980/o2oa/o2web/source/';
  868. del(dest, { dryRun: true, force: true }, cb);
  869. });
  870. gulp.task("git_dest", function () {
  871. var dest = "D:/O2/github/huqi1980/o2oa/o2web/source";
  872. return gulp.src(["source/**/*", "!./**/test/**"])
  873. .pipe(changed(dest))
  874. .pipe(gulp.dest(dest))
  875. });
  876. gulp.task("git", gulp.series('git_clean', 'git_dest'));
  877. gulp.task("default", gulp.series(gulp.parallel(appTasks, 'index'), "o2:new-v"));
  878. function build(){
  879. options.ev = "p";
  880. options.upload = o_options.upload || "";
  881. options.location = o_options.location || uploadOptions.location;
  882. options.host = o_options.host || uploadOptions.host;
  883. options.user = o_options.user || uploadOptions.user;
  884. options.pass = o_options.pass || uploadOptions.pass;
  885. options.port = o_options.port || uploadOptions.port;
  886. options.remotePath = o_options.remotePath || uploadOptions.remotePath;
  887. options.dest = o_options.dest || uploadOptions.dest || "dest";
  888. };
  889. gulp.task("build", gulp.series("clean", gulp.parallel(appTasks, 'index'), "o2:new-v"))