@shadospace/editor 1.0.7 → 1.0.8
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/package.json +1 -1
- package/scripts/init.js +74 -6
package/package.json
CHANGED
package/scripts/init.js
CHANGED
|
@@ -87,22 +87,90 @@ try {
|
|
|
87
87
|
})
|
|
88
88
|
|
|
89
89
|
// Copy UploadThing setup files
|
|
90
|
-
const
|
|
90
|
+
const coreDest = path.join(baseTargetDir, "app/api/uploadthing/core.ts")
|
|
91
|
+
|
|
92
|
+
if (fs.existsSync(coreDest)) {
|
|
93
|
+
console.log(`[tiptap-starter] ${coreDest} already exists, checking for missing routes.`)
|
|
94
|
+
let content = fs.readFileSync(coreDest, "utf8")
|
|
95
|
+
let modified = false
|
|
96
|
+
|
|
97
|
+
const hasImageUploader = content.includes("imageUploader")
|
|
98
|
+
const hasCoverImageUploader = content.includes("coverImageUploader")
|
|
99
|
+
|
|
100
|
+
if (!hasImageUploader || !hasCoverImageUploader) {
|
|
101
|
+
let routesToInsert = ""
|
|
102
|
+
if (!hasImageUploader) {
|
|
103
|
+
routesToInsert += `
|
|
104
|
+
imageUploader: f({
|
|
105
|
+
image: {
|
|
106
|
+
maxFileSize: "4MB",
|
|
107
|
+
maxFileCount: 1,
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
.middleware(async ({ req }) => {
|
|
111
|
+
const user = await auth(req)
|
|
112
|
+
if (!user) throw new UploadThingError("Unauthorized")
|
|
113
|
+
return { userId: user.id }
|
|
114
|
+
})
|
|
115
|
+
.onUploadComplete(async ({ metadata, file }) => {
|
|
116
|
+
console.log("Upload complete for userId:", metadata.userId)
|
|
117
|
+
console.log("file url", file.ufsUrl)
|
|
118
|
+
return { uploadedBy: metadata.userId }
|
|
119
|
+
}),`
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!hasCoverImageUploader) {
|
|
123
|
+
routesToInsert += `
|
|
124
|
+
coverImageUploader: f({
|
|
125
|
+
image: {
|
|
126
|
+
maxFileSize: "4MB",
|
|
127
|
+
maxFileCount: 1,
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
.middleware(async ({ req }) => {
|
|
131
|
+
const user = await auth(req)
|
|
132
|
+
if (!user) throw new UploadThingError("Unauthorized")
|
|
133
|
+
return { userId: user.id }
|
|
134
|
+
})
|
|
135
|
+
.onUploadComplete(async ({ metadata, file }) => {
|
|
136
|
+
console.log("Upload complete for userId:", metadata.userId)
|
|
137
|
+
console.log("file url", file.ufsUrl)
|
|
138
|
+
return { uploadedBy: metadata.userId }
|
|
139
|
+
}),`
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (content.includes("} satisfies FileRouter")) {
|
|
143
|
+
content = content.replace("} satisfies FileRouter", routesToInsert + "\n} satisfies FileRouter")
|
|
144
|
+
modified = true
|
|
145
|
+
} else {
|
|
146
|
+
console.warn(`[tiptap-starter] Could not find \`} satisfies FileRouter\` in ${coreDest}. Please add the routes manually.`)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (modified) {
|
|
151
|
+
fs.writeFileSync(coreDest, content)
|
|
152
|
+
console.log(`[tiptap-starter] Inserted missing routes into ${coreDest}`)
|
|
153
|
+
} else {
|
|
154
|
+
console.log(`[tiptap-starter] All required routes already present in ${coreDest}`)
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
// File doesn't exist, copy the default one
|
|
158
|
+
copyFile(path.join(__dirname, "../app/api/uploadthing/core.ts"), coreDest)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Copy other uploadthing files if they don't exist
|
|
162
|
+
const otherUploadthingFiles = [
|
|
91
163
|
{
|
|
92
164
|
src: path.join(__dirname, "../lib/uploadthing.ts"),
|
|
93
165
|
dest: path.join(baseTargetDir, "lib/uploadthing.ts"),
|
|
94
166
|
},
|
|
95
|
-
{
|
|
96
|
-
src: path.join(__dirname, "../app/api/uploadthing/core.ts"),
|
|
97
|
-
dest: path.join(baseTargetDir, "app/api/uploadthing/core.ts"),
|
|
98
|
-
},
|
|
99
167
|
{
|
|
100
168
|
src: path.join(__dirname, "../app/api/uploadthing/route.ts"),
|
|
101
169
|
dest: path.join(baseTargetDir, "app/api/uploadthing/route.ts"),
|
|
102
170
|
},
|
|
103
171
|
]
|
|
104
172
|
|
|
105
|
-
|
|
173
|
+
otherUploadthingFiles.forEach((file) => {
|
|
106
174
|
if (fs.existsSync(file.src)) {
|
|
107
175
|
copyFile(file.src, file.dest)
|
|
108
176
|
} else {
|