Skip to content

Commit 1e716a3

Browse files
authored
Merge branch 'main' into leetcode-api-module
2 parents 7ef8da5 + 6b2a891 commit 1e716a3

File tree

17 files changed

+164
-33
lines changed

17 files changed

+164
-33
lines changed

.github/workflows/post-leetcode-potd-to-discord.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
uses: ./.github/workflows/set-up-everything
3535

3636
- name: Prepare secrets
37-
run: (cd workspaces/post-leetcode-potd-to-discord && echo "$SECRETS_FILE" > secrets_DO_NOT_COMMIT_OR_SHARE.json)
37+
run: echo "$SECRETS_FILE" > workspaces/post-leetcode-potd-to-discord/secrets_DO_NOT_COMMIT_OR_SHARE.json
3838
env:
3939
SECRETS_FILE: ${{ secrets.SECRETS_FILE }}
4040

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff --git a/nullthrows.d.ts b/nullthrows.d.ts
2+
index d4953f2f47b79701e5f125b9c041fb185668dd53..a39a37b30cd206e037ecbbb66bc90dacd6adb3af 100644
3+
--- a/nullthrows.d.ts
4+
+++ b/nullthrows.d.ts
5+
@@ -1,5 +1,15 @@
6+
/**
7+
* Throws if value is null or undefined, otherwise returns value.
8+
*/
9+
+declare function nullthrows<T>(
10+
+ value?: T | null,
11+
+ message?: string,
12+
+): NonNullable<T>;
13+
+
14+
+// Patched based on https://github.com/microsoft/TypeScript/issues/46770#issuecomment-1039459991 and https://github.com/zertosh/nullthrows/pull/15
15+
+
16+
+declare namespace nullthrows {
17+
+ export { nullthrows as default };
18+
+}
19+
+export = nullthrows;
20+
21+
-export default function nullthrows<T>(value?: T | null, message?: string): T;

workspaces/adventure-pack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"dependencies": {
6060
"immutability-helper": "3.1.1",
6161
"invariant": "2.2.4",
62-
"nullthrows": "1.1.1",
62+
"nullthrows": "patch:nullthrows@npm%3A1.1.1#~/.yarn/patches/nullthrows-npm-1.1.1-3d1f817134.patch",
6363
"react": "18.3.1",
6464
"react-dom": "18.3.1",
6565
"react-syntax-highlighter": "15.5.0"

workspaces/download-leetcode-submissions/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ secrets_DO_NOT_COMMIT_OR_SHARE.json
33
submissions/
44
submissions.jsonl
55
submissions.sha512
6+
7+
dist/

workspaces/download-leetcode-submissions/README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To use:
1919
nano secrets_DO_NOT_COMMIT_OR_SHARE.json
2020
```
2121

22-
2. **Run the script!**
22+
2. **Run the script!** You can run a development version:
2323

2424
```sh
2525
# Install dependencies, if you haven't already:
@@ -33,7 +33,26 @@ To use:
3333
yarn start
3434
```
3535

36-
Submissions will be downloaded to a directory named `submissions`, grouped by problem and problem number range. Filenames take the form `{yyyymmdd-date}-{submission-id}-{result}.{extension}`, resulting in full paths like `submissions/2101-2200/2163-kth-distinct-string-in-an-array/20240805-1345920313-ac.c` for an accepted C solution submitted on August 5th, 2024.
36+
Or, build and run a distribution version:
37+
38+
```sh
39+
# It's easiest to do this from the package's directory:
40+
cd workspaces/download-leetcode-submissions
41+
42+
# Install dependencies, if you haven't already:
43+
yarn
44+
45+
# Package the script into an executable:
46+
yarn build
47+
48+
# Run it with Node!
49+
node dist/download-leetcode-submissions.cjs
50+
51+
# Or if your system can handle executable files, try running it directly:
52+
./dist/download-leetcode-submissions.cjs
53+
```
54+
55+
Submissions will be downloaded to a directory named `submissions`, grouped by problem and problem number range. Filenames take the form `{yyyymmdd-date}-{submission-id}-{result}.{extension}`, resulting in full paths like `submissions/2101-2200/2163-kth-distinct-string-in-an-array/20240805-1345920313-ac.c` for an accepted C solution submitted on August 5th, 2024.
3756

3857
## Metadata Files
3958

@@ -79,6 +98,10 @@ As such it's safe to run the script multiple times, without redoing too much wor
7998

8099
Like the rest of the [Code Chronicles Leetcode ecosystem](../../), this package is structured as a Node module, using [Yarn](https://yarnpkg.com/) as the package manager.
81100

82-
You can install dependencies by running `yarn`, either in this package's directory, or in the repository root. The usual `yarn format`, `yarn lint`, and `yarn typecheck` scripts are available to aid in development and occasionally to annoy.
101+
You can install dependencies by running `yarn`, either in this package's directory, or in the repository root. The usual `yarn format`, `yarn lint`, and `yarn typecheck` scripts are available to aid in development and occasionally to annoy. Read more in the repository's general [development guide](../../DEVELOPMENT.md).
102+
103+
This package supports an additional `package.json` script:
104+
105+
### `yarn build`
83106

84-
See also the repository's general [development guide](../../DEVELOPMENT.md).
107+
Builds a distribution version of this package, in a `dist` directory within the package's workspace.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import config from "@code-chronicles/eslint-config";
22

3-
export default [...config, { ignores: ["submissions/"] }];
3+
export default [...config, { ignores: ["dist/", "submissions/"] }];

workspaces/download-leetcode-submissions/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
"name": "Miorel-Lucian Palii",
1313
"url": "https://github.com/miorel"
1414
},
15+
"type": "module",
1516
"exports": "./src/main.ts",
1617
"scripts": {
18+
"build": "cross-env NODE_OPTIONS=\"--import tsx\" webpack && chmod +x dist/download-leetcode-submissions.cjs",
1719
"format": "prettier --color --write .",
1820
"lint": "eslint --color --max-warnings=0 .",
1921
"start": "tsx src/main.ts",
@@ -22,15 +24,19 @@
2224
"dependencies": {
2325
"@code-chronicles/leetcode-api": "workspace:*",
2426
"@code-chronicles/util": "workspace:*",
25-
"nullthrows": "1.1.1",
27+
"nullthrows": "patch:nullthrows@npm%3A1.1.1#~/.yarn/patches/nullthrows-npm-1.1.1-3d1f817134.patch",
2628
"zod": "3.23.8"
2729
},
2830
"devDependencies": {
2931
"@code-chronicles/eslint-config": "workspace:*",
3032
"@types/node": "22.5.5",
33+
"cross-env": "7.0.3",
3134
"eslint": "9.10.0",
3235
"prettier": "3.3.3",
36+
"ts-loader": "9.5.1",
3337
"tsx": "4.19.1",
34-
"typescript": "5.6.2"
38+
"typescript": "5.6.2",
39+
"webpack": "5.94.0",
40+
"webpack-cli": "5.1.4"
3541
}
3642
}

workspaces/download-leetcode-submissions/src/getDirnameForSubmission.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from "node:path";
22

3-
import type { TransformedSubmission } from "./transformSubmission";
3+
import type { TransformedSubmission } from "./transformSubmission.js";
44

55
const PROBLEMS_PER_GROUP = 100;
66

workspaces/download-leetcode-submissions/src/getFilenameForSubmission.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import nullthrows from "nullthrows";
33
import { SUBMISSION_STATUS_TO_ABBREVIATION } from "@code-chronicles/leetcode-api";
44
import { timestampInSecondsToYearMonthDay } from "@code-chronicles/util/timestampInSecondsToYearMonthDay";
55

6-
import { LANGUAGE_TO_FILE_EXTENSION } from "./constants";
7-
import type { TransformedSubmission } from "./transformSubmission";
6+
import { LANGUAGE_TO_FILE_EXTENSION } from "./constants.js";
7+
import type { TransformedSubmission } from "./transformSubmission.js";
88

99
export function getFilenameForSubmission({
1010
id,

workspaces/download-leetcode-submissions/src/main.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import { promiseAllLimitingConcurrency } from "@code-chronicles/util/promiseAllL
1010
import { sleep } from "@code-chronicles/util/sleep";
1111
import { whileReturnsTrueAsync } from "@code-chronicles/util/whileReturnsTrueAsync";
1212

13-
import { CONCURRENCY_LIMIT } from "./constants";
14-
import { getFilenameForSubmission } from "./getFilenameForSubmission";
15-
import { getDirnameForSubmission } from "./getDirnameForSubmission";
16-
import { readPriorSubmissions } from "./readPriorSubmissions";
17-
import { readSecrets } from "./readSecrets";
13+
import { CONCURRENCY_LIMIT } from "./constants.js";
14+
import { getDirnameForSubmission } from "./getDirnameForSubmission.js";
15+
import { getFilenameForSubmission } from "./getFilenameForSubmission.js";
16+
import { readPriorSubmissions } from "./readPriorSubmissions.js";
17+
import { readSecrets } from "./readSecrets.js";
1818
import {
1919
transformSubmission,
2020
type TransformedSubmission,
21-
} from "./transformSubmission";
22-
import { writeSubmissionsMetadataAndHashes } from "./writeSubmissionsMetadataAndHashes";
21+
} from "./transformSubmission.js";
22+
import { writeSubmissionsMetadataAndHashes } from "./writeSubmissionsMetadataAndHashes.js";
2323

2424
async function main(): Promise<void> {
2525
// TODO: maybe create the file from a template if it doesn't exist

0 commit comments

Comments
 (0)