vibe-design-system 1.9.12 → 2.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.
- package/bin/init.js +220 -116
- package/package.json +1 -1
package/bin/init.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* VDS
|
|
3
|
+
* VDS init: npx vibe-design-system init
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
5
|
+
* ADIM 1 — Bağımlılık kontrolü (storybook, @storybook/react-vite)
|
|
6
|
+
* ADIM 2 — .storybook/ (main.ts, preview.ts)
|
|
7
|
+
* ADIM 3 — vds-core/ kopyala
|
|
8
|
+
* ADIM 4 — package.json scriptleri
|
|
9
|
+
* ADIM 5 — .cursorrules
|
|
10
|
+
* ADIM 6 — src/stories/
|
|
11
|
+
* ADIM 7 — İlk tarama (scan + story-generator)
|
|
12
|
+
* ADIM 8 — Başarı mesajı
|
|
13
|
+
* ADIM 9 — Storybook örnek dosyalarını sil
|
|
12
14
|
*/
|
|
13
15
|
import fs from "fs";
|
|
14
16
|
import path from "path";
|
|
@@ -19,125 +21,205 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
19
21
|
const INSTALLER_ROOT = path.join(__dirname, "..");
|
|
20
22
|
const TEMPLATE_DIR = path.join(INSTALLER_ROOT, "vds-core-template");
|
|
21
23
|
|
|
24
|
+
const STORYBOOK_MAIN_TS = `import type { StorybookConfig } from "@storybook/react-vite";
|
|
25
|
+
const config: StorybookConfig = {
|
|
26
|
+
stories: ["../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
|
|
27
|
+
addons: ["@storybook/addon-essentials"],
|
|
28
|
+
framework: {
|
|
29
|
+
name: "@storybook/react-vite",
|
|
30
|
+
options: {},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
export default config;
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
const STORYBOOK_PREVIEW_TS = `import type { Preview } from "@storybook/react";
|
|
37
|
+
import "../src/index.css";
|
|
38
|
+
const preview: Preview = { parameters: { layout: "centered" } };
|
|
39
|
+
export default preview;
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
const CURSORRULES = `# VDS — Vibe Design System
|
|
43
|
+
Bu proje VDS kullanıyor. Komutlar:
|
|
44
|
+
- npm run vds → projeyi tara
|
|
45
|
+
- npm run vds:stories → Storybook story'lerini üret
|
|
46
|
+
- npm run vds:watch → değişiklikleri izle
|
|
47
|
+
- npm run storybook → design system'ı aç (localhost:6006)
|
|
48
|
+
|
|
49
|
+
Geliştirme kuralları:
|
|
50
|
+
- UI component'leri src/components/ui/ altına koy
|
|
51
|
+
- Variant'lar için cva() kullan
|
|
52
|
+
- Tailwind CSS kullan
|
|
53
|
+
- Named export veya default export — ikisi de çalışır
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
const WATCH_MJS = `#!/usr/bin/env node
|
|
57
|
+
import { spawnSync } from "child_process";
|
|
58
|
+
import path from "path";
|
|
59
|
+
import { fileURLToPath } from "url";
|
|
60
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
61
|
+
const projectRoot = path.join(__dirname, "..");
|
|
62
|
+
const r = spawnSync("node", [path.join(__dirname, "scan.mjs"), "--watch"], {
|
|
63
|
+
cwd: projectRoot,
|
|
64
|
+
stdio: "inherit",
|
|
65
|
+
});
|
|
66
|
+
process.exit(r.status ?? 0);
|
|
67
|
+
`;
|
|
68
|
+
|
|
69
|
+
const STORYBOOK_EXAMPLE_FILES = [
|
|
70
|
+
"Button.stories.js",
|
|
71
|
+
"Header.stories.js",
|
|
72
|
+
"Page.stories.js",
|
|
73
|
+
"Button.jsx",
|
|
74
|
+
"Header.jsx",
|
|
75
|
+
"Page.jsx",
|
|
76
|
+
];
|
|
77
|
+
|
|
22
78
|
function getProjectRoot() {
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(cwd, "package.json"), "utf-8"));
|
|
26
|
-
if (pkg.name === "vibe-design-system") return path.join(cwd, "..");
|
|
27
|
-
} catch (_) {}
|
|
28
|
-
return cwd;
|
|
79
|
+
return process.cwd();
|
|
29
80
|
}
|
|
30
81
|
|
|
31
|
-
function
|
|
32
|
-
const storybookDir = path.join(projectRoot, ".storybook");
|
|
33
|
-
if (fs.existsSync(storybookDir)) return true;
|
|
82
|
+
function readPackageJson(projectRoot) {
|
|
34
83
|
const pkgPath = path.join(projectRoot, "package.json");
|
|
84
|
+
if (!fs.existsSync(pkgPath)) return null;
|
|
35
85
|
try {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
86
|
+
return JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
87
|
+
} catch (_) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ADIM 1 — Bağımlılık kontrolü
|
|
93
|
+
function needsStorybook(projectRoot) {
|
|
94
|
+
const pkg = readPackageJson(projectRoot);
|
|
95
|
+
if (!pkg) return false;
|
|
96
|
+
const dev = pkg.devDependencies || {};
|
|
97
|
+
return !(dev.storybook && dev["@storybook/react-vite"]);
|
|
41
98
|
}
|
|
42
99
|
|
|
43
100
|
function installStorybook(projectRoot) {
|
|
44
|
-
console.log("📚 Storybook kuruluyor...");
|
|
45
|
-
const r = spawnSync(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
101
|
+
console.log("📚 Storybook bağımlılıkları kuruluyor...");
|
|
102
|
+
const r = spawnSync(
|
|
103
|
+
"npm",
|
|
104
|
+
["install", "--save-dev", "storybook", "@storybook/react", "@storybook/react-vite"],
|
|
105
|
+
{ cwd: projectRoot, stdio: "inherit" }
|
|
106
|
+
);
|
|
50
107
|
if (r.status !== 0) {
|
|
51
|
-
console.warn("⚠️
|
|
108
|
+
console.warn("⚠️ npm install storybook tamamlanamadı.");
|
|
52
109
|
}
|
|
53
110
|
}
|
|
54
111
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
112
|
+
// ADIM 2 — .storybook/
|
|
113
|
+
function ensureStorybook(projectRoot) {
|
|
114
|
+
const storybookDir = path.join(projectRoot, ".storybook");
|
|
115
|
+
if (!fs.existsSync(storybookDir)) {
|
|
116
|
+
fs.mkdirSync(storybookDir, { recursive: true });
|
|
117
|
+
console.log("📁 .storybook/ oluşturuldu.");
|
|
118
|
+
}
|
|
58
119
|
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
date: /Date$/i,
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
decorators: [
|
|
69
|
-
(Story) => (
|
|
70
|
-
<div className="dark" style={{ minHeight: "100vh", padding: "1rem" }}>
|
|
71
|
-
<Story />
|
|
72
|
-
</div>
|
|
73
|
-
),
|
|
74
|
-
],
|
|
75
|
-
};
|
|
120
|
+
const mainPath = path.join(storybookDir, "main.ts");
|
|
121
|
+
if (!fs.existsSync(mainPath)) {
|
|
122
|
+
fs.writeFileSync(mainPath, STORYBOOK_MAIN_TS, "utf-8");
|
|
123
|
+
console.log("📝 .storybook/main.ts yazıldı.");
|
|
124
|
+
}
|
|
76
125
|
|
|
77
|
-
|
|
78
|
-
|
|
126
|
+
const previewPath = path.join(storybookDir, "preview.ts");
|
|
127
|
+
if (!fs.existsSync(previewPath)) {
|
|
128
|
+
fs.writeFileSync(previewPath, STORYBOOK_PREVIEW_TS, "utf-8");
|
|
129
|
+
console.log("📝 .storybook/preview.ts yazıldı.");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
79
132
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (!fs.existsSync(
|
|
133
|
+
// ADIM 3 — vds-core/ kopyala
|
|
134
|
+
function copyDirRecursive(src, dest) {
|
|
135
|
+
if (!fs.existsSync(src)) return;
|
|
136
|
+
if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
|
|
137
|
+
for (const name of fs.readdirSync(src)) {
|
|
138
|
+
const srcPath = path.join(src, name);
|
|
139
|
+
const destPath = path.join(dest, name);
|
|
140
|
+
if (fs.statSync(srcPath).isDirectory()) {
|
|
141
|
+
copyDirRecursive(srcPath, destPath);
|
|
142
|
+
} else {
|
|
143
|
+
fs.copyFileSync(srcPath, destPath);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
83
147
|
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
if (fs.existsSync(
|
|
87
|
-
|
|
88
|
-
|
|
148
|
+
function ensureVdsCore(projectRoot) {
|
|
149
|
+
const vdsCoreDest = path.join(projectRoot, "vds-core");
|
|
150
|
+
if (!fs.existsSync(vdsCoreDest)) {
|
|
151
|
+
fs.mkdirSync(vdsCoreDest, { recursive: true });
|
|
152
|
+
}
|
|
153
|
+
copyDirRecursive(TEMPLATE_DIR, vdsCoreDest);
|
|
154
|
+
const watchPath = path.join(vdsCoreDest, "watch.mjs");
|
|
155
|
+
if (!fs.existsSync(watchPath)) {
|
|
156
|
+
fs.writeFileSync(watchPath, WATCH_MJS, "utf-8");
|
|
157
|
+
}
|
|
158
|
+
console.log("📦 vds-core/ hazır.");
|
|
89
159
|
}
|
|
90
160
|
|
|
161
|
+
// ADIM 4 — package.json scriptleri
|
|
91
162
|
function addScripts(projectRoot) {
|
|
92
163
|
const pkgPath = path.join(projectRoot, "package.json");
|
|
93
|
-
const pkg =
|
|
164
|
+
const pkg = readPackageJson(projectRoot);
|
|
165
|
+
if (!pkg) return;
|
|
94
166
|
const scripts = pkg.scripts || {};
|
|
95
|
-
|
|
96
|
-
if (!scripts
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (!scripts["
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
167
|
+
let changed = false;
|
|
168
|
+
if (!scripts.vds) {
|
|
169
|
+
scripts.vds = "node vds-core/scan.mjs";
|
|
170
|
+
changed = true;
|
|
171
|
+
}
|
|
172
|
+
if (!scripts["vds:stories"]) {
|
|
173
|
+
scripts["vds:stories"] = "node vds-core/story-generator.mjs";
|
|
174
|
+
changed = true;
|
|
175
|
+
}
|
|
176
|
+
if (!scripts["vds:watch"]) {
|
|
177
|
+
scripts["vds:watch"] = "node vds-core/watch.mjs";
|
|
178
|
+
changed = true;
|
|
179
|
+
}
|
|
180
|
+
if (!scripts.storybook) {
|
|
181
|
+
scripts.storybook = "storybook dev -p 6006";
|
|
182
|
+
changed = true;
|
|
183
|
+
}
|
|
184
|
+
if (!scripts["build-storybook"]) {
|
|
185
|
+
scripts["build-storybook"] = "storybook build";
|
|
186
|
+
changed = true;
|
|
187
|
+
}
|
|
188
|
+
if (changed) {
|
|
189
|
+
pkg.scripts = scripts;
|
|
112
190
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2), "utf-8");
|
|
113
|
-
|
|
114
|
-
if (r.status !== 0) console.warn("npm install uyarı verdi; manuel çalıştırın: npm install");
|
|
191
|
+
console.log("📜 package.json scriptleri eklendi.");
|
|
115
192
|
}
|
|
116
193
|
}
|
|
117
194
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
195
|
+
// ADIM 5 — .cursorrules
|
|
196
|
+
function ensureCursorrules(projectRoot) {
|
|
197
|
+
const p = path.join(projectRoot, ".cursorrules");
|
|
198
|
+
fs.writeFileSync(p, CURSORRULES, "utf-8");
|
|
199
|
+
console.log("📄 .cursorrules yazıldı.");
|
|
200
|
+
}
|
|
121
201
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
202
|
+
// ADIM 6 — src/stories/ (ve scan için gerekli src/components, src/pages)
|
|
203
|
+
function ensureStoriesDir(projectRoot) {
|
|
204
|
+
const srcDir = path.join(projectRoot, "src");
|
|
205
|
+
if (!fs.existsSync(srcDir)) fs.mkdirSync(srcDir, { recursive: true });
|
|
206
|
+
const storiesDir = path.join(srcDir, "stories");
|
|
207
|
+
if (!fs.existsSync(storiesDir)) {
|
|
208
|
+
fs.mkdirSync(storiesDir, { recursive: true });
|
|
209
|
+
console.log("📁 src/stories/ oluşturuldu.");
|
|
128
210
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
211
|
+
const componentsDir = path.join(srcDir, "components");
|
|
212
|
+
if (!fs.existsSync(componentsDir)) {
|
|
213
|
+
fs.mkdirSync(componentsDir, { recursive: true });
|
|
214
|
+
console.log("📁 src/components/ oluşturuldu (VDS taraması için).");
|
|
133
215
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
fs.copyFileSync(storyGenSrc, path.join(vdsCoreDest, "story-generator.mjs"));
|
|
216
|
+
const pagesDir = path.join(srcDir, "pages");
|
|
217
|
+
if (!fs.existsSync(pagesDir)) {
|
|
218
|
+
fs.mkdirSync(pagesDir, { recursive: true });
|
|
138
219
|
}
|
|
139
220
|
}
|
|
140
221
|
|
|
222
|
+
// ADIM 7 — İlk tarama
|
|
141
223
|
function runScan(projectRoot) {
|
|
142
224
|
const scanPath = path.join(projectRoot, "vds-core", "scan.mjs");
|
|
143
225
|
if (!fs.existsSync(scanPath)) return;
|
|
@@ -162,39 +244,61 @@ function runStoryGenerator(projectRoot) {
|
|
|
162
244
|
if (r.status !== 0) process.exitCode = r.status ?? 1;
|
|
163
245
|
}
|
|
164
246
|
|
|
165
|
-
|
|
247
|
+
// ADIM 9 — Storybook örnek dosyalarını sil
|
|
248
|
+
function removeStorybookExamples(projectRoot) {
|
|
249
|
+
const storiesDir = path.join(projectRoot, "src", "stories");
|
|
250
|
+
if (!fs.existsSync(storiesDir)) return;
|
|
251
|
+
for (const name of STORYBOOK_EXAMPLE_FILES) {
|
|
252
|
+
const filePath = path.join(storiesDir, name);
|
|
253
|
+
if (fs.existsSync(filePath)) {
|
|
254
|
+
try {
|
|
255
|
+
fs.unlinkSync(filePath);
|
|
256
|
+
console.log("🗑️ Silindi: src/stories/" + name);
|
|
257
|
+
} catch (_) {}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ——— main ———
|
|
263
|
+
console.log("🎨 VDS kuruluyor...\n");
|
|
166
264
|
|
|
167
265
|
const projectRoot = getProjectRoot();
|
|
168
|
-
const
|
|
169
|
-
if (!
|
|
266
|
+
const pkg = readPackageJson(projectRoot);
|
|
267
|
+
if (!pkg) {
|
|
170
268
|
console.error("❌ Bu klasörde package.json bulunamadı.");
|
|
171
|
-
console.error("VDS, mevcut bir React projesine kurulmalıdır.");
|
|
172
269
|
process.exit(1);
|
|
173
270
|
}
|
|
174
271
|
|
|
175
|
-
// 1
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
// 2. Install Storybook if not present
|
|
179
|
-
if (!isStorybookInstalled(projectRoot)) {
|
|
272
|
+
// ADIM 1
|
|
273
|
+
if (needsStorybook(projectRoot)) {
|
|
180
274
|
installStorybook(projectRoot);
|
|
181
275
|
} else {
|
|
182
|
-
console.log("📚 Storybook zaten
|
|
276
|
+
console.log("📚 Storybook zaten yüklü.");
|
|
183
277
|
}
|
|
184
278
|
|
|
185
|
-
//
|
|
186
|
-
|
|
279
|
+
// ADIM 2
|
|
280
|
+
ensureStorybook(projectRoot);
|
|
281
|
+
|
|
282
|
+
// ADIM 3
|
|
283
|
+
ensureVdsCore(projectRoot);
|
|
187
284
|
|
|
188
|
-
//
|
|
285
|
+
// ADIM 4
|
|
189
286
|
addScripts(projectRoot);
|
|
190
|
-
addVdsDependency(projectRoot);
|
|
191
287
|
|
|
192
|
-
//
|
|
193
|
-
|
|
288
|
+
// ADIM 5
|
|
289
|
+
ensureCursorrules(projectRoot);
|
|
290
|
+
|
|
291
|
+
// ADIM 6
|
|
292
|
+
ensureStoriesDir(projectRoot);
|
|
194
293
|
|
|
195
|
-
//
|
|
294
|
+
// ADIM 9 (örnek dosyaları taramadan önce silebiliriz; scan src/components ve src/pages tarar, src/stories değil)
|
|
295
|
+
removeStorybookExamples(projectRoot);
|
|
296
|
+
|
|
297
|
+
// ADIM 7
|
|
298
|
+
runScan(projectRoot);
|
|
196
299
|
runStoryGenerator(projectRoot);
|
|
197
300
|
|
|
198
|
-
|
|
199
|
-
console.log("
|
|
200
|
-
console.log("
|
|
301
|
+
// ADIM 8
|
|
302
|
+
console.log("\n✅ VDS kuruldu!");
|
|
303
|
+
console.log("→ npm run storybook ile design system'ını aç");
|
|
304
|
+
console.log("→ npm run vds:watch ile otomatik güncellemeyi başlat\n");
|