使用终端窗口的方式运行解析psd

This commit is contained in:
onvia 2023-07-31 09:09:25 +08:00
parent 9174aea6e1
commit 40ee90491e
7 changed files with 92 additions and 6 deletions

View File

@ -0,0 +1,11 @@
@echo off
set input1=%1%
set input2=%2%
cd /d %~dp0
%~dp0../../bin/node.exe ./index.js %input1% %input2%
pause
exit

View File

@ -0,0 +1,10 @@
# exec /bin/bash
#!/bin/sh
# node_dir=$(dirname $(dirname $(dirname $(realpath $0))))
cur_dir=$(dirname $0)
$(dirname $(dirname $cur_dir))/bin/node $cur_dir/index.js $1 $2
# echo 请按任意键继续..
# read -n 1

View File

@ -18,6 +18,7 @@ const configFile = path.join(`${packagePath}/config/psd.config.json`);
const nodejsFile = path.join(packagePath, "bin", `node${Os.platform() == 'darwin' ? "" : ".exe"}`);
const commandFile = path.join(packagePath, "libs", "psd2ui", `command.${Os.platform() == 'darwin' ? "sh" : "bat"}`);
const psd = path.join(packagePath, "libs", "psd2ui", "index.js");
let uuid2md5 = new Map();
@ -35,9 +36,13 @@ function _exec(options, tasks) {
// 处理权限问题
if (Os.platform() === 'darwin') {
if (fs.statSync(nodejsFile).mode != 33261) {
Editor.log(`[ccc-tnt-psd2ui] 设置权限`);
Editor.log(`[ccc-tnt-psd2ui] nodejsFile 设置权限`);
fs.chmodSync(nodejsFile, 33261);
}
if (fs.statSync(commandFile).mode != 33261) {
Editor.log(`[ccc-tnt-psd2ui] commandFile 设置权限`);
fs.chmodSync(commandFile, 33261);
}
}
Editor.log("[ccc-tnt-psd2ui] 命令参数:" + jsonContent);
@ -46,13 +51,29 @@ function _exec(options, tasks) {
let base64 = Buffer.from(jsonContent).toString("base64");
tasks.push(new Promise((rs) => {
// Editor.log(`[ccc-tnt-psd2ui] `, `${nodejsFile} ${psd}` + ' ' + `--json ${base64}`);
exec(`${nodejsFile} ${psd}` + ' ' + `--json ${base64}`, { windowsHide: false }, (err, stdout, stderr) => {
// exec(`${nodejsFile} ${psd}` + ' ' + `--json ${base64}`, { windowsHide: false }, (err, stdout, stderr) => {
// Editor.log("[ccc-tnt-psd2ui]:\n", stdout);
// if (stderr) {
// Editor.log(stderr);
// }
// rs();
// })
let shellScript = commandFile; // 你的脚本路径
let scriptArgs = `--json ${base64}`; // 你的脚本参数
let command =
Os.platform() == 'darwin' ? `osascript -e 'tell app "Terminal" to do script "cd ${process.cwd()}; ${shellScript} ${scriptArgs}"'`
: `start ${commandFile} ${scriptArgs}`;
exec(command, (error, stdout, stderr) => {
Editor.log("[ccc-tnt-psd2ui]:\n", stdout);
Editor.log("[ccc-tnt-psd2ui]: 程序执行完后请手动关闭终端窗口", );
if (stderr) {
Editor.log(stderr);
}
rs();
})
});
}));
return tasks;
}

View File

@ -0,0 +1,11 @@
@echo off
set input1=%1%
set input2=%2%
cd /d %~dp0
%~dp0../../bin/node.exe ./index.js %input1% %input2%
pause
exit

View File

@ -0,0 +1,10 @@
# exec /bin/bash
#!/bin/sh
# node_dir=$(dirname $(dirname $(dirname $(realpath $0))))
cur_dir=$(dirname $0)
$(dirname $(dirname $cur_dir))/bin/node $cur_dir/index.js $1 $2
# echo 请按任意键继续..
# read -n 1

View File

@ -15,6 +15,7 @@ const cacheFile = path.join(Editor.Project.path, "local", "psd-to-prefab-cache.j
const configFile = path.join(`${packagePath}/config/psd.config.json`);
const nodejsFile = path.join(packagePath, "bin", `node${Os.platform() == 'darwin' ? "" : ".exe"}`);
const commandFile = path.join(packagePath, "libs", "psd2ui", `command.${Os.platform() == 'darwin' ? "sh" : "bat"}`);
const psd = path.join(packagePath, "libs", "psd2ui", "index.js");
let uuid2md5: Map<string, string> = new Map();
@ -116,6 +117,11 @@ function _exec(options: any, tasks: any) {
console.log(`[ccc-tnt-psd2ui] 设置权限`);
fs.chmodSync(nodejsFile, 33261);
}
if (fs.statSync(commandFile).mode != 33261) {
console.log(`[ccc-tnt-psd2ui] commandFile 设置权限`);
fs.chmodSync(commandFile, 33261);
}
}
console.log("[ccc-tnt-psd2ui] 命令参数:" + jsonContent);
@ -124,13 +130,29 @@ function _exec(options: any, tasks: any) {
let base64 = Buffer.from(jsonContent).toString("base64");
tasks.push(new Promise<void>((rs) => {
// console.log(`[ccc-tnt-psd2ui] `, `${nodejsFile} ${psd}` + ' ' + `--json ${base64}`);
exec(`${nodejsFile} ${psd}` + ' ' + `--json ${base64}`, { windowsHide: false }, (err, stdout, stderr) => {
// exec(`${nodejsFile} ${psd}` + ' ' + `--json ${base64}`, { windowsHide: false }, (err, stdout, stderr) => {
// console.log("[ccc-tnt-psd2ui]:\n", stdout);
// if (stderr) {
// console.log(stderr);
// }
// rs();
// })
let shellScript = commandFile; // 你的脚本路径
let scriptArgs = `--json ${base64}`; // 你的脚本参数
let command =
Os.platform() == 'darwin' ? `osascript -e 'tell app "Terminal" to do script "cd ${process.cwd()}; ${shellScript} ${scriptArgs}"'`
: `start ${commandFile} ${scriptArgs}`;
exec(command, (error, stdout, stderr) => {
console.log("[ccc-tnt-psd2ui]:\n", stdout);
console.log("[ccc-tnt-psd2ui]: 程序执行完后请手动关闭终端窗口", );
if (stderr) {
console.log(stderr);
}
rs();
})
});
}));
return tasks;
}

View File

@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"release24x": "",
"release34x": ""
"release34x": "",
"testsh": "node src/test.js"
},
"author": "",
"license": "ISC",