Skip to content

Commit e659719

Browse files
committed
feat: initial commit
0 parents  commit e659719

20 files changed

+451
-0
lines changed

.editorconfig

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# http://editorconfig.org
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.json]
12+
insert_final_newline = ignore
13+
14+
[**.min.js]
15+
indent_style = ignore
16+
insert_final_newline = ignore
17+
18+
[MakeFile]
19+
indent_style = space
20+
21+
[*.md]
22+
trim_trailing_whitespace = false

.github/lock.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
ignoreUnless: {{ STALE_BOT }}
3+
---
4+
# Configuration for Lock Threads - https://github.com/dessant/lock-threads-app
5+
6+
# Number of days of inactivity before a closed issue or pull request is locked
7+
daysUntilLock: 60
8+
9+
# Skip issues and pull requests created before a given timestamp. Timestamp must
10+
# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable
11+
skipCreatedBefore: false
12+
13+
# Issues and pull requests with these labels will be ignored. Set to `[]` to disable
14+
exemptLabels: ['Type: Security']
15+
16+
# Label to add before locking, such as `outdated`. Set to `false` to disable
17+
lockLabel: false
18+
19+
# Comment to post before locking. Set to `false` to disable
20+
lockComment: >
21+
This thread has been automatically locked since there has not been
22+
any recent activity after it was closed. Please open a new issue for
23+
related bugs.
24+
25+
# Assign `resolved` as the reason for locking. Set to `false` to disable
26+
setLockReason: false

.github/stale.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
ignoreUnless: {{ STALE_BOT }}
3+
---
4+
# Number of days of inactivity before an issue becomes stale
5+
daysUntilStale: 60
6+
7+
# Number of days of inactivity before a stale issue is closed
8+
daysUntilClose: 7
9+
10+
# Issues with these labels will never be considered stale
11+
exemptLabels:
12+
- 'Type: Security'
13+
14+
# Label to use when marking an issue as stale
15+
staleLabel: 'Status: Abandoned'
16+
17+
# Comment to post when marking an issue as stale. Set to `false` to disable
18+
markComment: >
19+
This issue has been automatically marked as stale because it has not had
20+
recent activity. It will be closed if no further activity occurs. Thank you
21+
for your contributions.
22+
23+
# Comment to post when closing a stale issue. Set to `false` to disable
24+
closeComment: false

.github/workflows/test.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: test
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
lint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Install
13+
run: npm install
14+
- name: Run lint
15+
run: npm run lint
16+
17+
typecheck:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: Install
22+
run: npm install
23+
- name: Run typecheck
24+
run: npm run typecheck
25+
26+
tests:
27+
runs-on: ${{ matrix.os }}
28+
strategy:
29+
matrix:
30+
os: [ubuntu-latest, windows-latest]
31+
node-version:
32+
- 20.10.0
33+
- 21.x
34+
steps:
35+
- uses: actions/checkout@v4
36+
- name: Use Node.js ${{ matrix.node-version }}
37+
uses: actions/setup-node@v1
38+
with:
39+
node-version: ${{ matrix.node-version }}
40+
- name: Install
41+
run: npm install
42+
- name: Run tests
43+
run: npm test
44+
windows:
45+
runs-on: windows-latest
46+
strategy:
47+
matrix:
48+
node-version:
49+
- 20.10.0
50+
- 21.x
51+
steps:
52+
- uses: actions/checkout@v2
53+
- name: Use Node.js ${{ matrix.node-version }}
54+
uses: actions/setup-node@v1
55+
with:
56+
node-version: ${{ matrix.node-version }}
57+
- name: Install
58+
run: npm install
59+
- name: Run tests
60+
run: npm test

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
node_modules
2+
coverage
3+
.DS_STORE
4+
.nyc_output
5+
.idea
6+
.vscode/
7+
*.sublime-project
8+
*.sublime-workspace
9+
*.log
10+
build
11+
dist
12+
yarn.lock
13+
shrinkwrap.yaml
14+
package-lock.json

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build
2+
docs
3+
coverage
4+
*.html

LICENSE.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# The MIT License
2+
3+
Copyright (c) 2023
4+
5+
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:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
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.

README.md

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# AdonisJS package starter kit
2+
3+
> A boilerplate for creating AdonisJS packages
4+
5+
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.
6+
7+
## Setup
8+
9+
- Clone the repo on your computer, or use `giget` to download this repo without the Git history.
10+
```sh
11+
npx giget@latest gh:adonisjs/pkg-starter-kit
12+
```
13+
- Install dependencies.
14+
- Update the `package.json` file and define the `name`, `description`, `keywords`, and `author` properties.
15+
- The repo is configured with an MIT license. Feel free to change that if you are not publishing under the MIT license.
16+
17+
## Folder structure
18+
19+
The starter kit mimics the folder structure of the official packages. Feel free to rename files and folders as per your requirements.
20+
21+
```
22+
├── providers
23+
├── src
24+
├── bin
25+
├── stubs
26+
├── configure.ts
27+
├── index.ts
28+
├── LICENSE.md
29+
├── package.json
30+
├── README.md
31+
├── tsconfig.json
32+
├── tsnode.esm.js
33+
```
34+
35+
- The `configure.ts` file exports the `configure` hook to configure the package using the `node ace configure` command.
36+
- The `index.ts` file is the main entry point of the package.
37+
- The `tsnode.esm.js` file runs TypeScript code using TS-Node + SWC. Please read the code comment in this file to learn more.
38+
- The `bin` directory contains the entry point file to run Japa tests.
39+
- Learn more about [the `providers` directory](./providers/README.md).
40+
- Learn more about [the `src` directory](./src/README.md).
41+
- Learn more about [the `stubs` directory](./stubs/README.md).
42+
43+
### File system naming convention
44+
45+
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.
46+
47+
## Peer dependencies
48+
49+
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.
50+
51+
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`.
52+
53+
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.
54+
55+
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).
56+
57+
## Published files
58+
59+
Instead of publishing your repo's source code to npm, you must cherry-pick files and folders to publish only the required files.
60+
61+
The cherry-picking uses the `files` property inside the `package.json` file. By default, we publish the following files and folders.
62+
63+
```json
64+
{
65+
"files": ["build/src", "build/providers", "build/stubs", "build/index.d.ts", "build/index.js"]
66+
}
67+
```
68+
69+
If you create additional folders or files, mention them inside the `files` array.
70+
71+
## Exports
72+
73+
[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.
74+
75+
```json
76+
{
77+
"exports": {
78+
".": "./build/index.js",
79+
"./types": "./build/src/types.js"
80+
}
81+
}
82+
```
83+
84+
- The dot `.` export is the main export.
85+
- The `./types` exports all the types defined inside the `./build/src/types.js` file (the compiled output).
86+
87+
Feel free to change the exports as per your requirements.
88+
89+
## Testing
90+
91+
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.
92+
93+
- `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).
94+
- `npm run quick:test`: Runs only the tests without linting or coverage reporting.
95+
96+
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.
97+
98+
## TypeScript workflow
99+
100+
- The starter kit uses [tsc](https://www.typescriptlang.org/docs/handbook/compiler-options.html) for compiling the TypeScript to JavaScript when publishing the package.
101+
- [TS-Node](https://typestrong.org/ts-node/) and [SWC](https://swc.rs/) are used to run tests without compiling the source code.
102+
- 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.
103+
- You can perform type checking without compiling the source code using the `npm run type check` script.
104+
105+
Feel free to explore the `tsconfig.json` file for all the configured options.
106+
107+
## ESLint and Prettier setup
108+
109+
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.
110+
111+
## Using Stale bot
112+
113+
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.
114+
115+
Feel free to delete the `.github/stale.yml` and `.github/lock.yml` files if you decide not to use the Stale bot.

bin/test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { assert } from '@japa/assert'
2+
import { configure, processCLIArgs, run } from '@japa/runner'
3+
4+
processCLIArgs(process.argv.splice(2))
5+
6+
configure({
7+
files: ['tests/**/*.spec.ts'],
8+
plugins: [assert()],
9+
})
10+
11+
run()

configure.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
|--------------------------------------------------------------------------
3+
| Configure hook
4+
|--------------------------------------------------------------------------
5+
|
6+
| The configure hook is called when someone runs "node ace configure <package>"
7+
| command. You are free to perform any operations inside this function to
8+
| configure the package.
9+
|
10+
| To make things easier, you have access to the underlying "ConfigureCommand"
11+
| instance and you can use codemods to modify the source files.
12+
|
13+
*/
14+
15+
import ConfigureCommand from '@adonisjs/core/commands/configure'
16+
17+
export async function configure(_command: ConfigureCommand) {}

index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
|--------------------------------------------------------------------------
3+
| Package entrypoint
4+
|--------------------------------------------------------------------------
5+
|
6+
| Export values from the package entrypoint as you see fit.
7+
|
8+
*/
9+
10+
export { configure } from './configure.js'

0 commit comments

Comments
 (0)