schrun 0.3.7 → 0.3.9

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,31 +1,31 @@
1
- import { r as CONFIG_DIR, t as readJSON } from "./readJSON-BIHboQ76.mjs";
1
+ import { r as CONFIG_DIR, t as readJSON } from "./readJSON-B3iCCdQh.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 readConfig = await readdir(CONFIG_DIR);
9
- for (const filename of readConfig) {
10
- if (!filename.endsWith(".json")) continue;
11
- if (filename.match("pid.json")) continue;
12
- const [filenamesplit] = filename.split(".");
13
- const read = await readJSON(filenamesplit);
14
- if (!read.enabled) continue;
15
- const [command, ...args] = read.run.trim().split(/\s+/);
8
+ const readScheduleJSON = await readdir(CONFIG_DIR, "utf-8");
9
+ for (const readSchedule of readScheduleJSON) {
10
+ if (!readSchedule.endsWith(".json")) continue;
11
+ if (readSchedule.match("pid.json")) continue;
12
+ const [filenamesplit] = readSchedule.split(".");
13
+ const fileread = await readJSON(filenamesplit);
14
+ if (!fileread.enabled) continue;
15
+ const [command, ...args] = fileread.run.trim().split(/\+s/);
16
16
  if (!command) continue;
17
- cron.schedule(read.cron, () => {
17
+ cron.schedule(fileread.cron, () => {
18
18
  spawn(command, args, {
19
- detached: true,
20
- stdio: "inherit"
19
+ stdio: "inherit",
20
+ detached: true
21
21
  }).on("error", (error) => {
22
22
  consola.error(`コマンドの起動に失敗: ${command}`, error);
23
23
  });
24
24
  });
25
25
  }
26
26
  };
27
- startschedule().catch((error) => {
28
- consola.error("failed to up scheduler", error);
27
+ await startschedule().catch((error) => {
28
+ consola.error("Do not runnning daemon\n", error);
29
29
  process.exitCode = 1;
30
30
  });
31
31
  export { startschedule };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
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-BIHboQ76.mjs";
2
+ import { i as PID_FILE, n as CLI_COMMAND_NAME, r as CONFIG_DIR, t as readJSON } from "./readJSON-B3iCCdQh.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";
@@ -63,7 +63,7 @@ const stopSchedule = async () => {
63
63
  try {
64
64
  pid = Number(await readFile(PID_FILE, "utf-8"));
65
65
  } catch (error) {
66
- consola.warn("No look schedule pid file");
66
+ consola.warn("No Look Schedule Pid File");
67
67
  return;
68
68
  }
69
69
  if (!Number.isSafeInteger(pid) || pid <= 0) {
@@ -72,9 +72,9 @@ const stopSchedule = async () => {
72
72
  }
73
73
  try {
74
74
  process.kill(pid, "SIGINT");
75
- consola.success("Success Send stop scheduler");
75
+ consola.success("Failed Send Stop Scheduler");
76
76
  } catch (error) {
77
- consola.error("Failed Send stop scheduler", error);
77
+ consola.error("Failed Send Stop Scheduler\n", error);
78
78
  return;
79
79
  }
80
80
  await unlink(PID_FILE).catch(() => {});
@@ -1,18 +1,29 @@
1
1
  import { readFile } from "node:fs/promises";
2
+ import { consola } from "consola";
2
3
  import { join } from "node:path";
3
4
  import { homedir } from "node:os";
4
- import "zod";
5
- import typia from "typia";
5
+ import { z } from "zod";
6
6
  // src/constant/app.ts
7
7
  const CLI_COMMAND_NAME = "schrun";
8
8
  const CONFIG_DIR = join(`${homedir()}`, ".config", "schrun");
9
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
+ });
10
17
  // src/readJSON.ts
11
18
  const readJSON = async (FileName) => {
12
19
  const file = join(CONFIG_DIR, `${FileName}.json`);
13
20
  const reads = await readFile(file, "utf-8");
14
- const readparse = JSON.parse(reads);
15
- if (typia.is(readparse)) return readparse;
16
- else throw "The configuration format is invalid";
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
+ }
17
28
  };
18
29
  export { PID_FILE as i, CLI_COMMAND_NAME as n, CONFIG_DIR as r, readJSON 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.7",
4
+ "version": "0.3.9",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -16,7 +16,10 @@
16
16
  "url": "https://github.com/nazozokc"
17
17
  },
18
18
  "scripts": {
19
- "build": "bunx tsdown"
19
+ "build": "bunx tsdown",
20
+ "docs:dev": "bunx vitepress dev docs",
21
+ "docs:build": "bunx vitepress build docs",
22
+ "docs:preview": "bunx vitepress preview docs"
20
23
  },
21
24
  "files": [
22
25
  "dist",
@@ -26,10 +29,11 @@
26
29
  ],
27
30
  "devDependencies": {
28
31
  "@types/bun": "latest",
29
- "tsdown": "latest"
32
+ "tsdown": "latest",
33
+ "vitepress": "^1.6.4"
30
34
  },
31
35
  "peerDependencies": {
32
- "typescript": "^7"
36
+ "typescript": "^7.0.2"
33
37
  },
34
38
  "dependencies": {
35
39
  "cli-table3": "^0.6.5",