Skip to content

Commit c7db455

Browse files
committed
feat: initial commit
0 parents  commit c7db455

File tree

17 files changed

+6935
-0
lines changed

17 files changed

+6935
-0
lines changed

.github/workflows/nodejs.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Node build, test and publish
2+
3+
on:
4+
pull_request:
5+
types: [assigned, opened, synchronize, reopened]
6+
push:
7+
branches:
8+
- main
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Use Node.js 22
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 22
22+
cache: yarn
23+
- name: npm install, lint, build, and test
24+
run: |
25+
yarn install --immutable
26+
yarn lint
27+
yarn build
28+
yarn test
29+
env:
30+
CI: true
31+
32+
publish-npm:
33+
needs: build
34+
if: github.ref == 'refs/heads/main'
35+
permissions:
36+
contents: write
37+
issues: write
38+
id-token: write
39+
pull-requests: write
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v4
43+
- uses: actions/setup-node@v4
44+
with:
45+
node-version: 22
46+
cache: yarn
47+
- run: yarn install --immutable
48+
- run: yarn build
49+
- name: Release
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
53+
run: |
54+
yarn dlx semantic-release

.gitignore

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Custom
2+
src/generated
3+
.transpiled
4+
.nyc_output
5+
.eslintcache
6+
7+
# TypeScript incremental compilation cache
8+
*.tsbuildinfo
9+
10+
# Stock
11+
*.seed
12+
*.log
13+
*.csv
14+
*.dat
15+
*.out
16+
*.pid
17+
*.gz
18+
*.orig
19+
20+
work
21+
/build
22+
/dist
23+
pids
24+
logs
25+
results
26+
coverage
27+
lib-cov
28+
html-report
29+
xunit.xml
30+
node_modules
31+
npm-debug.log
32+
33+
.project
34+
.idea
35+
.settings
36+
.iml
37+
*.sublime-workspace
38+
*.sublime-project
39+
40+
.DS_Store*
41+
ehthumbs.db
42+
Icon?
43+
Thumbs.db
44+
.AppleDouble
45+
.LSOverride
46+
.Spotlight-V100
47+
.Trashes
48+
49+
.yarn/*
50+
!.yarn/patches
51+
!.yarn/plugins
52+
!.yarn/releases
53+
!.yarn/sdks
54+
!.yarn/versions
55+
56+
.node_repl_history
57+
58+
# TypeScript incremental compilation cache
59+
*.tsbuildinfo
60+
61+
# Managed by cpconfig
62+
/.commitlintrc.yaml
63+
/eslint.config.mts
64+
/tsconfig.json
65+
/tsconfig.build.json
66+
/.prettierrc.yaml
67+
/vitest.config.ts

.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Lines changed: 541 additions & 0 deletions
Large diffs are not rendered by default.

.yarn/releases/yarn-3.8.5.cjs

Lines changed: 875 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
nodeLinker: node-modules
2+
3+
plugins:
4+
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
5+
spec: "@yarnpkg/plugin-interactive-tools"
6+
7+
yarnPath: .yarn/releases/yarn-3.8.5.cjs

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# @openapi-typescript-infra/cpconfig
2+
3+
Shared configuration files for OpenAPI Typescript projects
4+
5+
- tsconfig.json - modern Node22+ Next-compatible, noEmit
6+
- tsconfig.build.json - emits to dist
7+
- tsconfig.tsup.json - disables incremental compilation
8+
- .commitlintrc.yaml - force conventional commit format
9+
- .prettierrc.yaml - stylez for days
10+
- eslint.config.mts - follow the rules AI
11+
- vitest.config.ts - test framework setup

package.json

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"name": "@openapi-typescript-infra/cpconfig",
3+
"version": "0.0.0",
4+
"description": "Standard Typescript/Node/React configuration for @openapi-typescript-infra projects",
5+
"main": "./dist/index.js",
6+
"exports": "./dist/index.js",
7+
"type": "module",
8+
"types": "dist/index.d.ts",
9+
"author": "Developers <[email protected]>",
10+
"license": "UNLICENSED",
11+
"packageManager": "[email protected]",
12+
"imports": {
13+
"#src/*": "./src/*"
14+
},
15+
"scripts": {
16+
"build": "tsc -p tsconfig.build.json",
17+
"clean": "yarn dlx rimraf ./dist",
18+
"lint": "eslint .",
19+
"postinstall": "cpconfig",
20+
"test": "vitest"
21+
},
22+
"files": [
23+
"dist",
24+
"src",
25+
"templates"
26+
],
27+
"keywords": [
28+
"typescript"
29+
],
30+
"repository": {
31+
"type": "git",
32+
"url": "git+https://github.com/openapi-typescript-infra/oti-cpconfig.git"
33+
},
34+
"publishConfig": {
35+
"access": "public"
36+
},
37+
"release": {
38+
"branches": [
39+
"main"
40+
],
41+
"plugins": [
42+
"@semantic-release/commit-analyzer",
43+
"@semantic-release/release-notes-generator",
44+
[
45+
"@semantic-release/exec",
46+
{
47+
"publishCmd": "yarn dlx pinst --disable"
48+
}
49+
],
50+
"@semantic-release/npm",
51+
"@semantic-release/github"
52+
]
53+
},
54+
"config": {
55+
"cpconfig": "./src/index.ts"
56+
},
57+
"dependencies": {
58+
"@typescript-eslint/eslint-plugin": "^8.46.3",
59+
"@typescript-eslint/parser": "^8.46.3",
60+
"cpconfig": "^1.3.1",
61+
"eslint": "^9.39.1",
62+
"eslint-config-prettier": "^10.1.8",
63+
"eslint-import-resolver-typescript": "^4.4.4",
64+
"eslint-plugin-import": "^2.32.0",
65+
"jiti": "^2.6.1",
66+
"prettier": "^3.6.2",
67+
"typescript-eslint": "^8.46.3"
68+
},
69+
"devDependencies": {
70+
"@semantic-release/exec": "^7.1.0",
71+
"@semantic-release/github": "^12.0.1",
72+
"@types/node": "^24.10.0",
73+
"typescript": "^5.9.3",
74+
"vitest": "^4.0.7"
75+
}
76+
}

src/index.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { describe, expect, test } from 'vitest';
2+
3+
import { config } from './index.js';
4+
5+
describe('Module exports', () => {
6+
test('should export expected elements', () => {
7+
expect(config).toBeInstanceOf(Function);
8+
const configValue = config({});
9+
expect(configValue['.commitlintrc.yaml']).toBeDefined();
10+
expect(configValue['eslint.config.mts']).toBeDefined();
11+
expect(configValue['tsconfig.json']).toBeDefined();
12+
expect(configValue['tsconfig.build.json']).toBeDefined();
13+
expect(configValue['.prettierrc.yaml']).toBeDefined();
14+
expect(configValue['vitest.config.ts']).toBeDefined();
15+
expect(configValue['.github/actionlint.yml']).toBeDefined();
16+
expect(configValue['tsconfig.tsup.json']).not.toBeDefined();
17+
});
18+
});

src/index.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import { createRequire } from 'node:module';
4+
5+
function hasPackage(name: string) {
6+
try {
7+
// Try to resolve from current working directory context
8+
const requireFn = typeof require !== 'undefined' ? require : createRequire(import.meta.url);
9+
const resolvedPath = requireFn.resolve(name, {
10+
paths: [path.resolve(process.cwd())],
11+
});
12+
return !!resolvedPath;
13+
} catch {
14+
return false;
15+
}
16+
}
17+
18+
const __dirname = path.dirname(new URL(import.meta.url).pathname);
19+
20+
const YAML_SENTINEL = '# Managed by cpconfig';
21+
const JSON_SENTINEL = '"Managed by cpconfig"';
22+
const JS_SENTINEL = '// Managed by cpconfig';
23+
24+
export function config() {
25+
return {
26+
'.commitlintrc.yaml': {
27+
contents: fs.readFileSync(path.resolve(__dirname, '../templates/.commitlintrc.yaml'), 'utf8'),
28+
sentinel: YAML_SENTINEL,
29+
},
30+
'eslint.config.mts': {
31+
contents: fs.readFileSync(path.resolve(__dirname, '../templates/eslint.config.mts'), 'utf8'),
32+
sentinel: JS_SENTINEL,
33+
},
34+
'tsconfig.json': {
35+
contents: fs.readFileSync(path.resolve(__dirname, '../templates/tsconfig.json'), 'utf8'),
36+
sentinel: JSON_SENTINEL,
37+
},
38+
'tsconfig.build.json': {
39+
contents: fs.readFileSync(
40+
path.resolve(__dirname, '../templates/tsconfig.build.json'),
41+
'utf8',
42+
),
43+
sentinel: JSON_SENTINEL,
44+
},
45+
'.prettierrc.yaml': {
46+
contents: fs.readFileSync(path.resolve(__dirname, '../templates/.prettierrc.yaml'), 'utf8'),
47+
sentinel: YAML_SENTINEL,
48+
},
49+
'vitest.config.ts': {
50+
contents: fs.readFileSync(
51+
path.resolve(__dirname, '../templates/vitest.config.ts.template'),
52+
'utf8',
53+
),
54+
sentinel: JS_SENTINEL,
55+
},
56+
...(hasPackage('tsup')
57+
? {
58+
'tsconfig.tsup.json': {
59+
contents: fs.readFileSync(
60+
path.resolve(__dirname, '../templates/tsconfig.tsup.json'),
61+
'utf8',
62+
),
63+
sentinel: JSON_SENTINEL,
64+
},
65+
}
66+
: undefined),
67+
};
68+
}

templates/.commitlintrc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Managed by cpconfig
2+
extends: "@commitlint/config-conventional"

0 commit comments

Comments
 (0)