prisma-generator-express 1.29.0 → 1.31.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/utils/copyFiles.js +42 -31
- package/dist/utils/copyFiles.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/copyFiles.ts +43 -29
package/dist/utils/copyFiles.js
CHANGED
|
@@ -41,39 +41,46 @@ const SHARED_FILES = [
|
|
|
41
41
|
'buildModelOpenApi.ts',
|
|
42
42
|
'operationDefinitions.ts',
|
|
43
43
|
'misc.ts',
|
|
44
|
-
'docsRenderer.ts',
|
|
45
44
|
];
|
|
46
45
|
const TARGET_FILES = {
|
|
47
46
|
express: ['routeConfig.ts'],
|
|
48
47
|
fastify: ['routeConfig.ts'],
|
|
49
48
|
};
|
|
50
49
|
function resolveTemplateDir(subpath) {
|
|
51
|
-
const fromSibling = path.join(__dirname, '..', subpath);
|
|
52
|
-
if (fs.existsSync(fromSibling))
|
|
53
|
-
return fromSibling;
|
|
54
50
|
const fromSrc = path.join(__dirname, '..', '..', 'src', subpath);
|
|
55
51
|
if (fs.existsSync(fromSrc))
|
|
56
52
|
return fromSrc;
|
|
57
|
-
|
|
53
|
+
const fromDist = path.join(__dirname, '..', subpath);
|
|
54
|
+
if (fs.existsSync(fromDist))
|
|
55
|
+
return fromDist;
|
|
56
|
+
throw new Error(`Template directory "${subpath}" not found.\n` +
|
|
57
|
+
` Searched:\n` +
|
|
58
|
+
` ${fromSrc}\n` +
|
|
59
|
+
` ${fromDist}\n` +
|
|
60
|
+
` __dirname: ${__dirname}\n` +
|
|
61
|
+
` Ensure template files are included in the published package.`);
|
|
58
62
|
}
|
|
59
63
|
function getTargetSourceDir(copyBase, target) {
|
|
60
64
|
if (target === 'express')
|
|
61
65
|
return copyBase;
|
|
62
|
-
|
|
66
|
+
const targetDir = path.join(copyBase, target);
|
|
67
|
+
if (!fs.existsSync(targetDir)) {
|
|
68
|
+
throw new Error(`Target template directory not found: ${targetDir}\n` +
|
|
69
|
+
` Expected directory for target "${target}".`);
|
|
70
|
+
}
|
|
71
|
+
return targetDir;
|
|
63
72
|
}
|
|
64
73
|
function escapeRegex(str) {
|
|
65
74
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
66
75
|
}
|
|
67
|
-
|
|
76
|
+
function copyFileSync(srcDir, destDir, filename, options) {
|
|
68
77
|
const srcPath = path.join(srcDir, filename);
|
|
69
78
|
const destPath = path.join(destDir, filename);
|
|
70
79
|
if (!fs.existsSync(srcPath)) {
|
|
71
80
|
if (options?.required) {
|
|
72
|
-
|
|
73
|
-
return false;
|
|
81
|
+
return `Required file not found: ${srcPath}`;
|
|
74
82
|
}
|
|
75
|
-
|
|
76
|
-
return true;
|
|
83
|
+
return null;
|
|
77
84
|
}
|
|
78
85
|
const destDirPath = path.dirname(destPath);
|
|
79
86
|
if (!fs.existsSync(destDirPath)) {
|
|
@@ -95,45 +102,49 @@ async function copyFile(srcDir, destDir, filename, options) {
|
|
|
95
102
|
content = header + content;
|
|
96
103
|
}
|
|
97
104
|
fs.writeFileSync(destPath, content);
|
|
98
|
-
|
|
99
|
-
return true;
|
|
105
|
+
return null;
|
|
100
106
|
}
|
|
101
107
|
async function copyFiles(options, target) {
|
|
102
108
|
const outputPath = options.generator.output?.value;
|
|
103
109
|
if (!outputPath)
|
|
104
110
|
return;
|
|
105
111
|
const copyBase = resolveTemplateDir('copy');
|
|
106
|
-
|
|
112
|
+
const errors = [];
|
|
107
113
|
console.log(` Copying utility files to: ${outputPath} (target: ${target})`);
|
|
108
114
|
for (const file of SHARED_FILES) {
|
|
109
|
-
const
|
|
110
|
-
if (
|
|
111
|
-
|
|
115
|
+
const err = copyFileSync(copyBase, outputPath, file, { required: true });
|
|
116
|
+
if (err)
|
|
117
|
+
errors.push(err);
|
|
118
|
+
}
|
|
119
|
+
let targetSrcDir;
|
|
120
|
+
try {
|
|
121
|
+
targetSrcDir = getTargetSourceDir(copyBase, target);
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
throw new Error(e.message);
|
|
112
125
|
}
|
|
113
|
-
const targetSrcDir = getTargetSourceDir(copyBase, target);
|
|
114
126
|
for (const file of TARGET_FILES[target]) {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (!ok)
|
|
119
|
-
allCopied = false;
|
|
127
|
+
const err = copyFileSync(targetSrcDir, outputPath, file, { required: true });
|
|
128
|
+
if (err)
|
|
129
|
+
errors.push(err);
|
|
120
130
|
}
|
|
121
131
|
const clientDir = path.join(outputPath, 'client');
|
|
122
132
|
if (!fs.existsSync(clientDir)) {
|
|
123
133
|
fs.mkdirSync(clientDir, { recursive: true });
|
|
124
134
|
}
|
|
125
135
|
const clientSrcDir = resolveTemplateDir('client');
|
|
126
|
-
const
|
|
136
|
+
const clientErr = copyFileSync(clientSrcDir, clientDir, 'encodeQueryParams.ts', {
|
|
127
137
|
required: true,
|
|
128
138
|
importRewrites: [{ from: '../copy/misc.js', to: '../misc.js' }],
|
|
129
139
|
});
|
|
130
|
-
if (
|
|
131
|
-
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
140
|
+
if (clientErr)
|
|
141
|
+
errors.push(clientErr);
|
|
142
|
+
if (errors.length > 0) {
|
|
143
|
+
throw new Error(`Failed to copy ${errors.length} required file(s):\n` +
|
|
144
|
+
errors.map((e) => ` - ${e}`).join('\n') +
|
|
145
|
+
`\n copyBase: ${copyBase}` +
|
|
146
|
+
`\n __dirname: ${__dirname}`);
|
|
137
147
|
}
|
|
148
|
+
console.log(` ✓ Utility files copied successfully`);
|
|
138
149
|
}
|
|
139
150
|
//# sourceMappingURL=copyFiles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copyFiles.js","sourceRoot":"","sources":["../../src/utils/copyFiles.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
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
12
|
|
|
14
13
|
const TARGET_FILES: Record<Target, string[]> = {
|
|
@@ -17,20 +16,32 @@ const TARGET_FILES: Record<Target, string[]> = {
|
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
function resolveTemplateDir(subpath: string): string {
|
|
20
|
-
const fromSibling = path.join(__dirname, '..', subpath)
|
|
21
|
-
if (fs.existsSync(fromSibling)) return fromSibling
|
|
22
|
-
|
|
23
19
|
const fromSrc = path.join(__dirname, '..', '..', 'src', subpath)
|
|
24
20
|
if (fs.existsSync(fromSrc)) return fromSrc
|
|
25
21
|
|
|
22
|
+
const fromDist = path.join(__dirname, '..', subpath)
|
|
23
|
+
if (fs.existsSync(fromDist)) return fromDist
|
|
24
|
+
|
|
26
25
|
throw new Error(
|
|
27
|
-
`Template directory "${subpath}" not found
|
|
26
|
+
`Template directory "${subpath}" not found.\n` +
|
|
27
|
+
` Searched:\n` +
|
|
28
|
+
` ${fromSrc}\n` +
|
|
29
|
+
` ${fromDist}\n` +
|
|
30
|
+
` __dirname: ${__dirname}\n` +
|
|
31
|
+
` Ensure template files are included in the published package.`,
|
|
28
32
|
)
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
function getTargetSourceDir(copyBase: string, target: Target): string {
|
|
32
36
|
if (target === 'express') return copyBase
|
|
33
|
-
|
|
37
|
+
const targetDir = path.join(copyBase, target)
|
|
38
|
+
if (!fs.existsSync(targetDir)) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Target template directory not found: ${targetDir}\n` +
|
|
41
|
+
` Expected directory for target "${target}".`,
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
return targetDir
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
interface CopyFileOptions {
|
|
@@ -42,22 +53,20 @@ function escapeRegex(str: string): string {
|
|
|
42
53
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
43
54
|
}
|
|
44
55
|
|
|
45
|
-
|
|
56
|
+
function copyFileSync(
|
|
46
57
|
srcDir: string,
|
|
47
58
|
destDir: string,
|
|
48
59
|
filename: string,
|
|
49
60
|
options?: CopyFileOptions,
|
|
50
|
-
):
|
|
61
|
+
): string | null {
|
|
51
62
|
const srcPath = path.join(srcDir, filename)
|
|
52
63
|
const destPath = path.join(destDir, filename)
|
|
53
64
|
|
|
54
65
|
if (!fs.existsSync(srcPath)) {
|
|
55
66
|
if (options?.required) {
|
|
56
|
-
|
|
57
|
-
return false
|
|
67
|
+
return `Required file not found: ${srcPath}`
|
|
58
68
|
}
|
|
59
|
-
|
|
60
|
-
return true
|
|
69
|
+
return null
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
const destDirPath = path.dirname(destPath)
|
|
@@ -88,8 +97,7 @@ async function copyFile(
|
|
|
88
97
|
}
|
|
89
98
|
|
|
90
99
|
fs.writeFileSync(destPath, content)
|
|
91
|
-
|
|
92
|
-
return true
|
|
100
|
+
return null
|
|
93
101
|
}
|
|
94
102
|
|
|
95
103
|
export async function copyFiles(
|
|
@@ -100,22 +108,25 @@ export async function copyFiles(
|
|
|
100
108
|
if (!outputPath) return
|
|
101
109
|
|
|
102
110
|
const copyBase = resolveTemplateDir('copy')
|
|
103
|
-
|
|
104
|
-
let allCopied = true
|
|
111
|
+
const errors: string[] = []
|
|
105
112
|
|
|
106
113
|
console.log(` Copying utility files to: ${outputPath} (target: ${target})`)
|
|
107
114
|
|
|
108
115
|
for (const file of SHARED_FILES) {
|
|
109
|
-
const
|
|
110
|
-
if (
|
|
116
|
+
const err = copyFileSync(copyBase, outputPath, file, { required: true })
|
|
117
|
+
if (err) errors.push(err)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let targetSrcDir: string
|
|
121
|
+
try {
|
|
122
|
+
targetSrcDir = getTargetSourceDir(copyBase, target)
|
|
123
|
+
} catch (e: any) {
|
|
124
|
+
throw new Error(e.message)
|
|
111
125
|
}
|
|
112
126
|
|
|
113
|
-
const targetSrcDir = getTargetSourceDir(copyBase, target)
|
|
114
127
|
for (const file of TARGET_FILES[target]) {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
})
|
|
118
|
-
if (!ok) allCopied = false
|
|
128
|
+
const err = copyFileSync(targetSrcDir, outputPath, file, { required: true })
|
|
129
|
+
if (err) errors.push(err)
|
|
119
130
|
}
|
|
120
131
|
|
|
121
132
|
const clientDir = path.join(outputPath, 'client')
|
|
@@ -124,7 +135,7 @@ export async function copyFiles(
|
|
|
124
135
|
}
|
|
125
136
|
|
|
126
137
|
const clientSrcDir = resolveTemplateDir('client')
|
|
127
|
-
const
|
|
138
|
+
const clientErr = copyFileSync(
|
|
128
139
|
clientSrcDir,
|
|
129
140
|
clientDir,
|
|
130
141
|
'encodeQueryParams.ts',
|
|
@@ -133,13 +144,16 @@ export async function copyFiles(
|
|
|
133
144
|
importRewrites: [{ from: '../copy/misc.js', to: '../misc.js' }],
|
|
134
145
|
},
|
|
135
146
|
)
|
|
136
|
-
if (
|
|
147
|
+
if (clientErr) errors.push(clientErr)
|
|
137
148
|
|
|
138
|
-
if (
|
|
139
|
-
console.log(` ✓ Utility files copied successfully`)
|
|
140
|
-
} else {
|
|
149
|
+
if (errors.length > 0) {
|
|
141
150
|
throw new Error(
|
|
142
|
-
|
|
151
|
+
`Failed to copy ${errors.length} required file(s):\n` +
|
|
152
|
+
errors.map((e) => ` - ${e}`).join('\n') +
|
|
153
|
+
`\n copyBase: ${copyBase}` +
|
|
154
|
+
`\n __dirname: ${__dirname}`,
|
|
143
155
|
)
|
|
144
156
|
}
|
|
157
|
+
|
|
158
|
+
console.log(` ✓ Utility files copied successfully`)
|
|
145
159
|
}
|