gulpfile.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  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. var name = file.path.replace(process.cwd(), "").replace(/\\/g, "/")
  377. name = ".."+name.substring(name.indexOf("/source")+7);
  378. content = "var csskey = encodeURIComponent(\""+name+"\");\no2.widget.css[csskey]="+content;
  379. file.contents = new Buffer.from(content);
  380. this.push(file);
  381. cb();
  382. });
  383. }
  384. function createBaseWorkConcatStyleTask(path){
  385. gulp.task(path+".base_work : style", function(){
  386. return gulp.src([
  387. "source/x_component_process_Work/$Main/default/css.wcss",
  388. "source/x_component_process_Xform/$Form/default/css.wcss",
  389. "source/o2_core/o2/widget/$Tab/mobileForm/css.wcss",
  390. "source/o2_core/o2/widget/$Menu/tab/css.wcss",
  391. "source/o2_core/o2/widget/$Tab/form/css.wcss",
  392. "source/x_component_process_Xform/$Form/default/doc.wcss",
  393. "source/o2_core/o2/widget/$Toolbar/documentEdit/css.wcss",
  394. "source/o2_core/o2/widget/$Toolbar/documentEdit_side/css.wcss"
  395. ])
  396. .pipe(concat_Style())
  397. .pipe(concat('js/base_work_style_temp.js'))
  398. .pipe(gulp.dest('source/x_desktop/'))
  399. })
  400. }
  401. function createBaseWorkConcatActionTask(path){
  402. gulp.task(path+".base_work : action", function(){
  403. return gulp.src([
  404. "source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  405. "source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.json",
  406. "source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  407. "source/o2_core/o2/xAction/services/x_query_assemble_surface.json",
  408. "source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  409. "source/o2_core/o2/xAction/services/x_program_center.json",
  410. "source/o2_core/o2/xAction/services/x_organization_assemble_personal.json"
  411. ])
  412. .pipe(concat_Actions())
  413. .pipe(concat('js/base_work_actions_temp.js'))
  414. .pipe(gulp.dest('source/x_desktop/'))
  415. })
  416. }
  417. function createBaseWorkConcatDelTempTask(path) {
  418. gulp.task(path+".base_work : clean", function(cb){
  419. var dest = [
  420. 'source/'+path+'/js/base_work_actions_temp.js',
  421. 'source/'+path+'/js/base_work_style_temp.js'
  422. ];
  423. return del(dest, cb);
  424. });
  425. }
  426. function createBaseWorkConcatBodyTask(path, isMin, thisOptions) {
  427. gulp.task(path+".base_work : concat", function(){
  428. var option = thisOptions || options;
  429. var src = [
  430. 'source/' + path + '/js/base_concat_head.js',
  431. 'source/o2_core/o2/lp/'+(option.lp || 'zh-cn')+'.js',
  432. 'source/x_component_process_Work/lp/'+(option.lp || 'zh-cn')+'.js',
  433. 'source/x_component_process_Xform/lp/'+(option.lp || 'zh-cn')+'.js',
  434. 'source/x_component_Selector/lp/'+(option.lp || 'zh-cn')+'.js',
  435. 'source/' + path + '/js/base_work_style_temp.js',
  436. 'source/o2_core/o2/widget/Common.js',
  437. 'source/o2_core/o2/widget/Dialog.js',
  438. 'source/o2_core/o2/widget/UUID.js',
  439. 'source/o2_core/o2/widget/Menu.js',
  440. 'source/o2_core/o2/widget/Toolbar.js',
  441. 'source/o2_core/o2/xDesktop/Common.js',
  442. 'source/o2_core/o2/xDesktop/Actions/RestActions.js',
  443. 'source/o2_core/o2/xAction/RestActions.js',
  444. 'source/o2_core/o2/xDesktop/Access.js',
  445. 'source/o2_core/o2/xDesktop/Dialog.js',
  446. 'source/o2_core/o2/xDesktop/Menu.js',
  447. 'source/o2_core/o2/xDesktop/UserData.js',
  448. 'source/x_component_Template/MPopupForm.js',
  449. 'source/o2_core/o2/xDesktop/Authentication.js',
  450. 'source/o2_core/o2/xDesktop/Window.js',
  451. 'source/x_component_Common/Main.js',
  452. 'source/x_component_process_Work/Main.js',
  453. 'source/x_component_Selector/package.js',
  454. 'source/x_component_Selector/Person.js',
  455. 'source/x_component_Selector/Identity.js',
  456. 'source/x_component_Selector/Unit.js',
  457. 'source/x_component_Selector/IdentityWidthDuty.js',
  458. 'source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js',
  459. 'source/x_component_Selector/UnitWithType.js',
  460. 'source/o2_core/o2/xScript/Actions/UnitActions.js',
  461. 'source/o2_core/o2/xScript/Actions/ScriptActions.js',
  462. 'source/o2_core/o2/xScript/Actions/CMSScriptActions.js',
  463. 'source/o2_core/o2/xScript/Actions/PortalScriptActions.js',
  464. 'source/o2_core/o2/xScript/Environment.js',
  465. 'source/x_component_Template/MTooltips.js',
  466. 'source/x_component_Template/MSelector.js',
  467. 'source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js',
  468. 'source/o2_core/o2/xAction/services/x_processplatform_assemble_surface.js',
  469. 'source/o2_core/o2/xAction/services/x_cms_assemble_control.js',
  470. 'source/o2_core/o2/xAction/services/x_organization_assemble_control.js',
  471. 'source/o2_core/o2/xAction/services/x_query_assemble_surface.js',
  472. 'source/o2_core/o2/xAction/services/x_organization_assemble_personal.js',
  473. 'source/' + path + '/js/base_work_actions_temp.js',
  474. 'source/' + path + '/js/base.js'
  475. ];
  476. var dest = option.dest+'/' + path + '/';
  477. return gulp.src(src)
  478. .pipe(concat('js/base_work.js'))
  479. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  480. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  481. host: option.host,
  482. user: option.user || 'anonymous',
  483. pass: option.pass || '@anonymous',
  484. port: option.port || 21,
  485. remotePath: (option.remotePath || '/') + path
  486. })))
  487. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  488. host: option.host,
  489. user: option.user || 'anonymous',
  490. pass: option.pass || null,
  491. port: option.port || 22,
  492. remotePath: (option.remotePath || '/') + path
  493. })))
  494. .pipe(gulp.dest(dest))
  495. .pipe(uglify())
  496. .pipe(rename({ extname: '.min.js' }))
  497. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  498. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  499. host: option.host,
  500. user: option.user || 'anonymous',
  501. pass: option.pass || '@anonymous',
  502. port: option.port || 21,
  503. remotePath: (option.remotePath || '/') + path
  504. })))
  505. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  506. host: option.host,
  507. user: option.user || 'anonymous',
  508. pass: option.pass || null,
  509. port: option.port || 22,
  510. remotePath: (option.remotePath || '/') + path
  511. })))
  512. .pipe(gulp.dest(dest))
  513. });
  514. }
  515. function createBaseWorkConcatTask(path, isMin, thisOptions){
  516. createBaseWorkConcatActionTask(path);
  517. createBaseWorkConcatStyleTask(path);
  518. createBaseWorkConcatBodyTask(path, isMin, thisOptions);
  519. createBaseWorkConcatDelTempTask(path);
  520. gulp.task( path+".base_work", gulp.series(path+".base_work : action", path+".base_work : style", path+".base_work : concat", path+".base_work : clean"));
  521. }
  522. function createBasePortalConcatStyleTask(path){
  523. gulp.task(path+".base_portal : style", function(){
  524. return gulp.src([
  525. "source/x_component_process_Work/$Main/default/css.wcss",
  526. "source/x_component_portal_Portal/$Main/default/css.wcss",
  527. "source/x_component_process_Xform/$Form/default/css.wcss",
  528. "source/o2_core/o2/widget/$Tab/mobileForm/css.wcss",
  529. "source/o2_core/o2/widget/$Menu/tab/css.wcss"
  530. ])
  531. .pipe(concat_Style())
  532. .pipe(concat('js/base_portal_style_temp.js'))
  533. .pipe(gulp.dest('source/x_desktop/'))
  534. })
  535. }
  536. function createBasePortalConcatActionTask(path){
  537. gulp.task(path+".base_portal : action", function(){
  538. return gulp.src([
  539. "source/o2_core/o2/xAction/services/x_organization_assemble_authentication.json",
  540. "source/o2_core/o2/xAction/services/x_portal_assemble_surface.json",
  541. "source/o2_core/o2/xAction/services/x_organization_assemble_control.json",
  542. "source/o2_core/o2/xAction/services/x_query_assemble_surface.json",
  543. "source/o2_core/o2/xAction/services/x_cms_assemble_control.json",
  544. "source/o2_core/o2/xAction/services/x_program_center.json",
  545. "source/o2_core/o2/xAction/services/x_organization_assemble_personal.json"
  546. ])
  547. .pipe(concat_Actions())
  548. .pipe(concat('js/base_portal_actions_temp.js'))
  549. .pipe(gulp.dest('source/x_desktop/'))
  550. })
  551. }
  552. function createBasePortalConcatDelTempTask(path) {
  553. gulp.task(path+".base_portal : clean", function(cb){
  554. var dest = [
  555. 'source/'+path+'/js/base_portal_actions_temp.js',
  556. 'source/'+path+'/js/base_portal_style_temp.js'
  557. ];
  558. return del(dest, cb);
  559. });
  560. }
  561. function createBasePortalConcatBodyTask(path, isMin, thisOptions) {
  562. gulp.task(path+".base_portal : concat", function(){
  563. var option = thisOptions || options;
  564. var src = [
  565. 'source/' + path + '/js/base_concat_head.js',
  566. 'source/o2_core/o2/lp/'+(option.lp || 'zh-cn')+'.js',
  567. 'source/' + path + '/js/base_portal_style_temp.js',
  568. 'source/o2_core/o2/widget/Common.js',
  569. 'source/o2_core/o2/widget/Dialog.js',
  570. 'source/o2_core/o2/widget/UUID.js',
  571. 'source/o2_core/o2/widget/Menu.js',
  572. 'source/o2_core/o2/widget/Toolbar.js',
  573. 'source/o2_core/o2/xDesktop/Common.js',
  574. 'source/o2_core/o2/xDesktop/Actions/RestActions.js',
  575. 'source/o2_core/o2/xAction/RestActions.js',
  576. 'source/o2_core/o2/xDesktop/Access.js',
  577. 'source/o2_core/o2/xDesktop/Dialog.js',
  578. 'source/o2_core/o2/xDesktop/Menu.js',
  579. 'source/o2_core/o2/xDesktop/UserData.js',
  580. 'source/x_component_Template/MPopupForm.js',
  581. 'source/o2_core/o2/xDesktop/Authentication.js',
  582. 'source/o2_core/o2/xDesktop/Window.js',
  583. 'source/x_component_Common/Main.js',
  584. 'source/x_component_process_Work/lp/'+(option.lp || 'zh-cn')+'.js',
  585. 'source/x_component_portal_Portal/lp/'+(option.lp || 'zh-cn')+'.js',
  586. 'source/x_component_process_Xform/lp/'+(option.lp || 'zh-cn')+'.js',
  587. 'source/x_component_Selector/lp/'+(option.lp || 'zh-cn')+'.js',
  588. 'source/x_component_portal_Portal/Main.js',
  589. 'source/x_component_Selector/package.js',
  590. 'source/x_component_Selector/Person.js',
  591. 'source/x_component_Selector/Identity.js',
  592. 'source/x_component_Selector/Unit.js',
  593. 'source/x_component_Selector/IdentityWidthDuty.js',
  594. 'source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js',
  595. 'source/x_component_Selector/UnitWithType.js',
  596. 'source/o2_core/o2/xScript/Actions/UnitActions.js',
  597. 'source/o2_core/o2/xScript/Actions/ScriptActions.js',
  598. 'source/o2_core/o2/xScript/Actions/CMSScriptActions.js',
  599. 'source/o2_core/o2/xScript/Actions/PortalScriptActions.js',
  600. 'source/o2_core/o2/xScript/PageEnvironment.js',
  601. 'source/o2_core/o2/xAction/services/x_organization_assemble_authentication.js',
  602. 'source/o2_core/o2/xAction/services/x_cms_assemble_control.js',
  603. 'source/o2_core/o2/xAction/services/x_organization_assemble_control.js',
  604. 'source/o2_core/o2/xAction/services/x_query_assemble_surface.js',
  605. 'source/o2_core/o2/xAction/services/x_organization_assemble_personal.js',
  606. 'source/' + path + '/js/base_portal_actions_temp.js',
  607. 'source/' + path + '/js/base.js'
  608. ];
  609. var dest = option.dest+'/' + path + '/';
  610. return gulp.src(src)
  611. .pipe(concat('js/base_portal.js'))
  612. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  613. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  614. host: option.host,
  615. user: option.user || 'anonymous',
  616. pass: option.pass || '@anonymous',
  617. port: option.port || 21,
  618. remotePath: (option.remotePath || '/') + path
  619. })))
  620. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  621. host: option.host,
  622. user: option.user || 'anonymous',
  623. pass: option.pass || null,
  624. port: option.port || 22,
  625. remotePath: (option.remotePath || '/') + path
  626. })))
  627. .pipe(gulp.dest(dest))
  628. // .pipe(gulp.src(src))
  629. .pipe(concat('js/base_portal.min.js'))
  630. .pipe(uglify())
  631. // .pipe(rename({ extname: '.min.js' }))
  632. .pipe(gulpif((option.upload == 'local' && option.location != ''), gulp.dest(option.location + path + '/')))
  633. .pipe(gulpif((option.upload == 'ftp' && option.host != ''), ftp({
  634. host: option.host,
  635. user: option.user || 'anonymous',
  636. pass: option.pass || '@anonymous',
  637. port: option.port || 21,
  638. remotePath: (option.remotePath || '/') + path
  639. })))
  640. .pipe(gulpif((option.upload == 'sftp' && option.host != ''), sftp({
  641. host: option.host,
  642. user: option.user || 'anonymous',
  643. pass: option.pass || null,
  644. port: option.port || 22,
  645. remotePath: (option.remotePath || '/') + path
  646. })))
  647. .pipe(gulp.dest(dest))
  648. });
  649. }
  650. function createBasePortalConcatTask(path, isMin, thisOptions){
  651. createBasePortalConcatActionTask(path);
  652. createBasePortalConcatStyleTask(path);
  653. createBasePortalConcatBodyTask(path, isMin, thisOptions);
  654. createBasePortalConcatDelTempTask(path);
  655. gulp.task( path+".base_portal", gulp.series(path+".base_portal : action", path+".base_portal : style", path+".base_portal : concat", path+".base_portal : clean"));
  656. }
  657. function getAppTask(path, isMin, thisOptions) {
  658. if (path==="x_component_process_Xform"){
  659. createDefaultTask(path, isMin, thisOptions);
  660. createXFormConcatTask(path, isMin, thisOptions);
  661. return gulp.series(path, path+" : concat");
  662. }else if (path==="o2_core"){
  663. createDefaultTask(path, isMin, thisOptions);
  664. createO2ConcatTask(path, isMin, thisOptions);
  665. return gulp.series(path, path+" : concat", path+".xDesktop : concat", path+" : bundle");
  666. }else if (path==="x_desktop") {
  667. createDefaultTask(path, isMin, thisOptions);
  668. createBaseWorkConcatTask(path, isMin, thisOptions);
  669. createBasePortalConcatTask(path, isMin, thisOptions);
  670. return gulp.series(path, path+".base_work", path+".base_portal");
  671. //return gulp.series(path, path+".base_work : concat");
  672. }else{
  673. createDefaultTask(path, isMin, thisOptions);
  674. return gulp.series(path);
  675. }
  676. }
  677. //var taskObj = {};
  678. apps.map(function (app) {
  679. var taskName;
  680. var isMin = (app.tasks.indexOf("min")!==-1);
  681. taskName = app.folder;
  682. appTasks.push(taskName);
  683. gulp.task(taskName, getAppTask(app.folder, isMin));
  684. // //var isMin = (app.tasks.indexOf("min")!==-1);
  685. // taskName = app.folder+"_release";
  686. // //appTasks.push(taskName);
  687. // gulp.task(taskName, getAppTask(app.folder, isMin, release_options));
  688. });
  689. // Object.keys(taskObj).map(function(k){
  690. // exports[k] = parallel(taskObj[k]);
  691. // });
  692. //exports[app.folder] = parallel(minTask, moveTask);
  693. function getCleanTask(path) {
  694. return function (cb) {
  695. if (path){
  696. var dest = (path=="/") ? options.dest+"/" : options.dest+'/' + path + '/';
  697. gutil.log("Clean", ":", gutil.colors.red(dest));
  698. del.sync(dest, cb);
  699. cb();
  700. }else{
  701. cb();
  702. }
  703. }
  704. }
  705. function cleanRemoteFtp(f, cb) {
  706. var file = options.remotePath + f;
  707. var ftp = new JSFtp({
  708. host: options.host,
  709. user: options.user || 'anonymous',
  710. pass: options.pass || null,
  711. port: options.port || 21
  712. });
  713. ftp.raw('dele ' + file, function (err) {
  714. if (err) { cb(); return; }
  715. if (file.substring(file.length - 3).toLowerCase() == ".js") {
  716. file = file.replace('.js', ".min.js");
  717. ftp.raw('dele ' + file, function (err) {
  718. if (err) { cb(); return; }
  719. if (file.indexOf("/") != -1) {
  720. var p = file.substring(0, file.lastIndexOf("/"));
  721. ftp.raw('rmd ' + p, function (err) {
  722. if (err) { cb(); return; }
  723. ftp.raw.quit();
  724. cb();
  725. });
  726. }
  727. });
  728. } else {
  729. if (file.indexOf("/") != -1) {
  730. var pPath = file.substring(0, file.lastIndexOf("/"));
  731. ftp.raw('rmd ' + pPath, function (err) {
  732. if (err) { cb(); return; }
  733. ftp.raw.quit();
  734. cb();
  735. });
  736. }
  737. }
  738. });
  739. }
  740. function cleanRemoteLocal(f, cb) {
  741. var file = options.location + f;
  742. del(file, { force: true, dryRun: true }, function () {
  743. if (file.substring(file.length - 3).toLowerCase() == ".js") {
  744. var minfile = file.replace('.js', ".min.js");
  745. del(minfile, { force: true, dryRun: true }, function () {
  746. var p = file.substring(0, file.lastIndexOf("/"));
  747. fs.rmdir(p, function (err) {
  748. if (err) { }
  749. cb();
  750. })
  751. });
  752. } else {
  753. var p = file.substring(0, file.lastIndexOf("/"));
  754. fs.rmdir(p, function (err) {
  755. if (err) { }
  756. cb();
  757. })
  758. }
  759. });
  760. }
  761. function getCleanRemoteTask(path) {
  762. return function (cb) {
  763. if (options.upload) {
  764. var file = path.replace(/\\/g, "/");
  765. file = file.substring(file.indexOf("source/") + 7);
  766. if (options.upload == 'local' && options.location != '') cleanRemoteLocal(file, cb);
  767. if (options.upload == 'ftp' && options.host != '') cleanRemoteFtp(file, cb);
  768. } else {
  769. if (cb) cb();
  770. }
  771. }
  772. }
  773. function getWatchTask(path) {
  774. return (path) ? function (cb) {
  775. gutil.log("watch", ":", gutil.colors.green(path, "is watching ..."));
  776. gulp.watch(['source/' + path + '/**/*', "!./**/test/**"], { "events": ['addDir', 'add', 'change'] }, gulp.parallel([path]));
  777. } : function(cb){cb();};
  778. }
  779. gulp.task("clean", getCleanTask(options.src))
  780. gulp.task("watch", getWatchTask(options.src));
  781. gulp.task("index", function () {
  782. var src = ['source/favicon.ico', 'source/index.html'];
  783. var dest = options.dest;
  784. return gulp.src(src)
  785. .pipe(changed(dest))
  786. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + '/')))
  787. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  788. host: options.host,
  789. user: options.user || 'anonymous',
  790. pass: options.pass || '@anonymous',
  791. port: options.port || 21,
  792. remotePath: (options.remotePath || '/')
  793. })))
  794. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), ftp({
  795. host: options.host,
  796. user: options.user || 'anonymous',
  797. pass: options.pass || null,
  798. port: options.port || 22,
  799. remotePath: (options.remotePath || '/')
  800. })))
  801. .pipe(gulp.dest(dest))
  802. .pipe(gutil.noop());
  803. });
  804. gulp.task("cleanAll", getCleanTask('/'));
  805. gulp.task("o2:new-v:html", function () {
  806. var path = "x_desktop";
  807. var src = '/source/x_desktop/*.html';
  808. var dest = options.dest + '/x_desktop/';
  809. return gulp.src(src)
  810. .pipe(assetRev())
  811. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
  812. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  813. host: options.host,
  814. user: options.user || 'anonymous',
  815. pass: options.pass || '@anonymous',
  816. port: options.port || 21,
  817. remotePath: (options.remotePath || '/') + path
  818. })))
  819. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
  820. host: options.host,
  821. user: options.user || 'anonymous',
  822. pass: options.pass || null,
  823. port: options.port || 22,
  824. remotePath: (options.remotePath || '/') + path
  825. })))
  826. .pipe(gulp.dest(dest))
  827. .pipe(gutil.noop());
  828. });
  829. gulp.task("o2:new-v:o2", function () {
  830. var path = "o2_core";
  831. var src = options.dest +'/o2_core/o2.js';
  832. var dest = options.dest +'/o2_core/';
  833. return gulp.src(src)
  834. .pipe(assetRev())
  835. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
  836. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  837. host: options.host,
  838. user: options.user || 'anonymous',
  839. pass: options.pass || '@anonymous',
  840. port: options.port || 21,
  841. remotePath: (options.remotePath || '/') + path
  842. })))
  843. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
  844. host: options.host,
  845. user: options.user || 'anonymous',
  846. pass: options.pass || null,
  847. port: options.port || 22,
  848. remotePath: (options.remotePath || '/') + path
  849. })))
  850. .pipe(gulp.dest(dest))
  851. .pipe(uglify())
  852. .pipe(rename({ extname: '.min.js' }))
  853. .pipe(gulpif((options.upload == 'local' && options.location != ''), gulp.dest(options.location + path + '/')))
  854. .pipe(gulpif((options.upload == 'ftp' && options.host != ''), ftp({
  855. host: options.host,
  856. user: options.user || 'anonymous',
  857. pass: options.pass || '@anonymous',
  858. port: options.port || 21,
  859. remotePath: (options.remotePath || '/') + path
  860. })))
  861. .pipe(gulpif((options.upload == 'sftp' && options.host != ''), sftp({
  862. host: options.host,
  863. user: options.user || 'anonymous',
  864. pass: options.pass || null,
  865. port: options.port || 22,
  866. remotePath: (options.remotePath || '/') + path
  867. })))
  868. .pipe(gulp.dest(dest))
  869. .pipe(gutil.noop());
  870. });
  871. gulp.task("o2:new-v", gulp.parallel("o2:new-v:o2", "o2:new-v:html"));
  872. gulp.task("git_clean", function (cb) {
  873. var dest = 'D:/O2/github/huqi1980/o2oa/o2web/source/';
  874. del(dest, { dryRun: true, force: true }, cb);
  875. });
  876. gulp.task("git_dest", function () {
  877. var dest = "D:/O2/github/huqi1980/o2oa/o2web/source";
  878. return gulp.src(["source/**/*", "!./**/test/**"])
  879. .pipe(changed(dest))
  880. .pipe(gulp.dest(dest))
  881. });
  882. gulp.task("git", gulp.series('git_clean', 'git_dest'));
  883. gulp.task("default", gulp.series(gulp.parallel(appTasks, 'index'), "o2:new-v"));
  884. function build(){
  885. options.ev = "p";
  886. options.upload = o_options.upload || "";
  887. options.location = o_options.location || uploadOptions.location;
  888. options.host = o_options.host || uploadOptions.host;
  889. options.user = o_options.user || uploadOptions.user;
  890. options.pass = o_options.pass || uploadOptions.pass;
  891. options.port = o_options.port || uploadOptions.port;
  892. options.remotePath = o_options.remotePath || uploadOptions.remotePath;
  893. options.dest = o_options.dest || uploadOptions.dest || "dest";
  894. };
  895. gulp.task("build", gulp.series("clean", gulp.parallel(appTasks, 'index'), "o2:new-v"))