@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
package/dist/src/template.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { TemplateConfig } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param relativePath -
|
|
3
|
+
* Reads a bundled template file as a string.
|
|
4
|
+
* @param relativePath - Path relative to the templates root
|
|
5
5
|
*/
|
|
6
6
|
export declare function readTemplate(relativePath: string): string;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @param variant -
|
|
8
|
+
* Reads and parses a variant's template.json.
|
|
9
|
+
* @param variant - Variant name
|
|
10
10
|
*/
|
|
11
11
|
export declare function fetchTemplateConfig(variant: string): TemplateConfig;
|
package/dist/src/template.js
CHANGED
|
@@ -2,19 +2,19 @@ import { readFileSync } from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
5
|
-
/**
|
|
5
|
+
/** Root directory of the bundled templates. */
|
|
6
6
|
const TEMPLATES_DIR = path.join(__dirname, '../templates');
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @param relativePath -
|
|
8
|
+
* Reads a bundled template file as a string.
|
|
9
|
+
* @param relativePath - Path relative to the templates root
|
|
10
10
|
*/
|
|
11
11
|
export function readTemplate(relativePath) {
|
|
12
12
|
const filePath = path.join(TEMPLATES_DIR, relativePath);
|
|
13
13
|
return readFileSync(filePath, 'utf8');
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @param variant -
|
|
16
|
+
* Reads and parses a variant's template.json.
|
|
17
|
+
* @param variant - Variant name
|
|
18
18
|
*/
|
|
19
19
|
export function fetchTemplateConfig(variant) {
|
|
20
20
|
const content = readTemplate(`nodejs/${variant}/template.json`);
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Supported project variants. */
|
|
2
2
|
export type Variant = 'base' | 'config-batch' | 'fastify' | 'discord-bot';
|
|
3
|
-
/**
|
|
3
|
+
/** All options for a project setup. */
|
|
4
4
|
export interface ProjectOptions {
|
|
5
5
|
name: string;
|
|
6
6
|
org: string;
|
|
@@ -19,15 +19,15 @@ export interface ProjectOptions {
|
|
|
19
19
|
overwrite: boolean;
|
|
20
20
|
outDir: string;
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
22
|
+
/** Schema of a variant's template.json. */
|
|
23
23
|
export interface TemplateConfig {
|
|
24
24
|
configSchema: boolean;
|
|
25
25
|
dependencies?: string[];
|
|
26
26
|
devDependencies?: string[];
|
|
27
27
|
scripts?: Record<string, string>;
|
|
28
28
|
depcheckIgnore?: string[];
|
|
29
|
-
/**
|
|
29
|
+
/** Files always copied (paths relative to the variant directory). */
|
|
30
30
|
src: string[];
|
|
31
|
-
/** --test
|
|
31
|
+
/** Files copied only with --test. */
|
|
32
32
|
testSrc?: string[];
|
|
33
33
|
}
|
package/dist/src/validate.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Validates a project name (npm package name rule): lowercase alphanumerics, hyphens, underscores and dots, starting with an alphanumeric, at most 214 characters.
|
|
3
|
+
* Returns an error message, or undefined if valid.
|
|
4
4
|
*/
|
|
5
5
|
export declare function validateProjectName(value: string | undefined): string | undefined;
|
|
6
6
|
/**
|
|
7
|
-
* GitHub
|
|
8
|
-
*
|
|
7
|
+
* Validates a GitHub organization / user name: alphanumerics, hyphens and dots, starting with an alphanumeric.
|
|
8
|
+
* Returns an error message, or undefined if valid.
|
|
9
9
|
*/
|
|
10
10
|
export declare function validateOrgName(value: string | undefined): string | undefined;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Validates a repository name: alphanumerics, hyphens, underscores and dots; a leading underscore is allowed.
|
|
13
|
+
* Returns an error message, or undefined if valid.
|
|
14
14
|
*/
|
|
15
15
|
export declare function validateRepoName(value: string | undefined): string | undefined;
|
|
16
16
|
/**
|
|
17
|
-
* SPDX
|
|
18
|
-
*
|
|
17
|
+
* Validates an SPDX license identifier by character set only (alphanumerics, dots and hyphens); it does not check that the identifier exists.
|
|
18
|
+
* Returns an error message, or undefined if valid.
|
|
19
19
|
*/
|
|
20
20
|
export declare function validateLicense(value: string | undefined): string | undefined;
|
package/dist/src/validate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Validates a project name (npm package name rule): lowercase alphanumerics, hyphens, underscores and dots, starting with an alphanumeric, at most 214 characters.
|
|
3
|
+
* Returns an error message, or undefined if valid.
|
|
4
4
|
*/
|
|
5
5
|
export function validateProjectName(value) {
|
|
6
6
|
if (!value)
|
|
@@ -10,8 +10,8 @@ export function validateProjectName(value) {
|
|
|
10
10
|
: undefined;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* GitHub
|
|
14
|
-
*
|
|
13
|
+
* Validates a GitHub organization / user name: alphanumerics, hyphens and dots, starting with an alphanumeric.
|
|
14
|
+
* Returns an error message, or undefined if valid.
|
|
15
15
|
*/
|
|
16
16
|
export function validateOrgName(value) {
|
|
17
17
|
if (!value)
|
|
@@ -21,8 +21,8 @@ export function validateOrgName(value) {
|
|
|
21
21
|
: '組織 / ユーザー名は英数字・ハイフン・ドットのみ使用できます';
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* Validates a repository name: alphanumerics, hyphens, underscores and dots; a leading underscore is allowed.
|
|
25
|
+
* Returns an error message, or undefined if valid.
|
|
26
26
|
*/
|
|
27
27
|
export function validateRepoName(value) {
|
|
28
28
|
if (!value)
|
|
@@ -32,8 +32,8 @@ export function validateRepoName(value) {
|
|
|
32
32
|
: 'リポジトリ名は英数字・ハイフン・アンダースコア・ドットのみ使用できます';
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* SPDX
|
|
36
|
-
*
|
|
35
|
+
* Validates an SPDX license identifier by character set only (alphanumerics, dots and hyphens); it does not check that the identifier exists.
|
|
36
|
+
* Returns an error message, or undefined if valid.
|
|
37
37
|
*/
|
|
38
38
|
export function validateLicense(value) {
|
|
39
39
|
if (!value)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { generateGitignore, patchDockerWorkflow, patchPackageJson, patchTsConfig, updateDepcheck, } from '../src/generate.js';
|
|
3
|
-
// ----
|
|
4
|
-
/**
|
|
3
|
+
// ---- Test fixtures ----
|
|
4
|
+
/** Base object equivalent to the template tsconfig.json. */
|
|
5
5
|
const BASE_TSCONFIG = {
|
|
6
6
|
compilerOptions: {
|
|
7
7
|
target: 'es2020',
|
|
@@ -12,7 +12,7 @@ const BASE_TSCONFIG = {
|
|
|
12
12
|
},
|
|
13
13
|
include: ['src/**/*'],
|
|
14
14
|
};
|
|
15
|
-
/**
|
|
15
|
+
/** Base object equivalent to the template package.json. */
|
|
16
16
|
const BASE_PACKAGE_JSON = {
|
|
17
17
|
name: '@book000/template',
|
|
18
18
|
version: '1.0.0',
|
|
@@ -51,58 +51,58 @@ describe('patchPackageJson', () => {
|
|
|
51
51
|
esm: false,
|
|
52
52
|
test: false,
|
|
53
53
|
};
|
|
54
|
-
it('org
|
|
54
|
+
it('lowercases the org in name even if it is uppercase', () => {
|
|
55
55
|
const result = patchPackageJson(BASE_PACKAGE_JSON, { ...baseOptions, org: 'Book000' }, 20);
|
|
56
56
|
expect(result.name).toBe('@book000/my-app');
|
|
57
57
|
});
|
|
58
|
-
it('--esm: type
|
|
58
|
+
it('--esm: type becomes "module"', () => {
|
|
59
59
|
const result = patchPackageJson(BASE_PACKAGE_JSON, { ...baseOptions, esm: true, test: false }, 20);
|
|
60
60
|
expect(result.type).toBe('module');
|
|
61
61
|
});
|
|
62
|
-
it('--esm --test: jest
|
|
62
|
+
it('--esm --test: the jest field gets the ESM config', () => {
|
|
63
63
|
const result = patchPackageJson(BASE_PACKAGE_JSON, { ...baseOptions, esm: true, test: true }, 20);
|
|
64
64
|
expect(result.jest.preset).toBe('ts-jest/presets/default-esm');
|
|
65
65
|
expect(result.jest.extensionsToTreatAsEsm).toContain('.ts');
|
|
66
66
|
});
|
|
67
|
-
it('--no-test: scripts.test
|
|
67
|
+
it('--no-test: scripts.test and the jest field are removed', () => {
|
|
68
68
|
const result = patchPackageJson(BASE_PACKAGE_JSON, { ...baseOptions, test: false }, 20);
|
|
69
69
|
expect(result.scripts.test).toBeUndefined();
|
|
70
70
|
expect(result.jest).toBeUndefined();
|
|
71
71
|
});
|
|
72
|
-
it('--no-test --esm: jest
|
|
72
|
+
it('--no-test --esm: the jest field is not added', () => {
|
|
73
73
|
const result = patchPackageJson(BASE_PACKAGE_JSON, { ...baseOptions, esm: true, test: false }, 20);
|
|
74
74
|
expect(result.jest).toBeUndefined();
|
|
75
75
|
});
|
|
76
|
-
it('homepage
|
|
76
|
+
it('empty homepage: the homepage field is not added', () => {
|
|
77
77
|
const result = patchPackageJson(BASE_PACKAGE_JSON, { ...baseOptions, homepage: '' }, 20);
|
|
78
78
|
expect(result.homepage).toBeUndefined();
|
|
79
79
|
});
|
|
80
|
-
it('homepage
|
|
80
|
+
it('homepage given: the homepage field is added', () => {
|
|
81
81
|
const result = patchPackageJson(BASE_PACKAGE_JSON, { ...baseOptions, homepage: 'https://example.com' }, 20);
|
|
82
82
|
expect(result.homepage).toBe('https://example.com');
|
|
83
83
|
});
|
|
84
84
|
});
|
|
85
85
|
// ---- patchTsConfig ----
|
|
86
86
|
describe('patchTsConfig', () => {
|
|
87
|
-
it('CJS
|
|
87
|
+
it('CJS (default): module stays "commonjs"', () => {
|
|
88
88
|
const result = patchTsConfig(BASE_TSCONFIG, { esm: false, test: false });
|
|
89
89
|
const opts = result.compilerOptions;
|
|
90
90
|
expect(opts.module).toBe('commonjs');
|
|
91
91
|
expect(opts.moduleResolution).toBe('bundler');
|
|
92
92
|
});
|
|
93
|
-
it('ESM: module
|
|
93
|
+
it('ESM: module becomes "es2015" and moduleResolution stays "bundler"', () => {
|
|
94
94
|
const result = patchTsConfig(BASE_TSCONFIG, { esm: true, test: false });
|
|
95
95
|
const opts = result.compilerOptions;
|
|
96
96
|
expect(opts.module).toBe('es2015');
|
|
97
97
|
expect(opts.moduleResolution).toBe('bundler');
|
|
98
98
|
});
|
|
99
|
-
it('--test:
|
|
99
|
+
it('--test: "jest" is added to types', () => {
|
|
100
100
|
const result = patchTsConfig(BASE_TSCONFIG, { esm: false, test: true });
|
|
101
101
|
const types = result.compilerOptions.types;
|
|
102
102
|
expect(types).toContain('node');
|
|
103
103
|
expect(types).toContain('jest');
|
|
104
104
|
});
|
|
105
|
-
it('--no-test: types
|
|
105
|
+
it('--no-test: types stays ["node"]', () => {
|
|
106
106
|
const result = patchTsConfig(BASE_TSCONFIG, { esm: false, test: false });
|
|
107
107
|
const types = result.compilerOptions.types;
|
|
108
108
|
expect(types).toEqual(['node']);
|
|
@@ -116,17 +116,17 @@ describe('patchDockerWorkflow', () => {
|
|
|
116
116
|
{ imageName: "tomacheese/twitter-dm-memo", context: ".", file: "Dockerfile", packageName: "twitter-dm-memo" }
|
|
117
117
|
]
|
|
118
118
|
`.trim();
|
|
119
|
-
it('imageName
|
|
119
|
+
it('replaces imageName', () => {
|
|
120
120
|
const result = patchDockerWorkflow(DOCKER_YML, 'book000', 'my-app');
|
|
121
121
|
expect(result).toContain('book000/my-app');
|
|
122
122
|
expect(result).not.toContain('tomacheese/twitter-dm-memo');
|
|
123
123
|
});
|
|
124
|
-
it('
|
|
124
|
+
it('lowercases the GHCR path even if org is uppercase', () => {
|
|
125
125
|
const result = patchDockerWorkflow(DOCKER_YML, 'Book000', 'my-app');
|
|
126
126
|
expect(result).toContain('book000/my-app');
|
|
127
127
|
expect(result).not.toContain('Book000');
|
|
128
128
|
});
|
|
129
|
-
it('packageName
|
|
129
|
+
it('replaces packageName', () => {
|
|
130
130
|
const result = patchDockerWorkflow(DOCKER_YML, 'book000', 'my-app');
|
|
131
131
|
expect(result).toContain('packageName: "my-app"');
|
|
132
132
|
expect(result).not.toContain('packageName: "twitter-dm-memo"');
|
|
@@ -134,14 +134,14 @@ describe('patchDockerWorkflow', () => {
|
|
|
134
134
|
});
|
|
135
135
|
// ---- generateGitignore ----
|
|
136
136
|
describe('generateGitignore', () => {
|
|
137
|
-
it('
|
|
137
|
+
it('basic: includes the pnpm section', () => {
|
|
138
138
|
const result = generateGitignore(false);
|
|
139
139
|
expect(result).toContain('node_modules/');
|
|
140
140
|
expect(result).toContain('# pnpm');
|
|
141
141
|
expect(result).toContain('pnpm-debug.log*');
|
|
142
142
|
expect(result).not.toContain('data/');
|
|
143
143
|
});
|
|
144
|
-
it('--ignore-data:
|
|
144
|
+
it('--ignore-data: additionally appends the data/ section', () => {
|
|
145
145
|
const result = generateGitignore(true);
|
|
146
146
|
expect(result).toContain('# pnpm');
|
|
147
147
|
expect(result).toContain('# データディレクトリ');
|
|
@@ -153,15 +153,15 @@ describe('updateDepcheck', () => {
|
|
|
153
153
|
const BASE_DEPCHECK = {
|
|
154
154
|
ignores: ['@types/node', 'run-z'],
|
|
155
155
|
};
|
|
156
|
-
it('depcheckIgnore
|
|
156
|
+
it('adds the depcheckIgnore packages to ignores', () => {
|
|
157
157
|
const result = updateDepcheck(BASE_DEPCHECK, ['typescript-json-schema'], false);
|
|
158
158
|
expect(result.ignores).toContain('typescript-json-schema');
|
|
159
159
|
});
|
|
160
|
-
it('--test: @types/jest
|
|
160
|
+
it('--test: adds @types/jest to ignores', () => {
|
|
161
161
|
const result = updateDepcheck(BASE_DEPCHECK, [], true);
|
|
162
162
|
expect(result.ignores).toContain('@types/jest');
|
|
163
163
|
});
|
|
164
|
-
it('
|
|
164
|
+
it('does not duplicate a package passed twice', () => {
|
|
165
165
|
const result = updateDepcheck(BASE_DEPCHECK, ['typescript-json-schema', 'typescript-json-schema'], false);
|
|
166
166
|
const ignores = result.ignores;
|
|
167
167
|
const count = ignores.filter((i) => i === 'typescript-json-schema').length;
|
|
@@ -1,70 +1,70 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { validateLicense, validateOrgName, validateProjectName, validateRepoName, } from '../src/validate.js';
|
|
3
3
|
describe('validateProjectName', () => {
|
|
4
|
-
it('my-app →
|
|
4
|
+
it('my-app → valid', () => {
|
|
5
5
|
expect(validateProjectName('my-app')).toBeUndefined();
|
|
6
6
|
});
|
|
7
|
-
it('MyApp →
|
|
7
|
+
it('MyApp → invalid (uppercase)', () => {
|
|
8
8
|
expect(validateProjectName('MyApp')).toBeDefined();
|
|
9
9
|
});
|
|
10
|
-
it('-bad-start →
|
|
10
|
+
it('-bad-start → invalid (starts with a hyphen)', () => {
|
|
11
11
|
expect(validateProjectName('-bad-start')).toBeDefined();
|
|
12
12
|
});
|
|
13
|
-
it('"has space" →
|
|
13
|
+
it('"has space" → invalid (whitespace)', () => {
|
|
14
14
|
expect(validateProjectName('has space')).toBeDefined();
|
|
15
15
|
});
|
|
16
|
-
it(`${'a'.repeat(215)} →
|
|
16
|
+
it(`${'a'.repeat(215)} → invalid (215 characters)`, () => {
|
|
17
17
|
expect(validateProjectName('a'.repeat(215))).toBeDefined();
|
|
18
18
|
});
|
|
19
|
-
it(`${'a'.repeat(214)} →
|
|
19
|
+
it(`${'a'.repeat(214)} → valid (214 characters)`, () => {
|
|
20
20
|
expect(validateProjectName('a'.repeat(214))).toBeUndefined();
|
|
21
21
|
});
|
|
22
|
-
it('
|
|
22
|
+
it('empty string → invalid (required)', () => {
|
|
23
23
|
expect(validateProjectName('')).toBeDefined();
|
|
24
24
|
});
|
|
25
|
-
it('undefined →
|
|
25
|
+
it('undefined → invalid (required)', () => {
|
|
26
26
|
expect(validateProjectName(undefined)).toBeDefined();
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
29
|
describe('validateOrgName', () => {
|
|
30
|
-
it('book000 →
|
|
30
|
+
it('book000 → valid', () => {
|
|
31
31
|
expect(validateOrgName('book000')).toBeUndefined();
|
|
32
32
|
});
|
|
33
|
-
it('Book.000 →
|
|
33
|
+
it('Book.000 → valid (uppercase and dots allowed)', () => {
|
|
34
34
|
expect(validateOrgName('Book.000')).toBeUndefined();
|
|
35
35
|
});
|
|
36
|
-
it('"bad org!" →
|
|
36
|
+
it('"bad org!" → invalid (whitespace and symbols)', () => {
|
|
37
37
|
expect(validateOrgName('bad org!')).toBeDefined();
|
|
38
38
|
});
|
|
39
|
-
it('
|
|
39
|
+
it('empty string → invalid (required)', () => {
|
|
40
40
|
expect(validateOrgName('')).toBeDefined();
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
43
|
describe('validateRepoName', () => {
|
|
44
|
-
it('my-repo →
|
|
44
|
+
it('my-repo → valid', () => {
|
|
45
45
|
expect(validateRepoName('my-repo')).toBeUndefined();
|
|
46
46
|
});
|
|
47
|
-
it('_private →
|
|
47
|
+
it('_private → valid (leading underscore)', () => {
|
|
48
48
|
expect(validateRepoName('_private')).toBeUndefined();
|
|
49
49
|
});
|
|
50
|
-
it('-bad →
|
|
50
|
+
it('-bad → invalid (starts with a hyphen)', () => {
|
|
51
51
|
expect(validateRepoName('-bad')).toBeDefined();
|
|
52
52
|
});
|
|
53
|
-
it('
|
|
53
|
+
it('empty string → invalid (required)', () => {
|
|
54
54
|
expect(validateRepoName('')).toBeDefined();
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
describe('validateLicense', () => {
|
|
58
|
-
it('MIT →
|
|
58
|
+
it('MIT → valid', () => {
|
|
59
59
|
expect(validateLicense('MIT')).toBeUndefined();
|
|
60
60
|
});
|
|
61
|
-
it('Apache-2.0 →
|
|
61
|
+
it('Apache-2.0 → valid', () => {
|
|
62
62
|
expect(validateLicense('Apache-2.0')).toBeUndefined();
|
|
63
63
|
});
|
|
64
|
-
it('"MIT License" →
|
|
64
|
+
it('"MIT License" → invalid (whitespace)', () => {
|
|
65
65
|
expect(validateLicense('MIT License')).toBeDefined();
|
|
66
66
|
});
|
|
67
|
-
it('
|
|
67
|
+
it('empty string → invalid (required)', () => {
|
|
68
68
|
expect(validateLicense('')).toBeDefined();
|
|
69
69
|
});
|
|
70
70
|
});
|
package/dist/tsdown.config.js
CHANGED
|
@@ -5,5 +5,5 @@ export default defineConfig({
|
|
|
5
5
|
target: 'node20',
|
|
6
6
|
clean: true,
|
|
7
7
|
});
|
|
8
|
-
//
|
|
9
|
-
// tsdown
|
|
8
|
+
// Keep `#!/usr/bin/env node` as the first line of src/index.ts.
|
|
9
|
+
// tsdown detects the shebang, preserves it in the output and runs chmod +x (no banner option needed).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@book000/create-ts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.78",
|
|
4
4
|
"description": "Create book000-style TypeScript projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"execa": "10.2.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@book000/eslint-config": "1.16.
|
|
32
|
+
"@book000/eslint-config": "1.16.119",
|
|
33
33
|
"@types/node": "26.6.6",
|
|
34
34
|
"eslint": "10.14.0",
|
|
35
35
|
"prettier": "3.9.10",
|
|
@@ -9,8 +9,8 @@ importers:
|
|
|
9
9
|
.:
|
|
10
10
|
devDependencies:
|
|
11
11
|
'@book000/eslint-config':
|
|
12
|
-
specifier: 1.16.
|
|
13
|
-
version: 1.16.
|
|
12
|
+
specifier: 1.16.119
|
|
13
|
+
version: 1.16.119(eslint@10.14.0(supports-color@8.1.1))(supports-color@8.1.1)(typescript@6.0.3)
|
|
14
14
|
'@types/jest':
|
|
15
15
|
specifier: 30.0.0
|
|
16
16
|
version: 30.0.0
|
|
@@ -206,8 +206,8 @@ packages:
|
|
|
206
206
|
'@bcoe/v8-coverage@0.2.3':
|
|
207
207
|
resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==}
|
|
208
208
|
|
|
209
|
-
'@book000/eslint-config@1.16.
|
|
210
|
-
resolution: {integrity: sha512-
|
|
209
|
+
'@book000/eslint-config@1.16.119':
|
|
210
|
+
resolution: {integrity: sha512-88ij8dAem4IRrHySoxd7m/Q477jAw7V6lJLefilzxnkD3l7hYME8+hNWnRx9A83GCbrOT1G1G60vgB4zmqC83Q==}
|
|
211
211
|
peerDependencies:
|
|
212
212
|
eslint: 10.14.0
|
|
213
213
|
|
|
@@ -2453,7 +2453,7 @@ snapshots:
|
|
|
2453
2453
|
|
|
2454
2454
|
'@bcoe/v8-coverage@0.2.3': {}
|
|
2455
2455
|
|
|
2456
|
-
'@book000/eslint-config@1.16.
|
|
2456
|
+
'@book000/eslint-config@1.16.119(eslint@10.14.0(supports-color@8.1.1))(supports-color@8.1.1)(typescript@6.0.3)':
|
|
2457
2457
|
dependencies:
|
|
2458
2458
|
'@typescript-eslint/parser': 8.72.1(eslint@10.14.0(supports-color@8.1.1))(supports-color@8.1.1)(typescript@6.0.3)
|
|
2459
2459
|
eslint: 10.14.0(supports-color@8.1.1)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* base
|
|
2
|
+
* Smoke tests for the base variant.
|
|
3
3
|
*
|
|
4
|
-
* TypeScript
|
|
5
|
-
*
|
|
4
|
+
* Checks basic TypeScript features and Node.js built-in behavior.
|
|
5
|
+
* Does not connect to external services.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
describe('TypeScript
|
|
9
|
-
it('async/await
|
|
8
|
+
describe('TypeScript basics', () => {
|
|
9
|
+
it('async/await works', async () => {
|
|
10
10
|
const delay = (ms: number): Promise<string> =>
|
|
11
11
|
new Promise((resolve) => setTimeout(() => resolve('ok'), ms))
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ describe('TypeScript 基本機能', () => {
|
|
|
14
14
|
expect(result).toBe('ok')
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
it('
|
|
17
|
+
it('generics work', () => {
|
|
18
18
|
function identity<T>(value: T): T {
|
|
19
19
|
return value
|
|
20
20
|
}
|
|
@@ -22,7 +22,7 @@ describe('TypeScript 基本機能', () => {
|
|
|
22
22
|
expect(identity('hello')).toBe('hello')
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
it('
|
|
25
|
+
it('throwing and catching an Error works', async () => {
|
|
26
26
|
const failingFn = async (): Promise<never> => {
|
|
27
27
|
throw new Error('test error')
|
|
28
28
|
}
|
|
@@ -13,8 +13,8 @@ importers:
|
|
|
13
13
|
version: 1.26.9
|
|
14
14
|
devDependencies:
|
|
15
15
|
'@book000/eslint-config':
|
|
16
|
-
specifier: 1.16.
|
|
17
|
-
version: 1.16.
|
|
16
|
+
specifier: 1.16.119
|
|
17
|
+
version: 1.16.119(eslint@10.14.0(supports-color@8.1.1))(supports-color@8.1.1)(typescript@6.0.3)
|
|
18
18
|
'@types/jest':
|
|
19
19
|
specifier: 30.0.0
|
|
20
20
|
version: 30.0.0
|
|
@@ -213,8 +213,8 @@ packages:
|
|
|
213
213
|
'@bcoe/v8-coverage@0.2.3':
|
|
214
214
|
resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==}
|
|
215
215
|
|
|
216
|
-
'@book000/eslint-config@1.16.
|
|
217
|
-
resolution: {integrity: sha512-
|
|
216
|
+
'@book000/eslint-config@1.16.119':
|
|
217
|
+
resolution: {integrity: sha512-88ij8dAem4IRrHySoxd7m/Q477jAw7V6lJLefilzxnkD3l7hYME8+hNWnRx9A83GCbrOT1G1G60vgB4zmqC83Q==}
|
|
218
218
|
peerDependencies:
|
|
219
219
|
eslint: 10.14.0
|
|
220
220
|
|
|
@@ -2872,7 +2872,7 @@ snapshots:
|
|
|
2872
2872
|
|
|
2873
2873
|
'@bcoe/v8-coverage@0.2.3': {}
|
|
2874
2874
|
|
|
2875
|
-
'@book000/eslint-config@1.16.
|
|
2875
|
+
'@book000/eslint-config@1.16.119(eslint@10.14.0(supports-color@8.1.1))(supports-color@8.1.1)(typescript@6.0.3)':
|
|
2876
2876
|
dependencies:
|
|
2877
2877
|
'@typescript-eslint/parser': 8.72.1(eslint@10.14.0(supports-color@8.1.1))(supports-color@8.1.1)(typescript@6.0.3)
|
|
2878
2878
|
eslint: 10.14.0(supports-color@8.1.1)
|
|
@@ -2,22 +2,22 @@ import { ConfigFramework } from '@book000/node-utils'
|
|
|
2
2
|
import { ConfigInterface } from './config'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Configuration framework implementation.
|
|
6
6
|
*/
|
|
7
7
|
class Configuration extends ConfigFramework<ConfigInterface> {
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Returns the validation rules.
|
|
10
10
|
*/
|
|
11
11
|
protected validates(): Record<string, (config: ConfigInterface) => boolean> {
|
|
12
12
|
return {
|
|
13
|
-
// TODO:
|
|
14
|
-
//
|
|
13
|
+
// TODO: add validation rules
|
|
14
|
+
// e.g. 'someKey is required': (config) => config.someKey !== undefined,
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Entry point.
|
|
21
21
|
*/
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
23
23
|
async function main(): Promise<void> {
|
|
@@ -28,7 +28,7 @@ async function main(): Promise<void> {
|
|
|
28
28
|
`Configuration validation failed: ${config.getValidateFailures().join(', ')}`
|
|
29
29
|
)
|
|
30
30
|
}
|
|
31
|
-
// TODO: config.get('key')
|
|
31
|
+
// TODO: read settings with config.get('key') and implement the batch logic
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
main().catch((error: unknown) => {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* config-batch
|
|
2
|
+
* Tests for the config-batch variant.
|
|
3
3
|
*
|
|
4
|
-
* @book000/node-utils
|
|
5
|
-
*
|
|
6
|
-
* 外部サービスへの接続は行わない。
|
|
4
|
+
* Checks that ConfigFramework from @book000/node-utils can be subclassed and that the validation logic works as expected.
|
|
5
|
+
* Does not connect to external services.
|
|
7
6
|
*/
|
|
8
7
|
|
|
9
8
|
import * as fs from 'node:fs'
|
|
@@ -11,13 +10,13 @@ import * as os from 'node:os'
|
|
|
11
10
|
import * as path from 'node:path'
|
|
12
11
|
import { ConfigFramework } from '@book000/node-utils'
|
|
13
12
|
|
|
14
|
-
/**
|
|
13
|
+
/** Configuration interface for tests. */
|
|
15
14
|
interface TestConfig {
|
|
16
15
|
apiKey: string
|
|
17
16
|
timeout: number
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
/**
|
|
19
|
+
/** ConfigFramework implementation for tests. */
|
|
21
20
|
class TestConfiguration extends ConfigFramework<TestConfig> {
|
|
22
21
|
protected validates(): Record<string, (config: TestConfig) => boolean> {
|
|
23
22
|
return {
|
|
@@ -45,13 +44,13 @@ describe('ConfigFramework', () => {
|
|
|
45
44
|
fs.rmSync(tmpDir, { recursive: true })
|
|
46
45
|
})
|
|
47
46
|
|
|
48
|
-
it('
|
|
47
|
+
it('can define a subclass', () => {
|
|
49
48
|
fs.writeFileSync(configPath, JSON.stringify({ apiKey: 'test', timeout: 30 }))
|
|
50
49
|
const config = new TestConfiguration(configPath)
|
|
51
50
|
expect(config).toBeDefined()
|
|
52
51
|
})
|
|
53
52
|
|
|
54
|
-
it('
|
|
53
|
+
it('accepts a valid configuration', () => {
|
|
55
54
|
fs.writeFileSync(
|
|
56
55
|
configPath,
|
|
57
56
|
JSON.stringify({ apiKey: 'test-key', timeout: 30 })
|
|
@@ -62,7 +61,7 @@ describe('ConfigFramework', () => {
|
|
|
62
61
|
expect(config.getValidateFailures()).toHaveLength(0)
|
|
63
62
|
})
|
|
64
63
|
|
|
65
|
-
it('
|
|
64
|
+
it('detects an invalid configuration (negative timeout)', () => {
|
|
66
65
|
fs.writeFileSync(
|
|
67
66
|
configPath,
|
|
68
67
|
JSON.stringify({ apiKey: 'test-key', timeout: -1 })
|