Ver código fonte

Bubgix: Auto install problems fixed.

lfabl 1 semana atrás
pai
commit
cf63415c5b
6 arquivos alterados com 276 adições e 141 exclusões
  1. 38 0
      bin/setup-mobile.js
  2. 37 0
      bin/setup-web.js
  3. 24 139
      bin/setup.js
  4. 172 0
      bin/type-kit.js
  5. 4 1
      package.json
  6. 1 1
      tsconfig.json

+ 38 - 0
bin/setup-mobile.js

@@ -0,0 +1,38 @@
+#!/usr/bin/env node
+/* eslint-disable */
+
+const fs = require("fs");
+const path = require("path");
+
+console.log("NCore UI Kit - Mobile Kurulumu");
+console.log("==============================");
+
+const targetDir = process.cwd();
+const targetPath = path.resolve(targetDir, "metro.config.js");
+
+if (fs.existsSync(targetPath)) {
+    let content = fs.readFileSync(targetPath, "utf-8");
+
+    if (!content.includes("withNCoreUIKit")) {
+        content = "const { withNCoreUIKit } = require(\"ncore-ui-kit/metro-config\");\n" + content;
+
+        if (/module\.exports\s*=\s*\{/.test(content)) {
+            content = content.replace(/module\.exports\s*=\s*\{/g, "const _ncoreMetroConfig = {");
+            content += "\nmodule.exports = withNCoreUIKit(_ncoreMetroConfig);\n";
+            fs.writeFileSync(targetPath, content);
+            console.log("✅ metro.config.js başarıyla güncellendi.");
+        }
+
+        else if (/module\.exports\s*=\s*([^;]+);?/.test(content)) {
+            content = content.replace(/module\.exports\s*=\s*([^;]+);?/g, "module.exports = withNCoreUIKit($1);");
+            fs.writeFileSync(targetPath, content);
+            console.log("✅ metro.config.js başarıyla güncellendi.");
+        } else {
+            console.log("⚠️ metro.config.js formatı anlaşılamadı. Lütfen config objesini withNCoreUIKit ile manuel olarak sarmalayın.");
+        }
+    } else {
+        console.log("✅ metro.config.js zaten ayarlı.");
+    }
+} else {
+    console.log("⚠️ metro.config.js bulunamadı. Mobile projesi değilse bu adımı atlayabilirsiniz.");
+}

+ 37 - 0
bin/setup-web.js

@@ -0,0 +1,37 @@
+#!/usr/bin/env node
+/* eslint-disable */
+
+const fs = require("fs");
+const path = require("path");
+
+console.log("NCore UI Kit - Web Kurulumu");
+console.log("===========================");
+
+const targetDir = process.cwd();
+const targetPath = path.resolve(targetDir, "webpack.config.js");
+
+if (fs.existsSync(targetPath)) {
+    let content = fs.readFileSync(targetPath, "utf-8");
+    if (!content.includes("withNCoreUIKitWebpack")) {
+        content = "const { withNCoreUIKitWebpack } = require(\"ncore-ui-kit/webpack-config\");\n" + content;
+
+        if (/module\.exports\s*=\s*\{/.test(content)) {
+            content = content.replace(/module\.exports\s*=\s*\{/g, "const _ncoreConfig = {");
+            content += "\nmodule.exports = withNCoreUIKitWebpack(_ncoreConfig, webpack);\n";
+            fs.writeFileSync(targetPath, content);
+            console.log("✅ webpack.config.js başarıyla güncellendi.");
+        }
+
+        else if (/module\.exports\s*=\s*([a-zA-Z0-9_]+)/.test(content)) {
+            content = content.replace(/module\.exports\s*=\s*([a-zA-Z0-9_]+);?/g, "module.exports = withNCoreUIKitWebpack($1, webpack);");
+            fs.writeFileSync(targetPath, content);
+            console.log("✅ webpack.config.js başarıyla güncellendi.");
+        } else {
+            console.log("⚠️ webpack.config.js formatı anlaşılamadı. Lütfen config objesini withNCoreUIKitWebpack ile manuel olarak sarmalayın.");
+        }
+    } else {
+        console.log("✅ webpack.config.js zaten ayarlı.");
+    }
+} else {
+    console.log("⚠️ webpack.config.js bulunamadı. Web projesi değilse bu adımı atlayabilirsiniz.");
+}

+ 24 - 139
bin/setup.js

@@ -1,154 +1,39 @@
 #!/usr/bin/env node
-/* eslint-disable @typescript-eslint/no-require-imports */
+/* eslint-disable */
 
-const fs = require("fs");
+const {
+    execSync
+} = require("child_process");
 const path = require("path");
+const fs = require("fs");
 
-const targetDir = process.cwd();
-const sourceDir = path.resolve(__dirname, "..");
-
-const args = process.argv.slice(2);
-const initAll = args.includes("--init-all");
-const initVscode = args.includes("--init-vscode") || initAll;
-const initEslint = args.includes("--init-eslint") || initAll;
-const initTsconfig = args.includes("--init-tsconfig") || initAll;
-
-console.log("NCore UI Kit Environment Setup Tool");
-console.log("=====================================");
-console.log(`Hedef Proje Dizini: ${targetDir}`);
-console.log("");
-
-if (!initVscode && !initEslint && !initTsconfig) {
-    console.log("Herhangi bir başlatma argümanı (--init-vscode, --init-eslint, --init-tsconfig, --init-all) bulunamadı.");
-    console.log("Otomatik ayar kopyalama/birleştirme işlemleri atlanıyor...");
-    console.log("Not: Ayarları projeye dahil etmek için kurulum komutuna ilgili bayrakları ekleyebilirsiniz.");
-    console.log("");
-    process.exit(0);
-}
-
-// JSON parse helper that ignores comments
-function parseJSON(content) {
-    try {
-        const jsonc = content.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => g ? "" : m);
-        return JSON.parse(jsonc);
-    } catch (e) {
-        console.error(e);
-
-        return null;
-    }
-}
-
-// 1. .vscode/settings.json
-if (initVscode) {
-    const sourceVscodeDir = path.join(sourceDir, ".vscode");
-    const targetVscodeDir = path.join(targetDir, ".vscode");
-
-    if (fs.existsSync(sourceVscodeDir)) {
-        if (!fs.existsSync(targetVscodeDir)) {
-            fs.mkdirSync(targetVscodeDir, {
-                recursive: true
-            });
-        }
-        const sourceSettings = path.join(sourceVscodeDir, "settings.json");
-        const targetSettings = path.join(targetVscodeDir, "settings.json");
-
-        if (fs.existsSync(sourceSettings)) {
-            if (fs.existsSync(targetSettings)) {
-                const targetContent = parseJSON(fs.readFileSync(targetSettings, "utf-8")) || {};
-                const sourceContent = parseJSON(fs.readFileSync(sourceSettings, "utf-8")) || {};
-                const merged = {
-                    ...sourceContent,
-                    ...targetContent
-                };
-                fs.writeFileSync(targetSettings, JSON.stringify(merged, null, 4));
-                console.log("✅ .vscode/settings.json birleştirildi (mevcut ayarlarınız korundu).");
-            } else {
-                fs.copyFileSync(sourceSettings, targetSettings);
-                console.log("✅ .vscode/settings.json kopyalandı.");
-            }
-        }
-    }
-}
+console.log("NCore UI Kit - Genel Kurulum (Web & Mobile)");
+console.log("===========================================");
 
-// 2 & 3. ESLint configs
-if (initEslint) {
-    const sourceEslint = path.join(sourceDir, "eslint.config.mjs");
-    const targetEslint = path.join(targetDir, "eslint.config.mjs");
-    if (fs.existsSync(sourceEslint)) {
-        if (!fs.existsSync(targetEslint)) {
-            fs.copyFileSync(sourceEslint, targetEslint);
-            console.log("✅ eslint.config.mjs kopyalandı.");
-        } else {
-            console.log("⚠️ eslint.config.mjs hedef projede zaten var, üzerine yazılmadı.");
-        }
-    }
+const setupWebPath = path.join(__dirname, "setup-web.js");
+const setupMobilePath = path.join(__dirname, "setup-mobile.js");
 
-    const sourceLocalRules = path.join(sourceDir, "eslint-local-rules");
-    const targetLocalRules = path.join(targetDir, "eslint-local-rules");
-    if (fs.existsSync(sourceLocalRules)) {
-        if (!fs.existsSync(targetLocalRules)) {
-            fs.mkdirSync(targetLocalRules, {
-                recursive: true
-            });
-        }
-        const files = fs.readdirSync(sourceLocalRules);
-        files.forEach(file => {
-            const sourceFile = path.join(sourceLocalRules, file);
-            const targetFile = path.join(targetLocalRules, file);
-            if (fs.lstatSync(sourceFile).isFile()) {
-                fs.copyFileSync(sourceFile, targetFile);
-            }
+try {
+    if (fs.existsSync(setupWebPath)) {
+        execSync(`node "${setupWebPath}"`, {
+            stdio: "inherit"
         });
-        console.log("✅ eslint-local-rules/ güncellendi.");
     }
+} catch (error) {
+    console.error("Web kurulumu sırasında bir hata oluştu:", error.message);
 }
 
-// 4. tsconfig.json
-if (initTsconfig) {
-    const sourceTsconfigPath = path.join(sourceDir, "tsconfig.json");
-    const targetTsconfigPath = path.join(targetDir, "tsconfig.json");
-
-    if (fs.existsSync(sourceTsconfigPath)) {
-        const sourceTsconfig = parseJSON(fs.readFileSync(sourceTsconfigPath, "utf-8")) || {};
+console.log(""); // Boşluk
 
-        // ncore-ui-kit iç path tanımlarını projeye aktarmamak için temizliyoruz
-        if (sourceTsconfig.compilerOptions && sourceTsconfig.compilerOptions.paths && sourceTsconfig.compilerOptions.paths["ncore-ui-kit"]) {
-            delete sourceTsconfig.compilerOptions.paths["ncore-ui-kit"];
-        }
-
-        if (fs.existsSync(targetTsconfigPath)) {
-            const targetTsconfig = parseJSON(fs.readFileSync(targetTsconfigPath, "utf-8")) || {};
-
-            // Üzerine ekleme metodu (hedef projenin ayarları önceliklidir)
-            const mergedTsconfig = {
-                ...sourceTsconfig,
-                ...targetTsconfig,
-                compilerOptions: {
-                    ...(sourceTsconfig.compilerOptions || {}),
-                    ...(targetTsconfig.compilerOptions || {})
-                }
-            };
-
-            // Paths birleştirme
-            if (sourceTsconfig.compilerOptions?.paths || targetTsconfig.compilerOptions?.paths) {
-                mergedTsconfig.compilerOptions.paths = {
-                    ...(sourceTsconfig.compilerOptions?.paths || {}),
-                    ...(targetTsconfig.compilerOptions?.paths || {})
-                };
-            }
-
-            // Kullanıcının include ve exclude ayarlarını KESİNLİKLE koru
-            if (targetTsconfig.include) mergedTsconfig.include = targetTsconfig.include;
-            if (targetTsconfig.exclude) mergedTsconfig.exclude = targetTsconfig.exclude;
-
-            fs.writeFileSync(targetTsconfigPath, JSON.stringify(mergedTsconfig, null, 4));
-            console.log("✅ tsconfig.json mevcut dosyanız ile birleştirildi (include/exclude ve proje ayarları korundu).");
-        } else {
-            fs.writeFileSync(targetTsconfigPath, JSON.stringify(sourceTsconfig, null, 4));
-            console.log("✅ tsconfig.json oluşturuldu.");
-        }
+try {
+    if (fs.existsSync(setupMobilePath)) {
+        execSync(`node "${setupMobilePath}"`, {
+            stdio: "inherit"
+        });
     }
+} catch (error) {
+    console.error("Mobile kurulumu sırasında bir hata oluştu:", error.message);
 }
 
 console.log("");
-console.log("NCore standartlarıyla iyi kodlamalar dileriz!");
+console.log("Not: Tip ayarlarını (tsconfig, eslint vb.) yapmak isterseniz 'npx ncore-type-kit' komutunu kullanabilirsiniz.");

+ 172 - 0
bin/type-kit.js

@@ -0,0 +1,172 @@
+#!/usr/bin/env node
+/* eslint-disable */
+/* eslint-disable @typescript-eslint/no-require-imports */
+
+const fs = require("fs");
+const path = require("path");
+
+const targetDir = process.cwd();
+const sourceDir = path.resolve(__dirname, "..");
+
+const args = process.argv.slice(2);
+const initAll = args.includes("--init-all");
+const initVscode = args.includes("--init-vscode") || initAll;
+const initEslint = args.includes("--init-eslint") || initAll;
+const initTsconfig = args.includes("--init-tsconfig") || initAll;
+
+console.log("NCore UI Kit Environment Setup Tool");
+console.log("=====================================");
+console.log(`Hedef Proje Dizini: ${targetDir}`);
+console.log("");
+
+if (!initVscode && !initEslint && !initTsconfig) {
+    console.log("Herhangi bir başlatma argümanı (--init-vscode, --init-eslint, --init-tsconfig, --init-all) bulunamadı.");
+    console.log("Otomatik ayar kopyalama/birleştirme işlemleri atlanıyor...");
+    console.log("Not: Ayarları projeye dahil etmek için kurulum komutuna ilgili bayrakları ekleyebilirsiniz.");
+    console.log("");
+
+    process.exit(0);
+}
+
+// JSON parse helper that ignores comments and trailing commas
+function parseJSON(content, isTarget = false) {
+    if (!content || content.trim() === "") return {};
+    try {
+        const jsonc = content.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => g ? "" : m);
+        const cleanJson = jsonc.replace(/,\s*([\]}])/g, "$1");
+
+        return JSON.parse(cleanJson);
+    } catch (e) {
+        console.error("JSON parse hatası: Dosya okunamadı veya düzgün formatta değil.");
+
+        if (isTarget) {
+            console.error("Hedef dosya parse edilemediği için işlem iptal ediliyor (veri kaybını önlemek için).");
+            process.exit(1);
+        }
+
+        return null;
+    }
+}
+
+// 1. .vscode/settings.json
+if (initVscode) {
+    const sourceVscodeDir = path.join(sourceDir, ".vscode");
+    const targetVscodeDir = path.join(targetDir, ".vscode");
+
+    if (fs.existsSync(sourceVscodeDir)) {
+        if (!fs.existsSync(targetVscodeDir)) {
+            fs.mkdirSync(targetVscodeDir, {
+                recursive: true
+            });
+        }
+
+        const sourceSettings = path.join(sourceVscodeDir, "settings.json");
+        const targetSettings = path.join(targetVscodeDir, "settings.json");
+
+        if (fs.existsSync(sourceSettings)) {
+            if (fs.existsSync(targetSettings)) {
+                const targetContent = parseJSON(fs.readFileSync(targetSettings, "utf-8"), true) || {};
+                const sourceContent = parseJSON(fs.readFileSync(sourceSettings, "utf-8")) || {};
+
+                const merged = {
+                    ...sourceContent,
+                    ...targetContent
+                };
+
+                fs.writeFileSync(targetSettings, JSON.stringify(merged, null, 4));
+
+                console.log("✅ .vscode/settings.json birleştirildi (mevcut ayarlarınız korundu).");
+            } else {
+                fs.copyFileSync(sourceSettings, targetSettings);
+                console.log("✅ .vscode/settings.json kopyalandı.");
+            }
+        }
+    }
+}
+
+// 2 & 3. ESLint configs
+if (initEslint) {
+    const sourceEslint = path.join(sourceDir, "eslint.config.mjs");
+    const targetEslint = path.join(targetDir, "eslint.config.mjs");
+
+    if (fs.existsSync(sourceEslint)) {
+        if (!fs.existsSync(targetEslint)) {
+            fs.copyFileSync(sourceEslint, targetEslint);
+            console.log("✅ eslint.config.mjs kopyalandı.");
+        } else {
+            console.log("⚠️ eslint.config.mjs hedef projede zaten var, üzerine yazılmadı.");
+        }
+    }
+
+    const sourceLocalRules = path.join(sourceDir, "eslint-local-rules");
+    const targetLocalRules = path.join(targetDir, "eslint-local-rules");
+
+    if (fs.existsSync(sourceLocalRules)) {
+        if (!fs.existsSync(targetLocalRules)) {
+            fs.mkdirSync(targetLocalRules, {
+                recursive: true
+            });
+        }
+
+        const files = fs.readdirSync(sourceLocalRules);
+
+        files.forEach(file => {
+            const sourceFile = path.join(sourceLocalRules, file);
+            const targetFile = path.join(targetLocalRules, file);
+
+            if (fs.lstatSync(sourceFile).isFile()) {
+                fs.copyFileSync(sourceFile, targetFile);
+            }
+        });
+
+        console.log("✅ eslint-local-rules/ güncellendi.");
+    }
+}
+
+// 4. tsconfig.json
+if (initTsconfig) {
+    const sourceTsconfigPath = path.join(sourceDir, "tsconfig.json");
+    const targetTsconfigPath = path.join(targetDir, "tsconfig.json");
+
+    if (fs.existsSync(sourceTsconfigPath)) {
+        const sourceTsconfig = parseJSON(fs.readFileSync(sourceTsconfigPath, "utf-8")) || {};
+
+        if (sourceTsconfig.compilerOptions && sourceTsconfig.compilerOptions.paths) {
+            delete sourceTsconfig.compilerOptions.paths;
+        }
+
+        if (fs.existsSync(targetTsconfigPath)) {
+            const targetTsconfig = parseJSON(fs.readFileSync(targetTsconfigPath, "utf-8"), true) || {};
+
+            const mergedTsconfig = {
+                ...sourceTsconfig,
+                ...targetTsconfig,
+                compilerOptions: {
+                    ...(sourceTsconfig.compilerOptions || {}),
+                    ...(targetTsconfig.compilerOptions || {})
+                }
+            };
+
+            if (targetTsconfig.compilerOptions?.paths) {
+                mergedTsconfig.compilerOptions.paths = {
+                    ...targetTsconfig.compilerOptions.paths
+                };
+            } else {
+                delete mergedTsconfig.compilerOptions.paths;
+            }
+
+            if (targetTsconfig.include) mergedTsconfig.include = targetTsconfig.include;
+
+            if (targetTsconfig.exclude) mergedTsconfig.exclude = targetTsconfig.exclude;
+
+            fs.writeFileSync(targetTsconfigPath, JSON.stringify(mergedTsconfig, null, 4));
+            console.log("✅ tsconfig.json mevcut dosyanız ile birleştirildi (include/exclude ve proje ayarları korundu).");
+        } else {
+            fs.writeFileSync(targetTsconfigPath, JSON.stringify(sourceTsconfig, null, 4));
+            console.log("✅ tsconfig.json oluşturuldu.");
+        }
+    }
+}
+
+console.log("");
+console.log("NCore standartlarıyla iyi kodlamalar dileriz!");

+ 4 - 1
package.json

@@ -52,7 +52,10 @@
         "build": "yarn clean && yarn lint && yarn type-check-build && yarn prepare && npm publish"
     },
     "bin": {
-        "ncore-setup": "./bin/setup.js"
+        "ncore-setup": "./bin/setup.js",
+        "ncore-setup-web": "./bin/setup-web.js",
+        "ncore-setup-mobile": "./bin/setup-mobile.js",
+        "ncore-type-kit": "./bin/type-kit.js"
     },
     "keywords": [
         "ncore",

+ 1 - 1
tsconfig.json

@@ -49,4 +49,4 @@
         "**/dist",
         "lib"
     ]
-}
+}