@jongh/cli 1.0.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.
@@ -0,0 +1,53 @@
1
+ import path from "node:path"
2
+ import fs from "fs-extra"
3
+ import { packageDirectorySync } from "pkg-dir"
4
+ import * as p from "@clack/prompts"
5
+ //TODO: json schema 제공
6
+ export async function getConfig(): Promise<{ outputPath: string }> {
7
+ const packageDirectory = packageDirectorySync() || process.cwd()
8
+ const configPath = path.join(packageDirectory, "park-ui.json")
9
+ try {
10
+ // 1. 프로젝트 루트 디렉토리 찾기
11
+
12
+ // 2. 설정 파일 읽기 시도
13
+ const config = await fs.readJSON(configPath)
14
+ return config
15
+ } catch {
16
+ // 4. 설정 파일이 없거나 잘못된 경우 사용자에게 입력받기
17
+ p.note("설정 파일이 존재하지 않습니다")
18
+ const config = await promptConfig() //3. 사용자에게 경로 관련 입력 받기
19
+
20
+ // 5. 새 설정 파일 저장
21
+ await fs.outputJSON(
22
+ configPath,
23
+ {
24
+ ...config,
25
+ },
26
+ { spaces: 2 },
27
+ )
28
+
29
+ return config
30
+ }
31
+ }
32
+
33
+ const promptConfig = async () =>
34
+ p.group(
35
+ {
36
+ outputPath: () =>
37
+ p.text({
38
+ message: "컴포넌트 저장 경로를 설정해주세요",
39
+ initialValue: "./src/components/ui",
40
+ validate: (value) => {
41
+ if (!value) return "Please enter a path."
42
+ if (!value.startsWith("."))
43
+ return "Please enter a relative path to the project root."
44
+ },
45
+ }),
46
+ },
47
+ {
48
+ onCancel: () => {
49
+ p.cancel("Operation cancelled.")
50
+ process.exit(0)
51
+ },
52
+ },
53
+ )
package/src/index.ts ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+
3
+ import yargs from "yargs"
4
+ import { hideBin } from "yargs/helpers"
5
+ import { getConfig } from "./getConfig"
6
+ import * as p from "@clack/prompts"
7
+ import { copyComponent } from "./fetchComponent"
8
+
9
+ const main = async () => {
10
+ await yargs(hideBin(process.argv))
11
+ .command(
12
+ "components add [components..]",
13
+ "Add components to your project",
14
+ (yargs) => {
15
+ return yargs
16
+ .positional("components", {
17
+ describe: "List of components to add",
18
+ type: "string",
19
+ array: true,
20
+ default: [],
21
+ })
22
+ .option("all", {
23
+ type: "boolean",
24
+ description: "Add all components",
25
+ default: false,
26
+ })
27
+ },
28
+ async (argv) => {
29
+ // 컴포넌트가 없고 --all 플래그도 없으면 에러
30
+ if (argv.components.length === 0 && !argv.all) {
31
+ p.note(
32
+ "Error: You need to specify at least one component or use the --all flag",
33
+ )
34
+ console.log('Run "cli --help" for more information')
35
+ return
36
+ }
37
+ const config = await getConfig()
38
+ await copyComponent(argv.components[0], config.outputPath)
39
+ },
40
+ )
41
+ .demandCommand(1, "You need at least one command before moving on")
42
+ .strict()
43
+ .help().argv
44
+ }
45
+
46
+ main()
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "emitDeclarationOnly": true,
5
+ "noImplicitAny": true,
6
+ "declaration": true,
7
+ "noEmit": false,
8
+ "declarationMap": true,
9
+ "declarationDir": "dist",
10
+ "outDir": "dist",
11
+ "baseUrl": "./"
12
+ },
13
+ "include": ["src"]
14
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { defineConfig } from "tsup"
2
+ import fs from "fs-extra"
3
+
4
+ export default defineConfig({
5
+ entry: ["src/index.ts"],
6
+ format: ["esm", "cjs"],
7
+ dts: true,
8
+ clean: true,
9
+ sourcemap: false,
10
+ minify: true,
11
+ async onSuccess() {
12
+ await fs.copy("../ui/src/components", "./dist/components")
13
+ },
14
+ })