@book000/create-ts 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/index.d.mts +1 -0
  2. package/dist/index.mjs +543 -0
  3. package/package.json +50 -0
  4. package/templates/gitignore/Node.gitignore +147 -0
  5. package/templates/nodejs/base/package.json +54 -0
  6. package/templates/nodejs/base/pnpm-lock.yaml +5639 -0
  7. package/templates/nodejs/base/pnpm-workspace.yaml +5 -0
  8. package/templates/nodejs/base/src/main.ts +13 -0
  9. package/templates/nodejs/base/template.json +8 -0
  10. package/templates/nodejs/base/test/smoke.test.ts +32 -0
  11. package/templates/nodejs/base/tsconfig.test.json +7 -0
  12. package/templates/nodejs/common/.depcheckrc.json +3 -0
  13. package/templates/nodejs/common/.devcontainer/devcontainer.json +9 -0
  14. package/templates/nodejs/common/.fixpackrc +4 -0
  15. package/templates/nodejs/common/.prettierrc.yml +7 -0
  16. package/templates/nodejs/common/Dockerfile +31 -0
  17. package/templates/nodejs/common/entrypoint.sh +4 -0
  18. package/templates/nodejs/common/eslint.config.mjs +1 -0
  19. package/templates/nodejs/common/package.json +29 -0
  20. package/templates/nodejs/common/pnpm-workspace.yaml +5 -0
  21. package/templates/nodejs/common/renovate.json +4 -0
  22. package/templates/nodejs/common/tsconfig.json +22 -0
  23. package/templates/nodejs/config-batch/package.json +59 -0
  24. package/templates/nodejs/config-batch/pnpm-lock.yaml +6128 -0
  25. package/templates/nodejs/config-batch/pnpm-workspace.yaml +5 -0
  26. package/templates/nodejs/config-batch/src/config.ts +7 -0
  27. package/templates/nodejs/config-batch/src/main.ts +38 -0
  28. package/templates/nodejs/config-batch/template.json +11 -0
  29. package/templates/nodejs/config-batch/test/config.test.ts +76 -0
  30. package/templates/nodejs/config-batch/tsconfig.test.json +7 -0
  31. package/templates/nodejs/discord-bot/package.json +60 -0
  32. package/templates/nodejs/discord-bot/pnpm-lock.yaml +6315 -0
  33. package/templates/nodejs/discord-bot/pnpm-workspace.yaml +5 -0
  34. package/templates/nodejs/discord-bot/src/config.ts +8 -0
  35. package/templates/nodejs/discord-bot/src/discord.ts +35 -0
  36. package/templates/nodejs/discord-bot/src/main.ts +53 -0
  37. package/templates/nodejs/discord-bot/template.json +11 -0
  38. package/templates/nodejs/discord-bot/test/discord.test.ts +68 -0
  39. package/templates/nodejs/discord-bot/tsconfig.test.json +7 -0
  40. package/templates/nodejs/fastify/package.json +59 -0
  41. package/templates/nodejs/fastify/pnpm-lock.yaml +6077 -0
  42. package/templates/nodejs/fastify/pnpm-workspace.yaml +5 -0
  43. package/templates/nodejs/fastify/src/main.ts +34 -0
  44. package/templates/nodejs/fastify/template.json +9 -0
  45. package/templates/nodejs/fastify/test/app.test.ts +49 -0
  46. package/templates/nodejs/fastify/tsconfig.test.json +7 -0
  47. package/templates/workflows/add-reviewer.yml +15 -0
  48. package/templates/workflows/docker.yml +92 -0
  49. package/templates/workflows/nodejs-ci-pnpm.yml +79 -0
@@ -0,0 +1,5 @@
1
+ allowBuilds:
2
+ esbuild: true
3
+ unrs-resolver: true
4
+ minimumReleaseAgeExclude:
5
+ - '@book000/*'
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 設定インターフェース
3
+ */
4
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
5
+ export interface ConfigInterface {
6
+ // TODO: 設定項目を追加する
7
+ }
@@ -0,0 +1,38 @@
1
+ import { ConfigFramework } from '@book000/node-utils'
2
+ import { ConfigInterface } from './config'
3
+
4
+ /**
5
+ * 設定フレームワーク実装
6
+ */
7
+ class Configuration extends ConfigFramework<ConfigInterface> {
8
+ /**
9
+ * バリデーションルールを返す
10
+ */
11
+ protected validates(): Record<string, (config: ConfigInterface) => boolean> {
12
+ return {
13
+ // TODO: バリデーションルールを追加する
14
+ // 例: 'someKey is required': (config) => config.someKey !== undefined,
15
+ }
16
+ }
17
+ }
18
+
19
+ /**
20
+ * エントリポイント
21
+ */
22
+ // eslint-disable-next-line @typescript-eslint/require-await
23
+ async function main(): Promise<void> {
24
+ const config = new Configuration('./data/config.json')
25
+ config.load()
26
+ if (!config.validate()) {
27
+ throw new Error(
28
+ `Configuration validation failed: ${config.getValidateFailures().join(', ')}`
29
+ )
30
+ }
31
+ // TODO: config.get('key') でアクセスして処理を実装する
32
+ }
33
+
34
+ main().catch((error: unknown) => {
35
+ console.error(error)
36
+ // eslint-disable-next-line unicorn/no-process-exit
37
+ process.exit(1)
38
+ })
@@ -0,0 +1,11 @@
1
+ {
2
+ "configSchema": true,
3
+ "dependencies": ["@book000/node-utils"],
4
+ "devDependencies": ["typescript-json-schema"],
5
+ "scripts": {
6
+ "generate-schema": "typescript-json-schema --required src/config.ts ConfigInterface -o schema/Configuration.json"
7
+ },
8
+ "depcheckIgnore": ["typescript-json-schema"],
9
+ "src": ["src/main.ts", "src/config.ts"],
10
+ "testSrc": ["test/config.test.ts", "tsconfig.test.json"]
11
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * config-batch バリアントのテスト
3
+ *
4
+ * @book000/node-utils の ConfigFramework が正しくサブクラス化できること、
5
+ * およびバリデーションロジックが期待通りに動作することを確認する。
6
+ * 外部サービスへの接続は行わない。
7
+ */
8
+
9
+ import * as fs from 'node:fs'
10
+ import * as os from 'node:os'
11
+ import * as path from 'node:path'
12
+ import { ConfigFramework } from '@book000/node-utils'
13
+
14
+ /** テスト用の設定インターフェース */
15
+ interface TestConfig {
16
+ apiKey: string
17
+ timeout: number
18
+ }
19
+
20
+ /** テスト用の ConfigFramework 実装 */
21
+ class TestConfiguration extends ConfigFramework<TestConfig> {
22
+ protected validates(): Record<string, (config: TestConfig) => boolean> {
23
+ return {
24
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
25
+ 'apiKey is required': (config) => config.apiKey !== undefined,
26
+ 'apiKey is string': (config) => typeof config.apiKey === 'string',
27
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
28
+ 'timeout is required': (config) => config.timeout !== undefined,
29
+ 'timeout is positive number': (config) =>
30
+ typeof config.timeout === 'number' && config.timeout > 0,
31
+ }
32
+ }
33
+ }
34
+
35
+ describe('ConfigFramework', () => {
36
+ let tmpDir: string
37
+ let configPath: string
38
+
39
+ beforeEach(() => {
40
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'node-utils-test-'))
41
+ configPath = path.join(tmpDir, 'config.json')
42
+ })
43
+
44
+ afterEach(() => {
45
+ fs.rmSync(tmpDir, { recursive: true })
46
+ })
47
+
48
+ it('サブクラスを定義できる', () => {
49
+ fs.writeFileSync(configPath, JSON.stringify({ apiKey: 'test', timeout: 30 }))
50
+ const config = new TestConfiguration(configPath)
51
+ expect(config).toBeDefined()
52
+ })
53
+
54
+ it('有効な設定を検証できる', () => {
55
+ fs.writeFileSync(
56
+ configPath,
57
+ JSON.stringify({ apiKey: 'test-key', timeout: 30 })
58
+ )
59
+ const config = new TestConfiguration(configPath)
60
+ config.load()
61
+ expect(config.validate()).toBe(true)
62
+ expect(config.getValidateFailures()).toHaveLength(0)
63
+ })
64
+
65
+ it('無効な設定を検出できる(負のタイムアウト)', () => {
66
+ fs.writeFileSync(
67
+ configPath,
68
+ JSON.stringify({ apiKey: 'test-key', timeout: -1 })
69
+ )
70
+ const config = new TestConfiguration(configPath)
71
+ config.load()
72
+ expect(config.validate()).toBe(false)
73
+ expect(config.getValidateFailures().length).toBeGreaterThan(0)
74
+ expect(config.getValidateFailures()).toContain('timeout is positive number')
75
+ })
76
+ })
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "types": ["node", "jest"]
5
+ },
6
+ "include": ["src/**/*", "test/**/*"]
7
+ }
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@book000/template",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "license": "MIT",
6
+ "author": "book000",
7
+ "scripts": {
8
+ "preinstall": "npx only-allow pnpm",
9
+ "start": "tsx ./src/main.ts",
10
+ "dev": "tsx watch ./src/main.ts",
11
+ "test": "jest --runInBand --passWithNoTests --detectOpenHandles --forceExit",
12
+ "lint": "run-z lint:prettier,lint:eslint,lint:tsc",
13
+ "lint:prettier": "prettier --check src/",
14
+ "lint:eslint": "eslint src/ -c eslint.config.mjs",
15
+ "lint:tsc": "tsc --noEmit",
16
+ "fix": "run-z fix:prettier fix:eslint",
17
+ "fix:eslint": "eslint src/ -c eslint.config.mjs --fix",
18
+ "fix:prettier": "prettier --write src/",
19
+ "generate-schema": "typescript-json-schema --required src/config.ts ConfigInterface -o schema/Configuration.json"
20
+ },
21
+ "dependencies": {
22
+ "@book000/node-utils": "*",
23
+ "discord.js": "*"
24
+ },
25
+ "devDependencies": {
26
+ "@book000/eslint-config": "*",
27
+ "@types/jest": "*",
28
+ "@types/node": "*",
29
+ "eslint": "*",
30
+ "jest": "*",
31
+ "prettier": "*",
32
+ "run-z": "*",
33
+ "ts-jest": "*",
34
+ "tsx": "*",
35
+ "typescript": "*",
36
+ "typescript-json-schema": "*"
37
+ },
38
+ "engines": {
39
+ "node": ">=24"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/book000/template.git"
44
+ },
45
+ "bugs": {
46
+ "url": "https://github.com/book000/template/issues"
47
+ },
48
+ "jest": {
49
+ "preset": "ts-jest",
50
+ "testEnvironment": "node",
51
+ "transform": {
52
+ "^.+\\.tsx?$": [
53
+ "ts-jest",
54
+ {
55
+ "tsconfig": "tsconfig.test.json"
56
+ }
57
+ ]
58
+ }
59
+ }
60
+ }