atomsystem 0.1.15 → 0.1.17
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/cli/init.js +86 -118
- package/package.json +1 -1
package/cli/init.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import inquirer from "inquirer";
|
|
3
3
|
import { exec } from "child_process";
|
|
4
|
-
import fs, { copyFileSync } from "fs";
|
|
5
|
-
import path from "path";
|
|
4
|
+
import fs, { copyFileSync, mkdirSync, readdirSync } from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
import { promisify } from "util";
|
|
8
|
+
|
|
9
|
+
const execPromise = promisify(exec);
|
|
6
10
|
|
|
7
11
|
// 현재 실행중인 CLI 파일의 디렉토리 찾기
|
|
8
12
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -16,31 +20,9 @@ const tokenDir = path.join(packageRoot, "tokens");
|
|
|
16
20
|
// 프로젝트 루트 경로 (사용자가 실행한 곳)
|
|
17
21
|
const projectRoot = process.cwd();
|
|
18
22
|
const targetTokenFile = path.join(projectRoot, "token.json");
|
|
19
|
-
const targetTokensDir = path.join(projectRoot, "
|
|
20
|
-
|
|
21
|
-
//
|
|
22
|
-
copyFileSync(tokenFile, targetTokenFile);
|
|
23
|
-
console.log(`✅ Copied: token.json -> ${targetTokenFile}`);
|
|
24
|
-
|
|
25
|
-
// tokens 디렉토리 복사
|
|
26
|
-
if (!fs.existsSync(targetTokensDir)) {
|
|
27
|
-
mkdirSync(targetTokensDir, { recursive: true });
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// tokens 폴더 내의 모든 .js 파일 복사
|
|
31
|
-
const tokenFiles = readdirSync(tokensDir).filter((file) =>
|
|
32
|
-
file.endsWith(".js")
|
|
33
|
-
);
|
|
34
|
-
tokenFiles.forEach((file) => {
|
|
35
|
-
const sourcePath = path.join(tokensDir, file);
|
|
36
|
-
const targetPath = path.join(targetTokensDir, file);
|
|
37
|
-
copyFileSync(sourcePath, targetPath);
|
|
38
|
-
console.log(`✅ Copied: ${file} -> ${targetPath}`);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
console.log("🚀 Token setup complete!");
|
|
42
|
-
|
|
43
|
-
// 사용자에게 질문을 던져서 Next.js와 React를 설치할지 물어봅니다.
|
|
23
|
+
const targetTokensDir = path.join(projectRoot, "tokens");
|
|
24
|
+
|
|
25
|
+
// 사용자에게 Next.js 설치 여부 질문
|
|
44
26
|
inquirer
|
|
45
27
|
.prompt([
|
|
46
28
|
{
|
|
@@ -50,108 +32,94 @@ inquirer
|
|
|
50
32
|
default: true,
|
|
51
33
|
},
|
|
52
34
|
])
|
|
53
|
-
.then((answers) => {
|
|
35
|
+
.then(async (answers) => {
|
|
54
36
|
if (answers.installPackages) {
|
|
55
37
|
console.log("Installing Next.js and React...");
|
|
56
38
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// app 디렉토리 생성 및 layout.tsx, page.tsx 파일 추가
|
|
102
|
-
const appDir = path.join(process.cwd(), "app");
|
|
103
|
-
const layoutPath = path.join(appDir, "layout.tsx");
|
|
104
|
-
const pagePath = path.join(appDir, "page.tsx");
|
|
105
|
-
|
|
106
|
-
// app 디렉토리가 없으면 생성
|
|
107
|
-
if (!fs.existsSync(appDir)) {
|
|
108
|
-
fs.mkdirSync(appDir);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// layout.tsx 파일 내용
|
|
112
|
-
const layoutContent = `export default function RootLayout({
|
|
113
|
-
children,
|
|
114
|
-
}: {
|
|
115
|
-
children: React.ReactNode
|
|
116
|
-
}) {
|
|
39
|
+
try {
|
|
40
|
+
await execPromise(
|
|
41
|
+
"npm install next@latest react@latest react-dom@latest tailwindcss"
|
|
42
|
+
);
|
|
43
|
+
console.log("✅ Installation complete!");
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.error("❌ Error during installation:", err);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// package.json 업데이트
|
|
50
|
+
const packageJsonPath = path.join(projectRoot, "package.json");
|
|
51
|
+
try {
|
|
52
|
+
const packageJson = JSON.parse(
|
|
53
|
+
fs.readFileSync(packageJsonPath, "utf8")
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
packageJson.scripts = {
|
|
57
|
+
...packageJson.scripts,
|
|
58
|
+
dev: "npm run build:token && next dev",
|
|
59
|
+
build: "next build",
|
|
60
|
+
build_token:
|
|
61
|
+
"node tokens/buildTokenSplit.js && node tokens/buildMergeCss.js",
|
|
62
|
+
start: "next start",
|
|
63
|
+
lint: "next lint",
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
67
|
+
console.log("✅ Updated package.json with scripts.");
|
|
68
|
+
} catch (err) {
|
|
69
|
+
console.error("❌ Error updating package.json:", err);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// app 디렉토리 생성 및 파일 추가
|
|
74
|
+
const appDir = path.join(projectRoot, "app");
|
|
75
|
+
if (!fs.existsSync(appDir)) mkdirSync(appDir);
|
|
76
|
+
|
|
77
|
+
const files = [
|
|
78
|
+
{
|
|
79
|
+
path: path.join(appDir, "layout.tsx"),
|
|
80
|
+
content: `export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
117
81
|
return (
|
|
118
82
|
<html lang="en">
|
|
119
83
|
<body>{children}</body>
|
|
120
84
|
</html>
|
|
121
85
|
)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
86
|
+
}`,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
path: path.join(appDir, "page.tsx"),
|
|
90
|
+
content: `export default function Page() {
|
|
127
91
|
return <h1>Hello, Next.js!</h1>
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
console.log("Created layout.tsx.");
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// page.tsx 파일 생성
|
|
141
|
-
fs.writeFile(pagePath, pageContent, (err) => {
|
|
142
|
-
if (err) {
|
|
143
|
-
console.error("Error creating page.tsx:", err);
|
|
144
|
-
} else {
|
|
145
|
-
console.log("Created page.tsx.");
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
);
|
|
92
|
+
}`,
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
files.forEach(({ path, content }) => {
|
|
97
|
+
fs.writeFileSync(path, content);
|
|
98
|
+
console.log(`✅ Created ${path}`);
|
|
99
|
+
});
|
|
151
100
|
} else {
|
|
152
|
-
console.log("Installation skipped.");
|
|
101
|
+
console.log("🚀 Installation skipped.");
|
|
153
102
|
}
|
|
103
|
+
|
|
104
|
+
// ✅ 토큰 파일 복사 (Next.js 설치 여부와 관계없이 실행)
|
|
105
|
+
copyFileSync(tokenFile, targetTokenFile);
|
|
106
|
+
console.log(`✅ Copied: token.json -> ${targetTokenFile}`);
|
|
107
|
+
|
|
108
|
+
if (!fs.existsSync(targetTokensDir))
|
|
109
|
+
mkdirSync(targetTokensDir, { recursive: true });
|
|
110
|
+
|
|
111
|
+
const tokenFiles = readdirSync(tokenDir).filter((file) =>
|
|
112
|
+
file.endsWith(".js")
|
|
113
|
+
);
|
|
114
|
+
tokenFiles.forEach((file) => {
|
|
115
|
+
const sourcePath = path.join(tokenDir, file);
|
|
116
|
+
const targetPath = path.join(targetTokensDir, file);
|
|
117
|
+
copyFileSync(sourcePath, targetPath);
|
|
118
|
+
console.log(`✅ Copied: ${file} -> ${targetPath}`);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
console.log("🚀 Token setup complete!");
|
|
154
122
|
})
|
|
155
123
|
.catch((error) => {
|
|
156
|
-
console.error("Error:", error);
|
|
124
|
+
console.error("❌ Error:", error);
|
|
157
125
|
});
|