Commit 7622eba2 authored by huoshizhe's avatar huoshizhe

feat:

parent 9fb2f138
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
"win": "cd publish && build.cmd" "win": "cd publish && build.cmd"
}, },
"author": "", "author": "",
"type": "module",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"compressing": "^1.5.0" "compressing": "^1.5.0"
......
{ {"ver":"1.1.2","uuid":"c35bb2f6-f24a-4850-ae44-643f2fdc7541","isBundle":false,"bundleName":"","priority":1,"compressionType":{},"optimizeHotUpdate":{},"inlineSpriteFrames":{},"isRemoteBundle":{"ios":false,"android":false},"subMetas":{}}
"ver": "1.1.2", \ No newline at end of file
"uuid": "c35bb2f6-f24a-4850-ae44-643f2fdc7541",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
"_groupIndex": 0, "_groupIndex": 0,
"groupIndex": 0, "groupIndex": 0,
"autoReleaseAssets": true, "autoReleaseAssets": true,
"_id": "57ea7c61-9b8b-498a-b024-c98ee9124beb" "_id": "f2080b9e-65f4-4a10-b460-eb81064a9d76"
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
...@@ -2540,7 +2540,7 @@ ...@@ -2540,7 +2540,7 @@
"_id": "bauV8xcDFGA6ssKG7KNZ9I" "_id": "bauV8xcDFGA6ssKG7KNZ9I"
}, },
{ {
"__type__": "f4edeRi+NdAabqAkVYRwFjK", "__type__": "3d918khiRNEu5DeFkBUA5L1",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
......
{ {
"ver": "1.2.9", "ver": "1.2.9",
"uuid": "57ea7c61-9b8b-498a-b024-c98ee9124beb", "uuid": "f2080b9e-65f4-4a10-b460-eb81064a9d76",
"asyncLoadAssets": false, "asyncLoadAssets": false,
"autoReleaseAssets": true, "autoReleaseAssets": true,
"subMetas": {} "subMetas": {}
......
{ {
"ver": "1.0.8", "ver": "1.0.8",
"uuid": "f4ede462-f8d7-4069-ba80-915611c058ca", "uuid": "3d918921-8913-44bb-90de-1640540392f5",
"isPlugin": false, "isPlugin": false,
"loadPluginInWeb": true, "loadPluginInWeb": true,
"loadPluginInNative": true, "loadPluginInNative": true,
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
"packages": "packages", "packages": "packages",
"name": "play", "name": "play",
"id": "9af72fd2-44a6-4131-8ea3-3e1b3fa22231", "id": "9af72fd2-44a6-4131-8ea3-3e1b3fa22231",
"version": "2.4.5", "version": "2.4.4",
"isNew": false "isNew": false
} }
\ No newline at end of file
{ {
"title": "play", "title": "play",
"packageName": "org.cocos2d.demo", "packageName": "org.cocos2d.demo",
"startScene": "57ea7c61-9b8b-498a-b024-c98ee9124beb", "startScene": "f2080b9e-65f4-4a10-b460-eb81064a9d76",
"excludeScenes": [], "excludeScenes": [],
"includeSDKBox": false, "includeSDKBox": false,
"orientation": { "orientation": {
...@@ -28,7 +28,8 @@ ...@@ -28,7 +28,8 @@
}, },
"ios": { "ios": {
"REMOTE_SERVER_ROOT": "", "REMOTE_SERVER_ROOT": "",
"packageName": "org.cocos2d.demo" "packageName": "org.cocos2d.demo",
"ios_enable_jit": true
}, },
"mac": { "mac": {
"REMOTE_SERVER_ROOT": "", "REMOTE_SERVER_ROOT": "",
...@@ -50,5 +51,6 @@ ...@@ -50,5 +51,6 @@
"scheme": "https", "scheme": "https",
"skipRecord": false "skipRecord": false
}, },
"appBundle": false "appBundle": false,
"agreements": {}
} }
{ {
"last-module-event-record-time": 1600677246969, "last-module-event-record-time": 1636882785201,
"migrate-history": [ "migrate-history": [
"cloud-function" "cloud-function"
] ]
......
import { buildAndroidBundle } from "./buildAndroidBundle.js";
import { buildWebDesktop } from "./buildWebDesktop.js";
import { build_check } from "./build_check.js"
import { changeSettingsToBundle, changeSettingToWebDesktop } from "./changeSettings.js";
import { replaceUuids } from "./replaceUuids.js";
import { copyDir, removeDir } from "./utils.js";
import { replaceIndexHtml } from "./replaceIndexHtml.js";
// 构建前检查
build_check();
// 清理旧文件
await removeDir('./publish/play');
await removeDir('./publish/form');
await removeDir('./publish/ios');
await removeDir('./publish/android');
await removeDir('./publish/web_desktop');
// 构建form
copyDir('../form', 'publish/form');
// 替换uuid
replaceUuids();
// 构建play
// 改设置为非bundle
changeSettingToWebDesktop();
// 构建web_desktop
await buildWebDesktop();
await copyDir('../play/build/web-desktop', 'publish/play');
replaceIndexHtml();
console.log('构建 web desktop 成功!');
// 改设置为bundle
changeSettingsToBundle();
await buildAndroidBundle();
await copyDir('../play/build_android/jsb-link/remote', 'publish/android');
console.log('构建 android bundle 成功!');
// 改设置为非bundle
changeSettingToWebDesktop();
\ No newline at end of file
import { spawn } from "child_process";
const creatorBasePath = 'C:\\CocosDashboard_1.0.6\\resources\\.editors\\Creator';
export function buildAndroidBundle() {
return new Promise((resolve, reject) => {
const buffer = spawn(
`${creatorBasePath}\\2.4.4\\CocosCreator.exe`,
['--path', './', '--build', "platform=ios;debug=false;md5Cache=true;buildPath=build_android;appABIs=['armeabi-v7a','x86','x86_64','arm64-v8a'];encryptJs=true;xxteaKey=6bbfce23-28b4-4a;zipCompressJs=true", '--force'],
{ cwd: '../play' }
);
buffer.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
buffer.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
buffer.on('close', (code) => {
console.log(`child process exited with code ${code}`);
resolve();
});
});
}
\ No newline at end of file
import { spawn } from "child_process";
const creatorBasePath = 'C:\\CocosDashboard_1.0.6\\resources\\.editors\\Creator';
export function buildWebDesktop() {
return new Promise((resolve, reject) => {
const buffer = spawn(
`${creatorBasePath}\\2.4.0\\CocosCreator.exe`,
['--path', './', '--build', 'platform=web-desktop;debug=true', '--force'],
{ cwd: '../play' }
);
buffer.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
buffer.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
buffer.on('close', (code) => {
console.log(`child process exited with code ${code}`);
resolve();
});
});
}
\ No newline at end of file
let fs = require('fs'); import fs from 'fs';
const dirNames = __dirname.split('/'); export function build_check() {
const projectName = dirNames[dirNames.length - 2]; const dirNames = process.cwd().split(/\/|\\/);
const path = '../play/assets' const projectName = dirNames[dirNames.length - 2];
let folderName = ''; const path = '../play/assets'
fs.readdirSync(path).find(fileName => { let folderName = '';
const st = fs.statSync(`${path}/${fileName}`); fs.readdirSync(path).find(fileName => {
if (st.isDirectory()) { const st = fs.statSync(`${path}/${fileName}`);
folderName = fileName; if (st.isDirectory()) {
} folderName = fileName;
}); }
});
if (projectName != folderName) { if (projectName != folderName) {
throw (`项目名(${projectName})与bundle文件夹名(${folderName})不相同`); throw (`项目名(${projectName})与bundle文件夹名(${folderName})不相同`);
} }
let same = false; let same = false;
const files = fs.readdirSync(`${path}/${folderName}/scene`); const files = fs.readdirSync(`${path}/${folderName}/scene`);
files.forEach(fileName => { files.forEach(fileName => {
fileName.split('.').forEach((str, idx, arr) => { fileName.split('.').forEach((str, idx, arr) => {
if (str == 'fire') { if (str == 'fire') {
const sceneName = arr[idx - 1]; const sceneName = arr[idx - 1];
if (folderName == sceneName) { if (folderName == sceneName) {
same = true; same = true;
}
} }
} })
}) });
});
if (!same) { if (!same) {
throw (`bundle文件夹名称(${folderName})与scene名称不相同`); throw (`bundle文件夹名称(${folderName})与scene名称不相同`);
}
} }
\ No newline at end of file
const fs = require('fs');
const { v4, parse } = require('uuid');
const { Base64 } = require('js-base64');
console.log('build_step_0 开始~!');
function getFolderName(path) {
let folderName = '';
fs.readdirSync(path).find(fileName => {
const st = fs.statSync(`${path}/${fileName}`);
if (st.isDirectory()) {
folderName = fileName;
}
});
return folderName;
}
function editFolderMeta(path, folderName) {
const metaPath = `${path}/${folderName}.meta`;
const metaDataStr = fs.readFileSync(metaPath);
const metaData = JSON.parse(metaDataStr);
metaData.isBundle = false;
fs.writeFileSync(metaPath, JSON.stringify(metaData));
}
function fileReplace(path, replaceStr, newStr) {
const fileStr = fs.readFileSync(path);
const newFileStr = fileStr.toString().replace(new RegExp(replaceStr.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), 'g'), newStr);
fs.writeFileSync(path, newFileStr);
}
const path = '../play/assets'
const folderName = getFolderName(path);
editFolderMeta(path, folderName);
const oldFireUuid = '57ea7c61-9b8b-498a-b024-c98ee9124beb';
const newFireUuid = v4();
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire.meta`, oldFireUuid, newFireUuid);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire`, oldFireUuid, newFireUuid);
fileReplace('../play/settings/builder.json', oldFireUuid, newFireUuid);
function getShortUuid(uuid) {
const bytes = parse(uuid).subarray(1);
return uuid.substring(0, 5) + Base64.fromUint8Array(bytes).substring(2);
}
const oldJsUuid = 'f4ede462-f8d7-4069-ba80-915611c058ca';
const oldJsShortUuid = 'f4edeRi+NdAabqAkVYRwFjK';
const oldJsId = 'e687yyoRBIzZAOVRL8Sseh';
const newJsUuid = v4();
const newJsShortUuid = getShortUuid(newJsUuid);
const newJsId = v4().replace(/-/g, '').substring(0, oldJsId.length);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.js.meta`, oldJsUuid, newJsUuid);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire`, oldFireUuid, newFireUuid);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire`, oldJsShortUuid, newJsShortUuid);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire`, oldJsId, newJsId);
console.log('build_step_0 完成~!');
import fs from "fs";
function getFolderName(path) {
let folderName = '';
fs.readdirSync(path).find(fileName => {
const st = fs.statSync(`${path}/${fileName}`);
if (st.isDirectory()) {
folderName = fileName;
}
});
return folderName;
}
function editFolderMeta(path, folderName, isBundle) {
const metaPath = `${path}/${folderName}.meta`;
const metaDataStr = fs.readFileSync(metaPath);
const metaData = JSON.parse(metaDataStr);
metaData.isBundle = isBundle;
metaData.isRemoteBundle = {
ios: isBundle,
android: isBundle
};
fs.writeFileSync(metaPath, JSON.stringify(metaData));
}
export function changeSettingToWebDesktop() {
const path = '../play/assets'
const folderName = getFolderName(path);
editFolderMeta(path, folderName, false);
}
export function changeSettingsToBundle() {
const path = '../play/assets'
const folderName = getFolderName(path);
editFolderMeta(path, folderName, true);
}
\ No newline at end of file
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
"description": "", "description": "",
"main": "build.js", "main": "build.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
}, },
"type": "module",
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
...@@ -14,4 +16,4 @@ ...@@ -14,4 +16,4 @@
"js-base64": "^3.7.2", "js-base64": "^3.7.2",
"uuid": "^8.3.2" "uuid": "^8.3.2"
} }
} }
\ No newline at end of file
import fs from "fs";
export function replaceIndexHtml() {
const data = fs.readFileSync('./index.html');
fs.writeFileSync('./publish/play/index.html', data);
}
\ No newline at end of file
import fs from 'fs';
import { v4, parse } from 'uuid';
import { Base64 } from 'js-base64';
export function replaceUuids() {
console.log('build_step_0 开始~!');
function getFolderName(path) {
let folderName = '';
fs.readdirSync(path).find(fileName => {
const st = fs.statSync(`${path}/${fileName}`);
if (st.isDirectory()) {
folderName = fileName;
}
});
return folderName;
}
function editFolderMeta(path, folderName) {
const metaPath = `${path}/${folderName}.meta`;
const metaDataStr = fs.readFileSync(metaPath);
const metaData = JSON.parse(metaDataStr);
metaData.isBundle = false;
fs.writeFileSync(metaPath, JSON.stringify(metaData));
}
function fileReplace(path, replaceStr, newStr) {
const fileStr = fs.readFileSync(path);
const newFileStr = fileStr.toString().replace(new RegExp(replaceStr.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), 'g'), newStr);
fs.writeFileSync(path, newFileStr);
}
const path = '../play/assets'
const folderName = getFolderName(path);
editFolderMeta(path, folderName);
const oldFireUuid = '57ea7c61-9b8b-498a-b024-c98ee9124beb';
const newFireUuid = v4();
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire.meta`, oldFireUuid, newFireUuid);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire`, oldFireUuid, newFireUuid);
fileReplace('../play/settings/builder.json', oldFireUuid, newFireUuid);
function getShortUuid(uuid) {
const bytes = parse(uuid).subarray(1);
return uuid.substring(0, 5) + Base64.fromUint8Array(bytes).substring(2);
}
const oldJsUuid = 'f4ede462-f8d7-4069-ba80-915611c058ca';
const oldJsShortUuid = 'f4edeRi+NdAabqAkVYRwFjK';
const oldJsId = 'e687yyoRBIzZAOVRL8Sseh';
const newJsUuid = v4();
const newJsShortUuid = getShortUuid(newJsUuid);
const newJsId = v4().replace(/-/g, '').substring(0, oldJsId.length);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.js.meta`, oldJsUuid, newJsUuid);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire`, oldFireUuid, newFireUuid);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire`, oldJsShortUuid, newJsShortUuid);
fileReplace(`../play/assets/${folderName}/scene/${folderName}.fire`, oldJsId, newJsId);
console.log('build_step_0 完成~!');
}
let fs = require('fs'); import fs from 'fs';
module.exports = {
fix2: function (num) {
if (num >= 10) {
return '' + num;
} else {
return '0' + num;
}
},
copyDir: async function (src, dst) { export function fix2(num) {
const exists = await fs.existsSync(dst); if (num >= 10) {
if (!exists) { return '' + num;
await fs.mkdirSync(dst); } else {
} return '0' + num;
//读取目录 }
const paths = await fs.readdirSync(src); }
for (let i = 0; i < paths.length; i++) {
let path = paths[i];
const newSrc = `${src}/${path}`;
const newDst = `${dst}/${path}`;
const st = await fs.statSync(newSrc);
if (st.isFile()) {
console.log('copy: ' + newDst);
const data = await fs.readFileSync(newSrc);
await fs.writeFileSync(newDst, data);
} else if (st.isDirectory()) {
arguments.callee(newSrc, newDst);
}
}
},
removeDir: async function (src) { export async function copyDir(src, dst) {
const exists = await fs.existsSync(src); const exists = await fs.existsSync(dst);
if (!exists) { if (!exists) {
return; await fs.mkdirSync(dst);
}
//读取目录
const paths = await fs.readdirSync(src);
for (let i = 0; i < paths.length; i++) {
let path = paths[i];
const newSrc = `${src}/${path}`;
const newDst = `${dst}/${path}`;
const st = await fs.statSync(newSrc);
if (st.isFile()) {
console.log('copy: ' + newDst);
const data = await fs.readFileSync(newSrc);
await fs.writeFileSync(newDst, data);
} else if (st.isDirectory()) {
copyDir(newSrc, newDst);
} }
}
}
//读取目录 export async function removeDir(src) {
const st = await fs.statSync(src); const exists = await fs.existsSync(src);
const paths = await fs.readdirSync(src); if (!exists) {
for (let i = 0; i < paths.length; i++) { return;
let path = paths[i]; }
const newSrc = `${src}/${path}`;
const st = await fs.statSync(newSrc); //读取目录
if (st.isFile()) { const st = await fs.statSync(src);
console.log('remove: ' + newSrc); const paths = await fs.readdirSync(src);
await fs.unlinkSync(newSrc); for (let i = 0; i < paths.length; i++) {
} else if (st.isDirectory()) { let path = paths[i];
await arguments.callee(newSrc); const newSrc = `${src}/${path}`;
} const st = await fs.statSync(newSrc);
if (st.isFile()) {
console.log('remove: ' + newSrc);
await fs.unlinkSync(newSrc);
} else if (st.isDirectory()) {
await removeDir(newSrc);
} }
await fs.rmdirSync(src);
} }
} await fs.rmdirSync(src);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment