Skip to content

Commit

Permalink
backtrack to node v18 to see err msg under esm loader. Fix strict TS …
Browse files Browse the repository at this point in the history
…errors to make it work again. Delete imgs folder as it interferes
  • Loading branch information
boyangwang committed Aug 10, 2023
1 parent fe1e82f commit a1c0e4b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "兰亭文存",
"type": "module",
"scripts": {
"tsnode": "ts-node",
"lint": "umi g tmp && npm run lint:js && npm run lint:prettier",
"lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
"lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
Expand Down Expand Up @@ -42,9 +43,11 @@
"@ant-design/pro-descriptions": "^1.0.16",
"@ant-design/pro-layout": "^6.4.16",
"@ant-design/pro-table": "^2.7.2",
"@types/node": "^20.4.9",
"@umijs/route-utils": "^1.0.32",
"antd": "^4.6.3",
"classnames": "^2.2.6",
"esm": "^3.2.25",
"lodash": "^4.17.11",
"omit.js": "^2.0.2",
"qs": "^6.9.0",
Expand All @@ -55,6 +58,7 @@
"react-highlight-words": "^0.16.0",
"react-markdown": "^5.0.3",
"remark-gfm": "^1.0.0",
"tslib": "^2.6.1",
"umi": "^3.2.14",
"umi-request": "^1.0.8",
"use-merge-value": "^1.0.1"
Expand Down Expand Up @@ -101,7 +105,7 @@
"pro-download": "1.0.1",
"puppeteer-core": "^5.0.0",
"ts-node": "^10.9.1",
"typescript": "^3.9.7"
"typescript": "^5.1.6"
},
"engines": {
"node": ">=14.0.0"
Expand Down
20 changes: 12 additions & 8 deletions scripts/compile-archives.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-console */
/* eslint-disable no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */

import * as fs from 'fs';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
Expand All @@ -10,7 +11,7 @@ import mysql, { Connection } from 'mysql';
import { execSync } from 'child_process';
import axios from 'axios';
import { createHmac } from 'crypto';
import { Archive, Archives } from './data';
import { Archive, Archives, FieldFreqMap } from './data';
import secrets from './secrets.json' assert { type: "json" };
import { exec } from './migrate-backend2';

Expand Down Expand Up @@ -96,11 +97,12 @@ function endConnection() {
connection.end();
}

function setField(archive: Archive, field: string, fileContent: string, archives: Archives) {
function setField(archive: Archive, field: keyof Archive, fileContent: string, archives: Archives) {
const regexArr = toFieldRegex(field).exec(fileContent);
if (regexArr && regexArr[1]) {
const fieldVal = getFieldFromFieldLine(field, regexArr[1]);
archive[field] = fieldVal;
const fieldVal: string | string[] = getFieldFromFieldLine(field, regexArr[1]);

(archive[field] as any) = fieldVal;
fileContent = fileContent.replace(regexArr[0], '');

updateFreqMap(field, fieldVal, archives);
Expand All @@ -112,11 +114,12 @@ function setField(archive: Archive, field: string, fileContent: string, archives

function updateFreqMap(field: string, fieldVal: string | string[], archives: Archives) {
if (['author', 'publisher', 'date', 'tag'].includes(field)) {
const validfield = field as keyof FieldFreqMap;
if (typeof fieldVal === 'string') {
archives.fieldFreqMap[field][fieldVal] = (archives.fieldFreqMap[field][fieldVal] || 0) + 1;
archives.fieldFreqMap[validfield][fieldVal] = (archives.fieldFreqMap[validfield][fieldVal] || 0) + 1;
} else {
(fieldVal as string[]).forEach((v) => {
archives.fieldFreqMap[field][v] = (archives.fieldFreqMap[field][v] || 0) + 1;
archives.fieldFreqMap[validfield][v] = (archives.fieldFreqMap[validfield][v] || 0) + 1;
});
}
}
Expand Down Expand Up @@ -425,9 +428,10 @@ async function compileArchives(
const archive = new Archive();
archive.id = getIdFromCommentFilename(f);

console.log(f);
let fileContent: string = fs.readFileSync(`${ARCHIVE_DIR}/comments/${f}`, 'utf-8');

['title', 'author', 'publisher', 'date', 'chapter', 'tag'].forEach((field) => {
(['title', 'author', 'publisher', 'date', 'chapter', 'tag'] as (keyof Archive)[]).forEach((field) => {
fileContent = setField(archive, field, fileContent, compiledArchives);
});
archive.remarks = fileContent.replace('# remarks', '');
Expand All @@ -449,7 +453,7 @@ async function compileArchives(

compiledArchives.archives = {};
archives.forEach((a) => {
compiledArchives.archives[a.id] = a;
compiledArchives.archives[parseInt(a.id)] = a;
});

if (isCompleteTask) {
Expand Down
4 changes: 4 additions & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
"@types/ali-oss": "^6.0.8",
"ali-oss": "^6.15.2",
"axios": "^0.21.1"
},
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
}
}
18 changes: 16 additions & 2 deletions scripts/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
import * as fs from 'fs';
console.log(fs.readdirSync('./'));
class Archive {
title: string = '';

author: string[] = [];

publisher: string = '';

origs: false | string[] = false;

likes: number = 0;
}

const archive = new Archive();
const keys: (keyof Archive)[] = ['title', 'author', 'publisher', 'origs', 'likes'];
let field: keyof Archive = keys[Math.floor(Math.random() * keys.length)];

archive[field] = 123;
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": false,
"allowJs": true,
"skipLibCheck": true,
Expand Down

0 comments on commit a1c0e4b

Please sign in to comment.