@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.
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +543 -0
- package/package.json +50 -0
- package/templates/gitignore/Node.gitignore +147 -0
- package/templates/nodejs/base/package.json +54 -0
- package/templates/nodejs/base/pnpm-lock.yaml +5639 -0
- package/templates/nodejs/base/pnpm-workspace.yaml +5 -0
- package/templates/nodejs/base/src/main.ts +13 -0
- package/templates/nodejs/base/template.json +8 -0
- package/templates/nodejs/base/test/smoke.test.ts +32 -0
- package/templates/nodejs/base/tsconfig.test.json +7 -0
- package/templates/nodejs/common/.depcheckrc.json +3 -0
- package/templates/nodejs/common/.devcontainer/devcontainer.json +9 -0
- package/templates/nodejs/common/.fixpackrc +4 -0
- package/templates/nodejs/common/.prettierrc.yml +7 -0
- package/templates/nodejs/common/Dockerfile +31 -0
- package/templates/nodejs/common/entrypoint.sh +4 -0
- package/templates/nodejs/common/eslint.config.mjs +1 -0
- package/templates/nodejs/common/package.json +29 -0
- package/templates/nodejs/common/pnpm-workspace.yaml +5 -0
- package/templates/nodejs/common/renovate.json +4 -0
- package/templates/nodejs/common/tsconfig.json +22 -0
- package/templates/nodejs/config-batch/package.json +59 -0
- package/templates/nodejs/config-batch/pnpm-lock.yaml +6128 -0
- package/templates/nodejs/config-batch/pnpm-workspace.yaml +5 -0
- package/templates/nodejs/config-batch/src/config.ts +7 -0
- package/templates/nodejs/config-batch/src/main.ts +38 -0
- package/templates/nodejs/config-batch/template.json +11 -0
- package/templates/nodejs/config-batch/test/config.test.ts +76 -0
- package/templates/nodejs/config-batch/tsconfig.test.json +7 -0
- package/templates/nodejs/discord-bot/package.json +60 -0
- package/templates/nodejs/discord-bot/pnpm-lock.yaml +6315 -0
- package/templates/nodejs/discord-bot/pnpm-workspace.yaml +5 -0
- package/templates/nodejs/discord-bot/src/config.ts +8 -0
- package/templates/nodejs/discord-bot/src/discord.ts +35 -0
- package/templates/nodejs/discord-bot/src/main.ts +53 -0
- package/templates/nodejs/discord-bot/template.json +11 -0
- package/templates/nodejs/discord-bot/test/discord.test.ts +68 -0
- package/templates/nodejs/discord-bot/tsconfig.test.json +7 -0
- package/templates/nodejs/fastify/package.json +59 -0
- package/templates/nodejs/fastify/pnpm-lock.yaml +6077 -0
- package/templates/nodejs/fastify/pnpm-workspace.yaml +5 -0
- package/templates/nodejs/fastify/src/main.ts +34 -0
- package/templates/nodejs/fastify/template.json +9 -0
- package/templates/nodejs/fastify/test/app.test.ts +49 -0
- package/templates/nodejs/fastify/tsconfig.test.json +7 -0
- package/templates/workflows/add-reviewer.yml +15 -0
- package/templates/workflows/docker.yml +92 -0
- package/templates/workflows/nodejs-ci-pnpm.yml +79 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Fastify from 'fastify'
|
|
2
|
+
import cors from '@fastify/cors'
|
|
3
|
+
// fastify-raw-body は生の POST ボディが必要な場合に利用する(Webhook 署名検証など)
|
|
4
|
+
// import fastifyRawBody from 'fastify-raw-body'
|
|
5
|
+
|
|
6
|
+
/** Fastify インスタンス */
|
|
7
|
+
const fastify = Fastify({
|
|
8
|
+
logger: true,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* エントリポイント
|
|
13
|
+
*/
|
|
14
|
+
async function main(): Promise<void> {
|
|
15
|
+
await fastify.register(cors, {
|
|
16
|
+
// TODO: 本番環境では許可するオリジンを明示的に設定すること(例: origin: 'https://example.com')
|
|
17
|
+
origin: false,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// fastify-raw-body を使う場合は以下を有効にする
|
|
21
|
+
// await fastify.register(fastifyRawBody)
|
|
22
|
+
|
|
23
|
+
fastify.get('/', (): { status: string } => {
|
|
24
|
+
return { status: 'ok' }
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
await fastify.listen({ port: 3000, host: '0.0.0.0' })
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
main().catch((error: unknown) => {
|
|
31
|
+
fastify.log.error(error)
|
|
32
|
+
// eslint-disable-next-line unicorn/no-process-exit
|
|
33
|
+
process.exit(1)
|
|
34
|
+
})
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fastify バリアントのテスト
|
|
3
|
+
*
|
|
4
|
+
* Fastify + @fastify/cors が正しく動作することを確認する。
|
|
5
|
+
* 実際のポートへのバインドは行わず、inject() でリクエストを注入する。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import Fastify from 'fastify'
|
|
9
|
+
import cors from '@fastify/cors'
|
|
10
|
+
|
|
11
|
+
describe('Fastify アプリケーション', () => {
|
|
12
|
+
it('Fastify インスタンスを作成できる', () => {
|
|
13
|
+
const app = Fastify()
|
|
14
|
+
expect(app).toBeDefined()
|
|
15
|
+
void app.close()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('@fastify/cors を登録できる', async () => {
|
|
19
|
+
const app = Fastify()
|
|
20
|
+
await app.register(cors, { origin: false })
|
|
21
|
+
expect(app).toBeDefined()
|
|
22
|
+
await app.close()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('GET / が 200 を返す', async () => {
|
|
26
|
+
const app = Fastify()
|
|
27
|
+
await app.register(cors, { origin: false })
|
|
28
|
+
|
|
29
|
+
app.get('/', async (_request, _reply) => {
|
|
30
|
+
return { status: 'ok' }
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const response = await app.inject({ method: 'GET', url: '/' })
|
|
34
|
+
expect(response.statusCode).toBe(200)
|
|
35
|
+
expect(JSON.parse(response.body)).toEqual({ status: 'ok' })
|
|
36
|
+
|
|
37
|
+
await app.close()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('存在しないルートが 404 を返す', async () => {
|
|
41
|
+
const app = Fastify()
|
|
42
|
+
await app.register(cors, { origin: false })
|
|
43
|
+
|
|
44
|
+
const response = await app.inject({ method: 'GET', url: '/nonexistent' })
|
|
45
|
+
expect(response.statusCode).toBe(404)
|
|
46
|
+
|
|
47
|
+
await app.close()
|
|
48
|
+
})
|
|
49
|
+
})
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# 任意のレジストリに Docker image を公開orビルドする。
|
|
2
|
+
# プルリクの作成・更新時に動作する。
|
|
3
|
+
|
|
4
|
+
name: Docker
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
- master
|
|
11
|
+
types:
|
|
12
|
+
- opened
|
|
13
|
+
- synchronize
|
|
14
|
+
paths:
|
|
15
|
+
- .github/workflows/docker.yml
|
|
16
|
+
pull_request_target:
|
|
17
|
+
branches:
|
|
18
|
+
- main
|
|
19
|
+
- master
|
|
20
|
+
types:
|
|
21
|
+
- opened
|
|
22
|
+
- synchronize
|
|
23
|
+
- reopened
|
|
24
|
+
- closed
|
|
25
|
+
merge_group:
|
|
26
|
+
|
|
27
|
+
concurrency:
|
|
28
|
+
# pull_request と pull_request_target が同一グループになると互いをキャンセルしてしまうため
|
|
29
|
+
# event_name を含めることで両イベントのキャンセルを独立させる
|
|
30
|
+
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}
|
|
31
|
+
cancel-in-progress: true
|
|
32
|
+
|
|
33
|
+
jobs:
|
|
34
|
+
post-approval-request:
|
|
35
|
+
name: Post approval request
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
# フォーク PR のときのみ承認リクエストを投稿する(closed は不要)
|
|
38
|
+
if: github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository && github.event.action != 'closed'
|
|
39
|
+
continue-on-error: true
|
|
40
|
+
permissions:
|
|
41
|
+
issues: write
|
|
42
|
+
pull-requests: write
|
|
43
|
+
steps:
|
|
44
|
+
- name: Find existing approval request comment
|
|
45
|
+
id: find-comment
|
|
46
|
+
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4
|
|
47
|
+
with:
|
|
48
|
+
issue-number: ${{ github.event.pull_request.number }}
|
|
49
|
+
comment-author: github-actions[bot]
|
|
50
|
+
body-includes: Environment 承認待ち
|
|
51
|
+
|
|
52
|
+
- name: Post or update approval request comment
|
|
53
|
+
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
|
|
54
|
+
with:
|
|
55
|
+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
|
|
56
|
+
issue-number: ${{ github.event.pull_request.number }}
|
|
57
|
+
edit-mode: replace
|
|
58
|
+
body: |
|
|
59
|
+
## Environment 承認待ち
|
|
60
|
+
|
|
61
|
+
この PR のビルドを実行するには、Environment `fork-pr-build` の承認が必要です。
|
|
62
|
+
|
|
63
|
+
[Actions run を確認して承認してください](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}?pr=${{ github.event.pull_request.number }})
|
|
64
|
+
|
|
65
|
+
approval-gate:
|
|
66
|
+
name: Approval gate
|
|
67
|
+
runs-on: ubuntu-latest
|
|
68
|
+
needs: post-approval-request
|
|
69
|
+
# post-approval-request の結果に関わらず常に実行する
|
|
70
|
+
if: always()
|
|
71
|
+
# フォーク PR かつ closed でない場合のみ Environment で手動承認が必要
|
|
72
|
+
environment: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository && github.event.action != 'closed' && 'fork-pr-build' || '' }}
|
|
73
|
+
permissions: {}
|
|
74
|
+
steps:
|
|
75
|
+
- name: Approval granted
|
|
76
|
+
run: echo "Approval gate passed"
|
|
77
|
+
|
|
78
|
+
docker-ci:
|
|
79
|
+
name: Docker CI
|
|
80
|
+
needs: approval-gate
|
|
81
|
+
if: always() && needs.approval-gate.result == 'success' && (github.event.action != 'closed' || github.event.pull_request.merged == true)
|
|
82
|
+
uses: book000/templates/.github/workflows/reusable-docker.yml@master
|
|
83
|
+
with:
|
|
84
|
+
targets: >-
|
|
85
|
+
[
|
|
86
|
+
{ imageName: "tomacheese/twitter-dm-memo", context: ".", file: "Dockerfile", packageName: "twitter-dm-memo" }
|
|
87
|
+
]
|
|
88
|
+
# registry: registry.hub.docker.com # default: ghcr.io
|
|
89
|
+
# platforms: linux/amd64 # default: linux/amd64,linux/arm64
|
|
90
|
+
secrets:
|
|
91
|
+
DOCKER_USERNAME: ${{ github.actor }}
|
|
92
|
+
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Node.js でビルド・テストを実行する。バージョンは .node-version に記載されているものを利用する
|
|
2
|
+
|
|
3
|
+
name: Node CI
|
|
4
|
+
|
|
5
|
+
on:
|
|
6
|
+
push:
|
|
7
|
+
branches:
|
|
8
|
+
- main
|
|
9
|
+
- master
|
|
10
|
+
pull_request:
|
|
11
|
+
branches:
|
|
12
|
+
- main
|
|
13
|
+
- master
|
|
14
|
+
pull_request_target:
|
|
15
|
+
branches:
|
|
16
|
+
- main
|
|
17
|
+
- master
|
|
18
|
+
types:
|
|
19
|
+
- opened
|
|
20
|
+
- synchronize
|
|
21
|
+
- reopened
|
|
22
|
+
merge_group:
|
|
23
|
+
|
|
24
|
+
concurrency:
|
|
25
|
+
# pull_request と pull_request_target が同一グループになると互いをキャンセルしてしまうため
|
|
26
|
+
# event_name を含めることで両イベントのキャンセルを独立させる
|
|
27
|
+
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}
|
|
28
|
+
cancel-in-progress: true
|
|
29
|
+
|
|
30
|
+
jobs:
|
|
31
|
+
post-approval-request:
|
|
32
|
+
name: Post approval request
|
|
33
|
+
runs-on: ubuntu-latest
|
|
34
|
+
# フォーク PR のときのみ承認リクエストを投稿する(closed は不要)
|
|
35
|
+
if: github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository && github.event.action != 'closed'
|
|
36
|
+
continue-on-error: true
|
|
37
|
+
permissions:
|
|
38
|
+
issues: write
|
|
39
|
+
pull-requests: write
|
|
40
|
+
steps:
|
|
41
|
+
- name: Find existing approval request comment
|
|
42
|
+
id: find-comment
|
|
43
|
+
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4
|
|
44
|
+
with:
|
|
45
|
+
issue-number: ${{ github.event.pull_request.number }}
|
|
46
|
+
comment-author: github-actions[bot]
|
|
47
|
+
body-includes: Environment 承認待ち
|
|
48
|
+
|
|
49
|
+
- name: Post or update approval request comment
|
|
50
|
+
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
|
|
51
|
+
with:
|
|
52
|
+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
|
|
53
|
+
issue-number: ${{ github.event.pull_request.number }}
|
|
54
|
+
edit-mode: replace
|
|
55
|
+
body: |
|
|
56
|
+
## Environment 承認待ち
|
|
57
|
+
|
|
58
|
+
この PR のビルドを実行するには、Environment `fork-pr-build` の承認が必要です。
|
|
59
|
+
|
|
60
|
+
[Actions run を確認して承認してください](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}?pr=${{ github.event.pull_request.number }})
|
|
61
|
+
|
|
62
|
+
approval-gate:
|
|
63
|
+
name: Approval gate
|
|
64
|
+
runs-on: ubuntu-latest
|
|
65
|
+
needs: post-approval-request
|
|
66
|
+
# post-approval-request の結果に関わらず常に実行する
|
|
67
|
+
if: always()
|
|
68
|
+
# フォーク PR かつ closed でない場合のみ Environment で手動承認が必要
|
|
69
|
+
environment: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository && github.event.action != 'closed' && 'fork-pr-build' || '' }}
|
|
70
|
+
permissions: {}
|
|
71
|
+
steps:
|
|
72
|
+
- name: Approval granted
|
|
73
|
+
run: echo "Approval gate passed"
|
|
74
|
+
|
|
75
|
+
node-ci:
|
|
76
|
+
name: Node CI
|
|
77
|
+
needs: approval-gate
|
|
78
|
+
if: always() && needs.approval-gate.result == 'success'
|
|
79
|
+
uses: book000/templates/.github/workflows/reusable-nodejs-ci-pnpm.yml@master
|