schrun 0.3.9 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/daemon.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as CONFIG_DIR, t as
|
|
1
|
+
import { r as CONFIG_DIR, t as readConfig } from "./readJSON-B8bhppKD.mjs";
|
|
2
2
|
import { readdir } from "node:fs/promises";
|
|
3
3
|
import { consola } from "consola";
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
@@ -8,9 +8,9 @@ const startschedule = async () => {
|
|
|
8
8
|
const readScheduleJSON = await readdir(CONFIG_DIR, "utf-8");
|
|
9
9
|
for (const readSchedule of readScheduleJSON) {
|
|
10
10
|
if (!readSchedule.endsWith(".json")) continue;
|
|
11
|
-
if (readSchedule
|
|
11
|
+
if (readSchedule === "pid.json") continue;
|
|
12
12
|
const [filenamesplit] = readSchedule.split(".");
|
|
13
|
-
const fileread = await
|
|
13
|
+
const fileread = await readConfig(filenamesplit);
|
|
14
14
|
if (!fileread.enabled) continue;
|
|
15
15
|
const [command, ...args] = fileread.run.trim().split(/\+s/);
|
|
16
16
|
if (!command) continue;
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { i as PID_FILE, n as CLI_COMMAND_NAME, r as CONFIG_DIR, t as
|
|
2
|
+
import { i as PID_FILE, n as CLI_COMMAND_NAME, r as CONFIG_DIR, t as readConfig } from "./readJSON-B8bhppKD.mjs";
|
|
3
3
|
import { cli, define } from "gunshi";
|
|
4
4
|
import { readFile, readdir, unlink, writeFile } from "node:fs/promises";
|
|
5
5
|
import { consola } from "consola";
|
|
6
|
-
import {
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import Table from "cli-table3";
|
|
9
9
|
// src/version.ts
|
|
@@ -13,7 +13,7 @@ const version = async () => {
|
|
|
13
13
|
};
|
|
14
14
|
// src/run/background.ts
|
|
15
15
|
const runbackground = async (FileName) => {
|
|
16
|
-
const [command, ...args] = (await
|
|
16
|
+
const [command, ...args] = (await readConfig(FileName)).run.split(/\s+/);
|
|
17
17
|
if (!command) {
|
|
18
18
|
consola.error("do not run commands");
|
|
19
19
|
return;
|
|
@@ -29,7 +29,7 @@ const runbackground = async (FileName) => {
|
|
|
29
29
|
};
|
|
30
30
|
// src/run/surface.ts
|
|
31
31
|
const runsurface = async (FileName) => {
|
|
32
|
-
const [command, ...args] = (await
|
|
32
|
+
const [command, ...args] = (await readConfig(FileName)).run.split(/\s+/);
|
|
33
33
|
if (!command) {
|
|
34
34
|
consola.error("do not run commands");
|
|
35
35
|
return;
|
|
@@ -44,18 +44,23 @@ const runsurface = async (FileName) => {
|
|
|
44
44
|
};
|
|
45
45
|
// src/run/startScheduler.ts
|
|
46
46
|
const startSchedule = async () => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
try {
|
|
48
|
+
const daemonPath = fileURLToPath(new URL("./daemon.mjs", import.meta.url));
|
|
49
|
+
const child = spawn(process.execPath, [daemonPath], {
|
|
50
|
+
detached: true,
|
|
51
|
+
stdio: "ignore"
|
|
52
|
+
});
|
|
53
|
+
if (child.pid === void 0) {}
|
|
54
|
+
child.on("error", (error) => {
|
|
55
|
+
new Error("Failed to start daemon:", error);
|
|
56
|
+
});
|
|
57
|
+
await writeFile(PID_FILE, String(child.pid), "utf-8");
|
|
58
|
+
child.unref();
|
|
59
|
+
consola.success("Success start scheduler");
|
|
60
|
+
} catch (error) {
|
|
61
|
+
consola.error("Error start schedule\n", error);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
59
64
|
};
|
|
60
65
|
// src/run/stopScheduler.ts
|
|
61
66
|
const stopSchedule = async () => {
|
|
@@ -113,7 +118,7 @@ const list = async () => {
|
|
|
113
118
|
for (const readdir of read) {
|
|
114
119
|
if (readdir.match("pid.json")) continue;
|
|
115
120
|
const [splits] = readdir.split(".");
|
|
116
|
-
const readfunc = await
|
|
121
|
+
const readfunc = await readConfig(splits);
|
|
117
122
|
table.push([
|
|
118
123
|
readfunc.description,
|
|
119
124
|
readfunc.cron,
|
|
@@ -15,7 +15,7 @@ const fileSchema = z.object({
|
|
|
15
15
|
enabled: z.boolean()
|
|
16
16
|
});
|
|
17
17
|
// src/readJSON.ts
|
|
18
|
-
const
|
|
18
|
+
const readConfig = async (FileName) => {
|
|
19
19
|
const file = join(CONFIG_DIR, `${FileName}.json`);
|
|
20
20
|
const reads = await readFile(file, "utf-8");
|
|
21
21
|
const safeParseSchema = fileSchema.safeParse(JSON.parse(reads));
|
|
@@ -26,4 +26,4 @@ const readJSON = async (FileName) => {
|
|
|
26
26
|
throw consola.log("failed return data files\n", error);
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
-
export { PID_FILE as i, CLI_COMMAND_NAME as n, CONFIG_DIR as r,
|
|
29
|
+
export { PID_FILE as i, CLI_COMMAND_NAME as n, CONFIG_DIR as r, readConfig as t };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "schrun",
|
|
3
3
|
"module": "src/index.ts",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.11",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
"execa": "^10.1.0",
|
|
42
42
|
"gunshi": "^0.37.3",
|
|
43
43
|
"node-cron": "^4.6.0",
|
|
44
|
-
"typia": "^15.2.1",
|
|
45
44
|
"zod": "^4.6.7"
|
|
46
45
|
}
|
|
47
46
|
}
|