Commit 9a995b61 authored by rockyl's avatar rockyl

资源去重

parent 6fecdea7
......@@ -233,6 +233,7 @@ async function execute$1(psdFile, options) {
};
const assets = [];
const imageHashMap = {};
await walkNode(tree, async function (node, parent) {
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
......@@ -296,7 +297,7 @@ async function execute$1(psdFile, options) {
} else {
viewNode.type = 'image';
const uuid = generateUUID();
let uuid = generateUUID();
const ext = '.png';
const imageFilePath = path.join(imagesPath, uuid + ext);
......@@ -307,18 +308,23 @@ async function execute$1(psdFile, options) {
//await node.origin.saveAsPng(imageFilePath);
if (buffer) {
properties.source = 'asset://' + uuid;
const fileNameHash = hash(buffer);
if (imageHashMap.hasOwnProperty(fileNameHash)) {
uuid = imageHashMap[fileNameHash];
} else {
imageHashMap[fileNameHash] = uuid;
assets.push({
name,
ext,
uuid,
hash: fileNameHash,
});
}
const hashFileName = hash(buffer);
const hashFilePath = path.join(imagesPath, hashFileName + ext);
const hashFilePath = path.join(imagesPath, fileNameHash + ext);
await fs.rename(imageFilePath, hashFilePath);
assets.push({
name,
ext,
uuid,
hash: hashFileName,
});
properties.source = 'asset://' + uuid;
}
}
}
......
This diff is collapsed.
......@@ -239,6 +239,7 @@ async function execute$1(psdFile, options) {
};
const assets = [];
const imageHashMap = {};
await walkNode(tree, async function (node, parent) {
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
......@@ -302,7 +303,7 @@ async function execute$1(psdFile, options) {
} else {
viewNode.type = 'image';
const uuid = generateUUID();
let uuid = generateUUID();
const ext = '.png';
const imageFilePath = path.join(imagesPath, uuid + ext);
......@@ -313,18 +314,23 @@ async function execute$1(psdFile, options) {
//await node.origin.saveAsPng(imageFilePath);
if (buffer) {
properties.source = 'asset://' + uuid;
const fileNameHash = hash(buffer);
if (imageHashMap.hasOwnProperty(fileNameHash)) {
uuid = imageHashMap[fileNameHash];
} else {
imageHashMap[fileNameHash] = uuid;
assets.push({
name,
ext,
uuid,
hash: fileNameHash,
});
}
const hashFileName = hash(buffer);
const hashFilePath = path.join(imagesPath, hashFileName + ext);
const hashFilePath = path.join(imagesPath, fileNameHash + ext);
await fs.rename(imageFilePath, hashFilePath);
assets.push({
name,
ext,
uuid,
hash: hashFileName,
});
properties.source = 'asset://' + uuid;
}
}
}
......
This diff is collapsed.
......@@ -239,6 +239,7 @@
};
const assets = [];
const imageHashMap = {};
await walkNode(tree, async function (node, parent) {
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
......@@ -302,7 +303,7 @@
} else {
viewNode.type = 'image';
const uuid = generateUUID();
let uuid = generateUUID();
const ext = '.png';
const imageFilePath = path.join(imagesPath, uuid + ext);
......@@ -313,18 +314,23 @@
//await node.origin.saveAsPng(imageFilePath);
if (buffer) {
properties.source = 'asset://' + uuid;
const fileNameHash = hash(buffer);
if (imageHashMap.hasOwnProperty(fileNameHash)) {
uuid = imageHashMap[fileNameHash];
} else {
imageHashMap[fileNameHash] = uuid;
assets.push({
name,
ext,
uuid,
hash: fileNameHash,
});
}
const hashFileName = hash(buffer);
const hashFilePath = path.join(imagesPath, hashFileName + ext);
const hashFilePath = path.join(imagesPath, fileNameHash + ext);
await fs.rename(imageFilePath, hashFilePath);
assets.push({
name,
ext,
uuid,
hash: hashFileName,
});
properties.source = 'asset://' + uuid;
}
}
}
......
This diff is collapsed.
......@@ -4,7 +4,7 @@
"main": "index.js",
"license": "MIT",
"scripts": {
"egret": "rollup -i egret-demo/generator.js -o egret-demo/generator.cjs.js -f cjs -m&&node egret-demo/generator.cjs.js",
"zeroing": "rollup -i zeroing-demo/generator.js -o zeroing-demo/generator.cjs.js -f cjs -m&&node zeroing-demo/generator.cjs.js"
"egret": "rollup -i egret-demo/generator.js -o egret-demo/generator.cjs.js -f cjs -m && node egret-demo/generator.cjs.js",
"zeroing": "rollup -i zeroing-demo/generator.js -o zeroing-demo/generator.cjs.js -f cjs -m && node zeroing-demo/generator.cjs.js"
}
}
......@@ -211,7 +211,7 @@ function savePng(png, output) {
(async function generate() {
const imagesPath = 'zeroing-demo/images_' + Date.now();
const {view, assets} = await execute('psd/test2.psd', {
const {view, assets} = await execute('psd/test3.psd', {
imagesPath,
});
......
This diff is collapsed.
......@@ -7,7 +7,7 @@ import {toZeroing} from "../../src/index";
(async function generate() {
const imagesPath = 'zeroing-demo/images_' + Date.now();
const {view, assets} = await toZeroing('psd/test2.psd', {
const {view, assets} = await toZeroing('psd/test3.psd', {
imagesPath,
});
......
......@@ -26,6 +26,7 @@ export async function execute(psdFile, options) {
};
const assets = [];
const imageHashMap = {};
await walkNode(tree, async function (node, parent) {
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
......@@ -89,7 +90,7 @@ export async function execute(psdFile, options) {
} else {
viewNode.type = 'image';
const uuid = generateUUID();
let uuid = generateUUID();
const ext = '.png';
const imageFilePath = path.join(imagesPath, uuid + ext);
......@@ -100,18 +101,23 @@ export async function execute(psdFile, options) {
//await node.origin.saveAsPng(imageFilePath);
if (buffer) {
properties.source = 'asset://' + uuid;
const fileNameHash = hash(buffer);
if (imageHashMap.hasOwnProperty(fileNameHash)) {
uuid = imageHashMap[fileNameHash];
} else {
imageHashMap[fileNameHash] = uuid;
assets.push({
name,
ext,
uuid,
hash: fileNameHash,
});
}
const hashFileName = hash(buffer);
const hashFilePath = path.join(imagesPath, hashFileName + ext);
const hashFilePath = path.join(imagesPath, fileNameHash + ext);
await fs.rename(imageFilePath, hashFilePath);
assets.push({
name,
ext,
uuid,
hash: hashFileName,
});
properties.source = 'asset://' + uuid;
}
}
}
......
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