打包任务

This commit is contained in:
onvia 2023-07-22 15:43:18 +08:00
parent 5c468c1747
commit e476a320b3
6 changed files with 646 additions and 272 deletions

View File

@ -1,144 +1,162 @@
"use strict"; "use strict";
var __importDefault = (this && this.__importDefault) || function (mod) { var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.unload = exports.load = exports.methods = void 0; exports.unload = exports.load = exports.methods = void 0;
//@ts-ignore //@ts-ignore
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 child_process_1 = __importDefault(require("child_process")); const os_1 = __importDefault(require("os"));
let exec = child_process_1.default.exec; const child_process_1 = __importDefault(require("child_process"));
const ENGINE_VER = "v342"; // let exec = child_process_1.default.exec;
const projectAssets = path_1.default.join(Editor.Project.path, "assets"); const ENGINE_VER = "v342"; //
const cacheFile = path_1.default.join(Editor.Project.path, "local", "psd-to-prefab-cache.json"); const packagePath = path_1.default.join(Editor.Project.path, "extensions", package_json_1.default.name);
const commandBat = path_1.default.join(Editor.Project.path, `extensions\\${package_json_1.default.name}\\libs\\psd2ui\\command.bat`); const projectAssets = path_1.default.join(Editor.Project.path, "assets");
const configFile = path_1.default.join(Editor.Project.path, `extensions\\${package_json_1.default.name}\\config\\psd.config.json`); const cacheFile = path_1.default.join(Editor.Project.path, "local", "psd-to-prefab-cache.json");
let uuid2md5 = new Map(); const configFile = path_1.default.join(`${packagePath}/config/psd.config.json`);
let cacheFileJson = {}; 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");
* @en let uuid2md5 = new Map();
* @zh 为扩展的主进程的注册方法 let cacheFileJson = {};
*/ /**
exports.methods = { * @en
openPanel() { * @zh 为扩展的主进程的注册方法
Editor.Panel.open(package_json_1.default.name); */
}, exports.methods = {
onClickPsd2UICache() { openPanel() {
console.log(`main-> onClickPsd2UICache111 `); Editor.Panel.open(package_json_1.default.name);
return new Promise((resolve, reject) => { },
console.log(`main-> onClickPsd2UICache`); onClickPsd2UICache() {
let options = { console.log(`main-> onClickPsd2UICache111 `);
"project-assets": projectAssets, return new Promise((resolve, reject) => {
"cache": cacheFile, console.log(`main-> onClickPsd2UICache`);
"init": true, let options = {
"engine-version": ENGINE_VER "project-assets": projectAssets,
}; "cache": cacheFile,
Promise.all(_exec(options, [])).then(() => { "init": true,
console.log("[psd2prefab] 执行缓存结束"); "engine-version": ENGINE_VER
resolve(); };
}); Promise.all(_exec(options, [])).then(() => {
}); console.log("[psd2prefab] 执行缓存结束");
}, resolve();
async onPsd2UIDropFiles(param) { });
let files = param.files; });
let isForceImg = param.isForceImg; },
let isImgOnly = param.isImgOnly; async onPsd2UIDropFiles(param) {
let output = param.output; let files = param.files;
let options = { let isForceImg = param.isForceImg;
"project-assets": projectAssets, let isImgOnly = param.isImgOnly;
"cache": cacheFile, let output = param.output;
"engine-version": ENGINE_VER, let options = {
}; "project-assets": projectAssets,
let tasks = []; "cache": cacheFile,
for (let i = 0; i < files.length; i++) { "engine-version": ENGINE_VER,
const file = files[i]; };
let stat = fs_extra_1.default.statSync(file); let tasks = [];
if (stat.isFile()) { for (let i = 0; i < files.length; i++) {
let ext = path_1.default.extname(file); const file = files[i];
if (ext != '.psd') { let stat = fs_extra_1.default.statSync(file);
continue; if (stat.isFile()) {
} let ext = path_1.default.extname(file);
} if (ext != '.psd') {
let args = JSON.parse(JSON.stringify(options)); continue;
args["input"] = file; }
if (output) { }
args["output"] = output; let args = JSON.parse(JSON.stringify(options));
} args["input"] = file;
if (isImgOnly) { if (output) {
// 只导出图片 args["output"] = output;
args["img-only"] = true; }
} if (isImgOnly) {
else { // 只导出图片
// 强制导出图片 args["img-only"] = true;
if (isForceImg) { }
args["force-img"] = true; else {
} // 强制导出图片
args["config"] = configFile; if (isForceImg) {
} args["force-img"] = true;
_exec(args, tasks); }
} args["config"] = configFile;
await Promise.all(tasks); }
genUUID2MD5Mapping(); _exec(args, tasks);
console.log("[ccc-tnt-psd2ui] psd 导出完成,输出位置为:", output ? output : "psd 同级目录"); }
}, await Promise.all(tasks);
}; genUUID2MD5Mapping();
function _exec(options, tasks) { console.log("[ccc-tnt-psd2ui] psd 导出完成,输出位置为:", output ? output : "psd 同级目录");
let jsonContent = JSON.stringify(options); },
// console.log("[ccc-tnt-psd2ui] 批处理命令参数:" + jsonContent); };
let base64 = Buffer.from(jsonContent).toString("base64"); function _exec(options, tasks) {
// console.log('[ccc-tnt-psd2ui] start ' + commandBat + ' ' + `--json ${base64}`); let jsonContent = JSON.stringify(options);
tasks.push(new Promise((rs) => { if (!fs_extra_1.default.existsSync(nodejsFile)) {
exec('start ' + commandBat + ' ' + `--json ${base64}`, { windowsHide: false }, (err, stdout, stderr) => { console.log(`main-> 没有批处理文件`, nodejsFile);
rs(); return tasks;
}); }
})); // 处理权限问题
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);
* }
* @param {*} event }
*/ console.log("[ccc-tnt-psd2ui] 批处理命令参数:" + jsonContent);
function onAssetDeletedListener(event) { let base64 = Buffer.from(jsonContent).toString("base64");
if (uuid2md5.has(event)) { tasks.push(new Promise((rs) => {
let md5 = uuid2md5.get(event); // console.log(`main-> `, `${nodejsFile} ${psd}` + ' ' + `--json ${base64}`);
console.log(`[ccc-tnt-psd2ui] 删除资源 md5: ${md5}, uuid: ${event}`); exec(`${nodejsFile} ${psd}` + ' ' + `--json ${base64}`, { windowsHide: false }, (err, stdout, stderr) => {
delete cacheFileJson[`${md5}`]; console.log("[ccc-tnt-psd2ui]:\n", stdout);
fs_extra_1.default.writeFileSync(cacheFile, JSON.stringify(cacheFileJson, null, 2)); if (stderr) {
} console.log(stderr);
} }
/** rs();
* 生成 uuid MD5 的映射 });
* }));
*/ return tasks;
function genUUID2MD5Mapping() { }
if (!fs_extra_1.default.existsSync(cacheFile)) { /**
return; * 资源删除的监听
} *
let content = fs_extra_1.default.readFileSync(cacheFile, 'utf-8'); * @param {*} event
let obj = JSON.parse(content); */
cacheFileJson = obj; function onAssetDeletedListener(event) {
for (const key in obj) { if (uuid2md5.has(event)) {
const element = obj[key]; let md5 = uuid2md5.get(event);
uuid2md5.set(element.textureUuid, key); console.log(`[ccc-tnt-psd2ui] 删除资源 md5: ${md5}, uuid: ${event}`);
} delete cacheFileJson[`${md5}`];
} fs_extra_1.default.writeFileSync(cacheFile, JSON.stringify(cacheFileJson, null, 2));
/** }
* @en Hooks triggered after extension loading is complete }
* @zh 扩展加载完成后触发的钩子 /**
*/ * 生成 uuid MD5 的映射
const load = function () { *
genUUID2MD5Mapping(); */
Editor.Message.addBroadcastListener("asset-db:asset-delete", onAssetDeletedListener); function genUUID2MD5Mapping() {
}; if (!fs_extra_1.default.existsSync(cacheFile)) {
exports.load = load; return;
/** }
* @en Hooks triggered after extension uninstallation is complete let content = fs_extra_1.default.readFileSync(cacheFile, 'utf-8');
* @zh 扩展卸载完成后触发的钩子 let obj = JSON.parse(content);
*/ cacheFileJson = obj;
const unload = function () { for (const key in obj) {
Editor.Message.removeBroadcastListener("asset-db:asset-delete", onAssetDeletedListener); const element = obj[key];
}; uuid2md5.set(element.textureUuid, key);
exports.unload = unload; }
}
/**
* @en Hooks triggered after extension loading is complete
* @zh 扩展加载完成后触发的钩子
*/
const load = function () {
genUUID2MD5Mapping();
Editor.Message.addBroadcastListener("asset-db:asset-delete", onAssetDeletedListener);
};
exports.load = load;
/**
* @en Hooks triggered after extension uninstallation is complete
* @zh 扩展卸载完成后触发的钩子
*/
const unload = function () {
Editor.Message.removeBroadcastListener("asset-db:asset-delete", onAssetDeletedListener);
};
exports.unload = unload;

View File

@ -1,121 +1,121 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const fs_extra_1 = require("fs-extra"); const fs_extra_1 = require("fs-extra");
const path_1 = require("path"); const path_1 = require("path");
const vue_1 = require("vue"); const vue_1 = require("vue");
const weakMap = new WeakMap(); const weakMap = new WeakMap();
const AssetDir = `${Editor.Project.path}/assets`; const AssetDir = `${Editor.Project.path}/assets`;
/** /**
* @zh 如果希望兼容 3.3 之前的版本可以使用下方的代码 * @zh 如果希望兼容 3.3 之前的版本可以使用下方的代码
* @en You can add the code below if you want compatibility with versions prior to 3.3 * @en You can add the code below if you want compatibility with versions prior to 3.3
*/ */
// Editor.Panel.define = Editor.Panel.define || function(options: any) { return options } // Editor.Panel.define = Editor.Panel.define || function(options: any) { return options }
module.exports = Editor.Panel.define({ module.exports = Editor.Panel.define({
listeners: { listeners: {
show() { }, show() { },
hide() { }, hide() { },
}, },
template: (0, fs_extra_1.readFileSync)((0, path_1.join)(__dirname, '../../../static/template/default/index.html'), 'utf-8'), template: (0, fs_extra_1.readFileSync)((0, path_1.join)(__dirname, '../../../static/template/default/index.html'), 'utf-8'),
style: (0, fs_extra_1.readFileSync)((0, path_1.join)(__dirname, '../../../static/style/default/index.css'), 'utf-8'), style: (0, fs_extra_1.readFileSync)((0, path_1.join)(__dirname, '../../../static/style/default/index.css'), 'utf-8'),
$: { $: {
app: '#app', app: '#app',
}, },
methods: {}, methods: {},
ready() { ready() {
if (this.$.app) { if (this.$.app) {
const app = (0, vue_1.createApp)({}); const app = (0, vue_1.createApp)({});
app.config.compilerOptions.isCustomElement = (tag) => tag.startsWith('ui-'); app.config.compilerOptions.isCustomElement = (tag) => tag.startsWith('ui-');
app.component('psd2ui', { app.component('psd2ui', {
template: (0, fs_extra_1.readFileSync)((0, path_1.join)(__dirname, '../../../static/template/vue/psd2ui.html'), 'utf-8'), template: (0, fs_extra_1.readFileSync)((0, path_1.join)(__dirname, '../../../static/template/vue/psd2ui.html'), 'utf-8'),
data() { data() {
return { return {
isImgOnly: false, isImgOnly: false,
isForceImg: false, isForceImg: false,
isProcessing: false, isProcessing: false,
outputPath: "", outputPath: "",
}; };
}, },
created() { created() {
let str = localStorage.getItem(`${Editor.Project.name}_psd2ui_output`); let str = localStorage.getItem(`${Editor.Project.name}_psd2ui_output`);
if (str) { if (str) {
this.outputPath = str; this.outputPath = str;
} }
}, },
beforeUnmount() { beforeUnmount() {
localStorage.setItem(`${Editor.Project.name}_psd2ui_output`, this.outputPath); localStorage.setItem(`${Editor.Project.name}_psd2ui_output`, this.outputPath);
}, },
methods: { methods: {
async onClickCache() { async onClickCache() {
if (this.isProcessing) if (this.isProcessing)
return; return;
this.isProcessing = true; this.isProcessing = true;
await Editor.Message.request("ccc-tnt-psd2ui", "on-click-cache"); await Editor.Message.request("ccc-tnt-psd2ui", "on-click-cache");
this.isProcessing = false; this.isProcessing = false;
}, },
onForceChanged(e) { onForceChanged(e) {
this.isForceImg = !this.isForceImg; this.isForceImg = !this.isForceImg;
}, },
onImgOnlyChanged() { onImgOnlyChanged() {
this.isImgOnly = !this.isImgOnly; this.isImgOnly = !this.isImgOnly;
}, },
async onClickDropArea(event) { async onClickDropArea(event) {
if (this.isProcessing) { if (this.isProcessing) {
Editor.Dialog.warn("当前有正在处理的文件,请等待完成。\n如果已完成请关闭 DOS 窗口。"); Editor.Dialog.warn("当前有正在处理的文件,请等待完成。\n如果已完成请关闭 DOS 窗口。");
return; return;
} }
let result = await Editor.Dialog.select({ let result = await Editor.Dialog.select({
'multi': true, 'multi': true,
'type': "file", 'type': "file",
'filters': [ 'filters': [
{ {
'extensions': ["psd"], 'extensions': ["psd"],
'name': "请选择 PSD" 'name': "请选择 PSD"
} }
] ]
}); });
let files = result.filePaths; let files = result.filePaths;
this.processPsd(files); this.processPsd(files);
}, },
onDragEnter(event) { onDragEnter(event) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
// event.target.add("drag-hovering") // event.target.add("drag-hovering")
}, },
onDragLeave(event) { onDragLeave(event) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
// event.target.remove("drag-hovering") // event.target.remove("drag-hovering")
}, },
async onDropFiles(event) { async onDropFiles(event) {
let files = []; let files = [];
[].forEach.call(event.dataTransfer.files, function (file) { [].forEach.call(event.dataTransfer.files, function (file) {
files.push(file.path); files.push(file.path);
}, false); }, false);
this.processPsd(files); this.processPsd(files);
}, },
async processPsd(files) { async processPsd(files) {
if (!files.length) { if (!files.length) {
return; return;
} }
if (this.isProcessing) { if (this.isProcessing) {
Editor.Dialog.warn("当前有正在处理的文件,请等待完成。\n如果已完成请关闭 DOS 窗口。"); Editor.Dialog.warn("当前有正在处理的文件,请等待完成。\n如果已完成请关闭 DOS 窗口。");
return; return;
} }
this.isProcessing = true; this.isProcessing = true;
await Editor.Message.request("ccc-tnt-psd2ui", "on-drop-file", { output: this.outputPath, files, isForceImg: this.isForceImg, isImgOnly: this.isImgOnly }); await Editor.Message.request("ccc-tnt-psd2ui", "on-drop-file", { output: this.outputPath, files, isForceImg: this.isForceImg, isImgOnly: this.isImgOnly });
this.isProcessing = false; this.isProcessing = false;
} }
}, },
}); });
app.mount(this.$.app); app.mount(this.$.app);
weakMap.set(this, app); weakMap.set(this, app);
} }
}, },
beforeClose() { }, beforeClose() { },
close() { close() {
const app = weakMap.get(this); const app = weakMap.get(this);
if (app) { if (app) {
app.unmount(); app.unmount();
} }
}, },
}); });

View File

@ -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
View 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
View 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
View 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);