FS 연습

polyfill

writeFile vs writeFileSync 명령어

컴포넌트 write

<aside> 💡 shadcn 방식 웹에 컴포넌트 정보 알려주는 json 올려놓음 → 해당 content 받아서 writefile

</aside>

TS-morph

async / await

transform

컴포넌트 string화

https://github.com/shadcn-ui/ui/blob/main/apps/www/scripts/build-registry.ts 참고

<aside> 💡 file 위치 찾아 read file → 원하는 위치에 write file

</aside>

export const writeButtonContentString = () => {
	const content = readFileSync(
		path.join(
			process.cwd(),
			"cli-export-practice/src/component/Button.tsx"
		),
		"utf-8"
	);
	fs.writeFileSync("buttonIndex.json", JSON.stringify(content), "utf-8");
};

+) build 명령어에 추가

// apps/www/package.json
"build": "contentlayer build && pnpm build:registry && next build",
"build:registry": "tsx --tsconfig ./tsconfig.scripts.json ./scripts/build-registry.ts",

+) exclude 속성 통해서 컴파일 대상에서 제외

// apps/www/tsconfig.json
"exclude": ["node_modules", "./scripts/build-registry.ts"]

❓컴파일 대상에서 제외해야 하는 이유?