@rhseung/ps-cli 1.3.2 → 1.4.0

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.
@@ -1,29 +1,30 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  runSolution
4
- } from "../chunk-EIFFWFLS.js";
4
+ } from "../chunk-OJZLQ6FK.js";
5
5
  import {
6
- detectLanguageFromFile,
7
- getSupportedLanguages,
8
- getSupportedLanguagesString
9
- } from "../chunk-TQXMB7XV.js";
6
+ Command,
7
+ CommandBuilder,
8
+ CommandDef,
9
+ getProblemId,
10
+ resolveLanguage,
11
+ resolveProblemContext
12
+ } from "../chunk-7SVCS23X.js";
10
13
  import {
11
- detectProblemIdFromPath,
12
- getProblemDirPath,
13
- getProblemId
14
- } from "../chunk-MOPDUECU.js";
15
- import "../chunk-CIG2LEJC.js";
16
- import "../chunk-FYS2JH42.js";
14
+ __decorateClass,
15
+ getSupportedLanguagesString
16
+ } from "../chunk-7MQMPJ3X.js";
17
17
 
18
18
  // src/commands/run.tsx
19
- import { useEffect, useState } from "react";
20
- import { render, Box, Text } from "ink";
21
- import { StatusMessage, Alert } from "@inkjs/ui";
22
19
  import { readdir } from "fs/promises";
23
20
  import { join } from "path";
21
+ import { StatusMessage, Alert } from "@inkjs/ui";
24
22
  import { Spinner } from "@inkjs/ui";
25
- import { jsx, jsxs } from "react/jsx-runtime";
26
- function RunCommand({
23
+ import { Box, Text } from "ink";
24
+
25
+ // src/hooks/use-run-solution.ts
26
+ import { useEffect, useState } from "react";
27
+ function useRunSolution({
27
28
  problemDir,
28
29
  language,
29
30
  inputFile,
@@ -55,6 +56,27 @@ function RunCommand({
55
56
  }, 2e3);
56
57
  });
57
58
  }, [problemDir, language, inputFile, onComplete]);
59
+ return {
60
+ status,
61
+ result,
62
+ error
63
+ };
64
+ }
65
+
66
+ // src/commands/run.tsx
67
+ import { jsx, jsxs } from "react/jsx-runtime";
68
+ function RunView({
69
+ problemDir,
70
+ language,
71
+ inputFile,
72
+ onComplete
73
+ }) {
74
+ const { status, result, error } = useRunSolution({
75
+ problemDir,
76
+ language,
77
+ inputFile,
78
+ onComplete
79
+ });
58
80
  if (status === "loading") {
59
81
  return /* @__PURE__ */ jsx(Box, { flexDirection: "column", children: /* @__PURE__ */ jsx(Spinner, { label: "\uCF54\uB4DC \uC2E4\uD589 \uC911..." }) });
60
82
  }
@@ -99,91 +121,70 @@ function RunCommand({
99
121
  }
100
122
  return null;
101
123
  }
102
- async function findInputFile(problemDir) {
103
- const files = await readdir(problemDir);
104
- const inputFile = files.find((f) => f === "input1.txt") || files.find((f) => f === "input.txt");
105
- if (!inputFile) {
106
- throw new Error("input.txt \uB610\uB294 input1.txt \uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
107
- }
108
- return join(problemDir, inputFile);
109
- }
110
- async function runCommand(problemId, language, inputFile) {
111
- const currentPathProblemId = detectProblemIdFromPath(process.cwd());
112
- const problemDir = problemId && currentPathProblemId !== problemId ? getProblemDirPath(problemId) : process.cwd();
113
- const inputPath = inputFile ? join(problemDir, inputFile) : await findInputFile(problemDir);
114
- const files = await readdir(problemDir);
115
- const solutionFile = files.find((f) => f.startsWith("solution."));
116
- if (!solutionFile) {
117
- throw new Error("solution.* \uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
118
- }
119
- const detectedLanguage = language ?? detectLanguageFromFile(solutionFile);
120
- if (!detectedLanguage) {
121
- throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uC5B8\uC5B4\uC785\uB2C8\uB2E4: ${solutionFile}`);
122
- }
123
- return new Promise((resolve) => {
124
- const { unmount } = render(
125
- /* @__PURE__ */ jsx(
126
- RunCommand,
127
- {
128
- problemDir,
129
- language: detectedLanguage,
130
- inputFile: inputPath,
131
- onComplete: () => {
132
- unmount();
133
- resolve();
134
- }
135
- }
136
- )
124
+ var RunCommand = class extends Command {
125
+ async execute(args, flags) {
126
+ const problemId = getProblemId(args);
127
+ const context = await resolveProblemContext(
128
+ problemId !== null ? [problemId.toString()] : []
137
129
  );
138
- });
139
- }
140
- var runHelp = `
141
- \uC0AC\uC6A9\uBC95:
142
- $ ps run [\uBB38\uC81C\uBC88\uD638] [\uC635\uC158]
143
-
144
- \uC124\uBA85:
145
- \uCF54\uB4DC\uB97C \uC2E4\uD589\uD569\uB2C8\uB2E4 (\uD14C\uC2A4\uD2B8 \uC5C6\uC774).
146
- - \uD604\uC7AC \uB514\uB809\uD1A0\uB9AC \uB610\uB294 \uC9C0\uC815\uD55C \uBB38\uC81C \uBC88\uD638\uC758 \uCF54\uB4DC \uC2E4\uD589
147
- - solution.* \uD30C\uC77C\uC744 \uC790\uB3D9\uC73C\uB85C \uCC3E\uC544 \uC5B8\uC5B4 \uAC10\uC9C0
148
- - input.txt \uB610\uB294 input1.txt\uB97C \uD45C\uC900 \uC785\uB825\uC73C\uB85C \uC0AC\uC6A9
149
- - \uD14C\uC2A4\uD2B8 \uCF00\uC774\uC2A4 \uAC80\uC99D \uC5C6\uC774 \uB2E8\uC21C \uC2E4\uD589
150
-
151
- \uC635\uC158:
152
- --language, -l \uC5B8\uC5B4 \uC120\uD0DD (\uC9C0\uC815 \uC2DC \uC790\uB3D9 \uAC10\uC9C0 \uBB34\uC2DC)
153
- \uC9C0\uC6D0 \uC5B8\uC5B4: ${getSupportedLanguagesString()}
154
- --input, -i \uC785\uB825 \uD30C\uC77C \uC9C0\uC815 (\uAE30\uBCF8\uAC12: input.txt \uB610\uB294 input1.txt)
155
-
156
- \uC608\uC81C:
157
- $ ps run # \uD604\uC7AC \uB514\uB809\uD1A0\uB9AC\uC5D0\uC11C \uC2E4\uD589
158
- $ ps run 1000 # 1000\uBC88 \uBB38\uC81C \uC2E4\uD589
159
- $ ps run --language python # Python\uC73C\uB85C \uC2E4\uD589
160
- $ ps run --input input2.txt # \uD2B9\uC815 \uC785\uB825 \uD30C\uC77C \uC0AC\uC6A9
161
- `;
162
- async function runExecute(args, flags) {
163
- if (flags.help) {
164
- console.log(runHelp.trim());
165
- process.exit(0);
166
- return;
167
- }
168
- const problemId = getProblemId(args);
169
- const validLanguages = getSupportedLanguages();
170
- const language = flags.language;
171
- if (flags.language && language && !validLanguages.includes(language)) {
172
- console.error(
173
- `\uC624\uB958: \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uC5B8\uC5B4\uC785\uB2C8\uB2E4. (${getSupportedLanguagesString()})`
130
+ const inputPath = flags.input ? join(context.problemDir, flags.input) : await this.findInputFile(context.problemDir);
131
+ const detectedLanguage = await resolveLanguage(
132
+ context.problemDir,
133
+ flags.language
174
134
  );
175
- process.exit(1);
135
+ await this.renderView(RunView, {
136
+ problemDir: context.problemDir,
137
+ language: detectedLanguage,
138
+ inputFile: inputPath
139
+ });
140
+ }
141
+ // 입력 파일 찾기: private 메서드
142
+ async findInputFile(problemDir) {
143
+ const files = await readdir(problemDir);
144
+ const inputFile = files.find((f) => f === "input1.txt") || files.find((f) => f === "input.txt");
145
+ if (!inputFile) {
146
+ throw new Error("input.txt \uB610\uB294 input1.txt \uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
147
+ }
148
+ return join(problemDir, inputFile);
176
149
  }
177
- await runCommand(problemId, language, flags.input);
178
- }
179
- var runCommandDef = {
180
- name: "run",
181
- help: runHelp,
182
- execute: runExecute
183
150
  };
184
- var run_default = runCommandDef;
151
+ RunCommand = __decorateClass([
152
+ CommandDef({
153
+ name: "run",
154
+ description: `\uCF54\uB4DC\uB97C \uC2E4\uD589\uD569\uB2C8\uB2E4 (\uD14C\uC2A4\uD2B8 \uC5C6\uC774).
155
+ - \uD604\uC7AC \uB514\uB809\uD1A0\uB9AC \uB610\uB294 \uC9C0\uC815\uD55C \uBB38\uC81C \uBC88\uD638\uC758 \uCF54\uB4DC \uC2E4\uD589
156
+ - solution.* \uD30C\uC77C\uC744 \uC790\uB3D9\uC73C\uB85C \uCC3E\uC544 \uC5B8\uC5B4 \uAC10\uC9C0
157
+ - input.txt \uB610\uB294 input1.txt\uB97C \uD45C\uC900 \uC785\uB825\uC73C\uB85C \uC0AC\uC6A9
158
+ - \uD14C\uC2A4\uD2B8 \uCF00\uC774\uC2A4 \uAC80\uC99D \uC5C6\uC774 \uB2E8\uC21C \uC2E4\uD589`,
159
+ flags: [
160
+ {
161
+ name: "language",
162
+ options: {
163
+ shortFlag: "l",
164
+ description: `\uC5B8\uC5B4 \uC120\uD0DD (\uC9C0\uC815 \uC2DC \uC790\uB3D9 \uAC10\uC9C0 \uBB34\uC2DC)
165
+ \uC9C0\uC6D0 \uC5B8\uC5B4: ${getSupportedLanguagesString()}`
166
+ }
167
+ },
168
+ {
169
+ name: "input",
170
+ options: {
171
+ shortFlag: "i",
172
+ description: "\uC785\uB825 \uD30C\uC77C \uC9C0\uC815 (\uAE30\uBCF8\uAC12: input.txt \uB610\uB294 input1.txt)"
173
+ }
174
+ }
175
+ ],
176
+ autoDetectProblemId: true,
177
+ autoDetectLanguage: true,
178
+ examples: [
179
+ "run # \uD604\uC7AC \uB514\uB809\uD1A0\uB9AC\uC5D0\uC11C \uC2E4\uD589",
180
+ "run 1000 # 1000\uBC88 \uBB38\uC81C \uC2E4\uD589",
181
+ "run --language python # Python\uC73C\uB85C \uC2E4\uD589",
182
+ "run --input input2.txt # \uD2B9\uC815 \uC785\uB825 \uD30C\uC77C \uC0AC\uC6A9"
183
+ ]
184
+ })
185
+ ], RunCommand);
186
+ var run_default = CommandBuilder.fromClass(RunCommand);
185
187
  export {
186
- run_default as default,
187
- runExecute,
188
- runHelp
188
+ RunCommand,
189
+ run_default as default
189
190
  };
@@ -4,20 +4,29 @@ import {
4
4
  getTierName,
5
5
  getUserStats,
6
6
  source_default
7
- } from "../chunk-2E4VSP6O.js";
7
+ } from "../chunk-NB4OIWND.js";
8
8
  import {
9
+ Command,
10
+ CommandBuilder,
11
+ CommandDef,
9
12
  getSolvedAcHandle
10
- } from "../chunk-CIG2LEJC.js";
11
- import "../chunk-FYS2JH42.js";
13
+ } from "../chunk-7SVCS23X.js";
14
+ import {
15
+ __decorateClass
16
+ } from "../chunk-7MQMPJ3X.js";
12
17
 
13
18
  // src/commands/stats.tsx
14
- import { useEffect, useState } from "react";
15
- import { render, Box, Text } from "ink";
16
19
  import { Alert } from "@inkjs/ui";
17
20
  import { Spinner } from "@inkjs/ui";
18
21
  import gradient from "gradient-string";
19
- import { jsx, jsxs } from "react/jsx-runtime";
20
- function StatsCommand({ handle, onComplete }) {
22
+ import { Box, Text } from "ink";
23
+
24
+ // src/hooks/use-user-stats.ts
25
+ import { useEffect, useState } from "react";
26
+ function useUserStats({
27
+ handle,
28
+ onComplete
29
+ }) {
21
30
  const [status, setStatus] = useState(
22
31
  "loading"
23
32
  );
@@ -38,6 +47,20 @@ function StatsCommand({ handle, onComplete }) {
38
47
  }, 3e3);
39
48
  });
40
49
  }, [handle, onComplete]);
50
+ return {
51
+ status,
52
+ user,
53
+ error
54
+ };
55
+ }
56
+
57
+ // src/commands/stats.tsx
58
+ import { jsx, jsxs } from "react/jsx-runtime";
59
+ function StatsView({ handle, onComplete }) {
60
+ const { status, user, error } = useUserStats({
61
+ handle,
62
+ onComplete
63
+ });
41
64
  if (status === "loading") {
42
65
  return /* @__PURE__ */ jsx(Box, { flexDirection: "column", children: /* @__PURE__ */ jsx(Spinner, { label: "\uD1B5\uACC4\uB97C \uBD88\uB7EC\uC624\uB294 \uC911..." }) });
43
66
  }
@@ -100,65 +123,48 @@ function StatsCommand({ handle, onComplete }) {
100
123
  }
101
124
  return null;
102
125
  }
103
- async function statsCommand(handle) {
104
- return new Promise((resolve) => {
105
- const { unmount } = render(
106
- /* @__PURE__ */ jsx(
107
- StatsCommand,
108
- {
109
- handle,
110
- onComplete: () => {
111
- unmount();
112
- resolve();
113
- }
114
- }
115
- )
116
- );
117
- });
118
- }
119
- var statsHelp = `
120
- \uC0AC\uC6A9\uBC95:
121
- $ ps stats [\uD578\uB4E4] [\uC635\uC158]
122
-
123
- \uC124\uBA85:
124
- Solved.ac\uC5D0\uC11C \uC0AC\uC6A9\uC790 \uD1B5\uACC4\uB97C \uC870\uD68C\uD569\uB2C8\uB2E4.
125
- - \uD2F0\uC5B4, \uB808\uC774\uD305, \uD574\uACB0\uD55C \uBB38\uC81C \uC218 \uB4F1 \uD45C\uC2DC
126
- - \uADF8\uB77C\uB370\uC774\uC158\uC73C\uB85C \uC2DC\uAC01\uC801\uC73C\uB85C \uD45C\uC2DC
127
-
128
- \uC635\uC158:
129
- --handle, -h Solved.ac \uD578\uB4E4 (\uC124\uC815\uC5D0 \uC800\uC7A5\uB41C \uAC12 \uC0AC\uC6A9 \uAC00\uB2A5)
130
-
131
- \uC608\uC81C:
132
- $ ps stats myhandle
133
- $ ps stats --handle myhandle
134
- `;
135
- async function statsExecute(args, flags) {
136
- if (flags.help) {
137
- console.log(statsHelp.trim());
138
- process.exit(0);
139
- return;
140
- }
141
- let handle = args[0] || flags.handle;
142
- if (!handle) {
143
- handle = getSolvedAcHandle();
144
- }
145
- if (!handle) {
146
- console.error("\uC624\uB958: Solved.ac \uD578\uB4E4\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694.");
147
- console.error(`\uC0AC\uC6A9\uBC95: ps stats <\uD578\uB4E4>`);
148
- console.error(`\uB3C4\uC6C0\uB9D0: ps stats --help`);
149
- console.error(`\uD78C\uD2B8: \uC124\uC815\uC5D0 \uD578\uB4E4\uC744 \uC800\uC7A5\uD558\uBA74 \uB9E4\uBC88 \uC785\uB825\uD560 \uD544\uC694\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.`);
150
- process.exit(1);
126
+ var StatsCommand = class extends Command {
127
+ async execute(args, flags) {
128
+ let handle = args[0] || flags.handle;
129
+ if (!handle) {
130
+ handle = getSolvedAcHandle();
131
+ }
132
+ if (!handle) {
133
+ console.error("\uC624\uB958: Solved.ac \uD578\uB4E4\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694.");
134
+ console.error(`\uC0AC\uC6A9\uBC95: ps stats <\uD578\uB4E4>`);
135
+ console.error(`\uB3C4\uC6C0\uB9D0: ps stats --help`);
136
+ console.error(
137
+ `\uD78C\uD2B8: \uC124\uC815\uC5D0 \uD578\uB4E4\uC744 \uC800\uC7A5\uD558\uBA74 \uB9E4\uBC88 \uC785\uB825\uD560 \uD544\uC694\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.`
138
+ );
139
+ process.exit(1);
140
+ return;
141
+ }
142
+ await this.renderView(StatsView, {
143
+ handle
144
+ });
151
145
  }
152
- await statsCommand(handle);
153
- }
154
- var statsCommandDef = {
155
- name: "stats",
156
- help: statsHelp,
157
- execute: statsExecute
158
146
  };
159
- var stats_default = statsCommandDef;
147
+ StatsCommand = __decorateClass([
148
+ CommandDef({
149
+ name: "stats",
150
+ description: `Solved.ac\uC5D0\uC11C \uC0AC\uC6A9\uC790 \uD1B5\uACC4\uB97C \uC870\uD68C\uD569\uB2C8\uB2E4.
151
+ - \uD2F0\uC5B4, \uB808\uC774\uD305, \uD574\uACB0\uD55C \uBB38\uC81C \uC218 \uB4F1 \uD45C\uC2DC
152
+ - \uADF8\uB77C\uB370\uC774\uC158\uC73C\uB85C \uC2DC\uAC01\uC801\uC73C\uB85C \uD45C\uC2DC`,
153
+ flags: [
154
+ {
155
+ name: "handle",
156
+ options: {
157
+ shortFlag: "h",
158
+ description: "Solved.ac \uD578\uB4E4 (\uC124\uC815\uC5D0 \uC800\uC7A5\uB41C \uAC12 \uC0AC\uC6A9 \uAC00\uB2A5)"
159
+ }
160
+ }
161
+ ],
162
+ autoDetectProblemId: false,
163
+ examples: ["stats myhandle", "stats --handle myhandle"]
164
+ })
165
+ ], StatsCommand);
166
+ var stats_default = CommandBuilder.fromClass(StatsCommand);
160
167
  export {
161
- stats_default as default,
162
- statsExecute,
163
- statsHelp
168
+ StatsCommand,
169
+ stats_default as default
164
170
  };