|
@@ -0,0 +1,130 @@
|
|
1
|
+const mv = require('mv');
|
|
2
|
+const fs = require('fs');
|
|
3
|
+const fse = require('fs-extra');
|
|
4
|
+const http = require('http');
|
|
5
|
+const path = require('path');
|
|
6
|
+const walk = require('walk');
|
|
7
|
+const unzip = require('unzip');
|
|
8
|
+const child_process = require('child_process');
|
|
9
|
+const ncp = require('ncp');
|
|
10
|
+
|
|
11
|
+const gameIconsUrl = "http://game-icons.net/archives/png/zip/ffffff/000000/game-icons.net.png.zip";
|
|
12
|
+const tempFilePath = "./temp.zip";
|
|
13
|
+const tempDir = "./temp";
|
|
14
|
+const imgDir = "./generator/img";
|
|
15
|
+const customIconDir = "./resources/custom-icons";
|
|
16
|
+const cssPath = "./generator/css/icons.css";
|
|
17
|
+//const processIconsCmd = "mogrify -background white -alpha shape *.png";
|
|
18
|
+const processIconsCmd = `mogrify -alpha copy -channel-fx "red=100%, blue=100%, green=100%" *.png`
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+// ----------------------------------------------------------------------------
|
|
22
|
+// Download
|
|
23
|
+// ----------------------------------------------------------------------------
|
|
24
|
+function downloadFile(url, dest) {
|
|
25
|
+ console.log("Downloading...");
|
|
26
|
+ return new Promise((resolve, reject) => {
|
|
27
|
+ http.get(url, response => {
|
|
28
|
+ const file = fs.createWriteStream(dest);
|
|
29
|
+ response.pipe(file);
|
|
30
|
+ file.on('close', resolve);
|
|
31
|
+ file.on('error', reject);
|
|
32
|
+ })
|
|
33
|
+ .on('error', reject);
|
|
34
|
+ });
|
|
35
|
+}
|
|
36
|
+
|
|
37
|
+// ----------------------------------------------------------------------------
|
|
38
|
+// Unzip
|
|
39
|
+// ----------------------------------------------------------------------------
|
|
40
|
+function unzipAll(src, dest) {
|
|
41
|
+ console.log("Unzipping...");
|
|
42
|
+ return new Promise((resolve, reject) => {
|
|
43
|
+ fs.createReadStream(tempFilePath)
|
|
44
|
+ .pipe(unzip.Parse())
|
|
45
|
+ .on('entry', entry => {
|
|
46
|
+ const fileName = entry.path;
|
|
47
|
+ const baseName = path.basename(fileName);
|
|
48
|
+ const type = entry.type;
|
|
49
|
+ if (type === "File") {
|
|
50
|
+ entry.pipe(fs.createWriteStream(path.join(dest, baseName)));
|
|
51
|
+ }
|
|
52
|
+ else {
|
|
53
|
+ entry.autodrain();
|
|
54
|
+ }
|
|
55
|
+ })
|
|
56
|
+ .on('close', resolve)
|
|
57
|
+ .on('error', reject);
|
|
58
|
+ });
|
|
59
|
+}
|
|
60
|
+
|
|
61
|
+// ----------------------------------------------------------------------------
|
|
62
|
+// Process icons
|
|
63
|
+// ----------------------------------------------------------------------------
|
|
64
|
+function processAll(path) {
|
|
65
|
+ console.log("Processing (this will take a while)...");
|
|
66
|
+ return new Promise((resolve, reject) => {
|
|
67
|
+ child_process.exec(processIconsCmd, {cwd: path}, (error, stdout, stderr) => {
|
|
68
|
+ if (error) {
|
|
69
|
+ reject(error);
|
|
70
|
+ }
|
|
71
|
+ else {
|
|
72
|
+ resolve();
|
|
73
|
+ }
|
|
74
|
+ });
|
|
75
|
+ });
|
|
76
|
+}
|
|
77
|
+
|
|
78
|
+// ----------------------------------------------------------------------------
|
|
79
|
+// Generate CSS
|
|
80
|
+// ----------------------------------------------------------------------------
|
|
81
|
+function generateCSS(src, dest) {
|
|
82
|
+ console.log("Generating CSS...");
|
|
83
|
+ return new Promise((resolve, reject) => {
|
|
84
|
+ fs.readdir(src, (err, files) => {
|
|
85
|
+ if (err) {
|
|
86
|
+ reject(err);
|
|
87
|
+ }
|
|
88
|
+ else {
|
|
89
|
+ const content = files
|
|
90
|
+ .map(name => `.icon-${name.replace(".png", "")} { background-image: url(../img/${name});}\n`)
|
|
91
|
+ .join("");
|
|
92
|
+ fs.writeFile(dest, content, err => {
|
|
93
|
+ if (err) {
|
|
94
|
+ reject(err);
|
|
95
|
+ }
|
|
96
|
+ else {
|
|
97
|
+ resolve();
|
|
98
|
+ }
|
|
99
|
+ });
|
|
100
|
+ }
|
|
101
|
+ });
|
|
102
|
+ });
|
|
103
|
+}
|
|
104
|
+
|
|
105
|
+// ----------------------------------------------------------------------------
|
|
106
|
+// Copy
|
|
107
|
+// ----------------------------------------------------------------------------
|
|
108
|
+function copyAll(src, dest) {
|
|
109
|
+ console.log("Copying...");
|
|
110
|
+ return new Promise((resolve, reject) => {
|
|
111
|
+ fse.copy(src, dest, err => {
|
|
112
|
+ if (err) {
|
|
113
|
+ reject(err);
|
|
114
|
+ }
|
|
115
|
+ else {
|
|
116
|
+ resolve();
|
|
117
|
+ }
|
|
118
|
+ });
|
|
119
|
+ });
|
|
120
|
+}
|
|
121
|
+
|
|
122
|
+fse.emptyDir(tempDir)
|
|
123
|
+//.then(() => downloadFile(gameIconsUrl, tempFilePath))
|
|
124
|
+.then(() => unzipAll(tempFilePath, tempDir))
|
|
125
|
+.then(() => copyAll(tempDir, imgDir))
|
|
126
|
+.then(() => copyAll(customIconDir, imgDir))
|
|
127
|
+.then(() => processAll(imgDir))
|
|
128
|
+.then(() => generateCSS(imgDir, cssPath))
|
|
129
|
+.then(() => console.log("Done."))
|
|
130
|
+.catch(err => cosole.log("Error", err));
|