jskelet 0.3.4 → 0.4.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.
@@ -9,8 +9,8 @@
9
9
  *
10
10
  * Sıra iki şekilde belirlenir:
11
11
  * 1. `jskelet.config.mjs` → `routes: ["./routes/api.js", …]` (açık liste)
12
- * 2. Liste yoksa `routes/` dizini alfabetik taranır. Bu durumda dosya adına
13
- * sayısal önek verin: `10-pages.js`, `50-blog.js`, `99-catch-all.js`.
12
+ * 2. Liste yoksa `routes/` alfabetik taranır, ardından her feature'ın
13
+ * `index.js` dosyası alfabetik eklenir. Catch-all'lar için sayısal önek.
14
14
  *
15
15
  * Modül sözleşmesi: default export ya da `register` adlı named export,
16
16
  * `(app, api) => void | Promise<void>` imzasıyla. `api` içinde `route`,
@@ -61,6 +61,29 @@ function discover(dir, out = []) {
61
61
  return out;
62
62
  }
63
63
 
64
+ /**
65
+ * `features/<name>/index.js` (veya `.mjs`) — feature-first kayıt noktası.
66
+ * @param {string} featuresDir
67
+ * @returns {string[]}
68
+ */
69
+ function discoverFeatures(featuresDir) {
70
+ if (!featuresDir || !fs.existsSync(featuresDir)) return [];
71
+
72
+ return fs
73
+ .readdirSync(featuresDir, { withFileTypes: true })
74
+ .filter((e) => e.isDirectory())
75
+ .map((e) => e.name)
76
+ .sort((a, b) => a.localeCompare(b))
77
+ .flatMap((name) => {
78
+ const dir = path.join(featuresDir, name);
79
+ for (const file of ["index.js", "index.mjs"]) {
80
+ const full = path.join(dir, file);
81
+ if (fs.existsSync(full)) return [full];
82
+ }
83
+ return [];
84
+ });
85
+ }
86
+
64
87
  /**
65
88
  * Route dosyalarına geçilen framework yüzeyi.
66
89
  */
@@ -84,7 +107,7 @@ export async function registerRoutes(app) {
84
107
 
85
108
  const files = config.routes
86
109
  ? config.routes.map((entry) => path.resolve(config.root, entry))
87
- : discover(config.dirs.routes);
110
+ : [...discover(config.dirs.routes), ...discoverFeatures(config.dirs.features)];
88
111
 
89
112
  if (!files.length) {
90
113
  console.warn(
@@ -1,7 +1,6 @@
1
1
  /**
2
- * `views/components/**` altındaki tüm modülleri yükler ve named export'larını
3
- * tek bir nesnede birleştirir. Bu nesne EJS şablonlarına local olarak geçer,
4
- * böylece `<%- card({ … }) %>` gibi çağrılar import gerektirmeden çalışır.
2
+ * `views/components/**` (ve feature/shared köklerindeki eşleri) altındaki
3
+ * tüm modülleri yükler ve named export'larını tek bir nesnede birleştirir.
5
4
  *
6
5
  * Elle bakılan bir barrel dosyası yok: yeni bir bileşen eklemek için dosyayı
7
6
  * oluşturmak yeterli.
@@ -44,17 +43,15 @@ function collect(dir, out = []) {
44
43
  }
45
44
 
46
45
  /**
47
- * @param {string} dir `views/components` dizininin mutlak yolu. Dizin yoksa
48
- * boş nesne döner: bileşen kullanmayan bir proje de çalışmalı.
49
- * @returns {Promise<Record<string, unknown>>}
46
+ * Tek bir `components/` dizinini yükler.
47
+ *
48
+ * @param {string} dir
49
+ * @param {Record<string, unknown>} components
50
+ * @param {Map<string, string>} origin
51
+ * @returns {Promise<void>}
50
52
  */
51
- export async function loadComponents(dir) {
52
- if (!dir || !fs.existsSync(dir)) return {};
53
-
54
- /** @type {Record<string, unknown>} */
55
- const components = {};
56
- /** @type {Map<string, string>} */
57
- const origin = new Map();
53
+ async function loadDir(dir, components, origin) {
54
+ if (!dir || !fs.existsSync(dir)) return;
58
55
 
59
56
  const barrel = path.join(dir, BARREL);
60
57
  const files = [
@@ -80,6 +77,22 @@ export async function loadComponents(dir) {
80
77
  origin.set(name, relative);
81
78
  }
82
79
  }
80
+ }
81
+
82
+ /**
83
+ * @param {string | string[]} dirs Tek dizin veya çoklu kök (feature/shared).
84
+ * @returns {Promise<Record<string, unknown>>}
85
+ */
86
+ export async function loadComponents(dirs) {
87
+ /** @type {Record<string, unknown>} */
88
+ const components = {};
89
+ /** @type {Map<string, string>} */
90
+ const origin = new Map();
91
+
92
+ const list = Array.isArray(dirs) ? dirs : [dirs];
93
+ for (const dir of list) {
94
+ await loadDir(dir, components, origin);
95
+ }
83
96
 
84
97
  return components;
85
98
  }