@loybung/launcher 5.2.0 → 5.4.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 +38 -32
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,36 +1,42 @@
1
1
  const fs = require("fs");
2
-
3
- const launcher = async ({ url, filepath, expire }, callback) => {
4
- try {
5
- const wait = (ms) => new Promise((res) => setTimeout(res, ms * 1000));
6
-
7
- console.clear();
8
- console.log("[- LOYBUNG Launcher -] => Fetching...");
9
-
10
- if (expire) {
11
- setInterval(() => {
12
- if (expire < Math.floor(Date.now() / 1000)) {
13
- throw new Error("[- LOYBUNG Launcher -] => Expired!");
2
+ class Launcher {
3
+ #a;
4
+ #b;
5
+ #c;
6
+ constructor(t) {
7
+ this.#a = t;
8
+ }
9
+ setPath(t) {
10
+ this.#b = t;
11
+ }
12
+ setExpire(t) {
13
+ this.#c = t;
14
+ }
15
+ async Run(t) {
16
+ try {
17
+ console.clear(), console.log("[- LOYBUNG Launcher -] => Fetching...");
18
+ let r = await fetch(this.#a);
19
+ if (!r.ok) throw Error("[- LOYBUNG Launcher -] => Fetch error!");
20
+ let e = await r.text();
21
+ fs.writeFile(this.#b, e, "utf8", async (t) => {
22
+ if (t) throw Error("[- LOYBUNG Launcher -] => Error!");
23
+ console.clear(),
24
+ console.log("[- LOYBUNG Launcher -] => Starting..."),
25
+ require(this.#b);
26
+ });
27
+ let h = setInterval(() => {
28
+ try {
29
+ if (!this.#c) return;
30
+ if (this.#c < Math.floor(Date.now() / 1e3))
31
+ throw Error("[- LOYBUNG Launcher -] => Expired!");
32
+ } catch (r) {
33
+ console.clear(), t(r), process.exit();
14
34
  }
15
- }, 1000);
35
+ }, 1e3);
36
+ this.#c || clearInterval(h);
37
+ } catch (i) {
38
+ console.clear(), t(i);
16
39
  }
17
-
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!`);
23
-
24
- console.clear();
25
- console.log("[- LOYBUNG Launcher -] => Starting...");
26
-
27
- const { run } = require(filepath);
28
- callback(run, expire);
29
- });
30
- } catch (error) {
31
- console.log(error.message);
32
- process.exit();
33
40
  }
34
- };
35
-
36
- module.exports = { launcher };
41
+ }
42
+ module.exports = { Launcher };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loybung/launcher",
3
- "version": "5.2.0",
3
+ "version": "5.4.0",
4
4
  "description": "LOYBUNG / Launcher",
5
5
  "main": "index.js",
6
6
  "scripts": {