@loybung/launcher 4.3.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +26 -28
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,39 +1,37 @@
1
1
  const fs = require("fs");
2
- const path = require("path");
3
2
 
4
- async function launcher(
5
- { url: url, filepath: filepath, expire: expire },
6
- callback
7
- ) {
8
- console.clear();
9
- console.log("( LOYBUNG Launcher ) => Fetching...");
3
+ const launcher = async ({ url, filepath, expire }, callback) => {
4
+ try {
5
+ const wait = (ms) => new Promise((res) => setTimeout(res, ms * 1000));
10
6
 
11
- const response = await fetch(url);
12
- if (!response.ok) {
13
- throw new Error(`ดึงข้อมูลผิดพลาด! | Status: ${response.status}`);
14
- }
15
- const textData = await response.text();
7
+ console.clear();
8
+ console.log("[- LOYBUNG Launcher -] => Fetching...");
16
9
 
17
- fs.writeFile(filepath, textData, "utf8", (err) => {
18
- if (err) {
19
- console.error("เกิดข้อผิดพลาดในการเขียนไฟล์:", err);
20
- return;
10
+ if (expire) {
11
+ setInterval(() => {
12
+ if (expire < Math.floor(Date.now() / 1000)) {
13
+ throw new Error("[- LOYBUNG Launcher -] => Expired!");
14
+ }
15
+ }, 1000);
21
16
  }
22
17
 
23
- let appPath = filepath;
24
- if (!path.isAbsolute(filepath)) {
25
- appPath = path.resolve(__dirname, filepath);
26
- }
18
+ const res = await fetch(url);
19
+ if (!res.ok) throw new Error(`[- LOYBUNG Launcher -] => Fetch error!`);
20
+ const textData = await res.text();
21
+ fs.writeFile(filepath, textData, "utf8", async (err) => {
22
+ if (err) throw new Error(`[- LOYBUNG Launcher -] => Error!`);
27
23
 
28
- const { run } = require(appPath);
29
- callback(run, expire);
30
- });
24
+ console.clear();
25
+ console.log("[- LOYBUNG Launcher -] => Starting... ( 2s )");
26
+ await wait(2);
31
27
 
32
- if (expire) {
33
- setInterval(() => {
34
- if (expire < Mathfloor(Date.now() / 1000)) process.exit();
35
- }, 5000);
28
+ const { run } = require(filepath);
29
+ callback(run, expire);
30
+ });
31
+ } catch (error) {
32
+ console.log(error.message);
33
+ process.exit();
36
34
  }
37
- }
35
+ };
38
36
 
39
37
  module.exports = { launcher };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loybung/launcher",
3
- "version": "4.3.0",
3
+ "version": "5.1.0",
4
4
  "description": "LOYBUNG / Launcher",
5
5
  "main": "index.js",
6
6
  "scripts": {