Skip to content

Commit

Permalink
chore: format @earthworm/xingrong-courses code
Browse files Browse the repository at this point in the history
  • Loading branch information
baboon-king committed Apr 18, 2024
1 parent 1ff5dc5 commit 7665a28
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ dist
pnpm-lock.yaml
pnpm-workspace.yaml
CHANGELOG.md
xingrong-courses
packages/xingrong-courses/data
packages/db/drizzle
40 changes: 20 additions & 20 deletions packages/xingrong-courses/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "@earthworm/xingrong-courses",
"version": "1.0.0",
"description": "",
"main": "src/index.ts",
"scripts": {
"upload:courses": "tsx src/courses.ts",
"upload:statements": "tsx src/statements.ts",
"upload": "pnpm run upload:courses && pnpm run upload:statements",
"pdf:parse": "tsx src/parsePDF/index.ts"
},
"dependencies": {
"@earthworm/db": "workspace:^",
"@earthworm/schema": "workspace:^",
"inquirer": "^9.2.13",
"pdf-parse": "^1.1.1"
},
"devDependencies": {
"@types/inquirer": "^9.0.7",
"@types/pdf-parse": "^1.1.4"
}
"name": "@earthworm/xingrong-courses",
"version": "1.0.0",
"description": "",
"main": "src/index.ts",
"scripts": {
"upload:courses": "tsx src/courses.ts",
"upload:statements": "tsx src/statements.ts",
"upload": "pnpm run upload:courses && pnpm run upload:statements",
"pdf:parse": "tsx src/parsePDF/index.ts"
},
"dependencies": {
"@earthworm/db": "workspace:^",
"@earthworm/schema": "workspace:^",
"inquirer": "^9.2.13",
"pdf-parse": "^1.1.1"
},
"devDependencies": {
"@types/inquirer": "^9.0.7",
"@types/pdf-parse": "^1.1.4"
}
}
23 changes: 5 additions & 18 deletions packages/xingrong-courses/src/courses.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { db } from "@earthworm/db";
import {
course as courseSchema,
statement as statementSchema,
} from "@earthworm/schema";
import fs from "fs";
import path from "path";

import { db } from "@earthworm/db";
import { course as courseSchema, statement as statementSchema } from "@earthworm/schema";

const courses = fs.readdirSync(path.resolve(__dirname, "../data/courses"));

(async function () {
Expand All @@ -28,19 +27,7 @@ const courses = fs.readdirSync(path.resolve(__dirname, "../data/courses"));
})();

function convertToChineseNumber(numStr: string): string {
const chineseNumbers = [
"零",
"一",
"二",
"三",
"四",
"五",
"六",
"七",
"八",
"九",
"十",
];
const chineseNumbers = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"];
let chineseStr = "第";
if (parseInt(numStr) >= 10) {
const [tens, ones] = numStr.split("");
Expand Down
2 changes: 2 additions & 0 deletions packages/xingrong-courses/src/parsePDF/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from "fs";
import path from "path";

import pdf from "pdf-parse";

import { inquire } from "./inquire";
import { parse } from "./parser";

Expand Down
3 changes: 2 additions & 1 deletion packages/xingrong-courses/src/parsePDF/inquire.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from "fs";

import inquirer from "inquirer";

export async function inquire(folderPath: string): Promise<string[]> {
Expand All @@ -16,7 +17,7 @@ export async function inquire(folderPath: string): Promise<string[]> {
if (answers.action === "生成所有文件路径") {
const allFiles = listAllFiles(folderPath);
allFiles.forEach((file) => console.log(file));
resolve(allFiles.map(({value})=> value));
resolve(allFiles.map(({ value }) => value));
} else if (answers.action === "手动选取文件") {
const files = listAllFiles(folderPath);
inquirer
Expand Down
1 change: 1 addition & 0 deletions packages/xingrong-courses/src/parsePDF/parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, expect, it } from "vitest";

import { parse } from "./parser";

describe("pdf parser ", () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/xingrong-courses/src/parsePDF/parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const STARTSIGN = "中文 英文 K.K.音标";
const ENDSIGN = "中文 原形 第三人称单数 过去式 ing形式";
export function parse(text: string) {
Expand Down Expand Up @@ -53,8 +52,7 @@ export function parse(text: string) {
i++;
}

const { english, soundmark } =
parseEnglishAndSoundmark(englishAndSoundmark);
const { english, soundmark } = parseEnglishAndSoundmark(englishAndSoundmark);

data.english = english;
data.soundmark = soundmark;
Expand Down
18 changes: 5 additions & 13 deletions packages/xingrong-courses/src/statements.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { db } from "@earthworm/db";
import { statement } from "@earthworm/schema";
import fs from "node:fs";
import path from "node:path";

import { db } from "@earthworm/db";
import { statement } from "@earthworm/schema";

const courses = fs.readdirSync(path.resolve(__dirname, "../data/courses"));


(async function () {

await db.delete(statement);

function createStatement(
order: number,
chinese: string,
english: string,
soundmark: string,
courseId: number
courseId: number,
) {
return db.insert(statement).values({
order,
Expand All @@ -33,21 +31,15 @@ const courses = fs.readdirSync(path.resolve(__dirname, "../data/courses"));
const cId = parseInt(path.parse(course).name);
const courseDataText = fs.readFileSync(
path.resolve(__dirname, `../data/courses/${course}`),
"utf-8"
"utf-8",
);

const courseData = JSON.parse(courseDataText);

const promiseAll = courseData.map((statement: any, index: number) => {
const { chinese, english, soundmark } = statement;

const result = createStatement(
orderIndex,
chinese,
english,
soundmark,
cId
);
const result = createStatement(orderIndex, chinese, english, soundmark, cId);
orderIndex++;
return result;
});
Expand Down
4 changes: 2 additions & 2 deletions packages/xingrong-courses/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "../../tsconfig.json"
}
"extends": "../../tsconfig.json"
}

0 comments on commit 7665a28

Please sign in to comment.