👍🎉 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 pdf
Add 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.ts
to change default options. See theDictItem
type 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.json
with the new dictionary name. Add locales for options, if any. engine.ts
MUST export at least two functions:getSrcPage
function 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.search
function 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
audio
field in the object which search engine returns.
- Register the ID at
- Other exported functions can be called from
View.tsx
via'DICT_ENGINE_METHOD'
message channel. Seesrc/typings/message
for typing details and searchDICT_ENGINE_METHOD
project-wise for examples. Messages MUST be sent viamessage
from'@/_helpers/browser-api'
instead of the nativesendMessage
function.
- 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.scss
SHOULD 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.js
attest/specs/components/dictionaries/[dictID]
.- See other dictionaries for example.
- You can offer url or axios config (See
mojidict
dictionary). All results from previous requests will be passed to the next request as array.
- Run
yarn fixtures
to 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.ts
to 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.