Commit c91f6f98 authored by huoshizhe's avatar huoshizhe

feat: 本地服务器

parent 9dda9208
{"ver":"1.1.2","uuid":"c35bb2f6-f24a-4850-ae44-643f2fdc7541","isBundle":false,"bundleName":"","priority":1,"compressionType":{"android":"default","ios":"default"},"optimizeHotUpdate":{"android":false,"ios":false},"inlineSpriteFrames":{"android":false,"ios":false},"isRemoteBundle":{"ios":false,"android":false},"subMetas":{}} {
\ No newline at end of file "ver": "1.1.2",
"uuid": "c35bb2f6-f24a-4850-ae44-643f2fdc7541",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {
"android": "default",
"ios": "default"
},
"optimizeHotUpdate": {
"android": false,
"ios": false
},
"inlineSpriteFrames": {
"android": false,
"ios": false
},
"isRemoteBundle": {
"ios": false,
"android": false
},
"subMetas": {}
}
\ No newline at end of file
import { import express from "express";
buildWebDesktop, import os from "os";
buildAndroidBundle, import readline from "readline";
buildIosBundle, import { build } from "./buildCocos.js";
buildWebBundle,
createConfigFile, const networkInfo = os.networkInterfaces();
build_check,
changeSettingsToBundle, let host = '';
changeSettingToWebDesktop, for (const infos of Object.values(networkInfo)) {
compressAll, for (const info of infos) {
replaceIndexHtml, if (info.family == 'IPv4') {
replaceUuids if (info.address.split('.')[0] != "127") {
} from "./buildCocos.js"; host = info.address;
import { copyDir, removeDir } from "./utils.js"; }
}
const startTime = new Date().getTime(); }
}
// 构建前检查
const projectName = build_check(); var app = express();
// 清理旧文件 app.use('/publish', express.static('publish'));
await removeDir('./publish/play');
await removeDir('./publish/form'); app.get('/', function (req, res) {
await removeDir('./publish/ios'); res.send('Hello World');
await removeDir('./publish/android'); })
await removeDir('./publish/web_desktop');
let port = '';
// 构建form var server = app.listen(8081, function () {
copyDir('../form/src', 'publish/form');
port = server.address().port
// 替换uuid
replaceUuids(); console.log("测试服务已启动:%s:%s", host, port)
// 构建play })
// 改设置为非bundle const rl = readline.createInterface({
changeSettingToWebDesktop(); input: process.stdin,
output: process.stdout
// 构建web_desktop })
await buildWebDesktop(); rl.on('line', async (str) => {
if (str.trim() == 'build') {
await copyDir('../play/build/web-desktop', 'publish/play'); await build();
console.log("测试服务已启动:%s:%s", host, port)
replaceIndexHtml(); console.log('输入 build 构建。')
} else {
console.log('构建 web desktop 成功!'); console.log("测试服务已启动:%s:%s", host, port)
console.log('输入 build 构建。')
// 改设置为bundle }
changeSettingsToBundle(); })
await buildAndroidBundle();
await copyDir('../play/build_android/jsb-link/remote', 'publish/android');
console.log('构建 android bundle 成功!');
await buildIosBundle();
await copyDir('../play/build_ios/jsb-link/remote', 'publish/ios');
console.log('构建 ios bundle 成功!');
await buildWebBundle();
await copyDir(`../play/build_web_desktop/web-desktop/assets/${projectName}`, 'publish/web_desktop');
console.log('构建 web bundle 成功!');
// 改设置为非bundle
changeSettingToWebDesktop();
createConfigFile(projectName);
compressAll(projectName);
const endTime = new Date().getTime();
const duration = new Date(endTime - startTime);
console.log(`打包完成!`);
console.log(`用时${duration.getMinutes()}${duration.getSeconds()}秒。`);
import { build } from "./buildCocos.js";
await build();
\ No newline at end of file
import { spawn } from "child_process"; import { spawn } from "child_process";
import fs from "fs"; import fs from "fs";
import compressing from 'compressing'; import compressing from 'compressing';
import { fix2 } from "./utils.js";
import { v4, parse } from 'uuid'; import { v4, parse } from 'uuid';
import { Base64 } from 'js-base64'; import { Base64 } from 'js-base64';
import { copyDir, removeDir, fix2 } from "./utils.js";
const creatorBasePath = 'C:\\CocosDashboard_1.0.6\\resources\\.editors\\Creator'; export async function build() {
const startTime = new Date().getTime();
// 构建前检查
const projectName = 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/src', '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 成功!');
await buildIosBundle();
await copyDir('../play/build_ios/jsb-link/remote', 'publish/ios');
console.log('构建 ios bundle 成功!');
await buildWebBundle();
await copyDir(`../play/build_web_desktop/web-desktop/assets/${projectName}`, 'publish/web_desktop');
console.log('构建 web bundle 成功!');
// 改设置为非bundle
changeSettingToWebDesktop();
createConfigFile(projectName);
compressAll(projectName);
const endTime = new Date().getTime();
const duration = new Date(endTime - startTime);
console.log(`打包完成!`);
console.log(`用时${duration.getMinutes()}${duration.getSeconds()}秒。`);
}
const creatorBasePath = 'C:\\CocosDashboard_1.0.6\\resources\\.editors\\Creator';
export function buildWebDesktop() { export function buildWebDesktop() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const buffer = spawn( const buffer = spawn(
......
This diff is collapsed.
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
"main": "build.js", "main": "build.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "node build.js",
"start": "node app.js" "start": "node app.js"
}, },
"type": "module", "type": "module",
...@@ -13,7 +14,8 @@ ...@@ -13,7 +14,8 @@
"dependencies": { "dependencies": {
"child_process": "^1.0.2", "child_process": "^1.0.2",
"compressing": "^1.5.1", "compressing": "^1.5.1",
"express": "^4.17.1",
"js-base64": "^3.7.2", "js-base64": "^3.7.2",
"uuid": "^8.3.2" "uuid": "^8.3.2"
} }
} }
\ 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