Skip to content

Commit

Permalink
fix: fix error msg hide
Browse files Browse the repository at this point in the history
  • Loading branch information
umbrella22 committed Dec 19, 2023
1 parent 7d3d073 commit 0210fc0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 65 deletions.
21 changes: 9 additions & 12 deletions .electron-vite/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import chalk from "chalk";
import { rollup, OutputOptions } from "rollup";
import { Listr } from "listr2";
import rollupOptions from "./rollup.config";
import { okayLog, errorLog, doneLog } from "./log";
import { errorLog, doneLog } from "./log";

const mainOpt = rollupOptions(process.env.NODE_ENV, "main");
const isCI = process.env.CI || false;
Expand All @@ -27,7 +27,7 @@ async function clean() {
"!build/lib/electron-build.*",
"!build/icons/icon.*",
]);
console.log(`\n${doneLog}clear done`);
doneLog('clear done')
if (process.env.BUILD_TARGET === "onlyClean") process.exit();
}

Expand All @@ -44,9 +44,8 @@ async function unionBuild() {
const build = await rollup(mainOpt);
await build.write(mainOpt.output as OutputOptions);
} catch (error) {
console.error(`\n${error}\n`);
console.log(`\n ${errorLog}failed to build main process`);
process.exit(1);
errorLog(`failed to build main process\n`);
return Promise.reject(error);
}
},
},
Expand All @@ -55,29 +54,27 @@ async function unionBuild() {
task: async (_, tasks) => {
try {
await build({ configFile: join(__dirname, "vite.config.ts") });
tasks.output = `${okayLog}take it away ${chalk.yellow(
tasks.output = `take it away ${chalk.yellow(
"`electron-builder`"
)}\n`;
} catch (error) {
console.error(`\n${error}\n`);
console.log(`\n ${errorLog}failed to build renderer process`);
process.exit(1);
errorLog(`failed to build renderer process\n`);
return Promise.reject(error);
}
},
options: { persistentOutput: true },
},
],
{
exitOnError: true,
}
);
tasksLister.run();
await tasksLister.run();
}

async function web() {
await deleteAsync(["dist/web/*", "!.gitkeep"]);
build({ configFile: join(__dirname, "vite.config") }).then((res) => {
console.log(`${doneLog}RendererProcess build success`);
doneLog('RendererProcess build success')
process.exit();
});
}
Expand Down
69 changes: 21 additions & 48 deletions .electron-vite/hot-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import AdmZip from "adm-zip";
import packageFile from "../package.json";
import buildConfig from "../build.json";
import { hotPublishConfigName } from "../src/main/config/const";
import { okayLog, infoLog, errorLog, doneLog } from "./log";
import { okayLog, errorLog, doneLog } from "./log";

const platformName = platform().includes("win32")
? "win"
: platform().includes("darwin")
? "mac"
: "linux";
? "mac"
: "linux";
const buildPath = join(
".",
"build",
Expand All @@ -49,42 +49,23 @@ const start = async () => {
console.log(chalk.green.bold(`Start packing \n`));

if (buildConfig.asar) {
console.log(
"\n" +
errorLog +
" " +
chalk.red(
"Please make sure the build.asar option in the Package.json file is set to false"
) +
"\n"
);
errorLog(`\n ${chalk.red(
"Please make sure the build.asar option in the Package.json file is set to false"
)}\n`)
return;
}

if (hotPublishConfigName === "") {
console.log(
"\n" +
errorLog +
" " +
chalk.red(
"HotPublishConfigName is not set, which will cause the update to fail, please set it in the config/index.js \n"
) +
chalk.red.bold(`\n Packing failed \n`)
);
errorLog(`\n ${chalk.red(
"HotPublishConfigName is not set, which will cause the update to fail, please set it in the config/index.js \n"
)}${chalk.red.bold(`\n Packing failed \n`)}`)
process.exit(1);
}

stat(join(buildPath, "resources", "app"), async (err, stats) => {
if (err) {
console.log(
"\n" +
errorLog +
" " +
chalk.red(
"No resource files were found, please execute this command after the build command"
) +
"\n"
);
errorLog(`\n ${chalk.red("No resource files were found, please execute this command after the build command"
)}\n`)
return;
}

Expand All @@ -101,7 +82,7 @@ const start = async () => {
await ensureDir(packResourcesPath);
await emptyDir(packResourcesPath);
await copy(resourcesPath, packResourcesPath);
console.log(`${okayLog} ${chalk.cyan.bold(`File copy complete \n`)}`);
okayLog(`${chalk.cyan.bold(`File copy complete \n`)}`)
await outputJSON(join(packPackagePath, "package.json"), {
name: packageFile.name,
productName: buildConfig.productName,
Expand All @@ -111,9 +92,7 @@ const start = async () => {
author: packageFile.author,
dependencies: packageFile.dependencies,
});
console.log(
`${okayLog} ${chalk.cyan.bold(`Rewrite package file complete \n`)}`
);
okayLog(`${chalk.cyan.bold(`Rewrite package file complete \n`)}`)
await ensureDir(outputPath);
await emptyDir(outputPath);
createZip(appPath, zipPath);
Expand All @@ -126,24 +105,18 @@ const start = async () => {
name: `${hashName}.zip`,
hash: sha256,
});
console.log(
`${okayLog} ${chalk.cyan.bold(
`Zip file complete, Start cleaning up redundant files \n`
)}`
);
okayLog(`${chalk.cyan.bold(
`Zip file complete, Start cleaning up redundant files \n`
)}`)
await remove(zipPath);
await remove(appPath);
console.log(
`${okayLog} ${chalk.cyan.bold(
`Cleaning up redundant files completed \n`
)}`
);
console.log("\n" + doneLog + " " + "The resource file is packaged!\n");
okayLog(`${chalk.cyan.bold(
`Cleaning up redundant files completed \n`
)}`)
doneLog("The resource file is packaged!\n")
console.log("File location: " + chalk.green(outputPath) + "\n");
} catch (error) {
console.log(
"\n" + errorLog + " " + chalk.red(error.message || error) + "\n"
);
errorLog(`\n ${chalk.red("Resource file packaging failed")}\n${chalk.red(error.message || error)}`);
process.exit(1);
}
});
Expand Down
20 changes: 15 additions & 5 deletions .electron-vite/log/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import chalk from 'chalk'

export const doneLog = chalk.bgGreen.white(' DONE ') + ' '
export const errorLog = chalk.bgRed.white(' ERROR ') + ' '
export const okayLog = chalk.bgBlue.white(' OKAY ') + ' '
export const warningLog = chalk.bgYellow.white(' WARNING ') + ' '
export const infoLog = chalk.bgCyan.white(' INFO ') + ' '
export const doneLog = (text: string) => {
console.log('\n' + chalk.bgGreen.white(' DONE ') + ' ' + text)
}
export const errorLog = (text: string) => {
console.log('\n ' + chalk.bgRed.white(' ERROR ') + ' ' + text)
}
export const okayLog = (text: string) => {
console.log('\n ' + chalk.bgBlue.white(' OKAY ') + ' ' + text)
}
export const warningLog = (text: string) => {
console.log('\n ' + chalk.bgYellow.white(' WARNING ') + ' ' + text)
}
export const infoLog = (text: string) => {
console.log('\n ' + chalk.bgCyan.white(' INFO ') + ' ' + text)
}

0 comments on commit 0210fc0

Please sign in to comment.