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