Skip to content

Commit

Permalink
Use a string loader
Browse files Browse the repository at this point in the history
  • Loading branch information
graphemecluster committed Oct 7, 2024
1 parent e817a85 commit 44ab32b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 229 deletions.
250 changes: 25 additions & 225 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "tshet-uinh",
"version": "0.15.1",
"description": "A JavaScript library for the Qieyun phonological system",
"module": "true",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
Expand Down Expand Up @@ -71,6 +72,7 @@
"open-cli": "^8.0.0",
"prettier": "^3.3.3",
"rollup": "^4.21.2",
"rollup-plugin-string": "^3.0.0",
"ts-node": "^10.9.2",
"tslib": "^2.7.0",
"typedoc": "^0.26.6",
Expand Down
4 changes: 1 addition & 3 deletions prepare/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ def main():
assert 各細分 == tuple(chr(ord('a') + i) for i in range(len(各細分)))

os.makedirs('src/data/raw', exist_ok=True)
with open('src/data/raw/廣韻.ts', 'w', newline='') as fout:
print('export default `\\', file=fout)
with open('src/data/raw/廣韻.txt', 'w', newline='') as fout:
cur韻目 = None
for 原書小韻號 in range(1, max原書小韻號 + 1):
韻目 = 韻目原貌by原書小韻[原書小韻號]
Expand All @@ -150,7 +149,6 @@ def main():
sep='',
file=fout,
)
print('` as string;', file=fout)


if __name__ == '__main__':
Expand Down
3 changes: 3 additions & 0 deletions rollup.config.mjs → rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// @ts-check

import typescript from '@rollup/plugin-typescript';
import { string } from 'rollup-plugin-string';

/** @type { import("rollup").RollupOptions[] } */
export default [
{
input: 'src/index.ts',
Expand All @@ -17,6 +19,7 @@ export default [
// NOTE Apparently needed with `"incremental": true` in tsconfig
outputToFilesystem: false,
}),
/** @type { import("rollup").Plugin } */ (string({ include: '**/*.txt' })),
],
},
];
2 changes: 1 addition & 1 deletion src/data/廣韻impl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { insertInto } from '../lib/utils';

import raw資料 from './raw/廣韻';
import raw資料 from './raw/廣韻.txt';

export interface 內部廣韻條目 {
字頭: string;
Expand Down
4 changes: 4 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.txt" {
const content: string;
export default content;
}

0 comments on commit 44ab32b

Please sign in to comment.