2017-03-30 16:11:38 +00:00
|
|
|
# Contribution guide
|
2018-09-01 09:02:04 +00:00
|
|
|
:v: Thanks for your contributions :v:
|
2017-03-26 12:32:19 +00:00
|
|
|
|
2018-09-01 09:02:04 +00:00
|
|
|
## Issues
|
|
|
|
Feature suggestions and bug reports are filed in https://github.com/syuilo/misskey/issues .
|
2019-05-25 16:06:36 +00:00
|
|
|
|
|
|
|
* Please search existing issues to avoid duplication. If your issue is already filed, please add your reaction or comment to the existing one.
|
|
|
|
* If you have multiple independent issues, please submit them separately.
|
|
|
|
|
2019-07-22 05:57:23 +00:00
|
|
|
## Branches
|
|
|
|
* **master** branch is tracking the latest release and used for production purposes.
|
|
|
|
* **develop** branch is where we work for the next release.
|
|
|
|
* **l10n_develop** branch is reserved for localization management.
|
|
|
|
|
2018-09-01 09:02:04 +00:00
|
|
|
## Localization (l10n)
|
2019-05-24 10:31:40 +00:00
|
|
|
Misskey uses [Crowdin](https://crowdin.com/project/misskey) for localization management.
|
|
|
|
You can improve our translations with your Crowdin account.
|
2019-07-22 05:57:23 +00:00
|
|
|
Your changes in Crowdin are automatically submitted as a PR (with the title "New Crowdin translations") to the repository.
|
|
|
|
The owner [@syuilo](https://github.com/syuilo) merges the PR into the develop branch before the next release.
|
2019-05-24 10:31:40 +00:00
|
|
|
|
2019-07-22 05:57:23 +00:00
|
|
|
If your language is not listed in Crowdin, please open an issue.
|
2017-03-26 12:32:19 +00:00
|
|
|
|
2018-09-01 09:15:25 +00:00
|
|
|
![Crowdin](https://d322cqt584bo4o.cloudfront.net/misskey/localized.svg)
|
2017-03-26 12:32:19 +00:00
|
|
|
|
2018-11-09 15:47:36 +00:00
|
|
|
## Internationalization (i18n)
|
2019-07-15 11:47:09 +00:00
|
|
|
Misskey uses the Vue.js plugin [Vue I18n](https://github.com/kazupon/vue-i18n).
|
|
|
|
Documentation of Vue I18n is available at http://kazupon.github.io/vue-i18n/introduction.html .
|
2018-11-09 15:47:36 +00:00
|
|
|
|
2018-09-01 09:02:04 +00:00
|
|
|
## Documentation
|
2019-05-26 03:48:37 +00:00
|
|
|
* Documents for contributors are located in [`/docs`](/docs).
|
|
|
|
* Documents for instance admins are located in [`/docs`](/docs).
|
|
|
|
* Documents for end users are located in [`/src/docs`](/src/docs).
|
2017-03-26 12:32:19 +00:00
|
|
|
|
2018-09-01 09:02:04 +00:00
|
|
|
## Test
|
2019-05-26 03:48:37 +00:00
|
|
|
* Test codes are located in [`/test`](/test).
|
2018-09-01 09:02:04 +00:00
|
|
|
|
|
|
|
## Continuous integration
|
2019-07-15 11:47:09 +00:00
|
|
|
Misskey uses CircleCI for executing automated tests.
|
2019-05-26 03:48:37 +00:00
|
|
|
Configuration files are located in [`/.circleci`](/.circleci).
|
2018-12-19 18:01:02 +00:00
|
|
|
|
2019-08-18 05:41:33 +00:00
|
|
|
## Adding MisskeyRoom items
|
|
|
|
Currently, we accept only 3D models created with [Blender](https://www.blender.org/).
|
|
|
|
|
|
|
|
* Use English for material, object and texture names
|
|
|
|
* Use meter for unit of length
|
|
|
|
* Your PR must include all source files of your models (for later editing)
|
|
|
|
* Your PR must include the glTF binary files (.glb) of your models
|
|
|
|
|
|
|
|
You can find information on glTF 2.0 at [glTF 2.0 — Blender Manual]( https://docs.blender.org/manual/en/dev/addons/io_scene_gltf2.html).
|
|
|
|
|
2019-07-14 01:05:19 +00:00
|
|
|
## FAQ
|
2019-07-15 11:47:09 +00:00
|
|
|
### How to resolve conflictions occurred at yarn.lock?
|
2019-07-15 12:32:09 +00:00
|
|
|
|
|
|
|
Just execute `yarn` to fix it.
|
2019-07-14 01:05:19 +00:00
|
|
|
|
2018-12-19 18:01:02 +00:00
|
|
|
## Glossary
|
|
|
|
### AP
|
2018-12-19 18:02:19 +00:00
|
|
|
Stands for _**A**ctivity**P**ub_.
|
2018-12-19 18:01:02 +00:00
|
|
|
|
|
|
|
### MFM
|
2018-12-19 18:02:19 +00:00
|
|
|
Stands for _**M**isskey **F**lavored **M**arkdown_.
|
2018-12-19 18:01:02 +00:00
|
|
|
|
|
|
|
### Mk
|
2018-12-19 18:02:19 +00:00
|
|
|
Stands for _**M**iss**k**ey_.
|
2018-12-19 18:44:19 +00:00
|
|
|
|
|
|
|
### SW
|
|
|
|
Stands for _**S**ervice**W**orker_.
|
2019-01-24 10:52:00 +00:00
|
|
|
|
|
|
|
### Nyaize
|
2019-02-26 09:00:47 +00:00
|
|
|
Convert な(na) to にゃ(nya)
|
2019-01-24 10:52:00 +00:00
|
|
|
|
|
|
|
#### Denyaize
|
2019-02-26 09:00:47 +00:00
|
|
|
Revert Nyaize
|
2019-02-07 05:54:14 +00:00
|
|
|
|
2019-07-15 11:47:09 +00:00
|
|
|
## TypeScript Coding Style
|
|
|
|
### Do not omit semicolons
|
|
|
|
This is to avoid Automatic Semicolon Insertion (ASI) hazard.
|
2019-04-17 07:59:39 +00:00
|
|
|
|
2019-07-15 11:47:09 +00:00
|
|
|
Ref:
|
|
|
|
* https://www.ecma-international.org/ecma-262/#sec-automatic-semicolon-insertion
|
|
|
|
* https://github.com/tc39/ecma262/pull/1062
|
|
|
|
|
|
|
|
### Do not omit curly brackets
|
2019-04-17 07:59:39 +00:00
|
|
|
Bad:
|
|
|
|
``` ts
|
|
|
|
if (foo)
|
|
|
|
bar;
|
|
|
|
else
|
|
|
|
baz;
|
|
|
|
```
|
|
|
|
|
|
|
|
Good:
|
|
|
|
``` ts
|
|
|
|
if (foo) {
|
|
|
|
bar;
|
|
|
|
} else {
|
|
|
|
baz;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-07-15 11:47:09 +00:00
|
|
|
As a special case, you can omit the curly brackets if
|
|
|
|
|
|
|
|
* the body of the `if`-statement have only one statement and,
|
|
|
|
* the `if`-statement does not have `else`-clause.
|
|
|
|
|
2019-04-17 07:59:39 +00:00
|
|
|
Good:
|
|
|
|
``` ts
|
|
|
|
if (foo) bar;
|
|
|
|
```
|
|
|
|
|
2019-07-22 05:57:23 +00:00
|
|
|
Make sure that the condition and the body statement are on the same line.
|
|
|
|
|
2019-07-15 11:47:09 +00:00
|
|
|
### Do not use `==` when it can simply be replaced with `===`.
|
2019-07-13 19:02:24 +00:00
|
|
|
🥰
|
|
|
|
|
2019-07-15 11:47:09 +00:00
|
|
|
### Use only boolean (or null related) values in the condition of an `if`-statement.
|
2019-07-13 19:02:24 +00:00
|
|
|
Bad:
|
|
|
|
``` ts
|
|
|
|
if (foo.length)
|
|
|
|
```
|
|
|
|
|
|
|
|
Good:
|
|
|
|
``` ts
|
|
|
|
if (foo.length > 0)
|
|
|
|
```
|
|
|
|
|
2019-07-15 11:47:09 +00:00
|
|
|
### Do not use `export default`
|
|
|
|
This is because the current language support does not work well with `export default`.
|
2019-04-17 07:59:39 +00:00
|
|
|
|
2019-07-15 11:47:09 +00:00
|
|
|
Ref:
|
2019-04-17 07:59:39 +00:00
|
|
|
* https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
|
2019-07-15 11:47:09 +00:00
|
|
|
* https://gfx.hatenablog.com/entry/2017/11/24/135343
|
2019-03-15 17:53:35 +00:00
|
|
|
|
2019-02-07 05:54:14 +00:00
|
|
|
Bad:
|
|
|
|
``` ts
|
|
|
|
export default function(foo: string): string {
|
|
|
|
```
|
|
|
|
|
|
|
|
Good:
|
|
|
|
``` ts
|
|
|
|
export function something(foo: string): string {
|
|
|
|
```
|
2019-02-07 19:08:25 +00:00
|
|
|
|
|
|
|
## Directory structure
|
|
|
|
```
|
2019-02-26 09:00:47 +00:00
|
|
|
src ... Source code
|
|
|
|
@types ... Type definitions
|
|
|
|
prelude ... Independence utils for coding JavaScript without side effects
|
|
|
|
misc ... Independence utils for Misskey without side effects
|
|
|
|
service ... Common functions with side effects
|
|
|
|
queue ... Job queues and Jobs
|
|
|
|
server ... Web Server
|
|
|
|
client ... Client
|
2019-02-07 19:08:25 +00:00
|
|
|
mfm ... MFM
|
|
|
|
|
2019-02-26 09:00:47 +00:00
|
|
|
test ... Test code
|
2019-02-07 19:08:25 +00:00
|
|
|
|
|
|
|
```
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
## Notes
|
|
|
|
### placeholder
|
|
|
|
SQLをクエリビルダで組み立てる際、使用するプレースホルダは重複してはならない
|
|
|
|
例えば
|
|
|
|
``` ts
|
|
|
|
query.andWhere(new Brackets(qb => {
|
|
|
|
for (const type of ps.fileType) {
|
|
|
|
qb.orWhere(`:type = ANY(note.attachedFileTypes)`, { type: type });
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
```
|
|
|
|
と書くと、ループ中で`type`というプレースホルダが複数回使われてしまいおかしくなる
|
|
|
|
だから次のようにする必要がある
|
|
|
|
```ts
|
|
|
|
query.andWhere(new Brackets(qb => {
|
|
|
|
for (const type of ps.fileType) {
|
|
|
|
const i = ps.fileType.indexOf(type);
|
|
|
|
qb.orWhere(`:type${i} = ANY(note.attachedFileTypes)`, { [`type${i}`]: type });
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
```
|
|
|
|
|
2019-05-20 12:44:16 +00:00
|
|
|
### Not `null` in TypeORM
|
|
|
|
```ts
|
|
|
|
const foo = await Foos.findOne({
|
|
|
|
bar: Not(null)
|
|
|
|
});
|
|
|
|
```
|
|
|
|
のようなクエリ(`bar`が`null`ではない)は期待通りに動作しない。
|
|
|
|
次のようにします:
|
|
|
|
```ts
|
|
|
|
const foo = await Foos.findOne({
|
|
|
|
bar: Not(IsNull())
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
### `null` in SQL
|
|
|
|
SQLを発行する際、パラメータが`null`になる可能性のある場合はSQL文を出し分けなければならない
|
|
|
|
例えば
|
|
|
|
``` ts
|
|
|
|
query.where('file.folderId = :folderId', { folderId: ps.folderId });
|
|
|
|
```
|
|
|
|
という処理で、`ps.folderId`が`null`だと結果的に`file.folderId = null`のようなクエリが発行されてしまい、これは正しいSQLではないので期待した結果が得られない
|
|
|
|
だから次のようにする必要がある
|
|
|
|
``` ts
|
|
|
|
if (ps.folderId) {
|
|
|
|
query.where('file.folderId = :folderId', { folderId: ps.folderId });
|
|
|
|
} else {
|
|
|
|
query.where('file.folderId IS NULL');
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### `[]` in SQL
|
|
|
|
SQLを発行する際、`IN`のパラメータが`[]`(空の配列)になる可能性のある場合はSQL文を出し分けなければならない
|
|
|
|
例えば
|
|
|
|
``` ts
|
|
|
|
const users = await Users.find({
|
|
|
|
id: In(userIds)
|
|
|
|
});
|
|
|
|
```
|
|
|
|
という処理で、`userIds`が`[]`だと結果的に`user.id IN ()`のようなクエリが発行されてしまい、これは正しいSQLではないので期待した結果が得られない
|
|
|
|
だから次のようにする必要がある
|
|
|
|
``` ts
|
|
|
|
const users = userIds.length > 0 ? await Users.find({
|
|
|
|
id: In(userIds)
|
|
|
|
}) : [];
|
|
|
|
```
|
|
|
|
|
2019-04-13 05:04:29 +00:00
|
|
|
### 配列のインデックス in SQL
|
|
|
|
SQLでは配列のインデックスは**1始まり**。
|
|
|
|
`[a, b, c]`の `a`にアクセスしたいなら`[0]`ではなく`[1]`と書く
|
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
### `undefined`にご用心
|
|
|
|
MongoDBの時とは違い、findOneでレコードを取得する時に対象レコードが存在しない場合 **`undefined`** が返ってくるので注意。
|
|
|
|
MongoDBは`null`で返してきてたので、その感覚で`if (x === null)`とか書くとバグる。代わりに`if (x == null)`と書いてください
|
2019-04-13 05:31:05 +00:00
|
|
|
|
|
|
|
### 簡素な`undefined`チェック
|
|
|
|
データベースからレコードを取得するときに、プログラムの流れ的に(ほぼ)絶対`undefined`にはならない場合でも、`undefined`チェックしないとTypeScriptに怒られます。
|
|
|
|
でもいちいち複数行を費やして、発生するはずのない`undefined`をチェックするのも面倒なので、`ensure`というユーティリティ関数を用意しています。
|
|
|
|
例えば、
|
|
|
|
``` ts
|
2019-04-13 05:34:34 +00:00
|
|
|
const user = await Users.findOne(userId);
|
2019-04-13 05:31:05 +00:00
|
|
|
// この時点で user の型は User | undefined
|
|
|
|
if (user == null) {
|
|
|
|
throw 'missing user';
|
|
|
|
}
|
|
|
|
// この時点で user の型は User
|
|
|
|
```
|
|
|
|
という処理を`ensure`を使うと
|
|
|
|
``` ts
|
2019-04-13 05:37:45 +00:00
|
|
|
const user = await Users.findOne(userId).then(ensure);
|
2019-04-13 05:31:05 +00:00
|
|
|
// この時点で user の型は User
|
|
|
|
```
|
|
|
|
という風に書けます。
|
2019-04-13 05:34:34 +00:00
|
|
|
もちろん`ensure`内部でエラーを握りつぶすようなことはしておらず、万が一`undefined`だった場合はPromiseがRejectされ後続の処理は実行されません。
|
|
|
|
``` ts
|
2019-04-13 05:37:45 +00:00
|
|
|
const user = await Users.findOne(userId).then(ensure);
|
2019-04-13 05:34:34 +00:00
|
|
|
// 万が一 Users.findOne の結果が undefined だったら、ensure でエラーが発生するので
|
|
|
|
// この行に到達することは無い
|
2019-04-13 05:36:35 +00:00
|
|
|
// なので、.then(ensure) は
|
|
|
|
// if (user == null) {
|
|
|
|
// throw 'missing user';
|
|
|
|
// }
|
|
|
|
// の糖衣構文のような扱いです
|
2019-04-13 05:34:34 +00:00
|
|
|
```
|
2019-05-13 17:57:04 +00:00
|
|
|
|
|
|
|
### Migration作成方法
|
|
|
|
```
|
2019-07-06 20:26:04 +00:00
|
|
|
npx ts-node ./node_modules/typeorm/cli.js migration:generate -n 変更の名前
|
2019-05-13 17:57:04 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
作成されたスクリプトは不必要な変更を含むため除去してください。
|