👍🎉 First off, thanks for taking the time to contribute! 🎉👍
- Read How to get started.
- Follow code style and commit style.
- Before submit, run test and build locally. Or leave it to CI.
git clone git@github.com:crimx/ext-saladict.git
cd ext-saladict
yarn install
yarn pdfAdd a .env file following the .env.example format(leave empty if you don't use these dictionaries).
Run yarn fixtures to download fixtures(only need to run once).
Run yarn storybook to view all the components.
Run yarn start --wextentry [entry id] to view a certain entry with WDS in a fake WebExtension environment.
Run yarn test to run Jest. Supports all the Jest options.
Run yarn build to start a full build.
Toggle:
--debug: Remove compression and generate sourcemaps.--analyze: Show detailed Webpack bundle analyzer.
For safety and maintainability reason, Saladict will not support adding dictionaries on the fly. All dictionaries must be merged to this project via pull requests.
If dictionary implementation makes use of private API please move it to an independent project, release on NPM, then import it to Saladict.
- Create a directory at
src/components/dictionaries/, with the name of the dict ID.- Use any existing dictionary as guidance, e.g. Bing. Copy files to the new directory.
- Replace the favicon with a new LOGO.
- Edit
config.tsto change default options. See theDictItemtype and explanation for more details. Register the dictionary in app config so that TypeScript generates the correct typings. Dict ID MUST follow alphabetical order. - Update
_locales.jsonwith the new dictionary name. Add locales for options, if any. engine.tsMUST export at least two functions:getSrcPagefunction which is responsible for generating source page url base on search text and app config. Source page url is opened when user clicks the dictionary title.searchfunction which is responsible for fetching, parsing and returning dictionary results. See the typings for more detail.- Extracting information from a webpage MUST use helper functions in ../helpers.ts for data cleansing.
- If the dictionary supports pronunciation:
- Register the ID at
config.autopron. - Include an
audiofield in the object which search engine returns.
- Register the ID at
- Other exported functions can be called from
View.tsxvia'DICT_ENGINE_METHOD'message channel. Seesrc/typings/messagefor typing details and searchDICT_ENGINE_METHODproject-wise for examples. Messages MUST be sent viamessagefrom'@/_helpers/browser-api'instead of the nativesendMessagefunction.
- Search result will ultimately be passed to a React PureComponent in
View.tsx, which SHOULD be a dumb component that renders the result accordingly. - Selectors in
_style.scssSHOULD follow ECSS-ish naming convention.
To develop the component in Storybook we need to intercept http requests from dictionary engines and replace with the downloaded results.
- Add
fixtures.jsattest/specs/components/dictionaries/[dictID].- See other dictionaries for example.
- You can offer url or axios config (See
mojidictdictionary). All results from previous requests will be passed to the next request as array.
- Run
yarn fixturesto download fixtures. - Edit
test/specs/components/dictionaries/[dictID]/request.mock.ts. It will intercept requests and return the downloaded fixtures. - Run
yarn storybook.
- Add
[dictID]/engine.spec.tsto test the engine.
This project follows the TypeScript variation of Standard JavaScript code style.
If you are using IDEs like VSCode, make sure eslint and prettier plugins are installed. Or you can just run building command to perform a TypeScript full check.
This project follows conventional commit style.
You can run yarn commit and follow the instructions, or use VSCode Conventional Commits extension in VSCode.