Skip to content

Commit

Permalink
chore: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainLanz committed Jul 7, 2023
0 parents commit e634ee8
Show file tree
Hide file tree
Showing 21 changed files with 714 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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

[*.md]
trim_trailing_whitespace = false
26 changes: 26 additions & 0 deletions .github/lock.yml
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
24 changes: 24 additions & 0 deletions .github/stale.yml
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
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: test
on:
- push
- pull_request
jobs:
linux:
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 18.x
- 19.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
windows:
runs-on: windows-latest
strategy:
matrix:
node-version:
- 18.x
- 19.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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
build
coverage
.idea
.vscode
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build
docs
coverage
*.html
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# The MIT License

Copyright (c) 2023, Romain Lanz, AdonisJS Core Team, contributors

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.
122 changes: 122 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# AdonisJS package starter kit

> A boilerplate for creating AdonisJS packages
This repo contains the default folder structure, development, and peer dependencies to create a package for AdonisJS v6.

You can create a package from scratch with your folder structure and workflow. However, using a default starter kit can speed up the process, as you have fewer decisions to make.

## 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
├── stubs
├── index.ts
├── LICENSE.md
├── package.json
├── README.md
└── tsconfig.json
```

- The `providers` directory is used to store service providers.
- The `src` directory contains the source code of the package. All business logic should be inside this folder.
- The `stubs` directory is used to keep scaffolding stubs. You might copy some stubs to the user application once they configure the package.
- The `index.ts` file is the main entry point of the package.

### File system naming convention

We use `snake_case` naming conventions for the file system. The rule is enforced using ESLint. However, feel free to disable 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 all the source code of your repo to npm, you must cherry-pick files and folders to publish only the required files.

The cherry-picking is done using the `files` property inside the `package.json` file. By default, we publish the following files and folders.

```json
{
"files": [
"src",
"providers",
"index.ts",
"build/src",
"build/providers",
"build/stubs",
"build/index.d.ts",
"build/index.d.ts.map",
"build/index.js"
]
}
```

If you notice, we are publishing both the source code (written in TypeScript) and the compiled output (JavaScript) to npm.

- The JavaScript runtime requires compiled output. So that is something you will have to publish.
- Publishing source code is optional. However, if you generate [declaration maps](https://www.typescriptlang.org/tsconfig#declarationMap), then the TypeScript language server (used by code editors like VSCode) will be able to jump to the actual source code when you perform `CTRL + CLICK`.

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 comes with a Github workflow file to run tests using Github Actions. The tests are executed against `Node.js 18.x` and `Node.js 19.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 at the time of 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 `NodeNext` module system. Meaning the packages are written using ES modules.
- You can perform type checking without compiling the source code using `npm run typecheck` 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. The configuration for both is 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 config, use custom plugins or remove both tools altogether.

## Using Stale bot (optional)

The [Stale bot](https://github.com/apps/stale) is a Github application that automatically marks issues and PRs as stale and closes after a certain duration of inactivity.

You may optionally configure it at the time of scaffolding the package.

## Unconfigurable bits

- **License**: The `LICENSE.md` file and the `license` property inside the `package.json` file are set to `MIT`. You can change them manually.
- **Editorconfig**: The `.editorconfig` file is used to define the formatting rules.
- **No package-lock file**: The `.npmrc` file is created with the rule to diable `package-lock.json` file. Feel free to revert the setting or use a different package manager.
31 changes: 31 additions & 0 deletions bin/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { assert } from '@japa/assert'
import { processCLIArgs, configure, run } from '@japa/runner'

/*
|--------------------------------------------------------------------------
| Configure tests
|--------------------------------------------------------------------------
|
| The configure method accepts the configuration to configure the Japa
| tests runner.
|
| The first method call "processCLIArgs" process the command line arguments
| and turns them into a config object. Using this method is not mandatory.
|
| Please consult japa.dev/runner-config for the config docs.
*/
processCLIArgs(process.argv.slice(2))
configure({
files: ['tests/**/*.spec.ts'],
plugins: [assert()],
})

/*
|--------------------------------------------------------------------------
| Run tests
|--------------------------------------------------------------------------
|
| The following "run" method is required to execute all the tests.
|
*/
run()
Empty file added index.ts
Empty file.
100 changes: 100 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"name": "@adonisjs/transmit",
"version": "0.0.1",
"description": "Server-Sent-Event module for AdonisJS.",
"keywords": [
"sse",
"server-sent-event",
"adonis",
"adonisjs",
"adonis-framework"
],
"license": "MIT",
"author": "Romain Lanz <[email protected]>",
"type": "module",
"main": "build/index.js",
"exports": {
".": "./build/index.js",
"./providers": "./build/providers/transmit_provider.js",
"./services/transmit": "./build/src/services/transmit.js",
"./types": "./build/src/types.js"
},
"scripts": {
"clean": "del-cli build",
"copy:templates": "copyfiles \"stubs/**/*.stub\" build",
"typecheck": "tsc --no-emit",
"lint": "eslint . --ext=.ts",
"format": "prettier --write .",
"quick:test": "node --enable-source-maps --loader=ts-node/esm bin/test.ts",
"pretest": "npm run lint",
"test": "c8 npm run quick:test",
"prebuild": "npm run lint && npm run clean",
"build": "tsc",
"postbuild": "npm run copy:templates",
"release": "np",
"version": "npm run build",
"prepublishOnly": "npm run build"
},
"dependencies": {
"@poppinss/matchit": "^3.1.2",
"emittery": "^1.0.1"
},
"devDependencies": {
"@adonisjs/core": "^6.1.5-5",
"@adonisjs/eslint-config": "^1.1.7",
"@adonisjs/prettier-config": "^1.1.7",
"@adonisjs/tsconfig": "^1.1.7",
"@japa/assert": "2.0.0-1",
"@japa/runner": "3.0.0-3",
"@swc/core": "^1.3.68",
"@types/node": "^20.3.3",
"c8": "^8.0.0",
"copyfiles": "^2.4.1",
"del-cli": "^5.0.0",
"eslint": "^8.44.0",
"np": "^8.0.4",
"prettier": "^2.8.8",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
},
"peerDependencies": {
"@adonisjs/core": "^6.1.5-5"
},
"files": [
"src",
"providers",
"index.ts",
"build/src",
"build/providers",
"build/stubs",
"build/index.d.ts",
"build/index.d.ts.map",
"build/index.js"
],
"engines": {
"node": ">=18.16.0"
},
"eslintConfig": {
"extends": "@adonisjs/eslint-config/package"
},
"prettier": "@adonisjs/prettier-config",
"publishConfig": {
"access": "public",
"tag": "latest"
},
"np": {
"message": "chore(release): %s",
"tag": "latest",
"branch": "main",
"anyBranch": false
},
"c8": {
"reporter": [
"text",
"html"
],
"exclude": [
"tests/**"
]
}
}
Loading

0 comments on commit e634ee8

Please sign in to comment.