schrun 0.3.8 → 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,29 +1,30 @@
1
- import { r as CONFIG_DIR, t as readJSON } from "./readJSON-BGWDrdep.mjs";
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";
5
5
  import cron from "node-cron";
6
6
  // src/run/daemon.ts
7
7
  const startschedule = async () => {
8
- const readScheduleJSON = await readdir(CONFIG_DIR);
8
+ const readScheduleJSON = await readdir(CONFIG_DIR, "utf-8");
9
9
  for (const readSchedule of readScheduleJSON) {
10
- if (readSchedule.endsWith(".json")) continue;
11
- if (readSchedule.match("pid.json")) continue;
10
+ if (!readSchedule.endsWith(".json")) continue;
11
+ if (readSchedule === "pid.json") continue;
12
12
  const [filenamesplit] = readSchedule.split(".");
13
- const fileread = await readJSON(filenamesplit);
14
- const [commands, ...args] = fileread.run.split(/\+s/);
15
- if (!commands) continue;
13
+ const fileread = await readConfig(filenamesplit);
14
+ if (!fileread.enabled) continue;
15
+ const [command, ...args] = fileread.run.trim().split(/\+s/);
16
+ if (!command) continue;
16
17
  cron.schedule(fileread.cron, () => {
17
- spawn(commands, args, {
18
- stdio: "ignore",
18
+ spawn(command, args, {
19
+ stdio: "inherit",
19
20
  detached: true
20
21
  }).on("error", (error) => {
21
- consola.error(`コマンドの起動に失敗: ${commands}`, error);
22
+ consola.error(`コマンドの起動に失敗: ${command}`, error);
22
23
  });
23
24
  });
24
25
  }
25
26
  };
26
- startschedule().catch((error) => {
27
+ await startschedule().catch((error) => {
27
28
  consola.error("Do not runnning daemon\n", error);
28
29
  process.exitCode = 1;
29
30
  });
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 readJSON } from "./readJSON-BGWDrdep.mjs";
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 { fork, spawn } from "node:child_process";
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 readJSON(FileName)).run.split(/\s+/);
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 readJSON(FileName)).run.split(/\s+/);
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
- const daemonPath = fileURLToPath(new URL("./daemon.mjs", import.meta.url));
48
- const child = fork(process.execPath, [daemonPath], {
49
- detached: true,
50
- stdio: "ignore"
51
- });
52
- if (child.pid === void 0) throw new Error("Failed to start daemon");
53
- child.on("error", (error) => {
54
- throw new Error("Failed to start daemon:", error);
55
- });
56
- await writeFile(PID_FILE, String(child.pid), "utf-8");
57
- child.unref();
58
- consola.success("Success start scheduler");
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 readJSON(splits);
121
+ const readfunc = await readConfig(splits);
117
122
  table.push([
118
123
  readfunc.description,
119
124
  readfunc.cron,
@@ -0,0 +1,29 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { consola } from "consola";
3
+ import { join } from "node:path";
4
+ import { homedir } from "node:os";
5
+ import { z } from "zod";
6
+ // src/constant/app.ts
7
+ const CLI_COMMAND_NAME = "schrun";
8
+ const CONFIG_DIR = join(`${homedir()}`, ".config", "schrun");
9
+ const PID_FILE = join(`${homedir()}`, ".config", "schrun", "pid.json");
10
+ // src/type.ts
11
+ const fileSchema = z.object({
12
+ description: z.string(),
13
+ cron: z.string(),
14
+ run: z.string(),
15
+ enabled: z.boolean()
16
+ });
17
+ // src/readJSON.ts
18
+ const readConfig = async (FileName) => {
19
+ const file = join(CONFIG_DIR, `${FileName}.json`);
20
+ const reads = await readFile(file, "utf-8");
21
+ const safeParseSchema = fileSchema.safeParse(JSON.parse(reads));
22
+ if (!safeParseSchema.success) throw consola.error(safeParseSchema.error);
23
+ try {
24
+ return safeParseSchema.data;
25
+ } catch (error) {
26
+ throw consola.log("failed return data files\n", error);
27
+ }
28
+ };
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.8",
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
  }
@@ -1,17 +0,0 @@
1
- import { readFile } from "node:fs/promises";
2
- import { join } from "node:path";
3
- import { homedir } from "node:os";
4
- import typia from "typia";
5
- // src/constant/app.ts
6
- const CLI_COMMAND_NAME = "schrun";
7
- const CONFIG_DIR = join(`${homedir()}`, ".config", "schrun");
8
- const PID_FILE = join(`${homedir()}`, ".config", "schrun", "pid.json");
9
- // src/readJSON.ts
10
- const readJSON = async (FileName) => {
11
- const file = join(CONFIG_DIR, `${FileName}.json`);
12
- const reads = await readFile(file, "utf-8");
13
- const readparse = JSON.parse(reads);
14
- if (typia.is(readparse)) return readparse;
15
- else throw "The configuration format is invalid";
16
- };
17
- export { PID_FILE as i, CLI_COMMAND_NAME as n, CONFIG_DIR as r, readJSON as t };