@ives_xxz/packages 1.0.7 → 1.0.8
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.
|
@@ -9,64 +9,62 @@ const configFileName = 'ccc-png-auto-compress.json';
|
|
|
9
9
|
|
|
10
10
|
/** 默认配置 */
|
|
11
11
|
const defaultConfig = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
enabled: true,
|
|
13
|
+
minQuality: 60,
|
|
14
|
+
maxQuality: 80,
|
|
15
|
+
colors: 256,
|
|
16
|
+
speed: 3,
|
|
17
|
+
excludeFolders: [],
|
|
18
|
+
excludeFiles: [],
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
/** 配置管理器 */
|
|
22
22
|
const ConfigManager = {
|
|
23
|
+
/**
|
|
24
|
+
* 获取配置
|
|
25
|
+
* @returns {object}
|
|
26
|
+
*/
|
|
27
|
+
get() {
|
|
28
|
+
const projectPath = Editor.Project.path || Editor.projectPath,
|
|
29
|
+
configFilePath = Path.join(projectPath, configFileDir, configFileName);
|
|
30
|
+
let config = null;
|
|
31
|
+
if (Fs.existsSync(configFilePath)) {
|
|
32
|
+
config = JSON.parse(Fs.readFileSync(configFilePath, 'utf8'));
|
|
33
|
+
} else {
|
|
34
|
+
config = { ...defaultConfig };
|
|
35
|
+
}
|
|
36
|
+
return config;
|
|
37
|
+
},
|
|
23
38
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
}
|
|
39
|
+
/**
|
|
40
|
+
* 保存配置
|
|
41
|
+
* @param {object} config 配置
|
|
42
|
+
* @returns {string}
|
|
43
|
+
*/
|
|
44
|
+
set(config) {
|
|
45
|
+
// 查找目录
|
|
46
|
+
const projectPath = Editor.Project.path || Editor.projectPath,
|
|
47
|
+
configDirPath = Path.join(projectPath, configFileDir);
|
|
48
|
+
if (!Fs.existsSync(configDirPath)) {
|
|
49
|
+
Fs.mkdirSync(configDirPath);
|
|
50
|
+
}
|
|
51
|
+
const configFilePath = Path.join(projectPath, configFileDir, configFileName);
|
|
52
|
+
// 读取本地配置
|
|
53
|
+
let object = Object.create(null);
|
|
54
|
+
if (Fs.existsSync(configFilePath)) {
|
|
55
|
+
object = JSON.parse(Fs.readFileSync(configFilePath, 'utf8'));
|
|
56
|
+
}
|
|
57
|
+
// 写入配置
|
|
58
|
+
for (const key in config) {
|
|
59
|
+
let value = config[key];
|
|
60
|
+
if (Array.isArray(value)) {
|
|
61
|
+
value = value.filter((_value) => _value !== '');
|
|
62
|
+
}
|
|
63
|
+
object[key] = value;
|
|
64
|
+
}
|
|
65
|
+
Fs.writeFileSync(configFilePath, JSON.stringify(object, null, 2));
|
|
66
|
+
return configFilePath;
|
|
67
|
+
},
|
|
68
|
+
};
|
|
71
69
|
|
|
72
70
|
module.exports = ConfigManager;
|
|
File without changes
|