mirror of
https://gitee.com/onvia/ccc-tnt-psd2ui
synced 2024-12-26 03:38:24 +00:00
打包任务
This commit is contained in:
parent
5c468c1747
commit
e476a320b3
28
ccc-tnt-psd2ui-v3.4.+/dist/main.js
vendored
28
ccc-tnt-psd2ui-v3.4.+/dist/main.js
vendored
@ -8,13 +8,16 @@ exports.unload = exports.load = exports.methods = void 0;
|
|||||||
const package_json_1 = __importDefault(require("../package.json"));
|
const package_json_1 = __importDefault(require("../package.json"));
|
||||||
const fs_extra_1 = __importDefault(require("fs-extra"));
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
||||||
const path_1 = __importDefault(require("path"));
|
const path_1 = __importDefault(require("path"));
|
||||||
|
const os_1 = __importDefault(require("os"));
|
||||||
const child_process_1 = __importDefault(require("child_process"));
|
const child_process_1 = __importDefault(require("child_process"));
|
||||||
let exec = child_process_1.default.exec;
|
let exec = child_process_1.default.exec;
|
||||||
const ENGINE_VER = "v342"; //
|
const ENGINE_VER = "v342"; //
|
||||||
|
const packagePath = path_1.default.join(Editor.Project.path, "extensions", package_json_1.default.name);
|
||||||
const projectAssets = path_1.default.join(Editor.Project.path, "assets");
|
const projectAssets = path_1.default.join(Editor.Project.path, "assets");
|
||||||
const cacheFile = path_1.default.join(Editor.Project.path, "local", "psd-to-prefab-cache.json");
|
const cacheFile = path_1.default.join(Editor.Project.path, "local", "psd-to-prefab-cache.json");
|
||||||
const commandBat = path_1.default.join(Editor.Project.path, `extensions\\${package_json_1.default.name}\\libs\\psd2ui\\command.bat`);
|
const configFile = path_1.default.join(`${packagePath}/config/psd.config.json`);
|
||||||
const configFile = path_1.default.join(Editor.Project.path, `extensions\\${package_json_1.default.name}\\config\\psd.config.json`);
|
const nodejsFile = path_1.default.join(packagePath, "bin", `node${os_1.default.platform() == 'darwin' ? "" : ".exe"}`);
|
||||||
|
const psd = path_1.default.join(packagePath, "libs", "psd2ui", "index.js");
|
||||||
let uuid2md5 = new Map();
|
let uuid2md5 = new Map();
|
||||||
let cacheFileJson = {};
|
let cacheFileJson = {};
|
||||||
/**
|
/**
|
||||||
@ -86,11 +89,26 @@ exports.methods = {
|
|||||||
};
|
};
|
||||||
function _exec(options, tasks) {
|
function _exec(options, tasks) {
|
||||||
let jsonContent = JSON.stringify(options);
|
let jsonContent = JSON.stringify(options);
|
||||||
// console.log("[ccc-tnt-psd2ui] 批处理命令参数:" + jsonContent);
|
if (!fs_extra_1.default.existsSync(nodejsFile)) {
|
||||||
|
console.log(`main-> 没有批处理文件`, nodejsFile);
|
||||||
|
return tasks;
|
||||||
|
}
|
||||||
|
// 处理权限问题
|
||||||
|
if (os_1.default.platform() === 'darwin') {
|
||||||
|
if (fs_extra_1.default.statSync(nodejsFile).mode != 33261) {
|
||||||
|
console.log(`[ccc-tnt-psd2ui] 设置权限`);
|
||||||
|
fs_extra_1.default.chmodSync(nodejsFile, 33261);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log("[ccc-tnt-psd2ui] 批处理命令参数:" + jsonContent);
|
||||||
let base64 = Buffer.from(jsonContent).toString("base64");
|
let base64 = Buffer.from(jsonContent).toString("base64");
|
||||||
// console.log('[ccc-tnt-psd2ui] start ' + commandBat + ' ' + `--json ${base64}`);
|
|
||||||
tasks.push(new Promise((rs) => {
|
tasks.push(new Promise((rs) => {
|
||||||
exec('start ' + commandBat + ' ' + `--json ${base64}`, { windowsHide: false }, (err, stdout, stderr) => {
|
// console.log(`main-> `, `${nodejsFile} ${psd}` + ' ' + `--json ${base64}`);
|
||||||
|
exec(`${nodejsFile} ${psd}` + ' ' + `--json ${base64}`, { windowsHide: false }, (err, stdout, stderr) => {
|
||||||
|
console.log("[ccc-tnt-psd2ui]:\n", stdout);
|
||||||
|
if (stderr) {
|
||||||
|
console.log(stderr);
|
||||||
|
}
|
||||||
rs();
|
rs();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
@ -2,16 +2,21 @@
|
|||||||
import packageJSON from '../package.json';
|
import packageJSON from '../package.json';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import Os from 'os';
|
||||||
|
|
||||||
import child_process from "child_process";
|
import child_process from "child_process";
|
||||||
let exec = child_process.exec;
|
let exec = child_process.exec;
|
||||||
|
|
||||||
|
|
||||||
const ENGINE_VER = "v342"; //
|
const ENGINE_VER = "v342"; //
|
||||||
|
const packagePath = path.join(Editor.Project.path, "extensions", packageJSON.name);
|
||||||
const projectAssets = path.join(Editor.Project.path, "assets");
|
const projectAssets = path.join(Editor.Project.path, "assets");
|
||||||
const cacheFile = path.join(Editor.Project.path, "local", "psd-to-prefab-cache.json");
|
const cacheFile = path.join(Editor.Project.path, "local", "psd-to-prefab-cache.json");
|
||||||
const commandBat = path.join(Editor.Project.path, `extensions\\${packageJSON.name}\\libs\\psd2ui\\command.bat`);
|
const configFile = path.join(`${packagePath}/config/psd.config.json`);
|
||||||
const configFile = path.join(Editor.Project.path, `extensions\\${packageJSON.name}\\config\\psd.config.json`);
|
|
||||||
|
const nodejsFile = path.join(packagePath, "bin", `node${Os.platform() == 'darwin' ? "" : ".exe"}`);
|
||||||
|
const psd = path.join(packagePath, "libs", "psd2ui", "index.js");
|
||||||
|
|
||||||
let uuid2md5: Map<string, string> = new Map();
|
let uuid2md5: Map<string, string> = new Map();
|
||||||
let cacheFileJson: Record<string, any> = {};
|
let cacheFileJson: Record<string, any> = {};
|
||||||
/**
|
/**
|
||||||
@ -92,14 +97,30 @@ export const methods: { [key: string]: (...any: any) => any } = {
|
|||||||
console.log("[ccc-tnt-psd2ui] psd 导出完成,输出位置为:", output ? output : "psd 同级目录");
|
console.log("[ccc-tnt-psd2ui] psd 导出完成,输出位置为:", output ? output : "psd 同级目录");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
function _exec(options: Record<string, any>, tasks: Promise<void>[]) {
|
function _exec(options: any, tasks: any) {
|
||||||
let jsonContent = JSON.stringify(options);
|
let jsonContent = JSON.stringify(options);
|
||||||
|
if (!fs.existsSync(nodejsFile)) {
|
||||||
|
console.log(`main-> 没有批处理文件`, nodejsFile);
|
||||||
|
|
||||||
// console.log("[ccc-tnt-psd2ui] 批处理命令参数:" + jsonContent);
|
return tasks;
|
||||||
|
}
|
||||||
|
// 处理权限问题
|
||||||
|
if (Os.platform() === 'darwin') {
|
||||||
|
if (fs.statSync(nodejsFile).mode != 33261) {
|
||||||
|
console.log(`[ccc-tnt-psd2ui] 设置权限`);
|
||||||
|
fs.chmodSync(nodejsFile, 33261);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("[ccc-tnt-psd2ui] 批处理命令参数:" + jsonContent);
|
||||||
let base64 = Buffer.from(jsonContent).toString("base64");
|
let base64 = Buffer.from(jsonContent).toString("base64");
|
||||||
// console.log('[ccc-tnt-psd2ui] start ' + commandBat + ' ' + `--json ${base64}`);
|
|
||||||
tasks.push(new Promise<void>((rs) => {
|
tasks.push(new Promise<void>((rs) => {
|
||||||
exec('start ' + commandBat + ' ' + `--json ${base64}`, { windowsHide: false }, (err, stdout, stderr) => {
|
// console.log(`main-> `, `${nodejsFile} ${psd}` + ' ' + `--json ${base64}`);
|
||||||
|
exec(`${nodejsFile} ${psd}` + ' ' + `--json ${base64}`, { windowsHide: false }, (err, stdout, stderr) => {
|
||||||
|
console.log("[ccc-tnt-psd2ui]:\n",stdout);
|
||||||
|
if (stderr) {
|
||||||
|
console.log(stderr);
|
||||||
|
}
|
||||||
rs();
|
rs();
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
@ -116,7 +137,7 @@ function onAssetDeletedListener(event: any) {
|
|||||||
let md5 = uuid2md5.get(event);
|
let md5 = uuid2md5.get(event);
|
||||||
console.log(`[ccc-tnt-psd2ui] 删除资源 md5: ${md5}, uuid: ${event}`);
|
console.log(`[ccc-tnt-psd2ui] 删除资源 md5: ${md5}, uuid: ${event}`);
|
||||||
delete cacheFileJson[`${md5}`];
|
delete cacheFileJson[`${md5}`];
|
||||||
fs.writeFileSync(cacheFile,JSON.stringify(cacheFileJson,null,2));
|
fs.writeFileSync(cacheFile, JSON.stringify(cacheFileJson, null, 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
190
package-lock.json
generated
Normal file
190
package-lock.json
generated
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
{
|
||||||
|
"name": "psd2ui-release",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 2,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "psd2ui-release",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"jszip": "^3.10.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/core-util-is": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmmirror.com/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
||||||
|
},
|
||||||
|
"node_modules/immediate": {
|
||||||
|
"version": "3.0.6",
|
||||||
|
"resolved": "https://registry.npmmirror.com/immediate/-/immediate-3.0.6.tgz",
|
||||||
|
"integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ=="
|
||||||
|
},
|
||||||
|
"node_modules/inherits": {
|
||||||
|
"version": "2.0.4",
|
||||||
|
"resolved": "https://registry.npmmirror.com/inherits/-/inherits-2.0.4.tgz",
|
||||||
|
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||||
|
},
|
||||||
|
"node_modules/isarray": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/isarray/-/isarray-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ=="
|
||||||
|
},
|
||||||
|
"node_modules/jszip": {
|
||||||
|
"version": "3.10.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/jszip/-/jszip-3.10.1.tgz",
|
||||||
|
"integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==",
|
||||||
|
"dependencies": {
|
||||||
|
"lie": "~3.3.0",
|
||||||
|
"pako": "~1.0.2",
|
||||||
|
"readable-stream": "~2.3.6",
|
||||||
|
"setimmediate": "^1.0.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/lie": {
|
||||||
|
"version": "3.3.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/lie/-/lie-3.3.0.tgz",
|
||||||
|
"integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"immediate": "~3.0.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/pako": {
|
||||||
|
"version": "1.0.11",
|
||||||
|
"resolved": "https://registry.npmmirror.com/pako/-/pako-1.0.11.tgz",
|
||||||
|
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
|
||||||
|
},
|
||||||
|
"node_modules/process-nextick-args": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
|
||||||
|
},
|
||||||
|
"node_modules/readable-stream": {
|
||||||
|
"version": "2.3.8",
|
||||||
|
"resolved": "https://registry.npmmirror.com/readable-stream/-/readable-stream-2.3.8.tgz",
|
||||||
|
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
|
||||||
|
"dependencies": {
|
||||||
|
"core-util-is": "~1.0.0",
|
||||||
|
"inherits": "~2.0.3",
|
||||||
|
"isarray": "~1.0.0",
|
||||||
|
"process-nextick-args": "~2.0.0",
|
||||||
|
"safe-buffer": "~5.1.1",
|
||||||
|
"string_decoder": "~1.1.1",
|
||||||
|
"util-deprecate": "~1.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/safe-buffer": {
|
||||||
|
"version": "5.1.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||||
|
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||||
|
},
|
||||||
|
"node_modules/setimmediate": {
|
||||||
|
"version": "1.0.5",
|
||||||
|
"resolved": "https://registry.npmmirror.com/setimmediate/-/setimmediate-1.0.5.tgz",
|
||||||
|
"integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA=="
|
||||||
|
},
|
||||||
|
"node_modules/string_decoder": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/string_decoder/-/string_decoder-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
|
||||||
|
"dependencies": {
|
||||||
|
"safe-buffer": "~5.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/util-deprecate": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"core-util-is": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmmirror.com/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
||||||
|
},
|
||||||
|
"immediate": {
|
||||||
|
"version": "3.0.6",
|
||||||
|
"resolved": "https://registry.npmmirror.com/immediate/-/immediate-3.0.6.tgz",
|
||||||
|
"integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ=="
|
||||||
|
},
|
||||||
|
"inherits": {
|
||||||
|
"version": "2.0.4",
|
||||||
|
"resolved": "https://registry.npmmirror.com/inherits/-/inherits-2.0.4.tgz",
|
||||||
|
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||||
|
},
|
||||||
|
"isarray": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/isarray/-/isarray-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ=="
|
||||||
|
},
|
||||||
|
"jszip": {
|
||||||
|
"version": "3.10.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/jszip/-/jszip-3.10.1.tgz",
|
||||||
|
"integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==",
|
||||||
|
"requires": {
|
||||||
|
"lie": "~3.3.0",
|
||||||
|
"pako": "~1.0.2",
|
||||||
|
"readable-stream": "~2.3.6",
|
||||||
|
"setimmediate": "^1.0.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lie": {
|
||||||
|
"version": "3.3.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/lie/-/lie-3.3.0.tgz",
|
||||||
|
"integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==",
|
||||||
|
"requires": {
|
||||||
|
"immediate": "~3.0.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pako": {
|
||||||
|
"version": "1.0.11",
|
||||||
|
"resolved": "https://registry.npmmirror.com/pako/-/pako-1.0.11.tgz",
|
||||||
|
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
|
||||||
|
},
|
||||||
|
"process-nextick-args": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
|
||||||
|
},
|
||||||
|
"readable-stream": {
|
||||||
|
"version": "2.3.8",
|
||||||
|
"resolved": "https://registry.npmmirror.com/readable-stream/-/readable-stream-2.3.8.tgz",
|
||||||
|
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
|
||||||
|
"requires": {
|
||||||
|
"core-util-is": "~1.0.0",
|
||||||
|
"inherits": "~2.0.3",
|
||||||
|
"isarray": "~1.0.0",
|
||||||
|
"process-nextick-args": "~2.0.0",
|
||||||
|
"safe-buffer": "~5.1.1",
|
||||||
|
"string_decoder": "~1.1.1",
|
||||||
|
"util-deprecate": "~1.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"safe-buffer": {
|
||||||
|
"version": "5.1.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||||
|
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||||
|
},
|
||||||
|
"setimmediate": {
|
||||||
|
"version": "1.0.5",
|
||||||
|
"resolved": "https://registry.npmmirror.com/setimmediate/-/setimmediate-1.0.5.tgz",
|
||||||
|
"integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA=="
|
||||||
|
},
|
||||||
|
"string_decoder": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/string_decoder/-/string_decoder-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
|
||||||
|
"requires": {
|
||||||
|
"safe-buffer": "~5.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"util-deprecate": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
package.json
Normal file
15
package.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "psd2ui-release",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"release24x": "",
|
||||||
|
"release34x": ""
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"jszip": "^3.10.1"
|
||||||
|
}
|
||||||
|
}
|
130
src/index.js
Normal file
130
src/index.js
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const JSZIP = require('jszip');
|
||||||
|
const OS = require('os');
|
||||||
|
const child_process = require('child_process');
|
||||||
|
|
||||||
|
const root = path.join(__dirname, "../");
|
||||||
|
let tmpFolder = "";
|
||||||
|
// 排除部分文件或文件夹
|
||||||
|
const exclude = name => !['@types', 'node_modules'].includes(name)
|
||||||
|
|
||||||
|
// zip 递归读取文件夹下的文件流
|
||||||
|
function readDir(zip, nowPath) {
|
||||||
|
// 读取目录中的所有文件及文件夹(同步操作)
|
||||||
|
let files = fs.readdirSync(nowPath)
|
||||||
|
|
||||||
|
//遍历检测目录中的文件
|
||||||
|
files.filter(exclude).forEach((fileName, index) => {
|
||||||
|
// 打印当前读取的文件名
|
||||||
|
console.log(fileName, index)
|
||||||
|
|
||||||
|
// 当前文件的全路径
|
||||||
|
let fillPath = path.join(nowPath, fileName)
|
||||||
|
|
||||||
|
// 获取一个文件的属性
|
||||||
|
let file = fs.statSync(fillPath)
|
||||||
|
|
||||||
|
// 如果是目录的话,继续查询
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
// 压缩对象中生成该目录
|
||||||
|
let dirlist = zip.folder(fileName)
|
||||||
|
// (递归)重新检索目录文件
|
||||||
|
readDir(dirlist, fillPath)
|
||||||
|
} else {
|
||||||
|
// 压缩目录添加文件
|
||||||
|
zip.file(fileName, fs.readFileSync(fillPath))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始压缩文件
|
||||||
|
function zipFolder({ target = __dirname, output = __dirname + '/result.zip' }) {
|
||||||
|
// 创建 zip 实例
|
||||||
|
const zip = new JSZIP()
|
||||||
|
|
||||||
|
// zip 递归读取文件夹下的文件流
|
||||||
|
readDir(zip, target)
|
||||||
|
|
||||||
|
// 设置压缩格式,开始打包
|
||||||
|
zip.generateAsync({
|
||||||
|
// nodejs 专用
|
||||||
|
type: 'nodebuffer',
|
||||||
|
// 压缩算法
|
||||||
|
compression: 'DEFLATE',
|
||||||
|
// 压缩级别
|
||||||
|
compressionOptions: { level: 9, },
|
||||||
|
}).then(content => {
|
||||||
|
// 将打包的内容写入 当前目录下的 result.zip中
|
||||||
|
fs.writeFileSync(output, content, 'utf-8')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// zipFolder({
|
||||||
|
// // 目标文件夹
|
||||||
|
// target: path.join(__dirname, 'test'),
|
||||||
|
// // 输出 zip
|
||||||
|
// output: __dirname + '/result.zip'
|
||||||
|
// })
|
||||||
|
|
||||||
|
|
||||||
|
console.log(`index-> `, path.join(__dirname, "../", 'ccc-tnt-psd2ui-v3.4.+'));
|
||||||
|
|
||||||
|
|
||||||
|
function taskStart(name, callback) {
|
||||||
|
tmpFolder = path.join(root, `${name}_tmp`);
|
||||||
|
callback(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyPlguin(name, callback) {
|
||||||
|
|
||||||
|
fs.copyFile(path.join(root, name), tmpFolder, () => {
|
||||||
|
callback(name);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function cd2TmpFolder(name, callback) {
|
||||||
|
|
||||||
|
child_process.exec(`cd ${tmpFolder}`, (err, stdout, stderr) => {
|
||||||
|
console.log(stdout);
|
||||||
|
console.log(stderr);
|
||||||
|
if (err) {
|
||||||
|
console.log(`child_process err-> `, err);
|
||||||
|
} else {
|
||||||
|
callback(name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function unstallPackage(name, callback, packageNames) {
|
||||||
|
for (let i = 0; i < packageNames.length; i++) {
|
||||||
|
const element = packageNames[i];
|
||||||
|
child_process.exec(`npm uninstall ${element}`, (err, stdout, stderr) => {
|
||||||
|
console.log(stdout);
|
||||||
|
console.log(stderr);
|
||||||
|
if (err) {
|
||||||
|
console.log(`child_process err-> `, err);
|
||||||
|
} else {
|
||||||
|
if (i == packageNames.length - 1) {
|
||||||
|
callback(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
taskStart("ccc-tnt-psd2ui-v3.4.+", (name) => {
|
||||||
|
copyPlguin(name, (name) => {
|
||||||
|
cd2TmpFolder(name, (name) => {
|
||||||
|
// unstallPackage(name, (name) => {
|
||||||
|
|
||||||
|
// }, [
|
||||||
|
// "@types/fs-extra",
|
||||||
|
// "@types/node",
|
||||||
|
// "typescript"
|
||||||
|
// ]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`index-> `, root);
|
Loading…
Reference in New Issue
Block a user