/docs/dev/README.md

https://github.com/spencerwooo/Substats · Markdown · 124 lines · 85 code · 39 blank · 0 comment · 0 complexity · 68223aa2fefa4051b397f36f63e908e7 MD5 · raw file

  1. ---
  2. sidebar: auto
  3. ---
  4. # How to contribute
  5. **Substats** is a serverless function deployed on Cloudflare Workers. You should use `wrangler` to build, debug and preview the project. More information: [Cloudflare Workers | Quick Start](https://developers.cloudflare.com/workers/quickstart).
  6. ## Setting up the project
  7. :::tip 🚥 Note
  8. You'll need global access to CLI tools installed by `yarn`, so you should add `yarn`'s global binary installation path to your `$PATH`.
  9. ```bash
  10. yarn global bin
  11. ```
  12. You can run the command directly to find the `/bin`'s path.
  13. :::
  14. Install `wrangler` globally:
  15. ```bash
  16. yarn global add @cloudflare/wrangler
  17. ```
  18. Install dependencies:
  19. ```bash
  20. yarn
  21. ```
  22. ## Familiarizing the structure
  23. The core API backend and the documentations share the same mono-repo. The structure of the project is shown below.
  24. <!-- prettier-ignore-start -->
  25. ::: vue
  26. .
  27. 📖 _Documentation section_
  28. `docs` _(Documentation, built with VuePress)_
  29.   
  30. 🚡 _API backend_
  31. `src`
  32. index.js _(API starting point)_
  33. `utils` _(Utility scripts folder)_
  34.    handlerImporter.js _(Imports all API handlers from below)_
  35. 🔑 _API handlers_
  36. `handlers` _(API integration handlers folder)_
  37.             feedly.js _(Feedly API integration)_
  38.             github.js _(GitHub API integration)_
  39.             _(You get the idea...)_
  40. 🚀 _Deployment_
  41. wrangler.toml _(Cloudflare worker deployment config)_
  42. :::
  43. <!-- prettier-ignore-end -->
  44. ## Building, preview and debugging
  45. Preview with [cloudflareworkers.com](https://cloudflareworkers.com):
  46. ```bash
  47. yarn dev
  48. ```
  49. Lint and automatically fix all fixable JavaScript files with `eslint`:
  50. ```bash
  51. yarn lint
  52. ```
  53. Prettify all JavaScript files with `prettier`:
  54. ```bash
  55. yarn pretty
  56. ```
  57. ## Storing secrets and authenticating
  58. If an API/Service requires authentication, you can store the required token/password/cookie etc., with Cloudflare Worker's secret, i.e., environment variables.
  59. You can create a mock account for your desired service, and authenticate with this account. **I strongly discourage you using your personal account for this task.** After you implement an auth-required service, you can make a PR and [email me](mailto:spencer.woo@outlook.com) the token/password/cookie etc., along with the name of the secret you used. For instance:
  60. <!-- prettier-ignore-start -->
  61. ::: vue
  62. <p style="margin-bottom: 0.01rem;">Please upload this secret and token! Thanks.</p>
  63. `Secret name`: YOUR_SERVICE_TOKEN _(Actual variable name used inside the worker)_
  64. `Secret token`: VGhpcyBpcyBhIHNlY3JldCB0b2tlbiE= _(The secret token itself)_
  65. :::
  66. <!-- prettier-ignore-end -->
  67. I will upload and store this value onto Cloudflare Worker before merging the PR. **DO NOT SEND ME YOUR ACTUAL USER ACCOUNT - PASSWORD COMBINATION!**
  68. An example is the [authentication-required Telegram Bot API](https://github.com/spencerwooo/Substats/blob/master/utils/handlers/telegram.js#L1-L14) that I used when implementing the Telegram Channel/Chat group member API. For details on how to use this secret global variable, see: [Environment Variables - Secrets](https://developers.cloudflare.com/workers/reference/apis/environment-variables/).
  69. ## Publishing <Badge text="admin" />
  70. Publish to Cloudflare Workers:
  71. ```bash
  72. yarn publish
  73. ```
  74. ## Documentations
  75. To contribute on documentations (i.e., [this website](https://substats.spencerwoo.com)), you'll need to build using `vuepress`.
  76. ### Live preview docs
  77. ```bash
  78. yarn docs:dev
  79. ```
  80. ### Building the docs
  81. ```bash
  82. yarn docs:build
  83. ```