@yopem-ui/cli 0.0.2

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/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @yopem-ui/cli
2
+
3
+ Copy Yopem UI components and configure StyleX in an existing React project.
4
+ Requires Bun. Until the registry is deployed, run the docs server on
5
+ `http://localhost:3100` before using the CLI.
6
+
7
+ ```sh
8
+ bunx @yopem-ui/cli init
9
+ bunx @yopem-ui/cli add button
10
+ bunx @yopem-ui/cli update button
11
+ ```
12
+
13
+ `init` supports Vite, TanStack Router, TanStack Start, React Router, Next.js App
14
+ Router, and Astro. Pass `--framework <name>` if autodetection is ambiguous.
15
+ Installed source changes stay intact on `init` and `add`; `update` rejects
16
+ modified files unless `--force` is supplied.
17
+
18
+ ## Licence
19
+
20
+ This project is licensed under the terms of the
21
+ [MIT license](https://github.com/yopem/ui/blob/main/LICENSE.md).
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@yopem-ui/cli",
3
+ "version": "0.0.2",
4
+ "description": "CLI for installing Yopem UI source components and StyleX setup",
5
+ "keywords": [
6
+ "cli",
7
+ "stylex",
8
+ "ui"
9
+ ],
10
+ "bugs": {
11
+ "url": "https://github.com/yopem/ui/issues"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Karyana Yandi <karyana@yandi.me>",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/yopem/ui.git",
18
+ "directory": "packages/cli"
19
+ },
20
+ "bin": {
21
+ "yopem-ui": "./src/cli.ts"
22
+ },
23
+ "files": [
24
+ "src"
25
+ ],
26
+ "type": "module",
27
+ "exports": {
28
+ "./cli": "./src/cli.ts",
29
+ "./init": "./src/init.ts",
30
+ "./install": "./src/install.ts"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "scripts": {
36
+ "typecheck": "tsc --noEmit"
37
+ },
38
+ "dependencies": {
39
+ "typescript-api": "npm:@typescript/typescript6@^6.0.2"
40
+ },
41
+ "engines": {
42
+ "bun": ">=1.3.0"
43
+ }
44
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import type { InitOptions } from "./init"
4
+
5
+ import { initProject } from "./init"
6
+ import { installItem } from "./install"
7
+
8
+ const usage =
9
+ "Usage: yopem-ui init [--framework vite|tanstack-router|tanstack-start|react-router|next|astro] | <add|update> <name> [--force]"
10
+
11
+ function isFramework(
12
+ value: string | undefined,
13
+ ): value is NonNullable<InitOptions["framework"]> {
14
+ return (
15
+ value === "vite" ||
16
+ value === "tanstack-router" ||
17
+ value === "tanstack-start" ||
18
+ value === "react-router" ||
19
+ value === "next" ||
20
+ value === "astro"
21
+ )
22
+ }
23
+
24
+ export async function runCli(args: string[], options: InitOptions = {}) {
25
+ const [command, name, ...flags] = args
26
+
27
+ if (command === "init") {
28
+ const framework = name === "--framework" ? args[2] : undefined
29
+
30
+ if (
31
+ args.length !== 1 &&
32
+ !(args.length === 3 && name === "--framework" && isFramework(framework))
33
+ ) {
34
+ throw new Error(usage)
35
+ }
36
+
37
+ const result = await initProject({
38
+ ...options,
39
+ framework: isFramework(framework) ? framework : undefined,
40
+ })
41
+
42
+ console.info(
43
+ `Configured ${result.framework} (${result.configured} file(s))`,
44
+ )
45
+
46
+ return result
47
+ }
48
+
49
+ if (
50
+ (command !== "add" && command !== "update") ||
51
+ !name ||
52
+ flags.some((flag) => flag !== "--force")
53
+ ) {
54
+ throw new Error(usage)
55
+ }
56
+
57
+ const result = await installItem(name, {
58
+ ...options,
59
+ mode: command,
60
+ force: flags.includes("--force"),
61
+ })
62
+
63
+ console.info(
64
+ `Installed ${result.installed} file(s), skipped ${result.skipped}`,
65
+ )
66
+
67
+ return result
68
+ }
69
+
70
+ if (import.meta.main) {
71
+ runCli(process.argv.slice(2)).catch((cause: unknown) => {
72
+ console.error(cause instanceof Error ? cause.message : cause)
73
+ process.exitCode = 1
74
+ })
75
+ }