schrun 0.3.8 → 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,29 +1,30 @@
1
- import { r as CONFIG_DIR, t as readJSON } from "./readJSON-BGWDrdep.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 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;
10
+ if (!readSchedule.endsWith(".json")) continue;
11
11
  if (readSchedule.match("pid.json")) continue;
12
12
  const [filenamesplit] = readSchedule.split(".");
13
13
  const fileread = await readJSON(filenamesplit);
14
- const [commands, ...args] = fileread.run.split(/\+s/);
15
- if (!commands) continue;
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,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-BGWDrdep.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";
@@ -1,17 +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 typia from "typia";
5
+ import { z } from "zod";
5
6
  // src/constant/app.ts
6
7
  const CLI_COMMAND_NAME = "schrun";
7
8
  const CONFIG_DIR = join(`${homedir()}`, ".config", "schrun");
8
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
+ });
9
17
  // src/readJSON.ts
10
18
  const readJSON = async (FileName) => {
11
19
  const file = join(CONFIG_DIR, `${FileName}.json`);
12
20
  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";
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
+ }
16
28
  };
17
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.8",
4
+ "version": "0.3.9",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "bin": {