@shadospace/editor 1.0.7 → 1.0.9
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 +104 -6
package/package.json
CHANGED
package/scripts/init.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import fs from "fs"
|
|
4
4
|
import path from "path"
|
|
5
5
|
import { fileURLToPath } from "url"
|
|
6
|
+
import { execSync } from "child_process"
|
|
6
7
|
|
|
7
8
|
const __filename = fileURLToPath(import.meta.url)
|
|
8
9
|
const __dirname = path.dirname(__filename)
|
|
@@ -87,22 +88,90 @@ try {
|
|
|
87
88
|
})
|
|
88
89
|
|
|
89
90
|
// Copy UploadThing setup files
|
|
90
|
-
const
|
|
91
|
+
const coreDest = path.join(baseTargetDir, "app/api/uploadthing/core.ts")
|
|
92
|
+
|
|
93
|
+
if (fs.existsSync(coreDest)) {
|
|
94
|
+
console.log(`[tiptap-starter] ${coreDest} already exists, checking for missing routes.`)
|
|
95
|
+
let content = fs.readFileSync(coreDest, "utf8")
|
|
96
|
+
let modified = false
|
|
97
|
+
|
|
98
|
+
const hasImageUploader = content.includes("imageUploader")
|
|
99
|
+
const hasCoverImageUploader = content.includes("coverImageUploader")
|
|
100
|
+
|
|
101
|
+
if (!hasImageUploader || !hasCoverImageUploader) {
|
|
102
|
+
let routesToInsert = ""
|
|
103
|
+
if (!hasImageUploader) {
|
|
104
|
+
routesToInsert += `
|
|
105
|
+
imageUploader: f({
|
|
106
|
+
image: {
|
|
107
|
+
maxFileSize: "4MB",
|
|
108
|
+
maxFileCount: 1,
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
.middleware(async ({ req }) => {
|
|
112
|
+
const user = await auth(req)
|
|
113
|
+
if (!user) throw new UploadThingError("Unauthorized")
|
|
114
|
+
return { userId: user.id }
|
|
115
|
+
})
|
|
116
|
+
.onUploadComplete(async ({ metadata, file }) => {
|
|
117
|
+
console.log("Upload complete for userId:", metadata.userId)
|
|
118
|
+
console.log("file url", file.ufsUrl)
|
|
119
|
+
return { uploadedBy: metadata.userId }
|
|
120
|
+
}),`
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (!hasCoverImageUploader) {
|
|
124
|
+
routesToInsert += `
|
|
125
|
+
coverImageUploader: f({
|
|
126
|
+
image: {
|
|
127
|
+
maxFileSize: "4MB",
|
|
128
|
+
maxFileCount: 1,
|
|
129
|
+
},
|
|
130
|
+
})
|
|
131
|
+
.middleware(async ({ req }) => {
|
|
132
|
+
const user = await auth(req)
|
|
133
|
+
if (!user) throw new UploadThingError("Unauthorized")
|
|
134
|
+
return { userId: user.id }
|
|
135
|
+
})
|
|
136
|
+
.onUploadComplete(async ({ metadata, file }) => {
|
|
137
|
+
console.log("Upload complete for userId:", metadata.userId)
|
|
138
|
+
console.log("file url", file.ufsUrl)
|
|
139
|
+
return { uploadedBy: metadata.userId }
|
|
140
|
+
}),`
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (content.includes("} satisfies FileRouter")) {
|
|
144
|
+
content = content.replace("} satisfies FileRouter", routesToInsert + "\n} satisfies FileRouter")
|
|
145
|
+
modified = true
|
|
146
|
+
} else {
|
|
147
|
+
console.warn(`[tiptap-starter] Could not find \`} satisfies FileRouter\` in ${coreDest}. Please add the routes manually.`)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (modified) {
|
|
152
|
+
fs.writeFileSync(coreDest, content)
|
|
153
|
+
console.log(`[tiptap-starter] Inserted missing routes into ${coreDest}`)
|
|
154
|
+
} else {
|
|
155
|
+
console.log(`[tiptap-starter] All required routes already present in ${coreDest}`)
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
// File doesn't exist, copy the default one
|
|
159
|
+
copyFile(path.join(__dirname, "../app/api/uploadthing/core.ts"), coreDest)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Copy other uploadthing files if they don't exist
|
|
163
|
+
const otherUploadthingFiles = [
|
|
91
164
|
{
|
|
92
165
|
src: path.join(__dirname, "../lib/uploadthing.ts"),
|
|
93
166
|
dest: path.join(baseTargetDir, "lib/uploadthing.ts"),
|
|
94
167
|
},
|
|
95
|
-
{
|
|
96
|
-
src: path.join(__dirname, "../app/api/uploadthing/core.ts"),
|
|
97
|
-
dest: path.join(baseTargetDir, "app/api/uploadthing/core.ts"),
|
|
98
|
-
},
|
|
99
168
|
{
|
|
100
169
|
src: path.join(__dirname, "../app/api/uploadthing/route.ts"),
|
|
101
170
|
dest: path.join(baseTargetDir, "app/api/uploadthing/route.ts"),
|
|
102
171
|
},
|
|
103
172
|
]
|
|
104
173
|
|
|
105
|
-
|
|
174
|
+
otherUploadthingFiles.forEach((file) => {
|
|
106
175
|
if (fs.existsSync(file.src)) {
|
|
107
176
|
copyFile(file.src, file.dest)
|
|
108
177
|
} else {
|
|
@@ -146,6 +215,35 @@ try {
|
|
|
146
215
|
`[tiptap-starter] globals.css not found. Please add \`@import "../components/editor/styles.css";\` manually to your CSS file.`
|
|
147
216
|
)
|
|
148
217
|
}
|
|
218
|
+
|
|
219
|
+
// Install lucide-react if missing
|
|
220
|
+
console.log("[tiptap-starter] Checking for lucide-react...")
|
|
221
|
+
|
|
222
|
+
let hasLucide = false
|
|
223
|
+
if (pkg.dependencies?.["lucide-react"] || pkg.devDependencies?.["lucide-react"]) {
|
|
224
|
+
hasLucide = true
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (!hasLucide) {
|
|
228
|
+
let command = "npm install lucide-react"
|
|
229
|
+
if (fs.existsSync(path.join(targetDir, "bun.lock"))) {
|
|
230
|
+
command = "bun add lucide-react"
|
|
231
|
+
} else if (fs.existsSync(path.join(targetDir, "pnpm-lock.yaml"))) {
|
|
232
|
+
command = "pnpm add lucide-react"
|
|
233
|
+
} else if (fs.existsSync(path.join(targetDir, "yarn.lock"))) {
|
|
234
|
+
command = "yarn add lucide-react"
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
console.log(`[tiptap-starter] Installing lucide-react with command: ${command}`)
|
|
238
|
+
try {
|
|
239
|
+
execSync(command, { cwd: targetDir, stdio: "inherit" })
|
|
240
|
+
console.log("[tiptap-starter] Successfully installed lucide-react")
|
|
241
|
+
} catch (error) {
|
|
242
|
+
console.error("[tiptap-starter] Failed to install lucide-react:", error)
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
console.log("[tiptap-starter] lucide-react is already installed.")
|
|
246
|
+
}
|
|
149
247
|
} catch (error) {
|
|
150
248
|
console.error(`[tiptap-starter] Error during initialization:`, error)
|
|
151
249
|
}
|