prisma-generator-express 1.30.0 → 1.32.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/generators/generateRouter.js +1 -1
- package/dist/generators/generateRouterFastify.js +1 -1
- package/dist/generators/generateUnifiedDocs.js +1 -1
- package/dist/generators/generateUnifiedDocs.js.map +1 -1
- package/dist/utils/copyFiles.js +35 -47
- package/dist/utils/copyFiles.js.map +1 -1
- package/package.json +1 -1
- package/src/copy/routeConfig.express.ts +14 -0
- package/src/copy/routeConfig.fastify.ts +19 -0
- package/src/copy/routeConfig.ts +31 -34
- package/src/generators/generateRouter.ts +1 -1
- package/src/generators/generateRouterFastify.ts +1 -1
- package/src/generators/generateUnifiedDocs.ts +1 -1
- package/src/utils/copyFiles.ts +38 -51
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
${modelName}Count,
|
|
46
46
|
${modelName}GroupBy
|
|
47
47
|
} from './${modelName}Handlers.js'
|
|
48
|
-
import type { RouteConfig } from '../routeConfig.js'
|
|
48
|
+
import type { RouteConfig } from '../routeConfig.target.js'
|
|
49
49
|
import { parseQueryParams } from '../parseQueryParams.js'
|
|
50
50
|
import { buildModelOpenApi } from '../buildModelOpenApi.js'
|
|
51
51
|
import { transformResult } from '../operationRuntime.js'
|
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
${modelName}Count,
|
|
45
45
|
${modelName}GroupBy,
|
|
46
46
|
} from './${modelName}Handlers.js'
|
|
47
|
-
import type { RouteConfig, FastifyHookHandler } from '../routeConfig.js'
|
|
47
|
+
import type { RouteConfig, FastifyHookHandler } from '../routeConfig.target.js'
|
|
48
48
|
import { parseQueryParams } from '../parseQueryParams.js'
|
|
49
49
|
import { buildModelOpenApi } from '../buildModelOpenApi.js'
|
|
50
50
|
import { mapError, transformResult } from '../operationRuntime.js'
|
|
@@ -11,7 +11,7 @@ function generateUnifiedDocs(models, target = 'express') {
|
|
|
11
11
|
const frameworkImport = target === 'fastify'
|
|
12
12
|
? `import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'`
|
|
13
13
|
: `import { Request, Response } from 'express'`;
|
|
14
|
-
const routeConfigImport = `import type { RouteConfig } from './routeConfig.js'`;
|
|
14
|
+
const routeConfigImport = `import type { RouteConfig } from './routeConfig.target.js'`;
|
|
15
15
|
const handlerType = target === 'fastify'
|
|
16
16
|
? `(config: any) => (request: FastifyRequest, reply: FastifyReply) => Promise<void>`
|
|
17
17
|
: `(config: any) => (req: Request, res: Response) => any`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateUnifiedDocs.js","sourceRoot":"","sources":["../../src/generators/generateUnifiedDocs.ts"],"names":[],"mappings":";;AAEA,kDAkLC;AAlLD,SAAgB,mBAAmB,CACjC,MAAgB,EAChB,SAAiB,SAAS;IAE1B,MAAM,OAAO,GAAG,MAAM;SACnB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,KAAK,kBAAkB,KAAK,IAAI,KAAK,UAAU,CAAC;SAC3E,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,MAAM,eAAe,GAAG,MAAM;SAC3B,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,KAAK,KAAK,MAAM,CAAC;SAC1C,IAAI,CAAC,KAAK,CAAC,CAAA;IAEd,MAAM,eAAe,GACnB,MAAM,KAAK,SAAS;QAClB,CAAC,CAAC,8EAA8E;QAChF,CAAC,CAAC,6CAA6C,CAAA;IAEnD,MAAM,iBAAiB,GAAG,
|
|
1
|
+
{"version":3,"file":"generateUnifiedDocs.js","sourceRoot":"","sources":["../../src/generators/generateUnifiedDocs.ts"],"names":[],"mappings":";;AAEA,kDAkLC;AAlLD,SAAgB,mBAAmB,CACjC,MAAgB,EAChB,SAAiB,SAAS;IAE1B,MAAM,OAAO,GAAG,MAAM;SACnB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,KAAK,k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,OAAO;;;;;;;;;;;;;;;;;;;;;EAqBP,CAAA;AACF,CAAC"}
|
package/dist/utils/copyFiles.js
CHANGED
|
@@ -41,47 +41,35 @@ const SHARED_FILES = [
|
|
|
41
41
|
'buildModelOpenApi.ts',
|
|
42
42
|
'operationDefinitions.ts',
|
|
43
43
|
'misc.ts',
|
|
44
|
+
'routeConfig.ts',
|
|
45
|
+
'docsRenderer.ts',
|
|
44
46
|
];
|
|
45
|
-
const TARGET_FILES = {
|
|
46
|
-
express: ['routeConfig.ts'],
|
|
47
|
-
fastify: ['routeConfig.ts'],
|
|
48
|
-
};
|
|
49
47
|
function resolveTemplateDir(subpath) {
|
|
50
|
-
const fromSibling = path.join(__dirname, '..', subpath);
|
|
51
|
-
if (fs.existsSync(fromSibling))
|
|
52
|
-
return fromSibling;
|
|
53
48
|
const fromSrc = path.join(__dirname, '..', '..', 'src', subpath);
|
|
54
49
|
if (fs.existsSync(fromSrc))
|
|
55
50
|
return fromSrc;
|
|
56
|
-
|
|
51
|
+
const fromDist = path.join(__dirname, '..', subpath);
|
|
52
|
+
if (fs.existsSync(fromDist))
|
|
53
|
+
return fromDist;
|
|
54
|
+
throw new Error(`Template directory "${subpath}" not found.\n` +
|
|
57
55
|
` Searched:\n` +
|
|
58
|
-
` ${fromSibling}\n` +
|
|
59
56
|
` ${fromSrc}\n` +
|
|
57
|
+
` ${fromDist}\n` +
|
|
58
|
+
` __dirname: ${__dirname}\n` +
|
|
60
59
|
` Ensure template files are included in the published package.`);
|
|
61
60
|
}
|
|
62
|
-
function getTargetSourceDir(copyBase, target) {
|
|
63
|
-
if (target === 'express')
|
|
64
|
-
return copyBase;
|
|
65
|
-
const targetDir = path.join(copyBase, target);
|
|
66
|
-
if (!fs.existsSync(targetDir)) {
|
|
67
|
-
throw new Error(`[prisma-generator-express] Target template directory not found: ${targetDir}\n` +
|
|
68
|
-
` Expected directory for target "${target}" at: ${targetDir}`);
|
|
69
|
-
}
|
|
70
|
-
return targetDir;
|
|
71
|
-
}
|
|
72
61
|
function escapeRegex(str) {
|
|
73
62
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
74
63
|
}
|
|
75
|
-
|
|
64
|
+
function copyFileSync(srcDir, destDir, filename, options) {
|
|
76
65
|
const srcPath = path.join(srcDir, filename);
|
|
77
|
-
const
|
|
66
|
+
const destFilename = options?.destFilename || filename;
|
|
67
|
+
const destPath = path.join(destDir, destFilename);
|
|
78
68
|
if (!fs.existsSync(srcPath)) {
|
|
79
69
|
if (options?.required) {
|
|
80
|
-
|
|
81
|
-
return false;
|
|
70
|
+
return `Required file not found: ${srcPath}`;
|
|
82
71
|
}
|
|
83
|
-
|
|
84
|
-
return true;
|
|
72
|
+
return null;
|
|
85
73
|
}
|
|
86
74
|
const destDirPath = path.dirname(destPath);
|
|
87
75
|
if (!fs.existsSync(destDirPath)) {
|
|
@@ -103,45 +91,45 @@ async function copyFile(srcDir, destDir, filename, options) {
|
|
|
103
91
|
content = header + content;
|
|
104
92
|
}
|
|
105
93
|
fs.writeFileSync(destPath, content);
|
|
106
|
-
|
|
107
|
-
return true;
|
|
94
|
+
return null;
|
|
108
95
|
}
|
|
109
96
|
async function copyFiles(options, target) {
|
|
110
97
|
const outputPath = options.generator.output?.value;
|
|
111
98
|
if (!outputPath)
|
|
112
99
|
return;
|
|
113
100
|
const copyBase = resolveTemplateDir('copy');
|
|
114
|
-
|
|
101
|
+
const errors = [];
|
|
115
102
|
console.log(` Copying utility files to: ${outputPath} (target: ${target})`);
|
|
116
103
|
for (const file of SHARED_FILES) {
|
|
117
|
-
const
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
const targetSrcDir = getTargetSourceDir(copyBase, target);
|
|
122
|
-
for (const file of TARGET_FILES[target]) {
|
|
123
|
-
const ok = await copyFile(targetSrcDir, outputPath, file, {
|
|
124
|
-
required: true,
|
|
125
|
-
});
|
|
126
|
-
if (!ok)
|
|
127
|
-
allCopied = false;
|
|
104
|
+
const err = copyFileSync(copyBase, outputPath, file, { required: true });
|
|
105
|
+
if (err)
|
|
106
|
+
errors.push(err);
|
|
128
107
|
}
|
|
108
|
+
const targetConfigFile = `routeConfig.${target}.ts`;
|
|
109
|
+
const err = copyFileSync(copyBase, outputPath, targetConfigFile, {
|
|
110
|
+
required: true,
|
|
111
|
+
destFilename: 'routeConfig.target.ts',
|
|
112
|
+
importRewrites: [{ from: './routeConfig', to: './routeConfig' }],
|
|
113
|
+
});
|
|
114
|
+
if (err)
|
|
115
|
+
errors.push(err);
|
|
129
116
|
const clientDir = path.join(outputPath, 'client');
|
|
130
117
|
if (!fs.existsSync(clientDir)) {
|
|
131
118
|
fs.mkdirSync(clientDir, { recursive: true });
|
|
132
119
|
}
|
|
133
120
|
const clientSrcDir = resolveTemplateDir('client');
|
|
134
|
-
const
|
|
121
|
+
const clientErr = copyFileSync(clientSrcDir, clientDir, 'encodeQueryParams.ts', {
|
|
135
122
|
required: true,
|
|
136
123
|
importRewrites: [{ from: '../copy/misc.js', to: '../misc.js' }],
|
|
137
124
|
});
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
125
|
+
if (clientErr)
|
|
126
|
+
errors.push(clientErr);
|
|
127
|
+
if (errors.length > 0) {
|
|
128
|
+
throw new Error(`Failed to copy ${errors.length} required file(s):\n` +
|
|
129
|
+
errors.map((e) => ` - ${e}`).join('\n') +
|
|
130
|
+
`\n copyBase: ${copyBase}` +
|
|
131
|
+
`\n __dirname: ${__dirname}`);
|
|
145
132
|
}
|
|
133
|
+
console.log(` ✓ Utility files copied successfully`);
|
|
146
134
|
}
|
|
147
135
|
//# sourceMappingURL=copyFiles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copyFiles.js","sourceRoot":"","sources":["../../src/utils/copyFiles.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|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E,EAAE,YAAY,EAAE,CAAC;KAChE,CACF,CAAA;IACD,IAAI,SAAS;QAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAErC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,kBAAkB,MAAM,CAAC,MAAM,sBAAsB;YACrD,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YACxC,iBAAiB,QAAQ,EAAE;YAC3B,kBAAkB,SAAS,EAAE,CAC9B,CAAA;IACH,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAA;AACtD,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Request, RequestHandler } from 'express'
|
|
2
|
+
import {
|
|
3
|
+
BaseOperationConfig,
|
|
4
|
+
BaseRouteConfig,
|
|
5
|
+
QueryBuilderConfig,
|
|
6
|
+
OpenApiServerConfig,
|
|
7
|
+
OpenApiSecuritySchemeConfig,
|
|
8
|
+
} from './routeConfig'
|
|
9
|
+
|
|
10
|
+
export type { QueryBuilderConfig, OpenApiServerConfig, OpenApiSecuritySchemeConfig }
|
|
11
|
+
|
|
12
|
+
export type OperationConfig = BaseOperationConfig<RequestHandler>
|
|
13
|
+
|
|
14
|
+
export type RouteConfig = BaseRouteConfig<RequestHandler, Request>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FastifyRequest, FastifyReply } from 'fastify'
|
|
2
|
+
import {
|
|
3
|
+
BaseOperationConfig,
|
|
4
|
+
BaseRouteConfig,
|
|
5
|
+
QueryBuilderConfig,
|
|
6
|
+
OpenApiServerConfig,
|
|
7
|
+
OpenApiSecuritySchemeConfig,
|
|
8
|
+
} from './routeConfig'
|
|
9
|
+
|
|
10
|
+
export type { QueryBuilderConfig, OpenApiServerConfig, OpenApiSecuritySchemeConfig }
|
|
11
|
+
|
|
12
|
+
export type FastifyHookHandler = (
|
|
13
|
+
request: FastifyRequest,
|
|
14
|
+
reply: FastifyReply,
|
|
15
|
+
) => Promise<void> | void
|
|
16
|
+
|
|
17
|
+
export type OperationConfig = BaseOperationConfig<FastifyHookHandler>
|
|
18
|
+
|
|
19
|
+
export type RouteConfig = BaseRouteConfig<FastifyHookHandler, FastifyRequest>
|
package/src/copy/routeConfig.ts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import type { FastifyRequest, FastifyReply } from 'fastify'
|
|
2
|
-
|
|
3
|
-
export type FastifyHookHandler = (
|
|
4
|
-
request: FastifyRequest,
|
|
5
|
-
reply: FastifyReply,
|
|
6
|
-
) => Promise<void> | void
|
|
7
|
-
|
|
8
|
-
export interface OperationConfig {
|
|
9
|
-
before?: FastifyHookHandler[]
|
|
10
|
-
after?: FastifyHookHandler[]
|
|
11
|
-
shape?: Record<string, any>
|
|
12
|
-
}
|
|
13
|
-
|
|
14
1
|
export interface QueryBuilderConfig {
|
|
15
2
|
enabled?: boolean
|
|
16
3
|
port?: number
|
|
@@ -33,7 +20,13 @@ export interface OpenApiSecuritySchemeConfig {
|
|
|
33
20
|
description?: string
|
|
34
21
|
}
|
|
35
22
|
|
|
36
|
-
export interface
|
|
23
|
+
export interface BaseOperationConfig<HookHandler> {
|
|
24
|
+
before?: HookHandler[]
|
|
25
|
+
after?: HookHandler[]
|
|
26
|
+
shape?: Record<string, any>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface BaseRouteConfig<HookHandler, RequestType> {
|
|
37
30
|
enableAll?: boolean
|
|
38
31
|
addModelPrefix?: boolean
|
|
39
32
|
customUrlPrefix?: string
|
|
@@ -49,7 +42,7 @@ export interface RouteConfig {
|
|
|
49
42
|
openApiSecurity?: Record<string, string[]>[]
|
|
50
43
|
|
|
51
44
|
guard?: {
|
|
52
|
-
resolveVariant?: (request:
|
|
45
|
+
resolveVariant?: (request: RequestType) => string | undefined
|
|
53
46
|
variantHeader?: string
|
|
54
47
|
}
|
|
55
48
|
|
|
@@ -61,22 +54,26 @@ export interface RouteConfig {
|
|
|
61
54
|
distinctCountLimit?: number
|
|
62
55
|
}
|
|
63
56
|
|
|
64
|
-
findUnique?:
|
|
65
|
-
findUniqueOrThrow?:
|
|
66
|
-
findFirst?:
|
|
67
|
-
findFirstOrThrow?:
|
|
68
|
-
findMany?:
|
|
69
|
-
findManyPaginated?:
|
|
70
|
-
create?:
|
|
71
|
-
createMany?:
|
|
72
|
-
createManyAndReturn?:
|
|
73
|
-
update?:
|
|
74
|
-
updateMany?:
|
|
75
|
-
updateManyAndReturn?:
|
|
76
|
-
upsert?:
|
|
77
|
-
delete?:
|
|
78
|
-
deleteMany?:
|
|
79
|
-
aggregate?:
|
|
80
|
-
count?:
|
|
81
|
-
groupBy?:
|
|
82
|
-
}
|
|
57
|
+
findUnique?: BaseOperationConfig<HookHandler>
|
|
58
|
+
findUniqueOrThrow?: BaseOperationConfig<HookHandler>
|
|
59
|
+
findFirst?: BaseOperationConfig<HookHandler>
|
|
60
|
+
findFirstOrThrow?: BaseOperationConfig<HookHandler>
|
|
61
|
+
findMany?: BaseOperationConfig<HookHandler>
|
|
62
|
+
findManyPaginated?: BaseOperationConfig<HookHandler>
|
|
63
|
+
create?: BaseOperationConfig<HookHandler>
|
|
64
|
+
createMany?: BaseOperationConfig<HookHandler>
|
|
65
|
+
createManyAndReturn?: BaseOperationConfig<HookHandler>
|
|
66
|
+
update?: BaseOperationConfig<HookHandler>
|
|
67
|
+
updateMany?: BaseOperationConfig<HookHandler>
|
|
68
|
+
updateManyAndReturn?: BaseOperationConfig<HookHandler>
|
|
69
|
+
upsert?: BaseOperationConfig<HookHandler>
|
|
70
|
+
delete?: BaseOperationConfig<HookHandler>
|
|
71
|
+
deleteMany?: BaseOperationConfig<HookHandler>
|
|
72
|
+
aggregate?: BaseOperationConfig<HookHandler>
|
|
73
|
+
count?: BaseOperationConfig<HookHandler>
|
|
74
|
+
groupBy?: BaseOperationConfig<HookHandler>
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type OperationConfig = BaseOperationConfig<any>
|
|
78
|
+
|
|
79
|
+
export type RouteConfig = BaseRouteConfig<any, any>
|
|
@@ -58,7 +58,7 @@ import {
|
|
|
58
58
|
${modelName}Count,
|
|
59
59
|
${modelName}GroupBy
|
|
60
60
|
} from './${modelName}Handlers.js'
|
|
61
|
-
import type { RouteConfig } from '../routeConfig.js'
|
|
61
|
+
import type { RouteConfig } from '../routeConfig.target.js'
|
|
62
62
|
import { parseQueryParams } from '../parseQueryParams.js'
|
|
63
63
|
import { buildModelOpenApi } from '../buildModelOpenApi.js'
|
|
64
64
|
import { transformResult } from '../operationRuntime.js'
|
|
@@ -55,7 +55,7 @@ import {
|
|
|
55
55
|
${modelName}Count,
|
|
56
56
|
${modelName}GroupBy,
|
|
57
57
|
} from './${modelName}Handlers.js'
|
|
58
|
-
import type { RouteConfig, FastifyHookHandler } from '../routeConfig.js'
|
|
58
|
+
import type { RouteConfig, FastifyHookHandler } from '../routeConfig.target.js'
|
|
59
59
|
import { parseQueryParams } from '../parseQueryParams.js'
|
|
60
60
|
import { buildModelOpenApi } from '../buildModelOpenApi.js'
|
|
61
61
|
import { mapError, transformResult } from '../operationRuntime.js'
|
|
@@ -17,7 +17,7 @@ export function generateUnifiedDocs(
|
|
|
17
17
|
? `import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'`
|
|
18
18
|
: `import { Request, Response } from 'express'`
|
|
19
19
|
|
|
20
|
-
const routeConfigImport = `import type { RouteConfig } from './routeConfig.js'`
|
|
20
|
+
const routeConfigImport = `import type { RouteConfig } from './routeConfig.target.js'`
|
|
21
21
|
|
|
22
22
|
const handlerType =
|
|
23
23
|
target === 'fastify'
|
package/src/utils/copyFiles.ts
CHANGED
|
@@ -8,66 +8,52 @@ const SHARED_FILES = [
|
|
|
8
8
|
'buildModelOpenApi.ts',
|
|
9
9
|
'operationDefinitions.ts',
|
|
10
10
|
'misc.ts',
|
|
11
|
+
'routeConfig.ts',
|
|
12
|
+
'docsRenderer.ts',
|
|
11
13
|
]
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
interface CopyFileOptions {
|
|
16
|
+
required?: boolean
|
|
17
|
+
importRewrites?: Array<{ from: string; to: string }>
|
|
18
|
+
destFilename?: string
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
function resolveTemplateDir(subpath: string): string {
|
|
19
|
-
const fromSibling = path.join(__dirname, '..', subpath)
|
|
20
|
-
if (fs.existsSync(fromSibling)) return fromSibling
|
|
21
|
-
|
|
22
22
|
const fromSrc = path.join(__dirname, '..', '..', 'src', subpath)
|
|
23
23
|
if (fs.existsSync(fromSrc)) return fromSrc
|
|
24
24
|
|
|
25
|
+
const fromDist = path.join(__dirname, '..', subpath)
|
|
26
|
+
if (fs.existsSync(fromDist)) return fromDist
|
|
27
|
+
|
|
25
28
|
throw new Error(
|
|
26
|
-
`
|
|
29
|
+
`Template directory "${subpath}" not found.\n` +
|
|
27
30
|
` Searched:\n` +
|
|
28
|
-
` ${fromSibling}\n` +
|
|
29
31
|
` ${fromSrc}\n` +
|
|
32
|
+
` ${fromDist}\n` +
|
|
33
|
+
` __dirname: ${__dirname}\n` +
|
|
30
34
|
` Ensure template files are included in the published package.`,
|
|
31
35
|
)
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
function getTargetSourceDir(copyBase: string, target: Target): string {
|
|
35
|
-
if (target === 'express') return copyBase
|
|
36
|
-
const targetDir = path.join(copyBase, target)
|
|
37
|
-
if (!fs.existsSync(targetDir)) {
|
|
38
|
-
throw new Error(
|
|
39
|
-
`[prisma-generator-express] Target template directory not found: ${targetDir}\n` +
|
|
40
|
-
` Expected directory for target "${target}" at: ${targetDir}`,
|
|
41
|
-
)
|
|
42
|
-
}
|
|
43
|
-
return targetDir
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface CopyFileOptions {
|
|
47
|
-
required?: boolean
|
|
48
|
-
importRewrites?: Array<{ from: string; to: string }>
|
|
49
|
-
}
|
|
50
|
-
|
|
51
38
|
function escapeRegex(str: string): string {
|
|
52
39
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
53
40
|
}
|
|
54
41
|
|
|
55
|
-
|
|
42
|
+
function copyFileSync(
|
|
56
43
|
srcDir: string,
|
|
57
44
|
destDir: string,
|
|
58
45
|
filename: string,
|
|
59
46
|
options?: CopyFileOptions,
|
|
60
|
-
):
|
|
47
|
+
): string | null {
|
|
61
48
|
const srcPath = path.join(srcDir, filename)
|
|
62
|
-
const
|
|
49
|
+
const destFilename = options?.destFilename || filename
|
|
50
|
+
const destPath = path.join(destDir, destFilename)
|
|
63
51
|
|
|
64
52
|
if (!fs.existsSync(srcPath)) {
|
|
65
53
|
if (options?.required) {
|
|
66
|
-
|
|
67
|
-
return false
|
|
54
|
+
return `Required file not found: ${srcPath}`
|
|
68
55
|
}
|
|
69
|
-
|
|
70
|
-
return true
|
|
56
|
+
return null
|
|
71
57
|
}
|
|
72
58
|
|
|
73
59
|
const destDirPath = path.dirname(destPath)
|
|
@@ -98,8 +84,7 @@ async function copyFile(
|
|
|
98
84
|
}
|
|
99
85
|
|
|
100
86
|
fs.writeFileSync(destPath, content)
|
|
101
|
-
|
|
102
|
-
return true
|
|
87
|
+
return null
|
|
103
88
|
}
|
|
104
89
|
|
|
105
90
|
export async function copyFiles(
|
|
@@ -110,23 +95,22 @@ export async function copyFiles(
|
|
|
110
95
|
if (!outputPath) return
|
|
111
96
|
|
|
112
97
|
const copyBase = resolveTemplateDir('copy')
|
|
113
|
-
|
|
114
|
-
let allCopied = true
|
|
98
|
+
const errors: string[] = []
|
|
115
99
|
|
|
116
100
|
console.log(` Copying utility files to: ${outputPath} (target: ${target})`)
|
|
117
101
|
|
|
118
102
|
for (const file of SHARED_FILES) {
|
|
119
|
-
const
|
|
120
|
-
if (
|
|
103
|
+
const err = copyFileSync(copyBase, outputPath, file, { required: true })
|
|
104
|
+
if (err) errors.push(err)
|
|
121
105
|
}
|
|
122
106
|
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
107
|
+
const targetConfigFile = `routeConfig.${target}.ts`
|
|
108
|
+
const err = copyFileSync(copyBase, outputPath, targetConfigFile, {
|
|
109
|
+
required: true,
|
|
110
|
+
destFilename: 'routeConfig.target.ts',
|
|
111
|
+
importRewrites: [{ from: './routeConfig', to: './routeConfig' }],
|
|
112
|
+
})
|
|
113
|
+
if (err) errors.push(err)
|
|
130
114
|
|
|
131
115
|
const clientDir = path.join(outputPath, 'client')
|
|
132
116
|
if (!fs.existsSync(clientDir)) {
|
|
@@ -134,7 +118,7 @@ export async function copyFiles(
|
|
|
134
118
|
}
|
|
135
119
|
|
|
136
120
|
const clientSrcDir = resolveTemplateDir('client')
|
|
137
|
-
const
|
|
121
|
+
const clientErr = copyFileSync(
|
|
138
122
|
clientSrcDir,
|
|
139
123
|
clientDir,
|
|
140
124
|
'encodeQueryParams.ts',
|
|
@@ -143,13 +127,16 @@ export async function copyFiles(
|
|
|
143
127
|
importRewrites: [{ from: '../copy/misc.js', to: '../misc.js' }],
|
|
144
128
|
},
|
|
145
129
|
)
|
|
146
|
-
if (
|
|
130
|
+
if (clientErr) errors.push(clientErr)
|
|
147
131
|
|
|
148
|
-
if (
|
|
149
|
-
console.log(` ✓ Utility files copied successfully`)
|
|
150
|
-
} else {
|
|
132
|
+
if (errors.length > 0) {
|
|
151
133
|
throw new Error(
|
|
152
|
-
|
|
134
|
+
`Failed to copy ${errors.length} required file(s):\n` +
|
|
135
|
+
errors.map((e) => ` - ${e}`).join('\n') +
|
|
136
|
+
`\n copyBase: ${copyBase}` +
|
|
137
|
+
`\n __dirname: ${__dirname}`,
|
|
153
138
|
)
|
|
154
139
|
}
|
|
140
|
+
|
|
141
|
+
console.log(` ✓ Utility files copied successfully`)
|
|
155
142
|
}
|