fix(scripts): support multiline replacement and rerun

This commit is contained in:
Luyu Cheng
2021-02-10 00:47:17 +08:00
parent 7c34c520c2
commit 9d31f8db00
2 changed files with 20 additions and 18 deletions

View File

@@ -13,8 +13,10 @@ const dictSizeMap = Object.fromEntries(
const sourceFilePath = path.join(__dirname, '..', 'src', 'resources', 'dictionary.ts')
fs.writeFileSync(
sourceFilePath,
fs.readFileSync(sourceFilePath, { encoding: 'utf-8' }).replace(/dicts\/([\w-]+.json)', length: \d+/gm, (original, dictFileName) => {
console.log(dictFileName)
return dictSizeMap[dictFileName] ? `dicts/${dictFileName}', length: ${dictSizeMap[dictFileName]}` : original
}),
fs
.readFileSync(sourceFilePath, { encoding: 'utf-8' })
.replace(/dicts\/([a-zA-Z0-9_-]+.json)',([\n\s]+)length: \d+/gm, (original, dictFileName, whiteSpace) => {
console.log(dictFileName)
return dictSizeMap[dictFileName] ? `dicts/${dictFileName}',${whiteSpace}length: ${dictSizeMap[dictFileName]}` : original
}),
)

View File

@@ -87,7 +87,7 @@ export const dictionaries: Dictionary[] = [
description: 'JavaScript API 词典',
category: '代码练习',
url: './dicts/java-arraylist.json',
length: 32,
length: 25,
},
{
id: 'javaCharacter',
@@ -95,7 +95,7 @@ export const dictionaries: Dictionary[] = [
description: 'JavaScript API 词典',
category: '代码练习',
url: './dicts/java-character.json',
length: 32,
length: 8,
},
{
id: 'javaHashmap',
@@ -103,7 +103,7 @@ export const dictionaries: Dictionary[] = [
description: 'JavaScript API 词典',
category: '代码练习',
url: './dicts/java-hashmap.json',
length: 32,
length: 22,
},
{
id: 'javaLinkedList',
@@ -111,7 +111,7 @@ export const dictionaries: Dictionary[] = [
description: 'JavaScript API 词典',
category: '代码练习',
url: './dicts/java-linkedlist.json',
length: 32,
length: 25,
},
{
id: 'javaString',
@@ -119,7 +119,7 @@ export const dictionaries: Dictionary[] = [
description: 'JavaScript API 词典',
category: '代码练习',
url: './dicts/java-string.json',
length: 32,
length: 48,
},
{
id: 'javaStringBuffer',
@@ -127,7 +127,7 @@ export const dictionaries: Dictionary[] = [
description: 'JavaScript API 词典',
category: '代码练习',
url: './dicts/java-stringBuffer.json',
length: 32,
length: 20,
},
{
@@ -136,7 +136,7 @@ export const dictionaries: Dictionary[] = [
description: '人教版三年级上册',
category: '少儿英语',
url: './dicts/PEPXiaoXue3_1_T.json',
length: 4464,
length: 64,
},
{
id: 'san2',
@@ -144,7 +144,7 @@ export const dictionaries: Dictionary[] = [
description: '人教版三年级下册',
category: '少儿英语',
url: './dicts/PEPXiaoXue3_2_T.json',
length: 4464,
length: 72,
},
{
id: 'si1',
@@ -152,7 +152,7 @@ export const dictionaries: Dictionary[] = [
description: '人教版四年级上册',
category: '少儿英语',
url: './dicts/PEPXiaoXue4_1_T.json',
length: 4464,
length: 84,
},
{
id: 'si2',
@@ -160,7 +160,7 @@ export const dictionaries: Dictionary[] = [
description: '人教版四年级下册',
category: '少儿英语',
url: './dicts/PEPXiaoXue4_2_T.json',
length: 4464,
length: 104,
},
{
id: 'wu1',
@@ -168,7 +168,7 @@ export const dictionaries: Dictionary[] = [
description: '人教版五年级上册',
category: '少儿英语',
url: './dicts/PEPXiaoXue5_1_T.json',
length: 4464,
length: 131,
},
{
id: 'wu2',
@@ -176,7 +176,7 @@ export const dictionaries: Dictionary[] = [
description: '人教版五年级下册',
category: '少儿英语',
url: './dicts/PEPXiaoXue5_2_T.json',
length: 4464,
length: 156,
},
{
id: 'liu1',
@@ -184,7 +184,7 @@ export const dictionaries: Dictionary[] = [
description: '人教版六年级上册',
category: '少儿英语',
url: './dicts/PEPXiaoXue6_1_T.json',
length: 4464,
length: 130,
},
{
id: 'liu2',
@@ -192,7 +192,7 @@ export const dictionaries: Dictionary[] = [
description: '人教版六年级下册',
category: '少儿英语',
url: './dicts/PEPXiaoXue6_2_T.json',
length: 4464,
length: 108,
},
{
id: 'qi1',