@ives_xxz/packages 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/AddComponent/main.js +32 -0
  2. package/AddComponent/package.json +26 -0
  3. package/AddComponent/panel/index.js +233 -0
  4. package/AddComponent/readme.md +38 -0
  5. package/AddComponent/scene-accessor.js +109 -0
  6. package/AddComponent/template-auto-dock.js +73 -0
  7. package/BitmapFontTools/i18n/en.js +1 -0
  8. package/BitmapFontTools/i18n/zh.js +1 -0
  9. package/BitmapFontTools/main.js +1 -0
  10. package/BitmapFontTools/package-lock.json +83 -0
  11. package/BitmapFontTools/package.json +37 -0
  12. package/BitmapFontTools/panel/font.css +1 -0
  13. package/BitmapFontTools/panel/font.js +58 -0
  14. package/BitmapFontTools/panel/font_panel.js +1 -0
  15. package/BitmapFontTools/panel/ttf.css +1 -0
  16. package/BitmapFontTools/panel/ttf.js +68 -0
  17. package/BitmapFontTools/panel/ttf_panel.js +1 -0
  18. package/FWAssetsFinder/main.js +9 -0
  19. package/FWAssetsFinder/package.json +20 -0
  20. package/FWAssetsFinder/panel/index.css +2 -0
  21. package/FWAssetsFinder/panel/index.html +52 -0
  22. package/FWAssetsFinder/panel/index.js +265 -0
  23. package/FWAssetsFinder/panel/less.css +71 -0
  24. package/FWAssetsFinder/panel/scene.js +194 -0
  25. package/FWExcelGenerator/main.js +367 -0
  26. package/FWExcelGenerator/package-lock.json +109 -0
  27. package/FWExcelGenerator/package.json +23 -0
  28. package/FWExcelGenerator/panel/index.js +648 -0
  29. package/FWLayerGenerator/main.js +186 -0
  30. package/FWLayerGenerator/package.json +21 -0
  31. package/FWLayerGenerator/panel/index.css +36 -0
  32. package/FWLayerGenerator/panel/index.html +17 -0
  33. package/FWLayerGenerator/panel/index.js +29 -0
  34. package/FWMask/inspector.js +26 -0
  35. package/FWMask/main.js +16 -0
  36. package/FWMask/package.json +6 -0
  37. package/FWPolygonPoints/main.js +149 -0
  38. package/FWPolygonPoints/package.json +9 -0
  39. package/PNG Auto Compress/CHANGELOG.md +32 -0
  40. package/PNG Auto Compress/LICENSE +21 -0
  41. package/PNG Auto Compress/README.md +113 -0
  42. package/PNG Auto Compress/config-manager.js +72 -0
  43. package/PNG Auto Compress/i18n/en.js +14 -0
  44. package/PNG Auto Compress/i18n/zh.js +14 -0
  45. package/PNG Auto Compress/images/setting.png +0 -0
  46. package/PNG Auto Compress/jsconfig.json +1 -0
  47. package/PNG Auto Compress/main.js +377 -0
  48. package/PNG Auto Compress/package.json +41 -0
  49. package/PNG Auto Compress/panel.setting/index.css +13 -0
  50. package/PNG Auto Compress/panel.setting/index.html +51 -0
  51. package/PNG Auto Compress/panel.setting/index.js +124 -0
  52. package/PNG Auto Compress/pngquant/macos/COPYRIGHT +687 -0
  53. package/PNG Auto Compress/pngquant/macos/README.md +78 -0
  54. package/PNG Auto Compress/pngquant/macos/pngquant +0 -0
  55. package/PNG Auto Compress/pngquant/macos/pngquant-compat +0 -0
  56. package/PNG Auto Compress/pngquant/windows/COPYRIGHT +687 -0
  57. package/PNG Auto Compress/pngquant/windows/Drag PNG here to reduce palette automatically.bat +11 -0
  58. package/PNG Auto Compress/pngquant/windows/Drag PNG here to reduce palette to 256.bat +10 -0
  59. package/PNG Auto Compress/pngquant/windows/README.txt +78 -0
  60. package/PNG Auto Compress/pngquant/windows/pngquant.exe +0 -0
  61. package/PNG Auto Compress/typings/cocos/editor.d.ts +1053 -0
  62. package/PNG Auto Compress/utils/file-utils.js +67 -0
  63. package/Quick Finder/CHANGELOG.md +100 -0
  64. package/Quick Finder/LICENSE +21 -0
  65. package/Quick Finder/README.en.md +141 -0
  66. package/Quick Finder/README.md +149 -0
  67. package/Quick Finder/i18n/en.js +42 -0
  68. package/Quick Finder/i18n/zh.js +42 -0
  69. package/Quick Finder/images/assets/animation-clip.png +0 -0
  70. package/Quick Finder/images/assets/asset.png +0 -0
  71. package/Quick Finder/images/assets/atlas.png +0 -0
  72. package/Quick Finder/images/assets/audio-clip.png +0 -0
  73. package/Quick Finder/images/assets/auto-atlas.png +0 -0
  74. package/Quick Finder/images/assets/bitmap-font.png +0 -0
  75. package/Quick Finder/images/assets/buffer.png +0 -0
  76. package/Quick Finder/images/assets/coffeescript.png +0 -0
  77. package/Quick Finder/images/assets/component.png +0 -0
  78. package/Quick Finder/images/assets/css.png +0 -0
  79. package/Quick Finder/images/assets/dragonbones-atlas.png +0 -0
  80. package/Quick Finder/images/assets/folder.png +0 -0
  81. package/Quick Finder/images/assets/html.png +0 -0
  82. package/Quick Finder/images/assets/javascript.png +0 -0
  83. package/Quick Finder/images/assets/json.png +0 -0
  84. package/Quick Finder/images/assets/label-atlas.png +0 -0
  85. package/Quick Finder/images/assets/markdown.png +0 -0
  86. package/Quick Finder/images/assets/material.png +0 -0
  87. package/Quick Finder/images/assets/mesh.png +0 -0
  88. package/Quick Finder/images/assets/mount.png +0 -0
  89. package/Quick Finder/images/assets/node.png +0 -0
  90. package/Quick Finder/images/assets/particle.png +0 -0
  91. package/Quick Finder/images/assets/physics-material.png +0 -0
  92. package/Quick Finder/images/assets/prefab.png +0 -0
  93. package/Quick Finder/images/assets/raw-asset.png +0 -0
  94. package/Quick Finder/images/assets/scene.png +0 -0
  95. package/Quick Finder/images/assets/shader.png +0 -0
  96. package/Quick Finder/images/assets/skeleton.png +0 -0
  97. package/Quick Finder/images/assets/spine.png +0 -0
  98. package/Quick Finder/images/assets/sprite-animation.png +0 -0
  99. package/Quick Finder/images/assets/sprite-atlas.png +0 -0
  100. package/Quick Finder/images/assets/sprite-frame.png +0 -0
  101. package/Quick Finder/images/assets/text.png +0 -0
  102. package/Quick Finder/images/assets/tiled-map.png +0 -0
  103. package/Quick Finder/images/assets/ttf-font.png +0 -0
  104. package/Quick Finder/images/assets/typescript.png +0 -0
  105. package/Quick Finder/images/search.png +0 -0
  106. package/Quick Finder/images/settings.png +0 -0
  107. package/Quick Finder/images/update.png +0 -0
  108. package/Quick Finder/images/version.png +0 -0
  109. package/Quick Finder/jsconfig.json +17 -0
  110. package/Quick Finder/lib/node-fetch.js +1649 -0
  111. package/Quick Finder/lib/vue.global.prod.js +7 -0
  112. package/Quick Finder/package.json +45 -0
  113. package/Quick Finder/src/common/config-manager.js +122 -0
  114. package/Quick Finder/src/eazax/browser-util.js +61 -0
  115. package/Quick Finder/src/eazax/color-util.js +37 -0
  116. package/Quick Finder/src/eazax/css/cocos-class.css +202 -0
  117. package/Quick Finder/src/eazax/css/cocos-tag.css +197 -0
  118. package/Quick Finder/src/eazax/css/eazax-colors.css +18 -0
  119. package/Quick Finder/src/eazax/editor-main-kit.js +53 -0
  120. package/Quick Finder/src/eazax/editor-main-util.js +112 -0
  121. package/Quick Finder/src/eazax/editor-renderer-kit.js +26 -0
  122. package/Quick Finder/src/eazax/file-util.js +158 -0
  123. package/Quick Finder/src/eazax/i18n.js +36 -0
  124. package/Quick Finder/src/eazax/main-event.js +81 -0
  125. package/Quick Finder/src/eazax/package-util.js +47 -0
  126. package/Quick Finder/src/eazax/renderer-event.js +80 -0
  127. package/Quick Finder/src/eazax/updater.js +92 -0
  128. package/Quick Finder/src/eazax/version-util.js +61 -0
  129. package/Quick Finder/src/eazax/window-util.js +80 -0
  130. package/Quick Finder/src/main/finder.js +101 -0
  131. package/Quick Finder/src/main/index.js +155 -0
  132. package/Quick Finder/src/main/opener.js +95 -0
  133. package/Quick Finder/src/main/panel-manager.js +159 -0
  134. package/Quick Finder/src/renderer/search/index.css +222 -0
  135. package/Quick Finder/src/renderer/search/index.html +46 -0
  136. package/Quick Finder/src/renderer/search/index.js +348 -0
  137. package/Quick Finder/src/renderer/settings/index.css +101 -0
  138. package/Quick Finder/src/renderer/settings/index.html +86 -0
  139. package/Quick Finder/src/renderer/settings/index.js +219 -0
  140. package/Quick Finder/typings/cocos/editor.d.ts +1053 -0
  141. package/Quick Finder/typings/vue.d.ts +1 -0
  142. package/README.md +93 -0
  143. package/package.json +12 -0
  144. package/unpack plist/main.js +253 -0
  145. package/unpack plist/package.json +13 -0
  146. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/CHANGELOG.md +30 -0
  147. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/LICENSE +21 -0
  148. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/README.en.md +111 -0
  149. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/README.md +115 -0
  150. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/i18n/en.js +55 -0
  151. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/i18n/zh.js +55 -0
  152. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/images/search.png +0 -0
  153. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/images/settings.png +0 -0
  154. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/images/update.png +0 -0
  155. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/images/version.png +0 -0
  156. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/jsconfig.json +17 -0
  157. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/lib/node-fetch.js +1649 -0
  158. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/lib/vue.global.prod.js +7 -0
  159. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/package.json +44 -0
  160. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/common/config-manager.js +104 -0
  161. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/browser-util.js +61 -0
  162. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/color-util.js +37 -0
  163. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/css/cocos-class.css +201 -0
  164. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/css/cocos-tag.css +197 -0
  165. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/css/eazax-colors.css +18 -0
  166. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/editor-main-kit.js +53 -0
  167. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/editor-main-util.js +147 -0
  168. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/editor-renderer-kit.js +26 -0
  169. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/file-util.js +158 -0
  170. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/i18n.js +36 -0
  171. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/main-event.js +81 -0
  172. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/package-util.js +47 -0
  173. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/renderer-event.js +80 -0
  174. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/updater.js +92 -0
  175. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/version-util.js +61 -0
  176. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/window-util.js +80 -0
  177. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/main/editor-api.js +90 -0
  178. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/main/finder.js +248 -0
  179. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/main/index.js +155 -0
  180. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/main/object-util.js +70 -0
  181. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/main/panel-manager.js +86 -0
  182. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/main/parser.js +161 -0
  183. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/main/printer.js +108 -0
  184. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/renderer/settings/index.css +61 -0
  185. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/renderer/settings/index.html +90 -0
  186. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/renderer/settings/index.js +191 -0
  187. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/typings/cocos/editor.d.ts +1053 -0
  188. package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/typings/vue.d.ts +1 -0
@@ -0,0 +1,72 @@
1
+ const Fs = require('fs');
2
+ const Path = require('path');
3
+
4
+ /** 配置文件保存目录 */
5
+ const configFileDir = 'local';
6
+
7
+ /** 配置文件名 */
8
+ const configFileName = 'ccc-png-auto-compress.json';
9
+
10
+ /** 默认配置 */
11
+ const defaultConfig = {
12
+ enabled: false,
13
+ minQuality: 40,
14
+ maxQuality: 80,
15
+ colors: 256,
16
+ speed: 3,
17
+ excludeFolders: [],
18
+ excludeFiles: [],
19
+ };
20
+
21
+ /** 配置管理器 */
22
+ const ConfigManager = {
23
+
24
+ /**
25
+ * 获取配置
26
+ * @returns {object}
27
+ */
28
+ get() {
29
+ const projectPath = Editor.Project.path || Editor.projectPath,
30
+ configFilePath = Path.join(projectPath, configFileDir, configFileName);
31
+ let config = null;
32
+ if (Fs.existsSync(configFilePath)) {
33
+ config = JSON.parse(Fs.readFileSync(configFilePath, 'utf8'));
34
+ } else {
35
+ config = { ...defaultConfig };
36
+ }
37
+ return config;
38
+ },
39
+
40
+ /**
41
+ * 保存配置
42
+ * @param {object} config 配置
43
+ * @returns {string}
44
+ */
45
+ set(config) {
46
+ // 查找目录
47
+ const projectPath = Editor.Project.path || Editor.projectPath,
48
+ configDirPath = Path.join(projectPath, configFileDir);
49
+ if (!Fs.existsSync(configDirPath)) {
50
+ Fs.mkdirSync(configDirPath);
51
+ }
52
+ const configFilePath = Path.join(projectPath, configFileDir, configFileName);
53
+ // 读取本地配置
54
+ let object = Object.create(null);
55
+ if (Fs.existsSync(configFilePath)) {
56
+ object = JSON.parse(Fs.readFileSync(configFilePath, 'utf8'));
57
+ }
58
+ // 写入配置
59
+ for (const key in config) {
60
+ let value = config[key];
61
+ if (Array.isArray(value)) {
62
+ value = value.filter(_value => _value !== '');
63
+ }
64
+ object[key] = value;
65
+ }
66
+ Fs.writeFileSync(configFilePath, JSON.stringify(object, null, 2));
67
+ return configFilePath;
68
+ },
69
+
70
+ }
71
+
72
+ module.exports = ConfigManager;
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ 'name': 'PNG Auto Compress',
3
+ 'setting': 'Setting',
4
+ // main
5
+ 'configSaved': 'Config saved',
6
+ 'willCompress': 'PNG resources will be compressed automatically after the build is completed...',
7
+ 'prepareCompress': 'Prepare to compress...',
8
+ 'notSupport': 'Does not support the current system platform!',
9
+ 'startCompress': 'Compress...',
10
+ 'compressDir': 'Asset path',
11
+ // setting panel
12
+ 'repository': '· Git repository of this extension: [ccc-png-auto-compress](https://gitee.com/ifaswind/ccc-png-auto-compress)',
13
+ 'apply': 'Apply',
14
+ };
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ 'name': '自动压缩 PNG 资源',
3
+ 'setting': '设置',
4
+ // main
5
+ 'configSaved': '配置已保存',
6
+ 'willCompress': '将在构建完成后自动压缩 PNG 资源...',
7
+ 'prepareCompress': '准备压缩 PNG 资源...',
8
+ 'notSupport': '不支持当前系统平台',
9
+ 'startCompress': '开始压缩 PNG 资源,请勿进行其他操作!',
10
+ 'compressDir': '资源目录',
11
+ // setting panel
12
+ 'repository': '· 本扩展的 Git 仓库:[ccc-png-auto-compress](https://gitee.com/ifaswind/ccc-png-auto-compress)',
13
+ 'apply': '应用',
14
+ };
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1,377 @@
1
+ const Fs = require('fs');
2
+ const Path = require('path');
3
+ const Os = require('os');
4
+ const { exec } = require('child_process');
5
+ const ConfigManager = require('./config-manager');
6
+ const FileUtils = require('./utils/file-utils');
7
+
8
+ /** 包名 */
9
+ const PACKAGE_NAME = require('./package.json').name;
10
+
11
+ /**
12
+ * i18n
13
+ * @param {string} key
14
+ * @returns {string}
15
+ */
16
+ const translate = (key) => Editor.T(`${PACKAGE_NAME}.${key}`);
17
+
18
+ /** 扩展名 */
19
+ const EXTENSION_NAME = translate('name');
20
+
21
+ /** 内置资源目录 */
22
+ const internalPath = Path.normalize('assets/internal/');
23
+
24
+ module.exports = {
25
+
26
+ /**
27
+ * 项目路径
28
+ * @type {string}
29
+ */
30
+ projectPath: null,
31
+
32
+ /**
33
+ * 资源根目录路径
34
+ * @type {string}
35
+ */
36
+ assetsPath: null,
37
+
38
+ /**
39
+ * 压缩引擎路径
40
+ * @type {string}
41
+ */
42
+ pngquantPath: null,
43
+
44
+ /**
45
+ * 日志
46
+ * @type {{ successCount: number, failedCount: number, successInfo: string, failedInfo: string }}
47
+ */
48
+ logger: null,
49
+
50
+ /**
51
+ * 需要排除的文件夹
52
+ * @type {string[]}
53
+ */
54
+ excludeFolders: null,
55
+
56
+ /**
57
+ * 需要排除的文件
58
+ * @type {string[]}
59
+ */
60
+ excludeFiles: null,
61
+
62
+ /**
63
+ * 扩展消息
64
+ * @type {{ [key: string]: Function }}
65
+ */
66
+ messages: {
67
+
68
+ /**
69
+ * 打开设置面板
70
+ */
71
+ 'open-setting-panel'() {
72
+ Editor.Panel.open(`${PACKAGE_NAME}.setting`);
73
+ },
74
+
75
+ /**
76
+ * 读取配置
77
+ * @param {any} event
78
+ */
79
+ 'read-config'(event) {
80
+ const config = ConfigManager.get();
81
+ event.reply(null, config);
82
+ },
83
+
84
+ /**
85
+ * 保存配置
86
+ * @param {any} event
87
+ * @param {any} config
88
+ */
89
+ 'save-config'(event, config) {
90
+ const configFilePath = ConfigManager.set(config);
91
+ Editor.log(`[${EXTENSION_NAME}]`, translate('configSaved'), configFilePath);
92
+ event.reply(null, true);
93
+ },
94
+
95
+ },
96
+
97
+ /**
98
+ * 生命周期:加载
99
+ */
100
+ load() {
101
+ // 绑定 this
102
+ this.onBuildStart = this.onBuildStart.bind(this);
103
+ this.onBuildFinished = this.onBuildFinished.bind(this);
104
+ // 监听事件
105
+ Editor.Builder.on('build-start', this.onBuildStart);
106
+ Editor.Builder.on('build-finished', this.onBuildFinished);
107
+ },
108
+
109
+ /**
110
+ * 生命周期:加载
111
+ */
112
+ unload() {
113
+ // 取消事件监听
114
+ Editor.Builder.removeListener('build-start', this.onBuildStart);
115
+ Editor.Builder.removeListener('build-finished', this.onBuildFinished);
116
+ },
117
+
118
+ /**
119
+ * 构建开始回调
120
+ * @param {BuildOptions} options
121
+ * @param {Function} callback
122
+ */
123
+ onBuildStart(options, callback) {
124
+ const config = ConfigManager.get();
125
+ if (config && config.enabled) {
126
+ Editor.log(`[${EXTENSION_NAME}]`, translate('willCompress'));
127
+ // 取消编辑器资源选中(解除占用)
128
+ Editor.Selection.clear('asset');
129
+ }
130
+ // Done
131
+ callback();
132
+ },
133
+
134
+ /**
135
+ * 构建完成回调
136
+ * @param {BuildOptions} options
137
+ * @param {Function} callback
138
+ */
139
+ async onBuildFinished(options, callback) {
140
+ const config = ConfigManager.get();
141
+
142
+ // 未开启直接跳过
143
+ if (!config || !config.enabled) {
144
+ callback();
145
+ return;
146
+ }
147
+
148
+ // 获取项目路径
149
+ this.projectPath = Editor.Project.path || Editor.projectPath;
150
+ this.assetsPath = Path.join(this.projectPath, 'assets');
151
+
152
+ // 获取压缩引擎路径
153
+ const platform = Os.platform(),
154
+ pngquantPath = this.pngquantPath = Path.join(__dirname, enginePathMap[platform]);
155
+ // 设置引擎文件的执行权限(仅 macOS)
156
+ if (pngquantPath && platform === 'darwin') {
157
+ if (Fs.statSync(pngquantPath).mode != 33261) {
158
+ // 默认为 33188
159
+ Fs.chmodSync(pngquantPath, 33261);
160
+ }
161
+ }
162
+
163
+ // 压缩引擎路径
164
+ if (!pngquantPath) {
165
+ Editor.log(`[${EXTENSION_NAME}]`, translate('notSupport'), platform);
166
+ callback();
167
+ return;
168
+ }
169
+
170
+ // 准备
171
+ Editor.log(`[${EXTENSION_NAME}]`, translate('prepareCompress'));
172
+
173
+ // 组装压缩命令
174
+ const qualityParam = `--quality ${config.minQuality}-${config.maxQuality}`,
175
+ speedParam = `--speed ${config.speed}`,
176
+ skipParam = '--skip-if-larger',
177
+ outputParam = '--ext=.png',
178
+ writeParam = '--force',
179
+ // colorsParam = config.colors,
180
+ // compressOptions = `${qualityParam} ${speedParam} ${skipParam} ${outputParam} ${writeParam} ${colorsParam}`;
181
+ compressOptions = `${qualityParam} ${speedParam} ${skipParam} ${outputParam} ${writeParam}`;
182
+
183
+ // 需要排除的文件夹
184
+ this.excludeFolders = config.excludeFolders ? config.excludeFolders.map(value => Path.normalize(value)) : [];
185
+ // 需要排除的文件
186
+ this.excludeFiles = config.excludeFiles ? config.excludeFiles.map(value => Path.normalize(value)) : [];
187
+
188
+ // 重置日志
189
+ this.logger = {
190
+ successCount: 0,
191
+ failedCount: 0,
192
+ successInfo: '',
193
+ failedInfo: ''
194
+ };
195
+
196
+ // 开始压缩
197
+ Editor.log(`[${EXTENSION_NAME}]`, translate('startCompress'));
198
+
199
+ // 遍历项目资源
200
+ const dest = options.dest,
201
+ dirs = ['res', 'assets', 'subpackages', 'remote'];
202
+ for (let i = 0; i < dirs.length; i++) {
203
+ const dirPath = Path.join(dest, dirs[i]);
204
+ if (!Fs.existsSync(dirPath)) {
205
+ continue;
206
+ }
207
+ Editor.log(`[${EXTENSION_NAME}]`, translate('compressDir'), dirPath);
208
+ // 压缩并记录结果
209
+ await this.compress(dirPath, compressOptions);
210
+ }
211
+
212
+ // 打印压缩结果
213
+ this.printResults();
214
+
215
+ // Done
216
+ callback();
217
+ },
218
+
219
+ /**
220
+ * 压缩
221
+ * @param {string} srcPath 文件路径
222
+ * @param {object} options 压缩参数
223
+ */
224
+ async compress(srcPath, options) {
225
+ const pngquantPath = this.pngquantPath,
226
+ tasks = [];
227
+ const handler = (filePath, stats) => {
228
+ // 过滤文件
229
+ if (!this.filter(filePath)) {
230
+ return;
231
+ }
232
+ // 加入压缩队列
233
+ tasks.push(new Promise(res => {
234
+ const sizeBefore = stats.size / 1024,
235
+ command = `"${pngquantPath}" ${options} -- "${filePath}"`;
236
+ // pngquant $OPTIONS -- "$FILE"
237
+ exec(command, (error, stdout, stderr) => {
238
+ this.recordResult(error, sizeBefore, filePath);
239
+ res();
240
+ });
241
+ }));
242
+ };
243
+ FileUtils.map(srcPath, handler);
244
+ await Promise.all(tasks);
245
+ },
246
+
247
+ /**
248
+ * 判断资源是否可以进行压缩
249
+ * @param {string} path 路径
250
+ */
251
+ filter(path) {
252
+ // 排除非 png 资源和内置资源
253
+ if (!path.endsWith('.png') || path.includes(internalPath)) {
254
+ return false;
255
+ }
256
+
257
+ // 获取资源的原始路径
258
+ const basename = Path.basename(path);
259
+ const uuid = basename.slice(0, basename.indexOf('.'));
260
+ const sourcePath = Editor.assetdb.uuidToFspath(uuid);
261
+
262
+ if (sourcePath) {
263
+ // 检查原始资源目录中是否存在spine相关文件
264
+ const sourceDir = Path.dirname(sourcePath);
265
+ const sourceBasename = Path.basename(sourcePath, '.png');
266
+
267
+ // 检查同目录下是否存在spine相关文件
268
+ const spineFiles = [
269
+ Path.join(sourceDir, sourceBasename + '.json'),
270
+ Path.join(sourceDir, sourceBasename + '.atlas'),
271
+ Path.join(sourceDir, sourceBasename + '.skel')
272
+ ];
273
+
274
+ for (const spineFile of spineFiles) {
275
+ if (Fs.existsSync(spineFile)) {
276
+ Editor.log("找到spine文件图片:",sourceDir+sourceBasename);
277
+ return false;
278
+ }
279
+ }
280
+ }
281
+
282
+ // 排除指定文件夹和文件
283
+ const assetPath = this.getAssetPath(path);
284
+ if (assetPath) {
285
+ const excludeFolders = this.excludeFolders,
286
+ excludeFiles = this.excludeFiles;
287
+ // 文件夹
288
+ for (let i = 0, l = excludeFolders.length; i < l; i++) {
289
+ if (assetPath.startsWith(excludeFolders[i])) {
290
+ return false;
291
+ }
292
+ }
293
+ // 文件
294
+ for (let i = 0, l = excludeFiles.length; i < l; i++) {
295
+ if (assetPath.startsWith(excludeFiles[i])) {
296
+ return false;
297
+ }
298
+ }
299
+ }
300
+ // 测试通过
301
+ return true;
302
+ },
303
+
304
+ /**
305
+ * 获取资源源路径
306
+ * @param {string} filePath
307
+ * @return {string}
308
+ */
309
+ getAssetPath(filePath) {
310
+ // 获取源路径(图像在项目中的实际路径)
311
+ const basename = Path.basename(filePath),
312
+ uuid = basename.slice(0, basename.indexOf('.')),
313
+ sourcePath = Editor.assetdb.uuidToFspath(uuid);
314
+ if (!sourcePath) {
315
+ // 图集资源
316
+ // 暂时还没有找到办法处理
317
+ return null;
318
+ }
319
+ return Path.relative(this.assetsPath, sourcePath);
320
+ },
321
+
322
+ /**
323
+ * 记录结果
324
+ * @param {object} error 错误
325
+ * @param {number} sizeBefore 压缩前尺寸
326
+ * @param {string} filePath 文件路径
327
+ */
328
+ recordResult(error, sizeBefore, filePath) {
329
+ const log = this.logger;
330
+ if (!error) {
331
+ // 成功
332
+ const fileName = Path.basename(filePath),
333
+ sizeAfter = Fs.statSync(filePath).size / 1024,
334
+ savedSize = sizeBefore - sizeAfter,
335
+ savedRatio = savedSize / sizeBefore * 100;
336
+ log.successCount++;
337
+ log.successInfo += `\n + ${'Successful'.padEnd(13, ' ')} | ${fileName.padEnd(50, ' ')} | ${(sizeBefore.toFixed(2) + ' KB').padEnd(13, ' ')} -> ${(sizeAfter.toFixed(2) + ' KB').padEnd(13, ' ')} | ${(savedSize.toFixed(2) + ' KB').padEnd(13, ' ')} | ${(savedRatio.toFixed(2) + '%').padEnd(20, ' ')}`;
338
+ } else {
339
+ // 失败
340
+ log.failedCount++;
341
+ log.failedInfo += `\n - ${'Failed'.padEnd(13, ' ')} | ${filePath.replace(this.projectPath, '')}`;
342
+ switch (error.code) {
343
+ case 98:
344
+ log.failedInfo += `\n ${' '.repeat(10)} - 失败原因:压缩后体积增大(已经不能再压缩了)`;
345
+ break;
346
+ case 99:
347
+ log.failedInfo += `\n ${' '.repeat(10)} - 失败原因:压缩后质量低于已配置最低质量`;
348
+ break;
349
+ case 127:
350
+ log.failedInfo += `\n ${' '.repeat(10)} - 失败原因:压缩引擎没有执行权限`;
351
+ break;
352
+ default:
353
+ log.failedInfo += `\n ${' '.repeat(10)} - 失败原因:code ${error.code}`;
354
+ break;
355
+ }
356
+ }
357
+ },
358
+
359
+ /**
360
+ * 打印结果
361
+ */
362
+ printResults() {
363
+ const log = this.logger,
364
+ header = `\n # ${'Result'.padEnd(13, ' ')} | ${'Name / Path'.padEnd(50, ' ')} | ${'Size Before'.padEnd(13, ' ')} -> ${'Size After'.padEnd(13, ' ')} | ${'Saved Size'.padEnd(13, ' ')} | ${'Compressibility'.padEnd(20, ' ')}`;
365
+ Editor.log('[PAC]', `压缩完成(${log.successCount} 张成功 | ${log.failedCount} 张失败)`);
366
+ Editor.log('[PAC]', '压缩日志 >>>' + header + log.successInfo + log.failedInfo);
367
+ },
368
+
369
+ }
370
+
371
+ /** 压缩引擎路径表 */
372
+ const enginePathMap = {
373
+ /** macOS */
374
+ 'darwin': 'pngquant/macos/pngquant',
375
+ /** Windows */
376
+ 'win32': 'pngquant/windows/pngquant'
377
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "ccc-png-auto-compress",
3
+ "version": "1.2.0.20210527",
4
+ "description": "项目构建完成之后自动压缩 PNG 资源",
5
+ "author": "ifaswind(陈皮皮)",
6
+ "author-info": {
7
+ "wechat": "im_chenpipi",
8
+ "email": "952157129@qq.com",
9
+ "git-home": "https://gitee.com/ifaswind",
10
+ "official-account": "公众号「菜鸟小栈」"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://gitee.com/ifaswind/ccc-png-auto-compress"
15
+ },
16
+ "main": "main.js",
17
+ "main-menu": {
18
+ "i18n:MAIN_MENU.package.title/i18n:ccc-png-auto-compress.name/i18n:ccc-png-auto-compress.setting": {
19
+ "message": "ccc-png-auto-compress:open-setting-panel",
20
+ "icon": "/images/setting.png"
21
+ }
22
+ },
23
+ "panel.setting": {
24
+ "main": "panel.setting/index.js",
25
+ "type": "fixed-size",
26
+ "title": "i18n:ccc-png-auto-compress.name",
27
+ "width": 500,
28
+ "height": 625
29
+ },
30
+ "reload": {
31
+ "renderer": [
32
+ "panel.setting/**/*"
33
+ ],
34
+ "ignore": [
35
+ "CHANGELOG.md",
36
+ "README.md",
37
+ "README.en.md"
38
+ ]
39
+ },
40
+ "_storeId": "a58eb676ce095a2722e6592149b3443e"
41
+ }
@@ -0,0 +1,13 @@
1
+ :host {
2
+ padding-left: 10px;
3
+ padding-right: 10px;
4
+ }
5
+
6
+ .main {
7
+ height: 100%;
8
+ overflow-y: auto;
9
+ }
10
+
11
+ .tip {
12
+ height: 60px;
13
+ }
@@ -0,0 +1,51 @@
1
+ <div class="main">
2
+ <!-- 标题 -->
3
+ <h2>{{titleLabel}}</h2>
4
+ <ui-box-container class="layout vertical left">
5
+ <div>
6
+ <ui-prop name="启用" type="boolean" v-value="enabled" tooltip="· 项目构建完成后自动压缩 PNG 资源"></ui-prop>
7
+ <!-- <ui-prop name="配置保存目录" tooltip="· 相对于项目根目录的路径">
8
+ <ui-select class="flex-1" v-value="configSaveDir">
9
+ <option value="local">local(默认不参与 Git 同步)</option>
10
+ <option value="settings">settings(默认参与 Git 同步)</option>
11
+ </ui-select>
12
+ </ui-prop> -->
13
+ <hr />
14
+ <ui-prop name="最低质量(%)" type="number" v-value="minQuality" tooltip="· 最低图像质量"></ui-prop>
15
+ <ui-prop name="最高质量(%)" type="number" v-value="maxQuality" tooltip="· 最高图像质量"></ui-prop>
16
+ <!-- <ui-prop name="色彩" type="number" v-value="colors" tooltip="· 图像色彩"></ui-prop> -->
17
+ <ui-prop slide name="速度" type="number" v-value="speed" min="1" max="10" step="1" precision="0"
18
+ tooltip="· 压缩速度与质量的权重,默认值为 3。&#10;· 10 档可能会降低 5% 的质量,但压缩速度比 3 档快 8 倍。">
19
+ </ui-prop>
20
+ <hr />
21
+ <ui-prop name="需要排除的文件夹" tooltip="· 相对于 assets/ 目录的路径&#10;· 多个值之间必须用 ',' 隔开" auto-height>
22
+ <ui-text-area class="flex-1" type="string" size="big" v-value="excludeFolders"
23
+ placeholder="textures/aaa/,&#10;textures/bbb/">
24
+ </ui-text-area>
25
+ </ui-prop>
26
+ <ui-prop name="需要排除的文件" tooltip="· 相对于 assets/ 目录的路径&#10;· 多个值之间必须用 ',' 隔开" auto-height>
27
+ <ui-text-area class="flex-1" type="string" size="big" v-value="excludeFiles"
28
+ placeholder="textures/abc.png,&#10;textures/123.png">
29
+ </ui-text-area>
30
+ </ui-prop>
31
+ <hr />
32
+ <ui-hint style="line-height: 19px;">
33
+ 💡 小贴士:如果 Spine Skeleton 或 DragonBones 的纹理在压缩后出现透明度丢失的情况,可以参考以下两种解决方案(二选一):
34
+ <br>
35
+ - 自行勾选 Spine Skeleton 或 DragonBones 纹理的 Premultiply Alpha(预乘)属性
36
+ <br>
37
+ - 在配置面板中配置排除 Spine Skeleton 或 DragonBones 的纹理,不进行压缩
38
+ </ui-hint>
39
+ <hr />
40
+ <!-- Git 仓库 -->
41
+ <ui-hint class="tip" style="margin-top: 5px;">
42
+ <ui-markdown style="height: 48px;" v-value="repositoryLabel"></ui-markdown>
43
+ </ui-hint>
44
+ <hr />
45
+ </div>
46
+ <!-- 应用按钮 -->
47
+ <ui-button class="button blue big" @click="onApplyBtnClick" v-disabled="isProcessing">{{applyLabel}}
48
+ </ui-button>
49
+ </ui-box-container>
50
+ <br>
51
+ </div>