publish_layame.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. // v1.1.9
  2. const ideModuleDir = global.ideModuleDir;
  3. const workSpaceDir = global.workSpaceDir;
  4. var Stream = require('stream');
  5. //引用插件模块
  6. const gulp = require(ideModuleDir + "gulp");
  7. const fs = require("fs");
  8. const path = require("path");
  9. const del = require(ideModuleDir + "del");
  10. let copyLibsTask = ["copyPlatformLibsJsFile"];
  11. let versiontask = ["version2"];
  12. let exec = require('child_process').exec;
  13. let tsconfigPath = path.join(workSpaceDir, "tsconfig.json");
  14. let isTS = fs.existsSync(tsconfigPath);
  15. let buildOptions = null;
  16. gulp.task("preCreate_LayaMe", copyLibsTask, function() {
  17. releaseDir = global.releaseDir;
  18. config = global.config;
  19. buildOptions = config.buildOptions;
  20. commandSuffix = global.commandSuffix;
  21. });
  22. // 是否build指定部分(debug版本layame)
  23. function toBuildPart(part) {
  24. if (!buildOptions) {
  25. return true;
  26. }
  27. if ('all' == part ) {
  28. return buildOptions.type == 'all';
  29. }
  30. if (buildOptions.type == 'all') {
  31. return true;
  32. }
  33. return (buildOptions.buildList.includes(part));
  34. }
  35. function toBuildTs() {
  36. if (!buildOptions) {
  37. return true;
  38. }
  39. return buildOptions.hasScript;
  40. }
  41. gulp.task("del", ["preCreate_LayaMe"], function(cb) {
  42. let buildFolder = path.join(workSpaceDir, "build");
  43. if (!isTS || !fs.existsSync(buildFolder)) {
  44. return cb();
  45. }
  46. let delList = [`${buildFolder}/**`];
  47. del(delList, { force: true }).then(paths => {
  48. cb();
  49. }).catch((err) => {
  50. throw err;
  51. })
  52. });
  53. gulp.task("tsc", ["del"], function(cb) {
  54. if (!isTS) {
  55. return cb();
  56. }
  57. if(!toBuildTs()) {
  58. return cb();
  59. }
  60. console.log('tsconfigPath', tsconfigPath);
  61. let tscPath = path.join(ideModuleDir, ".bin", `tsc${commandSuffix}`);
  62. return exec(` "${tscPath}" -p "${tsconfigPath}"`, {
  63. cwd: workSpaceDir,
  64. shell: true
  65. }, function(error, stdout, stderr) {
  66. let errStr = stderr || '';
  67. if (errStr.indexOf(": node: ") >= 0 || errStr.indexOf("'node'") >= 0) {
  68. // 提示未安装node
  69. console.log("err");
  70. console.log("node not installed");
  71. } else {
  72. if (error) console.log("error", error);
  73. if (stdout) console.log("stdout", stdout);
  74. if (stderr) console.log("stderr", stderr);
  75. cb();
  76. }
  77. });
  78. });
  79. function getFolderList(rootPath, fileList, fileType, deep= 0) {
  80. if (!fs.existsSync(rootPath)) {
  81. return fileList;
  82. }
  83. let dirList = fs.readdirSync(rootPath);
  84. let fileName, fileFullPath;
  85. for (let i = 0, len = dirList.length; i < len; i++) {
  86. fileName = dirList[i];
  87. fileFullPath = path.join(rootPath, fileName);
  88. if (fs.statSync(fileFullPath).isDirectory()) {
  89. getFolderList(fileFullPath, fileList, fileType, deep + 1);
  90. } else {
  91. if (!!fileType && !fileFullPath.endsWith(fileType)) {
  92. continue;
  93. }
  94. fileList.push({path: fileFullPath,deep:deep});
  95. }
  96. }
  97. }
  98. // 把ui里type为view的runtime删除
  99. gulp.task("deletRuntime", ["tsc"], function() {
  100. // const pageUIFolder = path.join(releaseDir, "pageUI");
  101. // let sceneList= [];
  102. // getFolderList(pageUIFolder, sceneList, ".json");
  103. // for (let i = 0, len = sceneList.length; i < len; i++) {
  104. // let filePath = sceneList[i].path;
  105. // let fileCon = fs.readFileSync(filePath, "utf8");
  106. // let jsonData = JSON.parse(fileCon);
  107. // if (jsonData.type == 'View') {
  108. // if (jsonData.props && jsonData.props.runtime) {
  109. // delete jsonData.props.runtime;
  110. // fs.writeFileSync(filePath, JSON.stringify(jsonData), 'utf8');
  111. // }
  112. // }
  113. // }
  114. });
  115. // 将引入的库的路径改为src根目录的LayaMeMain,并且将引入的该类合并到最终发布目录的根目录下的LayaMeMain.js里
  116. function sortJS (a, b) {
  117. return b.c - a.c;
  118. }
  119. function getFInfoByPath(path, list) {
  120. for (let i = 0, len = list.length; i < len; i++) {
  121. let info = list[i];
  122. if (info.path === path) {
  123. return info;
  124. }
  125. }
  126. return null;
  127. }
  128. gulp.task("mergeToLayaMeMain", ["deletRuntime"], function() {
  129. if (!toBuildPart('LayaMeMain')) {
  130. return;
  131. }
  132. let source = "src";
  133. if (isTS) {
  134. source = "build";
  135. }
  136. let sourceFolder = path.join(workSpaceDir, source);
  137. const scriptPath = path.join(sourceFolder, "script");
  138. let jsList= [];
  139. let scriptStrList = [];
  140. let filePath, fileCon, deep;
  141. // 遍历所有的script,合并到LayaMeMain.js
  142. jsList= [];
  143. scriptStrList = [];
  144. getFolderList(scriptPath, jsList, ".js");
  145. // sort jsList
  146. let needSort = false;
  147. let sortList = [];
  148. let otherList = [];
  149. for (let i = 0, len = jsList.length; i < len; i++) {
  150. let jsInfo = jsList[i];
  151. filePath = jsInfo.path;
  152. fileCon = fs.readFileSync(filePath, "utf8");
  153. jsInfo.content = fileCon;
  154. let extendsCls = fileCon.match((/\ s*extends \s*(.+?)\{/));
  155. if (extendsCls) {
  156. if (extendsCls[1]) {
  157. extendsCls = extendsCls[1].trim();
  158. if (extendsCls && !extendsCls.includes('.')) { // not include Laya.
  159. let importCls = fileCon.match(`import\\s*[{| ]\\s*${extendsCls}\\s*[}| ]\\s*from (.+?)["']`) ;
  160. // console.log( extendsCls, jsInfo.path, !!importCls );
  161. if (importCls && importCls[1]) {
  162. importCls = importCls[1].trim();
  163. importCls = importCls.substr(1); console.log( importCls);
  164. let deep = jsInfo.deep;
  165. let currPath = null;
  166. let _index = importCls.lastIndexOf('./');
  167. let parenPath = '';
  168. if (_index >= 0) {
  169. let fPath = jsInfo.path;
  170. let _index2 = fPath.indexOf('/') >= 0 ? fPath.lastIndexOf('/') : fPath.lastIndexOf('\\') ;
  171. currPath = fPath.substring(0,_index2);
  172. currPath = path.join(jsInfo.path,parenPath + '../', importCls) + '.js';
  173. jsInfo.extendsCls = extendsCls;// currPath;
  174. // console.log(jsInfo);
  175. needSort = true;
  176. if (!sortList.includes(jsInfo)) {
  177. sortList.push(jsInfo);
  178. }
  179. let importJs = getFInfoByPath(currPath, jsList);
  180. if (!importJs) {
  181. throw new Error('not found', currPath);
  182. }
  183. if (!jsInfo.c) {
  184. jsInfo.c = 0;
  185. }
  186. importJs.c = jsInfo.c + 1;
  187. if (!sortList.includes(importJs)) {
  188. sortList.push(importJs);
  189. }
  190. // console.log(currPath,_index,parenPath, jsInfo.path, importCls, extendsCls);
  191. }
  192. }
  193. }
  194. }
  195. }
  196. // .vs .fs 解析
  197. let fileConTmp = fileCon + '';
  198. let vsOrfsImport = fileConTmp.match(/import \s*(.+?) from \s*(.+?).[fv]s['"]/);
  199. while (vsOrfsImport) {
  200. let importVar = vsOrfsImport[1];
  201. let filetype = vsOrfsImport[0];
  202. let importFile = vsOrfsImport[2];
  203. importFile = importFile.replace("'", '');
  204. importFile = importFile.replace('"', '');
  205. if (filetype.indexOf('.vs') >= 0) {
  206. filetype = '.vs';
  207. } else {
  208. filetype = '.fs';
  209. }
  210. importFile = importFile + filetype;
  211. let importFilePath = path.join(filePath,'../',importFile );
  212. console.log('importFilePath', importFilePath);
  213. fileConTmp = fileConTmp.replace(vsOrfsImport[0], '');
  214. // console.log('fileConTmp', fileConTmp);
  215. vsOrfsImport = fileConTmp.match(/import \s*(.+?) from \s*(.+?).[fv]s['"]/);
  216. let srcPath = path.join(workSpaceDir, 'src');
  217. importFilePath = importFilePath.replace(sourceFolder, srcPath);
  218. let importFileStr = fs.readFileSync(importFilePath, 'utf8');
  219. importFileStr = importFileStr.replace(/\r?\n/gm, '\\n');
  220. importFileStr = importFileStr.replace(/"/gm,'\'');
  221. importFileStr = importFileStr.replace(/\t/gm,'\\t');
  222. importFileStr = importFileStr.replace(/\\n\s*/g,'\\n');
  223. importFileStr = importFileStr.replace(/\\n\\n/g,'\\n');
  224. // let lineList = importFileStr.split('\n');
  225. // let rStr = '';
  226. // for(let i = 0,len = lineList.length; i < len; i ++) {
  227. // let lineStr = lineList[i];
  228. // lineStr = lineStr.replace(/\r?\n/gm, '\\n');
  229. // lineStr = lineStr.replace(/"/gm,'\\"');
  230. // lineStr = lineStr.replace(/\t/gm,'\\t');
  231. // lineStr = lineStr.trim();
  232. // rStr = rStr + lineStr + '\\n';
  233. // }
  234. // // fs.writeFileSync(importFilePath + '2',rStr.replace(/\\n/gm,'\n'), 'utf8');
  235. jsInfo.content = `var ${importVar} = "${importFileStr}";\n` + jsInfo.content;
  236. }
  237. }
  238. // console.log('ssssssssss',sortList);
  239. if (needSort) {
  240. sortList.sort(sortJS);
  241. for (let i = 0, len = sortList.length; i < len; i++) {
  242. let jsInfo = sortList[i];
  243. scriptStrList.push(jsInfo.content);
  244. }
  245. }
  246. for (let i = 0, len = jsList.length; i < len; i++) {
  247. let jsInfo = jsList[i];
  248. if (!needSort || !sortList.includes(jsInfo)) {
  249. scriptStrList.push(jsInfo.content);
  250. }
  251. }
  252. let layaMeMainStr = '';
  253. const layaMeMainPath = path.join(sourceFolder, "LayaMeMain.js");
  254. if (fs.existsSync(layaMeMainPath)) {
  255. layaMeMainStr = fs.readFileSync(layaMeMainPath, "utf8");
  256. }
  257. if (scriptStrList.length > 0) {
  258. let scriptStrAll = scriptStrList.join('\n');
  259. layaMeMainStr = scriptStrAll + '\n' + layaMeMainStr;
  260. }
  261. if (layaMeMainStr) {
  262. // console.log(jsList.length,'layaMeMainStr' , layaMeMainStr);
  263. layaMeMainStr = layaMeMainStr.replace(/import/mg, "// import");
  264. // 去掉class前面的字符
  265. layaMeMainStr = layaMeMainStr.replace(/export\s+default\s+[class\.]+\s*/mg, "export class ");
  266. // layaMeMainStr = layaMeMainStr.replace(/export\s+default\s+[class\.]+\s*/mg, "class ");
  267. // layaMeMainStr = layaMeMainStr.replace(/export\s+[class\.]+\s*/mg, "class ");
  268. // layaMeMainStr = layaMeMainStr.replace(/export\s+[var\.]+\s*/mg, "var ");
  269. fs.writeFileSync(`${releaseDir}/LayaMeMain.js`, layaMeMainStr, "utf8");
  270. }
  271. });
  272. gulp.task("mergeToLayaMeLib", ["mergeToLayaMeMain"], function() {
  273. if (!toBuildPart('LayaMeMain')) {
  274. return;
  275. }
  276. let source = "src";
  277. if (isTS) {
  278. source = "build";
  279. }
  280. let sourceFolder = path.join(workSpaceDir, source);
  281. const scriptPath = path.join(sourceFolder, "classLibs");
  282. let jsList= [];
  283. let scriptStrList = [];
  284. let filePath, fileCon, deep;
  285. // 遍历所有的classLibs,合并到LayaMeLib.js
  286. jsList= [];
  287. scriptStrList = [];
  288. getFolderList(scriptPath, jsList, ".js");
  289. // sort jsList
  290. let needSort = false;
  291. let sortList = [];
  292. let otherList = [];
  293. for (let i = 0, len = jsList.length; i < len; i++) {
  294. let jsInfo = jsList[i];
  295. filePath = jsInfo.path;
  296. fileCon = fs.readFileSync(filePath, "utf8");
  297. jsInfo.content = fileCon;
  298. let extendsCls = fileCon.match((/\ s*extends \s*(.+?)\{/));
  299. if (extendsCls) {
  300. if (extendsCls[1]) {
  301. extendsCls = extendsCls[1].trim();
  302. if (extendsCls && !extendsCls.includes('.')) { // not include Laya.
  303. let importCls = fileCon.match(`import\\s*[{| ]\\s*${extendsCls}\\s*[}| ]\\s*from (.+?)["']`) ;
  304. // console.log( extendsCls, jsInfo.path, !!importCls );
  305. if (importCls && importCls[1]) {
  306. importCls = importCls[1].trim();
  307. importCls = importCls.substr(1); console.log( importCls);
  308. let deep = jsInfo.deep;
  309. let currPath = null;
  310. let _index = importCls.lastIndexOf('./');
  311. let parenPath = '';
  312. if (_index >= 0) {
  313. let fPath = jsInfo.path;
  314. let _index2 = fPath.indexOf('/') >= 0 ? fPath.lastIndexOf('/') : fPath.lastIndexOf('\\') ;
  315. currPath = fPath.substring(0,_index2);
  316. currPath = path.join(jsInfo.path,parenPath + '../', importCls) + '.js';
  317. jsInfo.extendsCls = extendsCls;// currPath;
  318. // console.log(jsInfo);
  319. needSort = true;
  320. if (!sortList.includes(jsInfo)) {
  321. sortList.push(jsInfo);
  322. }
  323. let importJs = getFInfoByPath(currPath, jsList);
  324. if (!importJs) {
  325. throw new Error('not found', currPath);
  326. }
  327. if (!jsInfo.c) {
  328. jsInfo.c = 0;
  329. }
  330. importJs.c = jsInfo.c + 1;
  331. if (!sortList.includes(importJs)) {
  332. sortList.push(importJs);
  333. }
  334. // console.log(currPath,_index,parenPath, jsInfo.path, importCls, extendsCls);
  335. }
  336. }
  337. }
  338. }
  339. }
  340. }
  341. // console.log('ssssssssss',sortList);
  342. if (needSort) {
  343. sortList.sort(sortJS);
  344. for (let i = 0, len = sortList.length; i < len; i++) {
  345. let jsInfo = sortList[i];
  346. scriptStrList.push(jsInfo.content);
  347. }
  348. }
  349. for (let i = 0, len = jsList.length; i < len; i++) {
  350. let jsInfo = jsList[i];
  351. if (!needSort || !sortList.includes(jsInfo)) {
  352. scriptStrList.push(jsInfo.content);
  353. }
  354. }
  355. let layaMeLibStr = '';
  356. // const layaMeLibPath = path.join(sourceFolder, "LayaMeLib.js");
  357. // if (fs.existsSync(layaMeLibPath)) {
  358. // layaMeLibStr = fs.readFileSync(layaMeLibPath, "utf8");
  359. // }
  360. if (scriptStrList.length > 0) {
  361. let scriptStrAll = scriptStrList.join('\n');
  362. layaMeLibStr = scriptStrAll + layaMeLibStr;
  363. }
  364. if (layaMeLibStr) {
  365. // console.log(jsList.length,'layaMeLibStr' , layaMeLibStr);
  366. layaMeLibStr = layaMeLibStr.replace(/import/mg, "// import");
  367. // 去掉class前面的字符
  368. layaMeLibStr = layaMeLibStr.replace(/export\s+default\s+[class\.]+\s*/mg, "export class ");
  369. // layaMeLibStr = layaMeLibStr.replace(/export\s+default\s+[class\.]+\s*/mg, "class ");
  370. // layaMeLibStr = layaMeLibStr.replace(/export\s+[class\.]+\s*/mg, "class ");
  371. // layaMeLibStr = layaMeLibStr.replace(/export\s+[var\.]+\s*/mg, "var ");
  372. fs.writeFileSync(`${releaseDir}/LayaMeLib.js`, layaMeLibStr, "utf8");
  373. }
  374. });
  375. // 修改extends Laya.Script3D 为 extends GameScript
  376. // 修改 config.json,把.ts替换为.js
  377. function commentImport (str){
  378. str = str.replace(/import/mg, "// import");
  379. return str;
  380. }
  381. function changeComponentsFile() {
  382. var stream = new Stream.Transform({ objectMode: true });
  383. let source = "src";
  384. if (isTS) {
  385. source = "build";
  386. }
  387. let sourceFolder = path.join(workSpaceDir, source);
  388. const scriptPath = path.join(sourceFolder, "script");
  389. const componentsPath = path.join(sourceFolder, "components");
  390. const actionScriptPath = path.join(sourceFolder, "actionScript", "actionFunc.js");
  391. const uiScriptPath = path.join(sourceFolder, "uiScript");
  392. let importPathList = [scriptPath, componentsPath, actionScriptPath, uiScriptPath];
  393. stream._transform = function (originalFile, unused, callback) {
  394. let fPath = originalFile.path;
  395. // throw new Error();
  396. let file = null;
  397. const getFile = () => {
  398. if (!file) {
  399. file = originalFile.clone({ contents: false });
  400. }
  401. return file;
  402. }
  403. // console.log('fPth', fPath, componentsPath);
  404. // 注释import
  405. for(let k =0; k <importPathList.length; k ++) {
  406. let _path = importPathList[k];
  407. if (fPath.startsWith(_path)) {
  408. file = getFile();
  409. let stringData = String(file.contents);
  410. stringData = commentImport(stringData);
  411. let finalBinaryData = Buffer.from(stringData);
  412. file.contents = finalBinaryData;
  413. }
  414. }
  415. if (fPath.indexOf('components') >= 0) {
  416. if ( fPath.endsWith('.js')) {
  417. file = getFile();
  418. let stringData = String(file.contents);
  419. stringData = stringData.replace(/extends\s+[Laya.Script3D\.]+\s*{/mg, "extends GameScript {");
  420. let finalBinaryData = Buffer.from(stringData);
  421. file.contents = finalBinaryData;
  422. } else if (fPath.endsWith('config.json')) {
  423. file = getFile();
  424. let stringData = String(file.contents);
  425. stringData = stringData.replace(/.ts\"/mg, '.js"');
  426. let finalBinaryData = Buffer.from(stringData);
  427. file.contents = finalBinaryData;
  428. }
  429. }
  430. // 去掉class前面的字符
  431. if (fPath.endsWith('.js')) {
  432. file = getFile();
  433. let stringData = String(file.contents);
  434. stringData = stringData.replace(/export\s+default\s+[class\.]+\s*/mg, "export class ");
  435. // stringData = stringData.replace(/export\s+default\s+[class\.]+\s*/mg, "class ");
  436. // stringData = stringData.replace(/export\s+[class\.]+\s*/mg, "class ");
  437. // stringData = stringData.replace(/export\s+[var\.]+\s*/mg, "var ");
  438. let finalBinaryData = Buffer.from(stringData);
  439. file.contents = finalBinaryData;
  440. }
  441. if (fPath.endsWith('.js')) {
  442. file = getFile();
  443. let filePath = fPath;
  444. let fileCon = String(file.contents);
  445. // .vs .fs 解析
  446. let fileConTmp = fileCon + '';
  447. let jsInfo = {content: fileCon};
  448. let vsOrfsImport = fileConTmp.match(/import \s*(.+?) from \s*(.+?).[fv]s['"]/);
  449. let hasVf = false;
  450. while (vsOrfsImport) {
  451. hasVf = true;
  452. let importVar = vsOrfsImport[1];
  453. let filetype = vsOrfsImport[0];
  454. let importFile = vsOrfsImport[2];
  455. importFile = importFile.replace("'", '');
  456. importFile = importFile.replace('"', '');
  457. if (filetype.indexOf('.vs') >= 0) {
  458. filetype = '.vs';
  459. } else {
  460. filetype = '.fs';
  461. }
  462. importFile = importFile + filetype;
  463. let importFilePath = path.join(filePath,'../',importFile );
  464. console.log('importFilePath', importFilePath);
  465. fileConTmp = fileConTmp.replace(vsOrfsImport[0], '');
  466. // console.log('fileConTmp', fileConTmp);
  467. vsOrfsImport = fileConTmp.match(/import \s*(.+?) from \s*(.+?).[fv]s['"]/);
  468. let srcPath = path.join(workSpaceDir, 'src');
  469. importFilePath = importFilePath.replace(sourceFolder, srcPath);
  470. let importFileStr = fs.readFileSync(importFilePath, 'utf8');
  471. importFileStr = importFileStr.replace(/\r?\n/gm, '\\n');
  472. importFileStr = importFileStr.replace(/"/gm,'\'');
  473. importFileStr = importFileStr.replace(/\t/gm,'\\t');
  474. importFileStr = importFileStr.replace(/\\n\s*/g,'\\n');
  475. importFileStr = importFileStr.replace(/\\n\\n/g,'\\n');
  476. jsInfo.content = `var ${importVar} = "${importFileStr}";\n` + jsInfo.content;
  477. }
  478. if (hasVf) {
  479. let finalBinaryData = Buffer.from(jsInfo.content);
  480. file.contents = finalBinaryData;
  481. }
  482. }
  483. if (file) {
  484. callback(null, file);
  485. } else {
  486. callback(null, originalFile);
  487. }
  488. };
  489. return stream;
  490. }
  491. gulp.task("genPreloadMap", ["mergeToLayaMeLib"], function() {
  492. let atlasList = [];
  493. getFolderList(releaseDir,atlasList, '.atlas');
  494. let preloadJson = {
  495. atlas: [],
  496. atlasPng:[],
  497. textures: []
  498. };
  499. let releaseDirTmp = releaseDir.replace(/\\/g, '/');
  500. for(let i = 0,len = atlasList.length; i < len; i ++) {
  501. let file = atlasList[i].path;
  502. file = file.replace(/\\/g, '/');
  503. file = file.replace(releaseDirTmp, '');
  504. file = file.replace('/', '');
  505. preloadJson.atlas.push(file);
  506. preloadJson.atlasPng.push( file.replace('.atlas', '.png'));
  507. }
  508. let texturesList = [];
  509. let texturesDir = path.join(releaseDir, 'textures');
  510. getFolderList(texturesDir,texturesList, '.png');
  511. getFolderList(texturesDir,texturesList, '.jpg');
  512. getFolderList(texturesDir,texturesList, '.jpeg');
  513. let texturesDirTmp = releaseDir.replace(/\\/g, '/');
  514. for(let i = 0,len = texturesList.length; i < len; i ++) {
  515. let file = texturesList[i].path;
  516. file = file.replace(/\\/g, '/');
  517. file = file.replace(texturesDirTmp, '');
  518. file = file.replace('/', '');
  519. preloadJson.textures.push(file);
  520. }
  521. fs.writeFileSync(path.join(releaseDir, 'preload.json'), JSON.stringify(preloadJson, null ,4), 'utf8');
  522. // console.log('atlasList', preloadJson);
  523. });
  524. gulp.task("copy", ["genPreloadMap"], function() {
  525. let source = "src";
  526. if (isTS) {
  527. source = "build";
  528. }
  529. let sourceFolder = path.join(workSpaceDir, source);
  530. let layameInfo = config.layameInfo;
  531. let filter1list = [];
  532. if (toBuildPart('uiScript')) {
  533. filter1list.push('uiScript/**/*.*');
  534. }
  535. if (toBuildPart('actionScript')) {
  536. filter1list.push('actionScript/**/*.*');
  537. }
  538. if (toBuildPart('components')) {
  539. filter1list.push('components/**/*.*');
  540. }
  541. let filter1 = ``;
  542. if (filter1list.length > 1) {
  543. filter1 = `${sourceFolder}/{`;
  544. filter1 += filter1list.join(',');
  545. filter1 += '}';
  546. } else if (filter1list.length == 1) {
  547. filter1 = `${sourceFolder}/{,`;
  548. filter1 += filter1list[0];
  549. filter1 += '}';
  550. } else {
  551. return;
  552. }
  553. let filters = [filter1];
  554. // console.log('filter1', filter1);throw new Error();
  555. if (isTS) {
  556. let filter2 = `${workSpaceDir}/src/{,`;
  557. let filter2list =[];
  558. if (toBuildPart('uiScript')) {
  559. filter2list.push('uiScript/**/!(*.ts)');
  560. }
  561. if (toBuildPart('actionScript')) {
  562. filter2list.push('actionScript/**/!(*.ts)');
  563. }
  564. if (toBuildPart('components')) {
  565. filter2list.push('components/**/!(*.ts)');
  566. }
  567. if (filter2list.length > 1) {
  568. filter2 += filter2list.join(',');
  569. } else if (filter2list.length == 1) {
  570. filter2 += filter2list[0];
  571. }
  572. filter2 += '}';
  573. filters.push(
  574. filter2
  575. );
  576. }
  577. return gulp.src(filters)
  578. .pipe(changeComponentsFile())
  579. .pipe(gulp.dest(releaseDir));
  580. });
  581. gulp.task("buildLayaMeProj", versiontask, function() {
  582. console.log("all tasks completed");
  583. });