🐛 Fix icon download
This commit is contained in:
40
script/build_with_pake_cli.mjs
vendored
40
script/build_with_pake_cli.mjs
vendored
@@ -1,6 +1,7 @@
|
|||||||
import shelljs from 'shelljs';
|
import shelljs from 'shelljs';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import os from 'os';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import path, { dirname } from 'path';
|
import path, { dirname } from 'path';
|
||||||
|
|
||||||
@@ -27,16 +28,35 @@ console.log('===========================\n');
|
|||||||
cd('node_modules/pake-cli');
|
cd('node_modules/pake-cli');
|
||||||
let params = `node cli.js ${process.env.URL} --name ${process.env.NAME}`;
|
let params = `node cli.js ${process.env.URL} --name ${process.env.NAME}`;
|
||||||
|
|
||||||
if (process.env.ICON) {
|
// Download Icons
|
||||||
const iconPath = path.join(__dirname, 'icon');
|
if (process.env.ICON && process.env.ICON !== '') {
|
||||||
axios({
|
let iconFile;
|
||||||
method: 'get',
|
switch (os.type()) {
|
||||||
url: process.env.ICON,
|
case 'Linux':
|
||||||
responseType: 'stream',
|
iconFile = 'icon.png';
|
||||||
}).then(function (response) {
|
break;
|
||||||
response.data.pipe(fs.createWriteStream(iconPath));
|
case 'Darwin':
|
||||||
params = `${params} --icon ${iconPath}`;
|
iconFile = 'icon.icns';
|
||||||
});
|
break;
|
||||||
|
case 'Windows_NT':
|
||||||
|
iconFile = 'icon.ico';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log("Unable to detect your OS system, won't download the icon!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
axios
|
||||||
|
.get(process.env.ICON, { responseType: 'arraybuffer' })
|
||||||
|
.then(response => {
|
||||||
|
fs.writeFileSync(iconFile, response.data);
|
||||||
|
params = `${params} --icon ${iconFile}`;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error occurred during icon download: ', error);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log("Won't download the icon as ICON environment variable is not defined!");
|
||||||
}
|
}
|
||||||
|
|
||||||
params = `${params} --height ${process.env.HEIGHT} --width ${process.env.WIDTH}`;
|
params = `${params} --height ${process.env.HEIGHT} --width ${process.env.WIDTH}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user