gulpfile.js 41 KB

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