gulpfile.js 41 KB

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