@shadospace/editor 1.0.6 → 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 +3 -3
- package/scripts/init.js +76 -6
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shadospace/editor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
|
+
"bin": "./scripts/init.js",
|
|
6
7
|
"files": [
|
|
7
8
|
"scripts/init.js",
|
|
8
9
|
"components/editor",
|
|
@@ -18,8 +19,7 @@
|
|
|
18
19
|
"start": "next start",
|
|
19
20
|
"lint": "eslint",
|
|
20
21
|
"format": "prettier --write \"**/*.{ts,tsx}\"",
|
|
21
|
-
"typecheck": "tsc --noEmit"
|
|
22
|
-
"postinstall": "node scripts/init.js"
|
|
22
|
+
"typecheck": "tsc --noEmit"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@floating-ui/react": "^0.27.19",
|
package/scripts/init.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
1
3
|
import fs from "fs"
|
|
2
4
|
import path from "path"
|
|
3
5
|
import { fileURLToPath } from "url"
|
|
@@ -85,22 +87,90 @@ try {
|
|
|
85
87
|
})
|
|
86
88
|
|
|
87
89
|
// Copy UploadThing setup files
|
|
88
|
-
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 = [
|
|
89
163
|
{
|
|
90
164
|
src: path.join(__dirname, "../lib/uploadthing.ts"),
|
|
91
165
|
dest: path.join(baseTargetDir, "lib/uploadthing.ts"),
|
|
92
166
|
},
|
|
93
|
-
{
|
|
94
|
-
src: path.join(__dirname, "../app/api/uploadthing/core.ts"),
|
|
95
|
-
dest: path.join(baseTargetDir, "app/api/uploadthing/core.ts"),
|
|
96
|
-
},
|
|
97
167
|
{
|
|
98
168
|
src: path.join(__dirname, "../app/api/uploadthing/route.ts"),
|
|
99
169
|
dest: path.join(baseTargetDir, "app/api/uploadthing/route.ts"),
|
|
100
170
|
},
|
|
101
171
|
]
|
|
102
172
|
|
|
103
|
-
|
|
173
|
+
otherUploadthingFiles.forEach((file) => {
|
|
104
174
|
if (fs.existsSync(file.src)) {
|
|
105
175
|
copyFile(file.src, file.dest)
|
|
106
176
|
} else {
|