-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7b66490
Showing
22 changed files
with
590 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# http://editorconfig.org | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.json] | ||
insert_final_newline = ignore | ||
|
||
[**.min.js] | ||
indent_style = ignore | ||
insert_final_newline = ignore | ||
|
||
[MakeFile] | ||
indent_style = space | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
ignoreUnless: {{ STALE_BOT }} | ||
--- | ||
# Configuration for Lock Threads - https://github.com/dessant/lock-threads-app | ||
|
||
# Number of days of inactivity before a closed issue or pull request is locked | ||
daysUntilLock: 60 | ||
|
||
# Skip issues and pull requests created before a given timestamp. Timestamp must | ||
# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable | ||
skipCreatedBefore: false | ||
|
||
# Issues and pull requests with these labels will be ignored. Set to `[]` to disable | ||
exemptLabels: ['Type: Security'] | ||
|
||
# Label to add before locking, such as `outdated`. Set to `false` to disable | ||
lockLabel: false | ||
|
||
# Comment to post before locking. Set to `false` to disable | ||
lockComment: > | ||
This thread has been automatically locked since there has not been | ||
any recent activity after it was closed. Please open a new issue for | ||
related bugs. | ||
# Assign `resolved` as the reason for locking. Set to `false` to disable | ||
setLockReason: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
ignoreUnless: {{ STALE_BOT }} | ||
--- | ||
# Number of days of inactivity before an issue becomes stale | ||
daysUntilStale: 60 | ||
|
||
# Number of days of inactivity before a stale issue is closed | ||
daysUntilClose: 7 | ||
|
||
# Issues with these labels will never be considered stale | ||
exemptLabels: | ||
- 'Type: Security' | ||
|
||
# Label to use when marking an issue as stale | ||
staleLabel: 'Status: Abandoned' | ||
|
||
# Comment to post when marking an issue as stale. Set to `false` to disable | ||
markComment: > | ||
This issue has been automatically marked as stale because it has not had | ||
recent activity. It will be closed if no further activity occurs. Thank you | ||
for your contributions. | ||
# Comment to post when closing a stale issue. Set to `false` to disable | ||
closeComment: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: test | ||
|
||
on: | ||
- push | ||
- pull_request | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install | ||
run: npm install | ||
- name: Run lint | ||
run: npm run lint | ||
|
||
typecheck: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install | ||
run: npm install | ||
- name: Run typecheck | ||
run: npm run typecheck | ||
|
||
tests: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest] | ||
node-version: | ||
- 20.10.0 | ||
- 21.x | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install | ||
run: npm install | ||
- name: Run tests | ||
run: npm test | ||
windows: | ||
runs-on: windows-latest | ||
strategy: | ||
matrix: | ||
node-version: | ||
- 20.10.0 | ||
- 21.x | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install | ||
run: npm install | ||
- name: Run tests | ||
run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
node_modules | ||
coverage | ||
.DS_STORE | ||
.nyc_output | ||
.idea | ||
.vscode/ | ||
*.sublime-project | ||
*.sublime-workspace | ||
*.log | ||
build | ||
dist | ||
yarn.lock | ||
shrinkwrap.yaml | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build | ||
docs | ||
coverage | ||
*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# The MIT License | ||
|
||
Copyright (c) 2024 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# AdonisJS package starter kit | ||
|
||
> A boilerplate for creating AdonisJS packages | ||
This repo provides you with a starting point for creating AdonisJS packages. Of course, you can create a package from scratch with your folder structure and workflow. However, using this starter kit can speed up the process, as you have fewer decisions to make. | ||
|
||
## Setup | ||
|
||
- Clone the repo on your computer, or use `giget` to download this repo without the Git history. | ||
```sh | ||
npx giget@latest gh:adonisjs/pkg-starter-kit | ||
``` | ||
- Install dependencies. | ||
- Update the `package.json` file and define the `name`, `description`, `keywords`, and `author` properties. | ||
- The repo is configured with an MIT license. Feel free to change that if you are not publishing under the MIT license. | ||
|
||
## Folder structure | ||
|
||
The starter kit mimics the folder structure of the official packages. Feel free to rename files and folders as per your requirements. | ||
|
||
``` | ||
├── providers | ||
├── src | ||
├── bin | ||
├── stubs | ||
├── configure.ts | ||
├── index.ts | ||
├── LICENSE.md | ||
├── package.json | ||
├── README.md | ||
├── tsconfig.json | ||
├── tsnode.esm.js | ||
``` | ||
|
||
- The `configure.ts` file exports the `configure` hook to configure the package using the `node ace configure` command. | ||
- The `index.ts` file is the main entry point of the package. | ||
- The `tsnode.esm.js` file runs TypeScript code using TS-Node + SWC. Please read the code comment in this file to learn more. | ||
- The `bin` directory contains the entry point file to run Japa tests. | ||
- Learn more about [the `providers` directory](./providers/README.md). | ||
- Learn more about [the `src` directory](./src/README.md). | ||
- Learn more about [the `stubs` directory](./stubs/README.md). | ||
|
||
### File system naming convention | ||
|
||
We use `snake_case` naming conventions for the file system. The rule is enforced using ESLint. However, turn off the rule and use your preferred naming conventions. | ||
|
||
## Peer dependencies | ||
|
||
The starter kit has a peer dependency on `@adonisjs/core@6`. Since you are creating a package for AdonisJS, you must make it against a specific version of the framework core. | ||
|
||
If your package needs Lucid to be functional, you may install `@adonisjs/lucid` as a development dependency and add it to the list of `peerDependencies`. | ||
|
||
As a rule of thumb, packages installed in the user application should be part of the `peerDependencies` of your package and not the main dependency. | ||
|
||
For example, if you install `@adonisjs/core` as a main dependency, then essentially, you are importing a separate copy of `@adonisjs/core` and not sharing the one from the user application. Here is a great article explaining [peer dependencies](https://blog.bitsrc.io/understanding-peer-dependencies-in-javascript-dbdb4ab5a7be). | ||
|
||
## Published files | ||
|
||
Instead of publishing your repo's source code to npm, you must cherry-pick files and folders to publish only the required files. | ||
|
||
The cherry-picking uses the `files` property inside the `package.json` file. By default, we publish the following files and folders. | ||
|
||
```json | ||
{ | ||
"files": ["build/src", "build/providers", "build/stubs", "build/index.d.ts", "build/index.js"] | ||
} | ||
``` | ||
|
||
If you create additional folders or files, mention them inside the `files` array. | ||
|
||
## Exports | ||
|
||
[Node.js Subpath exports](https://nodejs.org/api/packages.html#subpath-exports) allows you to define the exports of your package regardless of the folder structure. This starter kit defines the following exports. | ||
|
||
```json | ||
{ | ||
"exports": { | ||
".": "./build/index.js", | ||
"./types": "./build/src/types.js" | ||
} | ||
} | ||
``` | ||
|
||
- The dot `.` export is the main export. | ||
- The `./types` exports all the types defined inside the `./build/src/types.js` file (the compiled output). | ||
|
||
Feel free to change the exports as per your requirements. | ||
|
||
## Testing | ||
|
||
We configure the [Japa test runner](https://japa.dev/) with this starter kit. Japa is used in AdonisJS applications as well. Just run one of the following commands to execute tests. | ||
|
||
- `npm run test`: This command will first lint the code using ESlint and then run tests and report the test coverage using [c8](https://github.com/bcoe/c8). | ||
- `npm run quick:test`: Runs only the tests without linting or coverage reporting. | ||
|
||
The starter kit also has a Github workflow file to run tests using Github Actions. The tests are executed against `Node.js 20.x` and `Node.js 21.x` versions on both Linux and Windows. Feel free to edit the workflow file in the `.github/workflows` directory. | ||
|
||
## TypeScript workflow | ||
|
||
- The starter kit uses [tsc](https://www.typescriptlang.org/docs/handbook/compiler-options.html) for compiling the TypeScript to JavaScript when publishing the package. | ||
- [TS-Node](https://typestrong.org/ts-node/) and [SWC](https://swc.rs/) are used to run tests without compiling the source code. | ||
- The `tsconfig.json` file is extended from [`@adonisjs/tsconfig`](https://github.com/adonisjs/tooling-config/tree/main/packages/typescript-config) and uses the `NodeNext` module system. Meaning the packages are written using ES modules. | ||
- You can perform type checking without compiling the source code using the `npm run type check` script. | ||
|
||
Feel free to explore the `tsconfig.json` file for all the configured options. | ||
|
||
## ESLint and Prettier setup | ||
|
||
The starter kit configures ESLint and Prettier. Both configurations are stored within the `package.json` file and use our [shared config](https://github.com/adonisjs/tooling-config/tree/main/packages). Feel free to change the configuration, use custom plugins, or remove both tools altogether. | ||
|
||
## Using Stale bot | ||
|
||
The [Stale bot](https://github.com/apps/stale) is a Github application that automatically marks issues and PRs as stale and closes after a specific duration of inactivity. | ||
|
||
Feel free to delete the `.github/stale.yml` and `.github/lock.yml` files if you decide not to use the Stale bot. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { assert } from '@japa/assert' | ||
import { configure, processCLIArgs, run } from '@japa/runner' | ||
import { fileSystem } from '@japa/file-system' | ||
|
||
processCLIArgs(process.argv.splice(2)) | ||
|
||
configure({ | ||
files: ['tests/**/*.spec.ts'], | ||
plugins: [assert(), fileSystem()], | ||
}) | ||
|
||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { BaseCommand, args, flags } from '@adonisjs/core/ace' | ||
import { CommandOptions } from '@adonisjs/core/types/ace' | ||
import { generators } from '@adonisjs/core/app' | ||
import { stubsRoot } from '../stubs/main.js' | ||
|
||
export default class MakeAction extends BaseCommand { | ||
static commandName = 'make:action' | ||
static description = 'Create a new action handler class' | ||
static options: CommandOptions = {} | ||
|
||
@args.string({ description: 'Name of the action' }) | ||
declare name: string | ||
|
||
@flags.string({ | ||
description: 'Specify a feature folder to add the action to', | ||
alias: 'f', | ||
}) | ||
declare feature?: string | ||
|
||
@flags.boolean({ | ||
description: 'Inject HTTP Context into the action', | ||
showNegatedVariantInHelp: true, | ||
alias: 'c', | ||
}) | ||
declare http?: boolean | ||
|
||
async run() { | ||
const codemods = await this.createCodemods() | ||
const stub = this.parsed.flags.http ? 'http' : 'main' | ||
const feature = this.parsed.flags.feature | ||
? generators.createEntity(this.parsed.flags.feature) | ||
: { | ||
name: '', | ||
path: '', | ||
} | ||
|
||
await codemods.makeUsingStub(stubsRoot, `make/action/${stub}.stub`, { | ||
entity: generators.createEntity(this.name), | ||
feature, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Configure hook | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The configure hook is called when someone runs "node ace configure <package>" | ||
| command. You are free to perform any operations inside this function to | ||
| configure the package. | ||
| | ||
| To make things easier, you have access to the underlying "ConfigureCommand" | ||
| instance and you can use codemods to modify the source files. | ||
| | ||
*/ | ||
|
||
import ConfigureCommand from '@adonisjs/core/commands/configure' | ||
|
||
export async function configure(command: ConfigureCommand) { | ||
const codemods = await command.createCodemods() | ||
|
||
await codemods.updateRcFile((rcFile) => { | ||
rcFile.addCommand('@adocasts.com/actions/commands') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Package entrypoint | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Export values from the package entrypoint as you see fit. | ||
| | ||
*/ | ||
|
||
export { configure } from './configure.js' | ||
export { stubsRoot } from './stubs/main.js' |
Oops, something went wrong.