@esuiss/ui 0.1.0
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/LICENSE +21 -0
- package/README.md +10 -0
- package/index.mjs +186 -0
- package/package.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ademceper
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/index.mjs
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process"
|
|
3
|
+
import {
|
|
4
|
+
existsSync,
|
|
5
|
+
readdirSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
statSync,
|
|
8
|
+
writeFileSync,
|
|
9
|
+
} from "node:fs"
|
|
10
|
+
import path from "node:path"
|
|
11
|
+
|
|
12
|
+
const REGISTRY = "esuiss/esuiss-ui"
|
|
13
|
+
const COMMAND = "npx @esuiss/ui"
|
|
14
|
+
const INIT_ITEMS = ["theme", "button"]
|
|
15
|
+
const VALUE_FLAGS = new Set(["-c", "--cwd", "-p", "--path", "--diff", "--view"])
|
|
16
|
+
const UPSTREAM_CSS_IMPORT =
|
|
17
|
+
/^@import\s+["']shadcn\/tailwind\.css["'];?[^\S\n]*\n?/m
|
|
18
|
+
const UPSTREAM_PACKAGE = "shadcn"
|
|
19
|
+
|
|
20
|
+
const { version } = JSON.parse(
|
|
21
|
+
readFileSync(new URL("./package.json", import.meta.url), "utf8")
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
const usage = `@esuiss/ui ${version}
|
|
25
|
+
|
|
26
|
+
Usage:
|
|
27
|
+
${COMMAND} init [options] set up a project with the esuiss-ui theme and button
|
|
28
|
+
${COMMAND} add <component...> [options] add components, e.g. ${COMMAND} add button sidebar
|
|
29
|
+
|
|
30
|
+
Options for add:
|
|
31
|
+
-o, --overwrite overwrite existing files
|
|
32
|
+
--diff [path] show changes against the installed file
|
|
33
|
+
--view [path] show file contents
|
|
34
|
+
-y, --yes skip confirmation prompt
|
|
35
|
+
-c, --cwd <cwd> working directory
|
|
36
|
+
-p, --path <path> install location
|
|
37
|
+
--dry-run preview changes without writing files`
|
|
38
|
+
|
|
39
|
+
function exec(command, args, cwd) {
|
|
40
|
+
const result = spawnSync(command, args, {
|
|
41
|
+
cwd,
|
|
42
|
+
stdio: "inherit",
|
|
43
|
+
shell: process.platform === "win32",
|
|
44
|
+
})
|
|
45
|
+
if (result.status !== 0) process.exit(result.status ?? 1)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function run(args) {
|
|
49
|
+
exec("npx", ["--yes", "shadcn@latest", ...args])
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function toAddresses(args) {
|
|
53
|
+
return args.map((arg, index) => {
|
|
54
|
+
const previous = args[index - 1]
|
|
55
|
+
const isValue = previous !== undefined && VALUE_FLAGS.has(previous)
|
|
56
|
+
if (arg.startsWith("-") || isValue || arg.includes("/")) return arg
|
|
57
|
+
return `${REGISTRY}/${arg}`
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function flagValue(args, ...flags) {
|
|
62
|
+
const index = args.findIndex((arg) => flags.includes(arg))
|
|
63
|
+
return index === -1 ? undefined : args[index + 1]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function hasFlag(args, ...flags) {
|
|
67
|
+
return args.some((arg) => flags.includes(arg))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function isProject(dir) {
|
|
71
|
+
return existsSync(path.join(dir, "components.json"))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function findProject(baseDir, name) {
|
|
75
|
+
if (name && isProject(path.resolve(baseDir, name)))
|
|
76
|
+
return path.resolve(baseDir, name)
|
|
77
|
+
if (isProject(baseDir)) return baseDir
|
|
78
|
+
const candidates = readdirSync(baseDir, { withFileTypes: true })
|
|
79
|
+
.filter(
|
|
80
|
+
(entry) =>
|
|
81
|
+
entry.isDirectory() && isProject(path.join(baseDir, entry.name))
|
|
82
|
+
)
|
|
83
|
+
.map((entry) => path.join(baseDir, entry.name))
|
|
84
|
+
.sort(
|
|
85
|
+
(a, b) =>
|
|
86
|
+
statSync(path.join(b, "components.json")).mtimeMs -
|
|
87
|
+
statSync(path.join(a, "components.json")).mtimeMs
|
|
88
|
+
)
|
|
89
|
+
return candidates[0]
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function packageManager(dir) {
|
|
93
|
+
const lockfiles = [
|
|
94
|
+
["pnpm-lock.yaml", "pnpm", "remove"],
|
|
95
|
+
["bun.lock", "bun", "remove"],
|
|
96
|
+
["bun.lockb", "bun", "remove"],
|
|
97
|
+
["yarn.lock", "yarn", "remove"],
|
|
98
|
+
]
|
|
99
|
+
for (let current = dir; ; current = path.dirname(current)) {
|
|
100
|
+
const match = lockfiles.find(([file]) =>
|
|
101
|
+
existsSync(path.join(current, file))
|
|
102
|
+
)
|
|
103
|
+
if (match) return match.slice(1)
|
|
104
|
+
if (path.dirname(current) === current) return ["npm", "uninstall"]
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function removeUpstreamStyles(projectDir) {
|
|
109
|
+
const config = JSON.parse(
|
|
110
|
+
readFileSync(path.join(projectDir, "components.json"), "utf8")
|
|
111
|
+
)
|
|
112
|
+
const cssFile =
|
|
113
|
+
config.tailwind?.css && path.join(projectDir, config.tailwind.css)
|
|
114
|
+
if (cssFile && existsSync(cssFile)) {
|
|
115
|
+
const css = readFileSync(cssFile, "utf8")
|
|
116
|
+
if (UPSTREAM_CSS_IMPORT.test(css))
|
|
117
|
+
writeFileSync(cssFile, css.replace(UPSTREAM_CSS_IMPORT, ""))
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const manifest = JSON.parse(
|
|
121
|
+
readFileSync(path.join(projectDir, "package.json"), "utf8")
|
|
122
|
+
)
|
|
123
|
+
const installed =
|
|
124
|
+
manifest.dependencies?.[UPSTREAM_PACKAGE] ??
|
|
125
|
+
manifest.devDependencies?.[UPSTREAM_PACKAGE]
|
|
126
|
+
if (installed) {
|
|
127
|
+
const [manager, removeCommand] = packageManager(projectDir)
|
|
128
|
+
exec(manager, [removeCommand, UPSTREAM_PACKAGE], projectDir)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function init(args) {
|
|
133
|
+
const baseArgs = hasFlag(args, "-b", "--base") ? [] : ["--base", "base"]
|
|
134
|
+
run(["init", ...baseArgs, ...args])
|
|
135
|
+
|
|
136
|
+
const baseDir = path.resolve(flagValue(args, "-c", "--cwd") ?? ".")
|
|
137
|
+
const projectDir = findProject(baseDir, flagValue(args, "-n", "--name"))
|
|
138
|
+
if (!projectDir) {
|
|
139
|
+
console.error(
|
|
140
|
+
`${COMMAND} init: could not find the initialized project (components.json).`
|
|
141
|
+
)
|
|
142
|
+
process.exit(1)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
run([
|
|
146
|
+
"add",
|
|
147
|
+
...toAddresses(INIT_ITEMS),
|
|
148
|
+
"--overwrite",
|
|
149
|
+
"--yes",
|
|
150
|
+
"--cwd",
|
|
151
|
+
projectDir,
|
|
152
|
+
])
|
|
153
|
+
removeUpstreamStyles(projectDir)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const [command, ...args] = process.argv.slice(2)
|
|
157
|
+
|
|
158
|
+
switch (command) {
|
|
159
|
+
case "add": {
|
|
160
|
+
const addresses = toAddresses(args)
|
|
161
|
+
if (!addresses.some((arg) => arg.startsWith(`${REGISTRY}/`))) {
|
|
162
|
+
console.error(
|
|
163
|
+
`${COMMAND} add: name at least one component, e.g. ${COMMAND} add button`
|
|
164
|
+
)
|
|
165
|
+
process.exit(1)
|
|
166
|
+
}
|
|
167
|
+
run(["add", ...addresses])
|
|
168
|
+
break
|
|
169
|
+
}
|
|
170
|
+
case "init":
|
|
171
|
+
init(args)
|
|
172
|
+
break
|
|
173
|
+
case "-v":
|
|
174
|
+
case "--version":
|
|
175
|
+
console.log(version)
|
|
176
|
+
break
|
|
177
|
+
case undefined:
|
|
178
|
+
case "-h":
|
|
179
|
+
case "--help":
|
|
180
|
+
case "help":
|
|
181
|
+
console.log(usage)
|
|
182
|
+
break
|
|
183
|
+
default:
|
|
184
|
+
console.error(`${COMMAND}: unknown command "${command}"\n\n${usage}`)
|
|
185
|
+
process.exit(1)
|
|
186
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@esuiss/ui",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Add esuiss-ui components to your project.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"esuiss": "index.mjs"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"index.mjs"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
}
|
|
19
|
+
}
|