Skip to content

Commit af8b7c9

Browse files
authored
Initial commit
0 parents  commit af8b7c9

32 files changed

+2829
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**/dist
2+
**/node_modules
3+
*.log
4+
.env
5+
.DS_Store

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
pnpm test

.npmrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
engine-strict=true
2+
auto-install-peers=true

.prettierignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
node_modules
2+
dist
3+
build
4+
logs
5+
coverage
6+
.next
7+
.turbo
8+
.github
9+
.angular
10+
.svelte-kit
11+
.vscode
12+
*.log*
13+
*.log
14+
*.lock
15+
*.yaml
16+
*.yml
17+
*.sh
18+
*.svg
19+
*rc.*
20+
*.htm
21+
*.html
22+
*.json
23+
*.md
24+
.*ignore

.prettierrc.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@crashmax/prettier-config')

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Vitalij Ryndin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# node-esm
2+
3+
> _This template a pure ESM package. If you're having trouble importing it in your project, please [read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)._

apps/api/.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
HOST="localhost"
2+
PORT=5000

apps/api/package.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "api",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"scripts": {
6+
"start": "pnpm build && cross-env NODE_ENV=production node dist/index.js",
7+
"dev": "tsx watch src/index.ts",
8+
"build": "del-cli dist && tsc"
9+
},
10+
"dependencies": {
11+
"@node-esm/prisma": "workspace:^1.0.0",
12+
"dotenv": "^16.0.3",
13+
"envalid": "^7.3.1",
14+
"fastify": "^4.9.2"
15+
}
16+
}

apps/api/src/config.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'dotenv/config'
2+
import { cleanEnv, num, str } from 'envalid'
3+
4+
export const env = cleanEnv(process.env, {
5+
HOST: str({ default: 'localhost' }),
6+
PORT: num({ default: 5000 })
7+
})
8+
9+
export const server = {
10+
host: env.HOST,
11+
port: env.PORT,
12+
href: `http://${env.HOST}:${env.PORT}`
13+
}

apps/api/src/index.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Fastify from 'fastify'
2+
import { PrismaClient } from '@node-esm/prisma'
3+
import { server } from './config.js'
4+
5+
const fastify = Fastify()
6+
const prisma = new PrismaClient()
7+
await prisma.$connect()
8+
9+
fastify
10+
.listen(server)
11+
.then(() => console.log(`Fastify (${fastify.version}): ${server.href}`))
12+
.catch(console.log)
13+
14+
function onClose() {
15+
fastify.close()
16+
prisma.$disconnect()
17+
}
18+
19+
process.on('SIGTERM', onClose)
20+
process.on('SIGINT', onClose)

apps/api/tsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "@crashmax/tsconfig",
3+
"compilerOptions": {
4+
"outDir": "dist"
5+
},
6+
"include": [
7+
"src/**/*"
8+
]
9+
}

apps/calc/package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "calc",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"scripts": {
6+
"start": "pnpm build && cross-env NODE_ENV=production node dist/index.js",
7+
"dev": "tsx watch src/index.ts",
8+
"build": "del-cli dist && tsc"
9+
},
10+
"dependencies": {
11+
"@node-esm/shared": "workspace:*"
12+
}
13+
}

apps/calc/src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { sum } from '@node-esm/shared/sum'
2+
3+
console.log(sum(1, 1, 2, 3, 5, 8, 13))

apps/calc/tsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "@crashmax/tsconfig",
3+
"compilerOptions": {
4+
"outDir": "dist"
5+
},
6+
"include": [
7+
"src/**/*"
8+
]
9+
}

ava.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
files: ['./packages/**/*.test.ts', './apps/**/*.test.ts'],
3+
extensions: {
4+
ts: 'module'
5+
},
6+
nodeArguments: ['--loader=tsx', '--no-warnings']
7+
}

docker-compose.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '3.8'
2+
3+
services:
4+
postgres:
5+
image: postgres:14-alpine
6+
restart: always
7+
volumes:
8+
- pg-data:/var/lib/postgresql/data
9+
environment:
10+
POSTGRES_USER: node-esm
11+
POSTGRES_PASSWORD: node-esm
12+
POSTGRES_DB: node-esm
13+
ports:
14+
- 5432:5432
15+
16+
volumes:
17+
pg-data:

package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "node-esm",
3+
"version": "1.0.0",
4+
"description": "node-esm",
5+
"type": "module",
6+
"scripts": {
7+
"dev:apps": "pnpm -r --parallel --filter=./apps/* run dev",
8+
"build:apps": "pnpm -r --filter=./apps/* run build",
9+
"dev:packages": "pnpm -r --parallel --filter=./packages/* run dev",
10+
"build:packages": "pnpm -r --filter=./packages/* run build",
11+
"test": "ava",
12+
"test:watch": "ava --watch",
13+
"format": "prettier --write --ignore-unknown **",
14+
"prepare": "husky install"
15+
},
16+
"devDependencies": {
17+
"@crashmax/prettier-config": "^2.2.1",
18+
"@crashmax/tsconfig": "^1.0.2",
19+
"@types/node": "^18.11.17",
20+
"ava": "^5.1.0",
21+
"cross-env": "^7.0.3",
22+
"del-cli": "^5.0.0",
23+
"husky": "^8.0.2",
24+
"tsx": "^3.12.1",
25+
"typescript": "^4.9.4"
26+
},
27+
"packageManager": "[email protected]",
28+
"engines": {
29+
"npm": "^7.0.0",
30+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
31+
}
32+
}

packages/prisma/.env.example

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Environment variables declared in this file are automatically made available to Prisma.
2+
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
3+
4+
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
5+
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
6+
7+
DATABASE_URL="postgresql://node-esm:node-esm@localhost:5432/node-esm?schema=public"

packages/prisma/package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@node-esm/prisma",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"types": "./dist/index.d.ts",
6+
"exports": {
7+
".": "./dist/index.js"
8+
},
9+
"scripts": {
10+
"dev": "tsc --watch",
11+
"build": "prisma generate && del-cli dist && tsc",
12+
"migrate": "prisma migrate dev",
13+
"push": "prisma db push",
14+
"seed": "prisma db seed",
15+
"studio": "prisma studio",
16+
"prepare": "pnpm build"
17+
},
18+
"prisma": {
19+
"seed": "node prisma/seed.js"
20+
},
21+
"dependencies": {
22+
"@prisma/client": "^4.5.0"
23+
},
24+
"devDependencies": {
25+
"prisma": "^4.5.0"
26+
}
27+
}

packages/prisma/prisma/schema.prisma

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This is your Prisma schema file,
2+
// learn more about it in the docs: https://pris.ly/d/prisma-schema
3+
4+
generator client {
5+
provider = "prisma-client-js"
6+
output = "../node_modules/.prisma/client"
7+
}
8+
9+
datasource db {
10+
provider = "postgresql"
11+
url = env("DATABASE_URL")
12+
}
13+
14+
model User {
15+
id Int @id @default(autoincrement())
16+
name String @unique
17+
}

packages/prisma/prisma/seed.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { PrismaClient } from '../dist/index.js'
2+
3+
const prisma = new PrismaClient()
4+
await prisma.$connect()
5+
6+
async function seed() {}
7+
8+
seed()
9+
.then(() => console.log('✅ Successfully.'))
10+
.catch((err) => console.log('❌', err))

packages/prisma/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from '../node_modules/.prisma/client/index.js'

packages/prisma/tsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "@crashmax/tsconfig",
3+
"compilerOptions": {
4+
"outDir": "dist"
5+
},
6+
"include": [
7+
"src/**/*"
8+
]
9+
}

packages/shared/package.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "@node-esm/shared",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"exports": {
6+
"./*": "./dist/*"
7+
},
8+
"typesVersions": {
9+
"*": {
10+
"*": [
11+
"dist/*"
12+
]
13+
}
14+
},
15+
"scripts": {
16+
"dev": "tsc --watch",
17+
"build": "del-cli dist && tsc",
18+
"prepare": "pnpm build"
19+
}
20+
}

packages/shared/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './sum.js'

packages/shared/src/sum.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function sum(...num: number[]): number {
2+
return num.reduce((acc, value) => (acc += value), 0)
3+
}

packages/shared/test/sum.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import test from 'ava'
2+
import { sum } from '../src/sum.js'
3+
4+
test('shared/sum', (t) => {
5+
t.deepEqual(sum(2, 4), 6)
6+
})

packages/shared/tsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "@crashmax/tsconfig",
3+
"compilerOptions": {
4+
"outDir": "dist"
5+
},
6+
"include": [
7+
"src/**/*"
8+
]
9+
}

0 commit comments

Comments
 (0)