atcoder-workspace 1.1.0-beta.1

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.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +98 -0
  3. package/THIRD_PARTY_LICENSES +21 -0
  4. package/dist/atcoder/client.d.ts +2 -0
  5. package/dist/atcoder/client.js +23 -0
  6. package/dist/atcoder/new.d.ts +15 -0
  7. package/dist/atcoder/new.js +123 -0
  8. package/dist/atcoder/parser/contest-tasks.d.ts +6 -0
  9. package/dist/atcoder/parser/contest-tasks.js +86 -0
  10. package/dist/atcoder/parser/limits.d.ts +10 -0
  11. package/dist/atcoder/parser/limits.js +71 -0
  12. package/dist/atcoder/parser/problem-page.d.ts +12 -0
  13. package/dist/atcoder/parser/problem-page.js +136 -0
  14. package/dist/atcoder/parser/submission-status.d.ts +8 -0
  15. package/dist/atcoder/parser/submission-status.js +78 -0
  16. package/dist/atcoder/submit.d.ts +9 -0
  17. package/dist/atcoder/submit.js +182 -0
  18. package/dist/cli.d.ts +2 -0
  19. package/dist/cli.js +508 -0
  20. package/dist/config/config-store.d.ts +17 -0
  21. package/dist/config/config-store.js +92 -0
  22. package/dist/session/auth.d.ts +8 -0
  23. package/dist/session/auth.js +117 -0
  24. package/dist/session/store.d.ts +15 -0
  25. package/dist/session/store.js +75 -0
  26. package/dist/test-runner/diff.d.ts +7 -0
  27. package/dist/test-runner/diff.js +32 -0
  28. package/dist/test-runner/runner.d.ts +46 -0
  29. package/dist/test-runner/runner.js +274 -0
  30. package/dist/utils/errors.d.ts +15 -0
  31. package/dist/utils/errors.js +35 -0
  32. package/dist/utils/format.d.ts +9 -0
  33. package/dist/utils/format.js +89 -0
  34. package/dist/utils/i18n.d.ts +345 -0
  35. package/dist/utils/i18n.js +413 -0
  36. package/dist/utils/open.d.ts +8 -0
  37. package/dist/utils/open.js +50 -0
  38. package/dist/workspace/finder.d.ts +9 -0
  39. package/dist/workspace/finder.js +62 -0
  40. package/dist/workspace/initializer.d.ts +4 -0
  41. package/dist/workspace/initializer.js +109 -0
  42. package/package.json +38 -0
  43. package/src/atcoder/client.ts +21 -0
  44. package/src/atcoder/new.ts +107 -0
  45. package/src/atcoder/parser/contest-tasks.test.ts +37 -0
  46. package/src/atcoder/parser/contest-tasks.ts +61 -0
  47. package/src/atcoder/parser/limits.test.ts +52 -0
  48. package/src/atcoder/parser/limits.ts +75 -0
  49. package/src/atcoder/parser/problem-page.test.ts +68 -0
  50. package/src/atcoder/parser/problem-page.ts +126 -0
  51. package/src/atcoder/parser/submission-status.test.ts +36 -0
  52. package/src/atcoder/parser/submission-status.ts +54 -0
  53. package/src/atcoder/submit.ts +170 -0
  54. package/src/cli.ts +554 -0
  55. package/src/config/config-store.ts +72 -0
  56. package/src/session/auth.ts +87 -0
  57. package/src/session/store.ts +50 -0
  58. package/src/test-runner/diff.test.ts +26 -0
  59. package/src/test-runner/diff.ts +42 -0
  60. package/src/test-runner/runner.test.ts +70 -0
  61. package/src/test-runner/runner.ts +315 -0
  62. package/src/utils/errors.ts +31 -0
  63. package/src/utils/format.test.ts +69 -0
  64. package/src/utils/format.ts +95 -0
  65. package/src/utils/i18n.test.ts +74 -0
  66. package/src/utils/i18n.ts +418 -0
  67. package/src/utils/open.ts +47 -0
  68. package/src/workspace/finder.ts +29 -0
  69. package/src/workspace/initializer.ts +85 -0
  70. package/tsconfig.json +16 -0
@@ -0,0 +1,85 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { DEFAULT_CONFIG, saveConfig } from '../config/config-store';
4
+
5
+ const DEFAULT_CPP_TEMPLATE = `#include <bits/stdc++.h>
6
+
7
+ using namespace std;
8
+
9
+ int main() {
10
+ // Solve the problem here
11
+ return 0;
12
+ }
13
+ `;
14
+
15
+ const DEFAULT_PYTHON_TEMPLATE = `import sys
16
+
17
+ def main():
18
+ # Solve the problem here
19
+ pass
20
+
21
+ if __name__ == '__main__':
22
+ main()
23
+ `;
24
+
25
+ export function initWorkspace(
26
+ targetDir: string = process.cwd(),
27
+ defaultLanguage: string = 'cpp'
28
+ ): { alreadyInitialized: boolean; gitignoreUpdated: boolean } {
29
+ const atCoderCliDir = path.join(targetDir, '.atcoder-cli');
30
+ let alreadyInitialized = false;
31
+
32
+ if (fs.existsSync(atCoderCliDir)) {
33
+ alreadyInitialized = true;
34
+ } else {
35
+ fs.mkdirSync(atCoderCliDir, { recursive: true });
36
+ }
37
+
38
+ // Create default config if it doesn't exist
39
+ const configPath = path.join(atCoderCliDir, 'config.json');
40
+ if (!fs.existsSync(configPath)) {
41
+ saveConfig(targetDir, {
42
+ ...DEFAULT_CONFIG,
43
+ defaultLanguage
44
+ });
45
+ }
46
+
47
+ // Create default templates
48
+ const templatesDir = path.join(atCoderCliDir, 'templates');
49
+ const cppTemplateDir = path.join(templatesDir, 'cpp');
50
+ const pythonTemplateDir = path.join(templatesDir, 'python');
51
+
52
+ if (!fs.existsSync(cppTemplateDir)) {
53
+ fs.mkdirSync(cppTemplateDir, { recursive: true });
54
+ }
55
+ const cppFile = path.join(cppTemplateDir, 'main.cpp');
56
+ if (!fs.existsSync(cppFile)) {
57
+ fs.writeFileSync(cppFile, DEFAULT_CPP_TEMPLATE, 'utf8');
58
+ }
59
+
60
+ if (!fs.existsSync(pythonTemplateDir)) {
61
+ fs.mkdirSync(pythonTemplateDir, { recursive: true });
62
+ }
63
+ const pythonFile = path.join(pythonTemplateDir, 'main.py');
64
+ if (!fs.existsSync(pythonFile)) {
65
+ fs.writeFileSync(pythonFile, DEFAULT_PYTHON_TEMPLATE, 'utf8');
66
+ }
67
+
68
+ // Update or create .gitignore
69
+ const gitignorePath = path.join(targetDir, '.gitignore');
70
+ const ignoreRule = '\n# AtCoder CLI Session\n.atcoder-cli/session.json\n';
71
+ let gitignoreUpdated = false;
72
+
73
+ if (fs.existsSync(gitignorePath)) {
74
+ const content = fs.readFileSync(gitignorePath, 'utf8');
75
+ if (!content.includes('.atcoder-cli/session.json')) {
76
+ fs.writeFileSync(gitignorePath, content + ignoreRule, 'utf8');
77
+ gitignoreUpdated = true;
78
+ }
79
+ } else {
80
+ fs.writeFileSync(gitignorePath, ignoreRule.trim() + '\n', 'utf8');
81
+ gitignoreUpdated = true;
82
+ }
83
+
84
+ return { alreadyInitialized, gitignoreUpdated };
85
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "nodenext",
5
+ "moduleResolution": "nodenext",
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "declaration": true
13
+ },
14
+ "include": ["src/**/*"],
15
+ "exclude": ["node_modules", "dist", "**/*.spec.ts", "**/*.test.ts"]
16
+ }