init repo

This commit is contained in:
2025-09-11 13:41:58 +02:00
commit b4bb3e3eed
13 changed files with 178 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
package-lock.json
._*
.idea/
.DS_Store
node_modules/
dist/
+7
View File
@@ -0,0 +1,7 @@
.woodpecker/
test/
.gitignore
README.md
.prettierignore
.prettierrc
eslint.config.ts
+4
View File
@@ -0,0 +1,4 @@
.woodpecker
node_modules
test
dist
+11
View File
@@ -0,0 +1,11 @@
{
"arrowParens": "avoid",
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": false,
"printWidth": 120,
"semi": false,
"singleQuote": true,
"jsxSingleQuote": true,
"trailingComma": "none"
}
+19
View File
@@ -0,0 +1,19 @@
when:
- path:
include: ['src/**/*.ts']
steps:
install:
image: node
when:
- event: [pull_request, push, manual]
commands:
- npm install
test:
image: oven/bun:alpine
when:
- event: [pull_request, push, manual]
depends_on: install
commands:
- bun test
+8
View File
@@ -0,0 +1,8 @@
# Library template
Basic template to create a TypeScript library that works properly when included
## How to split in multiple file
Technically, there is nothing to do, but if you want to allow sub-imports, you have to :
1. In `package.json`, under `exports`, add `"./submodule": "./src/submodule.ts"`
2. In `tsconfig.json`, under `paths`, add `"lib-name/*": ["./src/*"]`
+15
View File
@@ -0,0 +1,15 @@
import js from '@eslint/js'
import globals from 'globals'
import tseslint from 'typescript-eslint'
import {defineConfig, globalIgnores} from 'eslint/config'
export default defineConfig([
tseslint.configs.recommended,
{
files: ['**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
plugins: {js},
extends: ['js/recommended'],
languageOptions: {globals: {...globals.browser, ...globals.node}}
},
globalIgnores(['dist'])
])
+35
View File
@@ -0,0 +1,35 @@
{
"scripts": {
"check": "clear ; npm run typecheck && npm run lint && npx prettier -c **/*.{js,jsx,ts,tsx} && clear && echo 'OK'",
"fmt": "prettier --write **/*.{js,jsx,ts,tsx}",
"lint": "eslint **/*.{js,jsx,ts,tsx}",
"test": "bun test",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"log": "git+https://git.pband.ch/typescript/log.git"
},
"devDependencies": {
"@eslint/js": "^9.35.0",
"@types/bun": "^1.2.21",
"bun": "^1.2.21",
"eslint": "^9.35.0",
"globals": "^16.4.0",
"jiti": "^2.5.1",
"prettier": "^3.6.2",
"typescript": "^5.9.2",
"typescript-eslint": "^8.43.0"
},
"name": "lib-template",
"description": "Template library for typescript projects",
"version": "1.0.0",
"author": "Pascal Perrenoud <pascal@pband.ch>",
"type": "module",
"main": "./src/index.ts",
"exports": {
".": "./src/index.ts"
}
}
+38
View File
@@ -0,0 +1,38 @@
import logger from 'log'
import fs from 'node:fs/promises'
import type {Ok} from './helpers'
const log = logger('config:env')
const FILE_EXT = "__FILE"
// Read from env or file
export async function read_env(key: string): Promise<Ok<string | undefined>> {
const path = process.env[key + FILE_EXT]
if (path !== undefined) return from_file(path)
else return {ok: true, data: process.env[key]}
}
async function from_file(path: string): Promise<Ok<string>> {
log.debug("Read a key from a file")
log.trace("Path :", path)
let content = await get_file_content(path)
if (!content.ok) return content
content.data = content.data.trim()
return content
}
async function get_file_content(path: string) : Promise<Ok<string>> {
log.debug('Read file content')
log.trace('Path :', path)
try {
const data = await fs.readFile(path, {encoding: 'utf-8'})
return {ok: true, data}
} catch (e) {
log.warn('Failed to read file', path)
log.debug('Error :', e)
return {ok: false}
}
}
+1
View File
@@ -0,0 +1 @@
export type Ok<T> = {ok: true, data: T} | {ok: false}
+17
View File
@@ -0,0 +1,17 @@
import logger from 'log'
import {Ok} from './helpers'
// TODO : re-export types used to describe schema
const log = logger('config')
export async function parse<S>(schema: S): Promise<Ok<unknown>> {
log.info("Parse configuration from env")
// TODO : Read config from env
// TODO : maybe double check config
return {ok: false}
}
+3
View File
@@ -0,0 +1,3 @@
import {test} from 'bun:test'
test('Basic test', () => 'Hello, world!')
+14
View File
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"declaration": true,
"outDir": "dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["src"]
}