@shadospace/editor 1.0.5 → 1.0.6
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 +89 -72
package/package.json
CHANGED
package/scripts/init.js
CHANGED
|
@@ -1,132 +1,149 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import path from
|
|
3
|
-
import { fileURLToPath } from
|
|
1
|
+
import fs from "fs"
|
|
2
|
+
import path from "path"
|
|
3
|
+
import { fileURLToPath } from "url"
|
|
4
4
|
|
|
5
|
-
const __filename = fileURLToPath(import.meta.url)
|
|
6
|
-
const __dirname = path.dirname(__filename)
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
6
|
+
const __dirname = path.dirname(__filename)
|
|
7
7
|
|
|
8
8
|
// Target directory (where the user is installing the package)
|
|
9
9
|
// INIT_CWD is set by npm/yarn/pnpm/bun during postinstall
|
|
10
|
-
const targetDir = process.env.INIT_CWD || process.cwd()
|
|
10
|
+
const targetDir = process.env.INIT_CWD || process.cwd()
|
|
11
11
|
|
|
12
|
-
console.log(`[tiptap-starter] Initializing in ${targetDir}`)
|
|
12
|
+
console.log(`[tiptap-starter] Initializing in ${targetDir}`)
|
|
13
13
|
|
|
14
14
|
// Verify that the target directory is a Next.js project with shadcn installed
|
|
15
|
-
const targetPackageJsonPath = path.join(targetDir,
|
|
15
|
+
const targetPackageJsonPath = path.join(targetDir, "package.json")
|
|
16
16
|
|
|
17
17
|
if (!fs.existsSync(targetPackageJsonPath)) {
|
|
18
|
-
console.error(
|
|
19
|
-
|
|
18
|
+
console.error(
|
|
19
|
+
`[tiptap-starter] Error: package.json not found in ${targetDir}. Please run this in the root of your project.`
|
|
20
|
+
)
|
|
21
|
+
process.exit(1)
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
let pkg
|
|
24
|
+
let pkg
|
|
23
25
|
try {
|
|
24
|
-
pkg = JSON.parse(fs.readFileSync(targetPackageJsonPath,
|
|
25
|
-
} catch
|
|
26
|
-
console.error(
|
|
27
|
-
|
|
26
|
+
pkg = JSON.parse(fs.readFileSync(targetPackageJsonPath, "utf8"))
|
|
27
|
+
} catch {
|
|
28
|
+
console.error(
|
|
29
|
+
`[tiptap-starter] Error: Failed to parse package.json in ${targetDir}`
|
|
30
|
+
)
|
|
31
|
+
process.exit(1)
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
const hasNext = pkg.dependencies?.next || pkg.devDependencies?.next
|
|
31
|
-
const hasShadcn = fs.existsSync(path.join(targetDir,
|
|
34
|
+
const hasNext = pkg.dependencies?.next || pkg.devDependencies?.next
|
|
35
|
+
const hasShadcn = fs.existsSync(path.join(targetDir, "components.json"))
|
|
32
36
|
|
|
33
37
|
if (!hasNext) {
|
|
34
|
-
console.error(
|
|
35
|
-
|
|
38
|
+
console.error(
|
|
39
|
+
`[tiptap-starter] Error: Next.js is not detected. This package is designed for Next.js projects.`
|
|
40
|
+
)
|
|
41
|
+
process.exit(1)
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
if (!hasShadcn) {
|
|
39
|
-
console.error(
|
|
40
|
-
|
|
45
|
+
console.error(
|
|
46
|
+
`[tiptap-starter] Error: shadcn/ui is not detected (components.json not found). Please initialize shadcn first.`
|
|
47
|
+
)
|
|
48
|
+
process.exit(1)
|
|
41
49
|
}
|
|
42
50
|
|
|
43
|
-
const sourceEditorDir = path.join(__dirname,
|
|
51
|
+
const sourceEditorDir = path.join(__dirname, "../components/editor")
|
|
44
52
|
|
|
45
53
|
// Detect if target project uses src directory
|
|
46
|
-
const hasSrc = fs.existsSync(path.join(targetDir,
|
|
47
|
-
const baseTargetDir = hasSrc ? path.join(targetDir,
|
|
54
|
+
const hasSrc = fs.existsSync(path.join(targetDir, "src"))
|
|
55
|
+
const baseTargetDir = hasSrc ? path.join(targetDir, "src") : targetDir
|
|
48
56
|
|
|
49
|
-
const targetEditorDir = path.join(baseTargetDir,
|
|
57
|
+
const targetEditorDir = path.join(baseTargetDir, "components/editor")
|
|
50
58
|
|
|
51
59
|
// Function to copy files
|
|
52
60
|
function copyFile(src, dest) {
|
|
53
61
|
if (fs.existsSync(dest)) {
|
|
54
|
-
console.log(
|
|
55
|
-
|
|
62
|
+
console.log(
|
|
63
|
+
`[tiptap-starter] ${path.basename(dest)} already exists, skipping.`
|
|
64
|
+
)
|
|
65
|
+
return
|
|
56
66
|
}
|
|
57
|
-
fs.mkdirSync(path.dirname(dest), { recursive: true })
|
|
58
|
-
fs.copyFileSync(src, dest)
|
|
59
|
-
console.log(`[tiptap-starter] Created ${dest}`)
|
|
67
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true })
|
|
68
|
+
fs.copyFileSync(src, dest)
|
|
69
|
+
console.log(`[tiptap-starter] Created ${dest}`)
|
|
60
70
|
}
|
|
61
71
|
|
|
62
72
|
// Files to copy
|
|
63
|
-
const files = [
|
|
64
|
-
'index.tsx',
|
|
65
|
-
'menu-bar.tsx',
|
|
66
|
-
'menubar-state.tsx',
|
|
67
|
-
'styles.css'
|
|
68
|
-
];
|
|
73
|
+
const files = ["index.tsx", "menu-bar.tsx", "menubar-state.tsx", "styles.css"]
|
|
69
74
|
|
|
70
75
|
try {
|
|
71
76
|
// Check if source files exist
|
|
72
|
-
files.forEach(file => {
|
|
73
|
-
const src = path.join(sourceEditorDir, file)
|
|
74
|
-
const dest = path.join(targetEditorDir, file)
|
|
77
|
+
files.forEach((file) => {
|
|
78
|
+
const src = path.join(sourceEditorDir, file)
|
|
79
|
+
const dest = path.join(targetEditorDir, file)
|
|
75
80
|
if (fs.existsSync(src)) {
|
|
76
|
-
copyFile(src, dest)
|
|
81
|
+
copyFile(src, dest)
|
|
77
82
|
} else {
|
|
78
|
-
console.error(`[tiptap-starter] Source file missing: ${src}`)
|
|
83
|
+
console.error(`[tiptap-starter] Source file missing: ${src}`)
|
|
79
84
|
}
|
|
80
|
-
})
|
|
85
|
+
})
|
|
81
86
|
|
|
82
87
|
// Copy UploadThing setup files
|
|
83
88
|
const uploadthingFiles = [
|
|
84
|
-
{
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
{
|
|
90
|
+
src: path.join(__dirname, "../lib/uploadthing.ts"),
|
|
91
|
+
dest: path.join(baseTargetDir, "lib/uploadthing.ts"),
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
src: path.join(__dirname, "../app/api/uploadthing/core.ts"),
|
|
95
|
+
dest: path.join(baseTargetDir, "app/api/uploadthing/core.ts"),
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
src: path.join(__dirname, "../app/api/uploadthing/route.ts"),
|
|
99
|
+
dest: path.join(baseTargetDir, "app/api/uploadthing/route.ts"),
|
|
100
|
+
},
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
uploadthingFiles.forEach((file) => {
|
|
90
104
|
if (fs.existsSync(file.src)) {
|
|
91
|
-
copyFile(file.src, file.dest)
|
|
105
|
+
copyFile(file.src, file.dest)
|
|
92
106
|
} else {
|
|
93
|
-
console.error(`[tiptap-starter] Source file missing: ${file.src}`)
|
|
107
|
+
console.error(`[tiptap-starter] Source file missing: ${file.src}`)
|
|
94
108
|
}
|
|
95
|
-
})
|
|
109
|
+
})
|
|
96
110
|
|
|
97
111
|
// Update globals.css
|
|
98
112
|
const possiblePaths = [
|
|
99
|
-
path.join(targetDir,
|
|
100
|
-
path.join(targetDir,
|
|
101
|
-
path.join(targetDir,
|
|
102
|
-
]
|
|
113
|
+
path.join(targetDir, "app/globals.css"),
|
|
114
|
+
path.join(targetDir, "src/app/globals.css"),
|
|
115
|
+
path.join(targetDir, "styles/globals.css"),
|
|
116
|
+
]
|
|
103
117
|
|
|
104
|
-
let globalsCssPath = possiblePaths.find(p => fs.existsSync(p))
|
|
118
|
+
let globalsCssPath = possiblePaths.find((p) => fs.existsSync(p))
|
|
105
119
|
|
|
106
120
|
if (globalsCssPath) {
|
|
107
|
-
const content = fs.readFileSync(globalsCssPath,
|
|
108
|
-
const importStatement = `@import "../components/editor/styles.css"
|
|
109
|
-
|
|
121
|
+
const content = fs.readFileSync(globalsCssPath, "utf8")
|
|
122
|
+
const importStatement = `@import "../components/editor/styles.css";`
|
|
123
|
+
|
|
110
124
|
if (!content.includes(importStatement)) {
|
|
111
|
-
const lines = content.split(
|
|
112
|
-
let insertIndex = 0
|
|
125
|
+
const lines = content.split("\n")
|
|
126
|
+
let insertIndex = 0
|
|
113
127
|
for (let i = 0; i < lines.length; i++) {
|
|
114
|
-
if (lines[i].startsWith(
|
|
115
|
-
insertIndex = i + 1
|
|
116
|
-
} else if (lines[i].trim() !==
|
|
117
|
-
break
|
|
128
|
+
if (lines[i].startsWith("@import")) {
|
|
129
|
+
insertIndex = i + 1
|
|
130
|
+
} else if (lines[i].trim() !== "") {
|
|
131
|
+
break
|
|
118
132
|
}
|
|
119
133
|
}
|
|
120
|
-
lines.splice(insertIndex, 0, importStatement)
|
|
121
|
-
fs.writeFileSync(globalsCssPath, lines.join(
|
|
122
|
-
console.log(`[tiptap-starter] Referenced styles in ${globalsCssPath}`)
|
|
134
|
+
lines.splice(insertIndex, 0, importStatement)
|
|
135
|
+
fs.writeFileSync(globalsCssPath, lines.join("\n"))
|
|
136
|
+
console.log(`[tiptap-starter] Referenced styles in ${globalsCssPath}`)
|
|
123
137
|
} else {
|
|
124
|
-
console.log(
|
|
138
|
+
console.log(
|
|
139
|
+
`[tiptap-starter] Styles already referenced in ${globalsCssPath}`
|
|
140
|
+
)
|
|
125
141
|
}
|
|
126
142
|
} else {
|
|
127
|
-
console.warn(
|
|
143
|
+
console.warn(
|
|
144
|
+
`[tiptap-starter] globals.css not found. Please add \`@import "../components/editor/styles.css";\` manually to your CSS file.`
|
|
145
|
+
)
|
|
128
146
|
}
|
|
129
|
-
|
|
130
147
|
} catch (error) {
|
|
131
|
-
console.error(`[tiptap-starter] Error during initialization:`, error)
|
|
148
|
+
console.error(`[tiptap-starter] Error during initialization:`, error)
|
|
132
149
|
}
|