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