|
@@ -7,70 +7,148 @@ const path = require("path");
|
|
|
const targetDir = process.cwd();
|
|
const targetDir = process.cwd();
|
|
|
const sourceDir = path.resolve(__dirname, "..");
|
|
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("NCore UI Kit Environment Setup Tool");
|
|
|
console.log("=====================================");
|
|
console.log("=====================================");
|
|
|
console.log(`Hedef Proje Dizini: ${targetDir}`);
|
|
console.log(`Hedef Proje Dizini: ${targetDir}`);
|
|
|
console.log("");
|
|
console.log("");
|
|
|
|
|
|
|
|
-// 1. .vscode/settings.json
|
|
|
|
|
-const sourceVscodeDir = path.join(sourceDir, ".vscode");
|
|
|
|
|
-const targetVscodeDir = path.join(targetDir, ".vscode");
|
|
|
|
|
|
|
+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);
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-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)) {
|
|
|
|
|
- fs.copyFileSync(sourceSettings, targetSettings);
|
|
|
|
|
- console.log("✅ .vscode/settings.json kopyalandı.");
|
|
|
|
|
|
|
+// 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;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 2. eslint.config.mjs
|
|
|
|
|
-const sourceEslint = path.join(sourceDir, "eslint.config.mjs");
|
|
|
|
|
-const targetEslint = path.join(targetDir, "eslint.config.mjs");
|
|
|
|
|
-if (fs.existsSync(sourceEslint)) {
|
|
|
|
|
- fs.copyFileSync(sourceEslint, targetEslint);
|
|
|
|
|
- console.log("✅ eslint.config.mjs kopyalandı.");
|
|
|
|
|
|
|
+// 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ı.");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 3. eslint-local-rules
|
|
|
|
|
-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
|
|
|
|
|
- });
|
|
|
|
|
|
|
+// 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ı.");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Copy all files in the directory
|
|
|
|
|
- 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);
|
|
|
|
|
|
|
+ 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
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
- console.log("✅ eslint-local-rules/ kopyalandı.");
|
|
|
|
|
|
|
+ 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
|
|
// 4. tsconfig.json
|
|
|
-const sourceTsconfig = path.join(sourceDir, "tsconfig.json");
|
|
|
|
|
-const targetTsconfig = path.join(targetDir, "tsconfig.json");
|
|
|
|
|
-if (fs.existsSync(sourceTsconfig)) {
|
|
|
|
|
- fs.copyFileSync(sourceTsconfig, targetTsconfig);
|
|
|
|
|
- console.log("✅ tsconfig.json kopyalandı.");
|
|
|
|
|
|
|
+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")) || {};
|
|
|
|
|
+
|
|
|
|
|
+ // 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.");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
console.log("");
|
|
console.log("");
|
|
|
-console.log("Kurulum tamamlandı! Lütfen package.json'ınızda aşağıdaki eklentilerin kurulu olduğundan emin olun:");
|
|
|
|
|
-console.log("- typescript-eslint");
|
|
|
|
|
-console.log("- eslint-plugin-local-rules");
|
|
|
|
|
-console.log("- jsonc-eslint-parser vb.");
|
|
|
|
|
console.log("NCore standartlarıyla iyi kodlamalar dileriz!");
|
|
console.log("NCore standartlarıyla iyi kodlamalar dileriz!");
|