diff --git a/package.json b/package.json index b223ab1..72ede99 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "start-release": "npm run build && serve dist", "lint": "eslint \"{src,test}/**/*.{ts,tsx}\"", "typecheck": "tsc --noEmit", - "test": "tap run", + "test": "tap run --allow-incomplete-coverage", "prebuild": "npm run lint && npm run typecheck && npm run test", "preview": "vite preview" }, diff --git a/build-resources/th-en-x-basic.dat b/src/assets/th-en-x-basic.ooo-thesaurus similarity index 100% rename from build-resources/th-en-x-basic.dat rename to src/assets/th-en-x-basic.ooo-thesaurus diff --git a/src/build-scripts/oooThesaurusParser.test.ts b/src/build-scripts/oooThesaurusParser.test.ts index 617fbb2..53a3062 100644 --- a/src/build-scripts/oooThesaurusParser.test.ts +++ b/src/build-scripts/oooThesaurusParser.test.ts @@ -4,7 +4,7 @@ import { extractWordsFromFile } from './oooThesaurusParser.js'; void t.test('extractWordsFromFile', async (t) => { const words = await extractWordsFromFile( - new URL('../../build-resources/th-en-x-basic.dat', import.meta.url), + new URL('../assets/th-en-x-basic.ooo-thesaurus', import.meta.url), ); //console.log(words); t.equal(words.length, 24691); diff --git a/src/build-scripts/viteThesaurusRegexPlugin.test.ts b/src/build-scripts/viteThesaurusRegexPlugin.test.ts index ec2952b..a860823 100644 --- a/src/build-scripts/viteThesaurusRegexPlugin.test.ts +++ b/src/build-scripts/viteThesaurusRegexPlugin.test.ts @@ -4,7 +4,7 @@ import { getRegexStringForThesaurusPath } from './viteThesaurusRegexPlugin.js'; void t.test('extractWordsFromFile', async (t) => { const regexString = await getRegexStringForThesaurusPath( - new URL('../../build-resources/th-en-x-basic.dat', import.meta.url), + new URL('../assets/th-en-x-basic.ooo-thesaurus', import.meta.url), ); const regex = new RegExp(regexString, 'gi'); diff --git a/src/build-scripts/viteThesaurusRegexPlugin.ts b/src/build-scripts/viteThesaurusRegexPlugin.ts index 15491b5..c535966 100644 --- a/src/build-scripts/viteThesaurusRegexPlugin.ts +++ b/src/build-scripts/viteThesaurusRegexPlugin.ts @@ -1,10 +1,13 @@ import type { PathLike } from 'node:fs'; +import fs from 'node:fs/promises'; +import path from 'node:path'; +import { Plugin } from 'vite'; import { extractWordsFromFile } from './oooThesaurusParser.js'; -/*type ViteThesaurusRegexPluginOptions = { - inputOooThesaurusPath: PathLike; - outputRegexPath: string; -};*/ +type ViteThesaurusRegexPluginOptions = { + sourceUrl: URL; + thesaurusPath: string; +}; const WORD_CHARACTER_REGEX_FRAGMENT = "[a-zA-Z']"; @@ -17,9 +20,18 @@ export const getRegexStringForThesaurusPath = async ( )}))`; }; -/*export const viteThesaurusRegexPlugin = ({ - inputOooThesaurusPath, - outputRegexPath, -}: ViteThesaurusRegexPluginOptions) => { -}; -*/ +export const viteThesaurusRegexPlugin = ({ + thesaurusPath, + sourceUrl, +}: ViteThesaurusRegexPluginOptions): Plugin => ({ + name: 'vite-thesaurus-regex-plugin', + async writeBundle(options) { + if (!options.dir) { + throw new Error('dir is empty'); + } + const regexString = await getRegexStringForThesaurusPath( + new URL(thesaurusPath, sourceUrl), + ); + await fs.writeFile(path.join(options.dir, thesaurusPath), regexString); + }, +}); diff --git a/src/index.tsx b/src/index.tsx index 16b5ec1..2dc4f9c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,9 +1,15 @@ import { render } from 'preact'; +import { SpellChecker } from './spellChecker'; import './style.css'; export function App() { - return