增加pake-cli 图标判断逻辑
This commit is contained in:
57
bin/builders/common.ts
vendored
57
bin/builders/common.ts
vendored
@@ -3,6 +3,7 @@ import prompts from 'prompts';
|
||||
import path from 'path';
|
||||
import fs from 'fs/promises';
|
||||
import { npmDirectory } from '@/utils/dir.js';
|
||||
import logger from '@/options/logger.js';
|
||||
|
||||
export async function promptText(message: string, initial?: string) {
|
||||
const response = await prompts({
|
||||
@@ -40,20 +41,50 @@ export async function mergeTauriConfig(
|
||||
Object.assign(tauriConf.tauri.windows[0], { url, ...tauriConfWindowOptions });
|
||||
tauriConf.package.productName = name;
|
||||
tauriConf.tauri.bundle.identifier = identifier;
|
||||
tauriConf.tauri.bundle.icon = [options.icon];
|
||||
if (process.platform === "win32") {
|
||||
const ico_path = path.join(npmDirectory, `src-tauri/png/${name.toLowerCase()}_32.ico`);
|
||||
tauriConf.tauri.bundle.resources = [`png/${name.toLowerCase()}_32.ico`];
|
||||
await fs.copyFile(options.icon, ico_path);
|
||||
}
|
||||
if (process.platform === "linux") {
|
||||
const installSrc = `/usr/share/applications/${name}.desktop`;
|
||||
const assertSrc = `src-tauri/assets/${name}.desktop`;
|
||||
const assertPath = path.join(npmDirectory, assertSrc);
|
||||
tauriConf.tauri.bundle.deb.files = {
|
||||
[installSrc]: assertPath
|
||||
const exists = await fs.stat(options.icon)
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
if (exists) {
|
||||
let updateIconPath = true;
|
||||
let customIconExt = path.extname(options.icon).toLowerCase();
|
||||
if (process.platform === "win32") {
|
||||
if (customIconExt === ".ico") {
|
||||
const ico_path = path.join(npmDirectory, `src-tauri/png/${name.toLowerCase()}_32.ico`);
|
||||
tauriConf.tauri.bundle.resources = [`png/${name.toLowerCase()}_32.ico`];
|
||||
await fs.copyFile(options.icon, ico_path);
|
||||
} else {
|
||||
updateIconPath = false;
|
||||
logger.warn(`icon file in Windows must be 256 * 256 pix with .ico type, but you give ${customIconExt}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (process.platform === "linux") {
|
||||
tauriConf.package.productName = name.toLowerCase();
|
||||
if (customIconExt === ".png") {
|
||||
const installSrc = `/usr/share/applications/${name.toLowerCase()}.desktop`;
|
||||
const assertSrc = `src-tauri/assets/${name.toLowerCase()}.desktop`;
|
||||
const assertPath = path.join(npmDirectory, assertSrc);
|
||||
tauriConf.tauri.bundle.deb.files = {
|
||||
[installSrc]: assertPath
|
||||
}
|
||||
} else {
|
||||
updateIconPath = false;
|
||||
logger.warn(`icon file in Linux must be 512 * 512 pix with .png type, but you give ${customIconExt}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (process.platform === "darwin") {
|
||||
if (customIconExt !== ".icns") {
|
||||
updateIconPath = false;
|
||||
logger.warn(`icon file in MacOS must be .icns type, but you give ${customIconExt}`);
|
||||
}
|
||||
}
|
||||
if (updateIconPath) {
|
||||
tauriConf.tauri.bundle.icon = [options.icon];
|
||||
} else {
|
||||
logger.warn(`icon file will not change with default.`);
|
||||
}
|
||||
} else {
|
||||
logger.warn("the custom icon path may not exists. we will use default icon to replace it");
|
||||
}
|
||||
|
||||
|
||||
|
||||
99
dist/cli.js
vendored
99
dist/cli.js
vendored
@@ -6,11 +6,11 @@ import isurl from 'is-url';
|
||||
import prompts from 'prompts';
|
||||
import path from 'path';
|
||||
import fs from 'fs/promises';
|
||||
import chalk from 'chalk';
|
||||
import crypto from 'crypto';
|
||||
import axios from 'axios';
|
||||
import { fileTypeFromBuffer } from 'file-type';
|
||||
import { dir } from 'tmp-promise';
|
||||
import chalk from 'chalk';
|
||||
import ora from 'ora';
|
||||
import shelljs from 'shelljs';
|
||||
import updateNotifier from 'update-notifier';
|
||||
@@ -1593,6 +1593,24 @@ function validateUrlInput(url) {
|
||||
|
||||
const npmDirectory = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
|
||||
const logger = {
|
||||
info(...msg) {
|
||||
log.info(...msg.map((m) => chalk.blue.bold(m)));
|
||||
},
|
||||
debug(...msg) {
|
||||
log.debug(...msg);
|
||||
},
|
||||
error(...msg) {
|
||||
log.error(...msg.map((m) => chalk.red.bold(m)));
|
||||
},
|
||||
warn(...msg) {
|
||||
log.info(...msg.map((m) => chalk.yellow.bold(m)));
|
||||
},
|
||||
success(...msg) {
|
||||
log.info(...msg.map((m) => chalk.green.bold(m)));
|
||||
}
|
||||
};
|
||||
|
||||
function promptText(message, initial) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const response = yield prompts({
|
||||
@@ -1617,19 +1635,53 @@ function mergeTauriConfig(url, options, tauriConf) {
|
||||
Object.assign(tauriConf.tauri.windows[0], Object.assign({ url }, tauriConfWindowOptions));
|
||||
tauriConf.package.productName = name;
|
||||
tauriConf.tauri.bundle.identifier = identifier;
|
||||
tauriConf.tauri.bundle.icon = [options.icon];
|
||||
if (process.platform === "win32") {
|
||||
const ico_path = path.join(npmDirectory, `src-tauri/png/${name.toLowerCase()}_32.ico`);
|
||||
tauriConf.tauri.bundle.resources = [`png/${name.toLowerCase()}_32.ico`];
|
||||
yield fs.copyFile(options.icon, ico_path);
|
||||
const exists = yield fs.stat(options.icon)
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
if (exists) {
|
||||
let updateIconPath = true;
|
||||
let customIconExt = path.extname(options.icon).toLowerCase();
|
||||
if (process.platform === "win32") {
|
||||
if (customIconExt === ".ico") {
|
||||
const ico_path = path.join(npmDirectory, `src-tauri/png/${name.toLowerCase()}_32.ico`);
|
||||
tauriConf.tauri.bundle.resources = [`png/${name.toLowerCase()}_32.ico`];
|
||||
yield fs.copyFile(options.icon, ico_path);
|
||||
}
|
||||
else {
|
||||
updateIconPath = false;
|
||||
logger.warn(`icon file in Windows must be 256 * 256 pix with .ico type, but you give ${customIconExt}`);
|
||||
}
|
||||
}
|
||||
if (process.platform === "linux") {
|
||||
tauriConf.package.productName = name.toLowerCase();
|
||||
if (customIconExt === ".png") {
|
||||
const installSrc = `/usr/share/applications/${name.toLowerCase()}.desktop`;
|
||||
const assertSrc = `src-tauri/assets/${name.toLowerCase()}.desktop`;
|
||||
const assertPath = path.join(npmDirectory, assertSrc);
|
||||
tauriConf.tauri.bundle.deb.files = {
|
||||
[installSrc]: assertPath
|
||||
};
|
||||
}
|
||||
else {
|
||||
updateIconPath = false;
|
||||
logger.warn(`icon file in Linux must be 512 * 512 pix with .png type, but you give ${customIconExt}`);
|
||||
}
|
||||
}
|
||||
if (process.platform === "darwin") {
|
||||
if (customIconExt !== ".icns") {
|
||||
updateIconPath = false;
|
||||
logger.warn(`icon file in MacOS must be .icns type, but you give ${customIconExt}`);
|
||||
}
|
||||
}
|
||||
if (updateIconPath) {
|
||||
tauriConf.tauri.bundle.icon = [options.icon];
|
||||
}
|
||||
else {
|
||||
logger.warn(`icon file will not change with default.`);
|
||||
}
|
||||
}
|
||||
if (process.platform === "linux") {
|
||||
const installSrc = `/usr/share/applications/${name}.desktop`;
|
||||
const assertSrc = `src-tauri/assets/${name}.desktop`;
|
||||
const assertPath = path.join(npmDirectory, assertSrc);
|
||||
tauriConf.tauri.bundle.deb.files = {
|
||||
[installSrc]: assertPath
|
||||
};
|
||||
else {
|
||||
logger.warn("the custom icon path may not exists. we will use default icon to replace it");
|
||||
}
|
||||
let configPath = "";
|
||||
switch (process.platform) {
|
||||
@@ -1660,24 +1712,6 @@ function getIdentifier(name, url) {
|
||||
return `pake-${postFixHash}`;
|
||||
}
|
||||
|
||||
const logger = {
|
||||
info(...msg) {
|
||||
log.info(...msg.map((m) => chalk.blue.bold(m)));
|
||||
},
|
||||
debug(...msg) {
|
||||
log.debug(...msg);
|
||||
},
|
||||
error(...msg) {
|
||||
log.error(...msg.map((m) => chalk.red.bold(m)));
|
||||
},
|
||||
warn(...msg) {
|
||||
log.info(...msg.map((m) => chalk.yellow.bold(m)));
|
||||
},
|
||||
success(...msg) {
|
||||
log.info(...msg.map((m) => chalk.green.bold(m)));
|
||||
}
|
||||
};
|
||||
|
||||
const IS_MAC = process.platform === 'darwin';
|
||||
const IS_WIN = process.platform === 'win32';
|
||||
const IS_LINUX = process.platform === 'linux';
|
||||
@@ -1876,7 +1910,8 @@ var tauri$2 = {
|
||||
wix: {
|
||||
language: [
|
||||
"en-US"
|
||||
]
|
||||
],
|
||||
template: "assets/main.wxs"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user