From 40ee90491e77beb972a39aa9afd32bf4ac17fa72 Mon Sep 17 00:00:00 2001 From: onvia Date: Mon, 31 Jul 2023 09:09:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=BB=88=E7=AB=AF=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E7=9A=84=E6=96=B9=E5=BC=8F=E8=BF=90=E8=A1=8C=E8=A7=A3?= =?UTF-8?q?=E6=9E=90psd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/command.bat | 11 ++++++++ ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/command.sh | 10 +++++++ ccc-tnt-psd2ui-v2.4.x/main.js | 27 ++++++++++++++++--- ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/command.bat | 11 ++++++++ ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/command.sh | 10 +++++++ ccc-tnt-psd2ui-v3.4.+/src/main.ts | 26 ++++++++++++++++-- package.json | 3 ++- 7 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/command.bat create mode 100755 ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/command.sh create mode 100644 ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/command.bat create mode 100755 ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/command.sh diff --git a/ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/command.bat b/ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/command.bat new file mode 100644 index 0000000..4ab2b0a --- /dev/null +++ b/ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/command.bat @@ -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 \ No newline at end of file diff --git a/ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/command.sh b/ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/command.sh new file mode 100755 index 0000000..77dd7b5 --- /dev/null +++ b/ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/command.sh @@ -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 \ No newline at end of file diff --git a/ccc-tnt-psd2ui-v2.4.x/main.js b/ccc-tnt-psd2ui-v2.4.x/main.js index cccfc1b..0c53d39 100644 --- a/ccc-tnt-psd2ui-v2.4.x/main.js +++ b/ccc-tnt-psd2ui-v2.4.x/main.js @@ -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; } diff --git a/ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/command.bat b/ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/command.bat new file mode 100644 index 0000000..4ab2b0a --- /dev/null +++ b/ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/command.bat @@ -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 \ No newline at end of file diff --git a/ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/command.sh b/ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/command.sh new file mode 100755 index 0000000..77dd7b5 --- /dev/null +++ b/ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/command.sh @@ -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 \ No newline at end of file diff --git a/ccc-tnt-psd2ui-v3.4.+/src/main.ts b/ccc-tnt-psd2ui-v3.4.+/src/main.ts index 80d4b77..f0dac49 100644 --- a/ccc-tnt-psd2ui-v3.4.+/src/main.ts +++ b/ccc-tnt-psd2ui-v3.4.+/src/main.ts @@ -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 = 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((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; } diff --git a/package.json b/package.json index e1b4fc6..049f564 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "release24x": "", - "release34x": "" + "release34x": "", + "testsh": "node src/test.js" }, "author": "", "license": "ISC",