gulpfile.js 41 KB

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