Git Product home page Git Product logo

docs.adonisjs.com's Introduction


AdonisJS official documentation

Source code and documentation for the official documentation website hosted on docs.adonisjs.com

Setup

Follow the below mentioned steps to setup the project on your local.

  • Fork the repo
  • Pull the repo on your local
  • Install all dependencies using npm install.
  • Start the AdonisJS development server using node ace serve --watch

We do not follow any build process for rendering markdown to HTML. Instead, we compile markdown files on every page request. This ensures, we do not have to run any background compilers to compile markdown and then re-compile everything on a single change. The process is as simple as

--> New HTTP request --> Finding markdown file for the url --> Compile and serve it

Environment variables

Following environment variables are required to start the development server or create the production build.

PORT=3333
HOST=0.0.0.0
NODE_ENV=development
APP_KEY=iPbHJ0Wdr8_hA4DLTj83lKedQP9I5rJO
CACHE_VIEWS=false
DEBUG_DOCS=true
ALGOLIA_API_KEY=
COPY_REDIRECTS_FILE=false
REPOSITORY_URL=https://github.com/adonisjs/docs.adonisjs.com

The ALGOLIA_API_KEY environment variable is optional and required only if you want to enable search.

If you are deploying a translated version of the docs, then set the COPY_REDIRECTS_FILE=false. Since the redirects file is applicable only for the official documentation to avoid breaking the preview.adonisjs.com URLs.

Content structure

The markdown content is saved inside the content directory and each documentation type (we call them zones) has its own subfolder.

The navigation for the website header and the sidebar is driven by the menu.json file inside each zone's subdirectory.

content
โ”œโ”€โ”€ cookbooks
โ”‚ย ย  โ”œโ”€โ”€ menu.json
โ”œโ”€โ”€ guides
โ”‚ย ย  โ”œโ”€โ”€ menu.json
โ”œโ”€โ”€ reference
โ”‚ย ย  โ””โ”€โ”€ menu.json
โ””โ”€โ”€ releases
    โ”œโ”€โ”€ menu.json

The menu.json file has the following structure

{
  "name": "Database",
  "categories": [
    {
      "name": "root",
      "docs": [
        {
          "title": "Connection",
          "permalink": "database/connection",
          "contentPath": "database/connection.md",
        }
      ]
    }
  ]
}
  • The top level object is the group name. You can have one or more groups inside a zone and they will be listed in a dropdown in the header nav.
  • If there is no only one group. You can name it as root.
  • Each group can have one or more categories. The categories are listed inside the sidebar.
  • The category with name root will not be printed in the HTML.
  • Each category can have one or more docs.
  • The docs further have a title, permalink and the path to the content file. The path is relative from the zone root.

Rendering HTML

We make use of a self written @dimerapp/content module to render markdown to HTML using Edge templates in the middle.

We begin by first converting Markdown to an AST and then render each node of the AST using Edge templates. This allow to spit custom markup. Checkout the ./resources/views/elements directory to see how we are using it.

The code blocks are rendered using the shiki. The module uses VsCode grammar and themes to process the code blocks. Also, code blocks are processed on the backend and the client receives formatted HTML.

Configuring @dimerapp/content

The @dimerapp/content module does not come with any CLI or opinions on how the content should be structured.

So we have to self configure @dimerapp/content module. This is done inside the start/content.ts file, which relies on the config/markdown.ts file.

CSS and frontend JavaScript

The styles are written in Vanilla CSS and stored inside the ./resources/css directory. To organize things a bit, we have split them inside multiple .css files.

We also make use of Alpine.js for adding small interactive components, like the header nav dropdown and the codegroup toggle.

The @hotwire/turbo is used to navigate between pages without doing a complete refresh.

Custom JS Hacks

Re-rendering HTML pages resets the scroll position of the sidebar, which is kind of annoying. So we make use of turbo events turbo:before-render and turbo:render to store the sidebar position and then restore it after navigation.

On first page visit, we scroll the active sidebar item into the view using the scrollIntoView method.

Deployment

Run the following command to create the production build.

npm run build

The output is written to the public directory and you can deploy it on any host capable of serving static files.

The official website is hosted on pages.cloudflare.com

Important environment variables

The ALGOLIA_API_KEY environment variable is optional and required only if you want to enable search.

If you are deploying a translated version of the docs, then set the COPY_REDIRECTS_FILE=false. Since the redirects file is applicable only for the official documentation to avoid breaking the preview.adonisjs.com URLs.

Translating docs to different languages

You are free to fork this repo and translate docs to different languages and publish them on a separate subdomain.

Disclaimer: The translated documentation is considered a community effort. The website and translations are/will never be supported or maintained by the core team.

Process for translating docs

  • Notify everyone about the translated docs on this pinned issue.
  • We can issue you a subdomain for the language once you have translated more than 50% of the docs.
  • As the documentation is updated on the official website, we will drop a link to the PR on the pinned issue and you can pull back those changes.
  • We recommend not localizing the URLs. Just translate the docs content.
  • Feel free to send a PR to Algolia for indexing the translated website. Here is a reference to algolia config for the official website.

docs.adonisjs.com's People

Contributors

amitavroy avatar asadjivani avatar babakfp avatar barbapapazes avatar bjornarhagen avatar bnoufel avatar brkn avatar bumbummen99 avatar evoactivity avatar hackerrahul avatar hlozancic avatar jrrmcalcio avatar julien-r44 avatar kevinrouchut avatar liam-edwards avatar lookingit avatar mastermunj avatar maximemrf avatar melchyore avatar muco-rolle avatar n7olkachev avatar nazarepiedady avatar ndianabasi avatar prastoin avatar rcsio avatar rokaicker avatar romainlanz avatar thetutlage avatar twobitfool avatar vkaelin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docs.adonisjs.com's Issues

`this.defer` does't work as expected in migrations

I'm creating a dictionary table. Immediately after creation, it must be filled with certain static data. I take an example from the documentation, but it doesn't work:

this.defer(async (db) => {
      const users = await db.select('*').from('users') // TS2339: Property 'select' does not exist on type 'QueryClientContract'.
      await Promise.all(users.map((user) => {
        return db
          .table('user_emails')
          .insert({ user_id: user.id, email: user.email })
      }))
    })

And runtime error:

[ error ]  db.select is not a function

Package version

"@adonisjs/core": "5.7.5",
"@adonisjs/lucid": "17.2.0",

Node.js and npm version

8.3.1

Docker compose volume issue

I noticed that whenever im working on macOS the docker-compose, argon2 and bcrypt issues arise
turned out

volumes:
     - ./:/home/node/app

is linking the container to the node_modules on the host so

     - /home/node/app/node_modules

adding this will exclude the node_modules usage from host, and creates an anonymous volume that holds the node_modules, thought it solves the issue, what its doing actually is creating a new "node_modules" which means we end up with 3 places with node_modules, not a very pretty solution,

Sadly this solution needs an image rebuild each time the package.json is updated

Reference:
https://burnedikt.com/dockerized-node-development-and-mounting-node-volumes/

Additional Example to Request Validation

Package version

latest

Describe the bug

It took me a bit to validate additional request properties alongside the request body. An example on how to do so would likely save others some time.

Reproduction repo

No response

Portuguese Translation

Translating process

How to start?

First thing you should do is reply to this issue picking one of the following topics that have ๐Ÿ’ค. After that go to this repo and fork it. Create a branch with the name of the topic you pick and start translating each subsection.

How do i merge my translation?

After you finish the translation of your topic, submit a PR on the branch pt-translation-merging. Other translator should check your translation for misspelling and translating conventions.

Can i review other people PR?

Absolutely. Please look at our Translation conventions table in the end of this issue

The topic that i choose is too big, how to get help?

It's essentialy the same process. Have someone fork your repo, create a branch with the subtopic translation, and submit to your topic branch as a PR. You can review his PR and get all the help you need. You can use this issue to call for help.

How do you control the stages of a Topic?

๐Ÿ’ค No fork :zzz:
โœ๐Ÿผ forked :writing_hand:
๐Ÿ‘€ fork under review :eyes:
๐Ÿ“— translation merged :green_book:


Guides

๐Ÿ“— introduction-installation-release
โœ๏ธ Fundamentals @guntribam/Fundamentals
๐Ÿ’ค Http
๐Ÿ’ค Views & Templates
๐Ÿ’ค Validator
๐Ÿ’ค Database
๐Ÿ’ค ORM
๐Ÿ’ค Authentication
๐Ÿ’ค Security
๐Ÿ’ค Digging deeper

Reference

Database

๐Ÿ’ค First Section(Connection, Connection manager, etc)
๐Ÿ’ค ORM
๐Ÿ’ค Relationships

Validator

๐Ÿ’ค Schema types
๐Ÿ’ค Validation rules

Views & Templates

๐Ÿ’ค Globals
๐Ÿ’ค Tags

Cookbooks

๐Ÿ’ค Using socket.io
๐Ÿ’ค Writing tests
๐Ÿ’ค Deployment
๐Ÿ’ค Validator

Releases

๐Ÿ’ค Out of preview
๐Ÿ’ค December release -2020
๐Ÿ’ค October release -2020
๐Ÿ’ค August release -2020
๐Ÿ’ค Introducing AdonisJS V5 Preview


Translation conventions

English Portuguese
breaking changes - mudanรงas nรฃo retrocompatรญveis
- quebras de cรณdigo
framework framework
build construรงรฃo
release - lanรงamento
- liberaรงรฃo

Query Scopes Documentation

Documentation of Query Scopes - https://docs.adonisjs.com/guides/models/query-scopes appears to be incorrect.

The ModelQueryBuilderContract does not appear to have a function called withScopes, after looking through the tests, it appears it should be apply

e.g.

Post
    .query()
    .withScopes((scopes) => scopes.published())

should be

Post
    .query()
    .apply((scopes) => scopes.published())

It is correct in the reference page - https://docs.adonisjs.com/reference/orm/query-builder#apply

Global transactions documentation missing `await` keyword

In the global transactions documentation, I think the cleanup function should be an async function and should have the await keyword.

Currently, it is return () => Database.rollbackGlobalTransaction(), I think it should be: return async () => await Database.rollbackGlobalTransaction(), since the rollbackGlobalTransaction() function returns a promise.

I can open a PR, just wanted to make sure this wasn't intentional.

Cloudflare Email Address Obfuscation false positive

On the installation page, Cloudflare replaces

npm init adonis-ts-app@latest hello-world

with:

npm init [email protected] hello-world

This can be fixed by disabling thee Cloudflare's Email Address Obfuscation feature.

Typo in adonis at a glance page

the sentence As per the standards today, the CSS and the frontend JavaScript need to transpiled and minified before serving it to the browser is missing the be before transpiled

Explanation for why to pick database vs redis api token storage

Package version

none

Describe the bug

On the API Tokens page it's stated that the database is the best options for secondary auth while redis is best for the main form of auth. This seems fine to me but I think it would be a lot clearer with another line explaining the reason why the database or redis are more suited to the task.

Reproduction repo

No response

Drive documentation references both `serveAssets` and `serveFiles`

Package version

latest

Describe the bug

Drive documentation seems to reference a config variable called serveAssets and serveFiles interchangeably. In my code, it's defaulted to serveFiles so it seems like the serveAssets may be incorrect.

image

Reproduction repo

No response

Documentation on Dockerizing AdonisJS incomplete

Package version

n/a

Describe the bug

The documentation for /Cookbooks/dockerize-adonis/ is incomplete by omitting what to do about the APP_KEY value. Following the instructions verbatim, and copy/pasting the config files here verbatim will result in the following output in the container's log.

2023-08-29 14:10:18 Exception: E_MISSING_ENV_VALUE: Missing environment variable "APP_KEY"
2023-08-29 14:10:18     at ensureValue (/home/node/app/node_modules/@adonisjs/env/build/src/Schema/helpers.js:26:15)
2023-08-29 14:10:18     at Object.validate [as APP_KEY] (/home/node/app/node_modules/@adonisjs/env/build/src/Schema/string.js:45:35)
2023-08-29 14:10:18     at /home/node/app/node_modules/@adonisjs/env/build/src/Env/index.js:87:60
2023-08-29 14:10:18     at Array.forEach (<anonymous>)
2023-08-29 14:10:18     at Env.process (/home/node/app/node_modules/@adonisjs/env/build/src/Env/index.js:86:44)
2023-08-29 14:10:18     at Application.loadEnvironmentVariables (/home/node/app/node_modules/@adonisjs/application/build/src/Application.js:303:18)
2023-08-29 14:10:18     at Application.setup (/home/node/app/node_modules/@adonisjs/application/build/src/Application.js:518:14)
2023-08-29 14:10:18     at AppKernel.boot (/home/node/app/node_modules/@adonisjs/core/build/src/Ignitor/Kernel/index.js:55:32)
2023-08-29 14:10:18     at HttpServer.start (/home/node/app/node_modules/@adonisjs/core/build/src/Ignitor/HttpServer/index.js:85:31)
2023-08-29 14:10:18     at Object.<anonymous> (/home/node/server.ts:21:4)
2023-08-29 14:11:34 {"level":30,"time":1693332694392,"pid":8,"hostname":"4cbf60af4c7b","name":"my-project-api","msg":"started server on 0.0.0.0:3333"}

The APP_KEY value is never mentioned in this guide.

Reproduction repo

No response

AdonisJS Community Translations

Please notify us about the translation you are maintaining and the associated repo. Also make sure to subscribe to this issue to receive documentation updates notifications

Ace - decorator flags

Discussed in adonisjs/core#3166

Originally posted by sergefabre September 13, 2021
Hello,
I'm following the example on the docs about the flags.boolean decorator, but the property does not exist with my version of Adonis.
Here is an extract of my package.json file:

"dependencies": {
    "@adonisjs/ally": "^4.1.1",
    "@adonisjs/auth": "^8.0.9",
    "@adonisjs/core": "^5.3.4",
    "@adonisjs/lucid": "^16.0.0",
    "@adonisjs/repl": "^3.1.6",
    "@adonisjs/view": "^6.1.0",

Here is the problem in my IDE (VS Code):
image
Telling me that default does not exist in the type Partial<Omit<CommandFlag, "type" | "propertyName">>.

I don't know if I'm doing something wrong, or if the docs are for a more recent or dev version (it doesn't show up in the docs website, you used to be able to do this with the legacy docs).

Improve type information at Wildcard

Documentation for Custom messages with wildcard callback is missing types for it's parameters.

I've assumed types are correct at MessageBag.

Change proposal on the code example

const wildCardError = (
  field: string,
  rule: string,
  arrayExpressionPointer?: string,
  options?: any
) => {
  return `${rule} validation error on ${field}`
}

{
  messages: {
    '*': wildCardError,
    'username.required': 'Username is required to sign up',
  }
}

mysql bigint

Our vendor databases use bigint as the primary key which is rather annoying.

Out of the box lucid (mysql driver) doesn't appear to support it.

After a few hours of trying to find a solution there is a setting that can be enabled to support this.

connections: {
    mysql: {
      client: 'mysql',
      connection: {
        host: Env.get('MYSQL_HOST'),
        port: Env.get('MYSQL_PORT'),
        user: Env.get('MYSQL_USER'),
        password: Env.get('MYSQL_PASSWORD', ''),
        database: Env.get('MYSQL_DB_NAME'),
        supportBigNumbers: true, // <---- here
      },
      migrations: {
        naturalSort: true,
      },
      healthCheck: false,
      debug: false,
    },
  }

Can you please add this to the documentation regarding supportBigNumbers: true as it would save a lot of headaches.

Thanks

Documentation includes features that haven't been released yet.

Package version

N/A

Describe the bug

As a developer, I would expect the documentation on "docs.adonisjs.com" to reflect what is currently possible, and not documentation for features that have yet to be released.

For instance, this is currently not possible:
https://docs.adonisjs.com/guides/testing/introduction#truncate-database-after-each-run-cycle

It wasn't until after updating Adonis and searching around did I figure out that it's still a feature sitting in the develop branch of adonisjs/lucid, and not something that is currently available to me.

Just thought I'd throw this out there, in the hopes that this is taken into consideration in the future, for a better developer experience. I'm also not sure if this something is already being considered and this slipped by, or if there's just no formal process for ensuring that the feature is available before it lands on the docs.

Reproduction repo

No response

Driver config: mysql2

On the documentation it says to install the following

npm i mysql2

but it says to use it

mysql: {
  client: 'mysql',
  connection: {
    host: Env.get('MYSQL_HOST'),
    port: Env.get('MYSQL_PORT'),
    user: Env.get('MYSQL_USER'),
    password: Env.get('MYSQL_PASSWORD', ''),
    database: Env.get('MYSQL_DB_NAME'),
  },
  migrations: {
    naturalSort: true,
  },
  healthCheck: false,
  debug: false,
}

i am not quite sure if this is a bug or its supposed to work that way, i changed the client: 'mysql' to 'mysql2' and it worked, could you confirm?
this should solve mysql 8.* issues

[official doc bug] Testing upload image example seems out of date

Official spec example from here link seems not to work,

running version : "@adonisjs/core": "^5.6.0"

it dose not have file.createPng('1mb') method and fakeDrive.hasFile() method,
and if follow the import { file } from '@ioc:Adonis/Core/Helpers'
it can get a new file.generatePng() method there, but as the same time .file('avatar', fakeAvatar) will get fail because of the type error

hoping the team can update the new doc to help people get into the adonis more easily.

beforePaginate hook example throws error

Package version

15.0.1

Node.js and npm version

14.17.0, 6.14.3

Issue

Trying to implement beforePaginate as the suggested solution to adonisjs/lucid#647 using the documented example at (https://docs.adonisjs.com/reference/orm/decorators#beforepaginate)

import { beforePaginate, BaseModel } from '@ioc:Adonis/Lucid/Orm'

class Post extends BaseModel {

  @beforePaginate()
  public static withoutSoftDeletes(query) {
    query.whereNull('deleted_at')
  }

}

returns the following error

query.whereNull is not a function

AdonisJS webpack-encore DELETED my assets files

adonisjs-error

why my assets files always deleted by webpack-encore while compiling (npm run dev) like on the pic, while creating the adonisjs project I choose "true" for configure webpack-encore. I newbie at webpack or something like that, please help me I'm so stuck here. thanks for the answer and I appreciate it. ๐Ÿ˜„๐Ÿ˜„

Documentation about IOC Container

Hi. I was trying the other day to use the new version of the framework to achieve something like Spring Boot does in Java with with it's IOC Container, and I noticed that website lacks a little more information about this. I wanted to write something like:

export default interface FooRepositoryInterface {
  findAll(): Promise<Foo>
}
export default class FooRepository implements FooRepositoryInterface{
  findAll(): Promise<Foo> {
    // Implementation
  }
}
export default interface FooServiceInterface {
  list(): Promise<Foo>
}
export default class FooService implements FooServiceInterface {

  constructor(public FooRepositoryInterface repository) {}

  list(): Promise<Foo> {
    return repository.findAll()
  }
}
export default class FooController {

  constructor(public FooServiceInterface service) {}

  index() {
    service.list()
  }
}

It is possible to achieve this kind of behavior with the current version of the framework? If it is, could you guys provide me some examples or guides in how to register the dependencies on the IOC container correctly? I tried to register the classes on the provider but I could achieve the result I wanted.
Thanks in advance.

Wrong documentation for database driver config

Package version

5.8.4

Describe the bug

Link of documentation: https://docs.adonisjs.com/guides/database/introduction#drivers-config

The documentation guides us to install the package mysql2 but in the config example the client used is mysql. After I changed it to mysql2 the config started to work.

Also, the code generated by node ace configure @adonisjs/lucid generates a file with a comment that instructs to install mysql instead of mysql2.

Reproduction repo

No response

Limiter documentation issue

Package version

latest

Describe the bug

The docs mention in-memory store for the rate limiter, however, this isn't true as it doesn't exist in the application.

image

Reproduction repo

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.