gulpfile.js 40 KB

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