@book000/create-ts 0.2.76 → 0.2.78
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/README.md +85 -0
- package/dist/index.mjs +37 -32
- package/dist/src/generate.d.ts +11 -9
- package/dist/src/generate.js +11 -9
- package/dist/src/index.js +14 -26
- package/dist/src/prompts.d.ts +6 -6
- package/dist/src/prompts.js +10 -11
- package/dist/src/template.d.ts +4 -4
- package/dist/src/template.js +5 -5
- package/dist/src/types.d.ts +5 -5
- package/dist/src/validate.d.ts +8 -8
- package/dist/src/validate.js +8 -8
- package/dist/test/generate.test.js +22 -22
- package/dist/test/validate.test.js +20 -20
- package/dist/tsdown.config.js +2 -2
- package/package.json +2 -2
- package/templates/nodejs/base/package.json +1 -1
- package/templates/nodejs/base/pnpm-lock.yaml +5 -5
- package/templates/nodejs/base/src/main.ts +1 -1
- package/templates/nodejs/base/test/smoke.test.ts +7 -7
- package/templates/nodejs/config-batch/package.json +1 -1
- package/templates/nodejs/config-batch/pnpm-lock.yaml +5 -5
- package/templates/nodejs/config-batch/src/config.ts +2 -2
- package/templates/nodejs/config-batch/src/main.ts +6 -6
- package/templates/nodejs/config-batch/test/config.test.ts +8 -9
- package/templates/nodejs/discord-bot/package.json +1 -1
- package/templates/nodejs/discord-bot/pnpm-lock.yaml +5 -5
- package/templates/nodejs/discord-bot/src/config.ts +3 -3
- package/templates/nodejs/discord-bot/src/discord.ts +6 -6
- package/templates/nodejs/discord-bot/src/main.ts +4 -4
- package/templates/nodejs/discord-bot/test/discord.test.ts +9 -9
- package/templates/nodejs/fastify/package.json +1 -1
- package/templates/nodejs/fastify/pnpm-lock.yaml +5 -5
- package/templates/nodejs/fastify/src/main.ts +5 -5
- package/templates/nodejs/fastify/test/app.test.ts +8 -8
- package/templates/workflows/docker.yml +6 -7
- package/templates/workflows/nodejs-ci-pnpm.yml +1 -1
|
@@ -16,8 +16,8 @@ importers:
|
|
|
16
16
|
version: 14.28.1
|
|
17
17
|
devDependencies:
|
|
18
18
|
'@book000/eslint-config':
|
|
19
|
-
specifier: 1.16.
|
|
20
|
-
version: 1.16.
|
|
19
|
+
specifier: 1.16.119
|
|
20
|
+
version: 1.16.119(eslint@10.14.0(supports-color@8.1.1))(supports-color@8.1.1)(typescript@6.0.3)
|
|
21
21
|
'@types/jest':
|
|
22
22
|
specifier: 30.0.0
|
|
23
23
|
version: 30.0.0
|
|
@@ -216,8 +216,8 @@ packages:
|
|
|
216
216
|
'@bcoe/v8-coverage@0.2.3':
|
|
217
217
|
resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==}
|
|
218
218
|
|
|
219
|
-
'@book000/eslint-config@1.16.
|
|
220
|
-
resolution: {integrity: sha512-
|
|
219
|
+
'@book000/eslint-config@1.16.119':
|
|
220
|
+
resolution: {integrity: sha512-88ij8dAem4IRrHySoxd7m/Q477jAw7V6lJLefilzxnkD3l7hYME8+hNWnRx9A83GCbrOT1G1G60vgB4zmqC83Q==}
|
|
221
221
|
peerDependencies:
|
|
222
222
|
eslint: 10.14.0
|
|
223
223
|
|
|
@@ -2960,7 +2960,7 @@ snapshots:
|
|
|
2960
2960
|
|
|
2961
2961
|
'@bcoe/v8-coverage@0.2.3': {}
|
|
2962
2962
|
|
|
2963
|
-
'@book000/eslint-config@1.16.
|
|
2963
|
+
'@book000/eslint-config@1.16.119(eslint@10.14.0(supports-color@8.1.1))(supports-color@8.1.1)(typescript@6.0.3)':
|
|
2964
2964
|
dependencies:
|
|
2965
2965
|
'@typescript-eslint/parser': 8.72.1(eslint@10.14.0(supports-color@8.1.1))(supports-color@8.1.1)(typescript@6.0.3)
|
|
2966
2966
|
eslint: 10.14.0(supports-color@8.1.1)
|
|
@@ -3,15 +3,15 @@ import { ConfigFramework } from '@book000/node-utils'
|
|
|
3
3
|
import { ConfigInterface } from './config'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Discord
|
|
6
|
+
* Main class of the Discord bot.
|
|
7
7
|
*/
|
|
8
8
|
export class Discord {
|
|
9
9
|
private readonly client: Client
|
|
10
10
|
private readonly config: ConfigFramework<ConfigInterface>
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @param client - Discord
|
|
14
|
-
* @param config -
|
|
13
|
+
* @param client - Discord client
|
|
14
|
+
* @param config - Configuration framework
|
|
15
15
|
*/
|
|
16
16
|
constructor(client: Client, config: ConfigFramework<ConfigInterface>) {
|
|
17
17
|
this.client = client
|
|
@@ -19,17 +19,17 @@ export class Discord {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Returns the configuration framework.
|
|
23
23
|
*/
|
|
24
24
|
protected getConfig(): ConfigFramework<ConfigInterface> {
|
|
25
25
|
return this.config
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Called when the bot is ready.
|
|
30
30
|
*/
|
|
31
31
|
public onReady(): void {
|
|
32
32
|
console.log(`Logged in as ${this.client.user?.tag ?? 'unknown'}`)
|
|
33
|
-
// TODO: this.getConfig().get('key')
|
|
33
|
+
// TODO: read settings with this.getConfig().get('key') and implement the bot's behavior
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -4,24 +4,24 @@ import { ConfigInterface } from './config'
|
|
|
4
4
|
import { Discord } from './discord'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Configuration framework implementation.
|
|
8
8
|
*/
|
|
9
9
|
class Configuration extends ConfigFramework<ConfigInterface> {
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Returns the validation rules.
|
|
12
12
|
*/
|
|
13
13
|
protected validates(): Record<string, (config: ConfigInterface) => boolean> {
|
|
14
14
|
return {
|
|
15
15
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
16
16
|
'token is required': (config) => config.token !== undefined,
|
|
17
17
|
'token is string': (config) => typeof config.token === 'string',
|
|
18
|
-
// TODO:
|
|
18
|
+
// TODO: add validation rules
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* Entry point.
|
|
25
25
|
*/
|
|
26
26
|
async function main(): Promise<void> {
|
|
27
27
|
const config = new Configuration('./data/config.json')
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* discord-bot
|
|
2
|
+
* Tests for the discord-bot variant.
|
|
3
3
|
*
|
|
4
|
-
* discord.js
|
|
5
|
-
*
|
|
4
|
+
* Checks that the discord.js Client can be initialized and the basic behavior of the Discord class.
|
|
5
|
+
* Does not log in with a real token.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { Client, GatewayIntentBits } from 'discord.js'
|
|
@@ -10,7 +10,7 @@ import { Discord } from '../src/discord'
|
|
|
10
10
|
import type { ConfigFramework } from '@book000/node-utils'
|
|
11
11
|
import type { ConfigInterface } from '../src/config'
|
|
12
12
|
|
|
13
|
-
/**
|
|
13
|
+
/** Mock ConfigFramework for tests. */
|
|
14
14
|
const createMockConfig = (): ConfigFramework<ConfigInterface> =>
|
|
15
15
|
({
|
|
16
16
|
get: jest.fn(),
|
|
@@ -19,7 +19,7 @@ const createMockConfig = (): ConfigFramework<ConfigInterface> =>
|
|
|
19
19
|
getValidateFailures: jest.fn().mockReturnValue([]),
|
|
20
20
|
}) as unknown as ConfigFramework<ConfigInterface>
|
|
21
21
|
|
|
22
|
-
describe('Discord
|
|
22
|
+
describe('Discord class', () => {
|
|
23
23
|
let client: Client
|
|
24
24
|
|
|
25
25
|
beforeEach(() => {
|
|
@@ -30,13 +30,13 @@ describe('Discord クラス', () => {
|
|
|
30
30
|
client.destroy()
|
|
31
31
|
})
|
|
32
32
|
|
|
33
|
-
it('Discord
|
|
33
|
+
it('can create a Discord instance', () => {
|
|
34
34
|
const mockConfig = createMockConfig()
|
|
35
35
|
const discord = new Discord(client, mockConfig)
|
|
36
36
|
expect(discord).toBeDefined()
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
it('onReady()
|
|
39
|
+
it('can call onReady()', () => {
|
|
40
40
|
const mockConfig = createMockConfig()
|
|
41
41
|
const discord = new Discord(client, mockConfig)
|
|
42
42
|
const consoleSpy = jest.spyOn(console, 'log').mockImplementation()
|
|
@@ -48,13 +48,13 @@ describe('Discord クラス', () => {
|
|
|
48
48
|
})
|
|
49
49
|
|
|
50
50
|
describe('discord.js Client', () => {
|
|
51
|
-
it('Client
|
|
51
|
+
it('can create a Client instance', () => {
|
|
52
52
|
const testClient = new Client({ intents: [GatewayIntentBits.Guilds] })
|
|
53
53
|
expect(testClient).toBeDefined()
|
|
54
54
|
testClient.destroy()
|
|
55
55
|
})
|
|
56
56
|
|
|
57
|
-
it('
|
|
57
|
+
it('can set multiple intents', () => {
|
|
58
58
|
const testClient = new Client({
|
|
59
59
|
intents: [
|
|
60
60
|
GatewayIntentBits.Guilds,
|
|
@@ -16,8 +16,8 @@ importers:
|
|
|
16
16
|
version: 5.12.8
|
|
17
17
|
devDependencies:
|
|
18
18
|
'@book000/eslint-config':
|
|
19
|
-
specifier: 1.16.
|
|
20
|
-
version: 1.16.
|
|
19
|
+
specifier: 1.16.119
|
|
20
|
+
version: 1.16.119(eslint@10.14.0(supports-color@8.1.1))(supports-color@8.1.1)(typescript@6.0.3)
|
|
21
21
|
'@types/jest':
|
|
22
22
|
specifier: 30.0.0
|
|
23
23
|
version: 30.0.0
|
|
@@ -216,8 +216,8 @@ packages:
|
|
|
216
216
|
'@bcoe/v8-coverage@0.2.3':
|
|
217
217
|
resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==}
|
|
218
218
|
|
|
219
|
-
'@book000/eslint-config@1.16.
|
|
220
|
-
resolution: {integrity: sha512-
|
|
219
|
+
'@book000/eslint-config@1.16.119':
|
|
220
|
+
resolution: {integrity: sha512-88ij8dAem4IRrHySoxd7m/Q477jAw7V6lJLefilzxnkD3l7hYME8+hNWnRx9A83GCbrOT1G1G60vgB4zmqC83Q==}
|
|
221
221
|
peerDependencies:
|
|
222
222
|
eslint: 10.14.0
|
|
223
223
|
|
|
@@ -2668,7 +2668,7 @@ snapshots:
|
|
|
2668
2668
|
|
|
2669
2669
|
'@bcoe/v8-coverage@0.2.3': {}
|
|
2670
2670
|
|
|
2671
|
-
'@book000/eslint-config@1.16.
|
|
2671
|
+
'@book000/eslint-config@1.16.119(eslint@10.14.0(supports-color@8.1.1))(supports-color@8.1.1)(typescript@6.0.3)':
|
|
2672
2672
|
dependencies:
|
|
2673
2673
|
'@typescript-eslint/parser': 8.72.1(eslint@10.14.0(supports-color@8.1.1))(supports-color@8.1.1)(typescript@6.0.3)
|
|
2674
2674
|
eslint: 10.14.0(supports-color@8.1.1)
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import Fastify from 'fastify'
|
|
2
2
|
import cors from '@fastify/cors'
|
|
3
|
-
// fastify-raw-body
|
|
3
|
+
// fastify-raw-body is for when the raw POST body is needed (e.g. webhook signature verification)
|
|
4
4
|
// import fastifyRawBody from 'fastify-raw-body'
|
|
5
5
|
|
|
6
|
-
/** Fastify
|
|
6
|
+
/** Fastify instance. */
|
|
7
7
|
const fastify = Fastify({
|
|
8
8
|
logger: true,
|
|
9
9
|
})
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Entry point.
|
|
13
13
|
*/
|
|
14
14
|
async function main(): Promise<void> {
|
|
15
15
|
await fastify.register(cors, {
|
|
16
|
-
// TODO:
|
|
16
|
+
// TODO: in production, set the allowed origins explicitly (e.g. origin: 'https://example.com')
|
|
17
17
|
origin: false,
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
// fastify-raw-body
|
|
20
|
+
// Enable the following to use fastify-raw-body
|
|
21
21
|
// await fastify.register(fastifyRawBody)
|
|
22
22
|
|
|
23
23
|
fastify.get('/', (): { status: string } => {
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* fastify
|
|
2
|
+
* Tests for the fastify variant.
|
|
3
3
|
*
|
|
4
|
-
* Fastify
|
|
5
|
-
*
|
|
4
|
+
* Checks that Fastify and @fastify/cors work.
|
|
5
|
+
* Requests are injected with inject() instead of binding a real port.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import Fastify from 'fastify'
|
|
9
9
|
import cors from '@fastify/cors'
|
|
10
10
|
|
|
11
|
-
describe('Fastify
|
|
12
|
-
it('Fastify
|
|
11
|
+
describe('Fastify application', () => {
|
|
12
|
+
it('can create a Fastify instance', () => {
|
|
13
13
|
const app = Fastify()
|
|
14
14
|
expect(app).toBeDefined()
|
|
15
15
|
void app.close()
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
it('@fastify/cors
|
|
18
|
+
it('can register @fastify/cors', async () => {
|
|
19
19
|
const app = Fastify()
|
|
20
20
|
await app.register(cors, { origin: false })
|
|
21
21
|
expect(app).toBeDefined()
|
|
22
22
|
await app.close()
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
it('GET /
|
|
25
|
+
it('GET / returns 200', async () => {
|
|
26
26
|
const app = Fastify()
|
|
27
27
|
await app.register(cors, { origin: false })
|
|
28
28
|
|
|
@@ -37,7 +37,7 @@ describe('Fastify アプリケーション', () => {
|
|
|
37
37
|
await app.close()
|
|
38
38
|
})
|
|
39
39
|
|
|
40
|
-
it('
|
|
40
|
+
it('returns 404 for an unknown route', async () => {
|
|
41
41
|
const app = Fastify()
|
|
42
42
|
await app.register(cors, { origin: false })
|
|
43
43
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
1
|
+
# Builds (and publishes) a Docker image to a registry.
|
|
2
|
+
# Runs when a pull request is created or updated.
|
|
3
3
|
|
|
4
4
|
name: Docker
|
|
5
5
|
|
|
@@ -25,8 +25,7 @@ on:
|
|
|
25
25
|
merge_group:
|
|
26
26
|
|
|
27
27
|
concurrency:
|
|
28
|
-
# pull_request
|
|
29
|
-
# event_name を含めることで両イベントのキャンセルを独立させる
|
|
28
|
+
# event_name keeps pull_request and pull_request_target from cancelling each other.
|
|
30
29
|
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}
|
|
31
30
|
cancel-in-progress: true
|
|
32
31
|
|
|
@@ -34,7 +33,7 @@ jobs:
|
|
|
34
33
|
post-approval-request:
|
|
35
34
|
name: Post approval request
|
|
36
35
|
runs-on: ubuntu-latest
|
|
37
|
-
#
|
|
36
|
+
# Post the approval request only for fork PRs (not needed on closed)
|
|
38
37
|
if: github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository && github.event.action != 'closed'
|
|
39
38
|
continue-on-error: true
|
|
40
39
|
permissions:
|
|
@@ -66,9 +65,9 @@ jobs:
|
|
|
66
65
|
name: Approval gate
|
|
67
66
|
runs-on: ubuntu-latest
|
|
68
67
|
needs: post-approval-request
|
|
69
|
-
# post-approval-request
|
|
68
|
+
# Always run, regardless of the result of post-approval-request
|
|
70
69
|
if: always()
|
|
71
|
-
#
|
|
70
|
+
# Manual approval via the Environment is required only for fork PRs that are not closed
|
|
72
71
|
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
72
|
permissions: {}
|
|
74
73
|
steps:
|