@skalfa/skalfa-app-core 1.0.0 → 1.0.3

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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -0
  3. package/dist/{api.util.js → api/api.js} +2 -2
  4. package/dist/api/index.d.ts +1 -0
  5. package/dist/api/index.js +1 -0
  6. package/dist/{auth.util.js → auth/auth.js} +1 -1
  7. package/dist/auth/index.d.ts +1 -0
  8. package/dist/auth/index.js +1 -0
  9. package/dist/{cavity.util.js → cavity/cavity.js} +2 -2
  10. package/dist/cavity/index.d.ts +1 -0
  11. package/dist/cavity/index.js +1 -0
  12. package/dist/cn/index.d.ts +1 -0
  13. package/dist/cn/index.js +1 -0
  14. package/dist/conversion/index.d.ts +1 -0
  15. package/dist/conversion/index.js +1 -0
  16. package/dist/encryption/index.d.ts +1 -0
  17. package/dist/encryption/index.js +1 -0
  18. package/dist/{form.util.d.ts → form/form.d.ts} +2 -2
  19. package/dist/{form.util.js → form/form.js} +3 -3
  20. package/dist/form/index.d.ts +1 -0
  21. package/dist/form/index.js +1 -0
  22. package/dist/index.d.ts +12 -12
  23. package/dist/index.js +12 -12
  24. package/dist/resource/index.d.ts +1 -0
  25. package/dist/resource/index.js +1 -0
  26. package/dist/{resource.util.d.ts → resource/resource.d.ts} +1 -1
  27. package/dist/{resource.util.js → resource/resource.js} +2 -2
  28. package/dist/shortcut/index.d.ts +1 -0
  29. package/dist/shortcut/index.js +1 -0
  30. package/dist/table/index.d.ts +1 -0
  31. package/dist/table/index.js +1 -0
  32. package/dist/{table.util.d.ts → table/table.d.ts} +2 -2
  33. package/dist/{table.util.js → table/table.js} +2 -2
  34. package/dist/validation/index.d.ts +1 -0
  35. package/dist/validation/index.js +1 -0
  36. package/dist/{validation.util.js → validation/validation.js} +1 -1
  37. package/package.json +3 -3
  38. package/dist/commands/barrels.d.ts +0 -1
  39. package/dist/commands/barrels.js +0 -22
  40. package/dist/commands/blueprint.d.ts +0 -3
  41. package/dist/commands/blueprint.js +0 -306
  42. package/dist/commands/light.d.ts +0 -1
  43. package/dist/commands/light.js +0 -16
  44. package/dist/commands/use-pdf.d.ts +0 -1
  45. package/dist/commands/use-pdf.js +0 -17
  46. package/dist/langs/index.d.ts +0 -1
  47. package/dist/langs/index.js +0 -1
  48. /package/dist/{api.util.d.ts → api/api.d.ts} +0 -0
  49. /package/dist/{auth.util.d.ts → auth/auth.d.ts} +0 -0
  50. /package/dist/{cavity.util.d.ts → cavity/cavity.d.ts} +0 -0
  51. /package/dist/{cn.util.d.ts → cn/cn.d.ts} +0 -0
  52. /package/dist/{cn.util.js → cn/cn.js} +0 -0
  53. /package/dist/{conversion.util.d.ts → conversion/conversion.d.ts} +0 -0
  54. /package/dist/{conversion.util.js → conversion/conversion.js} +0 -0
  55. /package/dist/{encryption.util.d.ts → encryption/encryption.d.ts} +0 -0
  56. /package/dist/{encryption.util.js → encryption/encryption.js} +0 -0
  57. /package/dist/{commands/logger.d.ts → logger.d.ts} +0 -0
  58. /package/dist/{commands/logger.js → logger.js} +0 -0
  59. /package/dist/{shortcut.util.d.ts → shortcut/shortcut.d.ts} +0 -0
  60. /package/dist/{shortcut.util.js → shortcut/shortcut.js} +0 -0
  61. /package/dist/{validation.util.d.ts → validation/validation.d.ts} +0 -0
  62. /package/dist/{langs → validation}/validation.langs.d.ts +0 -0
  63. /package/dist/{langs → validation}/validation.langs.js +0 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Skalfa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ <p align="center">
2
+ <img src="https://skalfa.sejedigital.com/images/logo-skalfa.png" alt="Skalfa Logo" width="300" />
3
+ </p>
4
+
5
+ # @skalfa/skalfa-app-core
6
+
7
+ > Core framework engine and foundational utility hook library for the Skalfa Next.js frontend.
8
+
9
+ ---
10
+
11
+ ## About this Package
12
+
13
+ This package is part of the **Skalfa Framework**, a premium development ecosystem designed to build high-performance, modular web applications and APIs.
14
+
15
+ ### Usage Scope & Standalone Status
16
+ > 🔒 **Skalfa Ecosystem Integration:** This package is designed to run **integrated within the Skalfa ecosystem** (such as Skalfa API or Skalfa App). It relies on the global service registry and core framework abstractions to operate.
17
+
18
+ ---
19
+
20
+ ## Documentation
21
+
22
+ See the usage documentation at [Documentation](https://skalfa.sejedigital.com).
23
+
24
+ ---
25
+
26
+ ## Installation
27
+
28
+ You can install this package using your preferred package manager:
29
+
30
+ ```bash
31
+ # Using npm
32
+ npm install @skalfa/skalfa-app-core
33
+
34
+ # Using bun
35
+ bun add @skalfa/skalfa-app-core
36
+ ```
37
+
38
+ ---
39
+
40
+ ## Pre-installed Dependencies
41
+
42
+ The following key dependencies are packaged and managed within this project:
43
+
44
+ | Dependency | Scope | Version |
45
+ | :--- | :--- | :--- |
46
+ | `axios` | runtime | `^1.12.0` |
47
+ | `clsx` | runtime | `^2.1.1` |
48
+ | `crypto-js` | runtime | `^4.2.0` |
49
+ | `js-cookie` | runtime | `^3.0.5` |
50
+ | `lz-string` | runtime | `^1.5.0` |
51
+ | `moment` | runtime | `^2.30.1` |
52
+ | `tailwind-merge` | runtime | `^3.0.2` |
53
+ | `validator` | runtime | `^13.15.22` |
54
+ | `@types/node` | development | `^20.0.0` |
55
+ | `@types/react` | development | `^19.0.0` |
56
+ | `@types/react-dom` | development | `^19.0.0` |
57
+ | `typescript` | development | `^6.0.3` |
58
+
59
+ ---
60
+
61
+ ## License
62
+
63
+ This package is licensed under the **MIT License**. For full license text, see the [LICENSE](LICENSE) file.
@@ -2,8 +2,8 @@
2
2
  import { useEffect, useState } from "react";
3
3
  import axios from "axios";
4
4
  import { redirect } from "next/navigation";
5
- import { auth } from "./auth.util";
6
- import { cavity } from "./cavity.util";
5
+ import { auth } from "../auth";
6
+ import { cavity } from "../cavity";
7
7
  // =========================>
8
8
  // ## Build auth bearer
9
9
  // =========================>
@@ -0,0 +1 @@
1
+ export * from "./api";
@@ -0,0 +1 @@
1
+ export * from "./api";
@@ -1,6 +1,6 @@
1
1
  import { redirect } from 'next/navigation';
2
2
  import Cookies from 'js-cookie';
3
- import { encryption } from './encryption.util';
3
+ import { encryption } from '../encryption';
4
4
  export const auth = {
5
5
  // ==============================>
6
6
  // ## Path of login page
@@ -0,0 +1 @@
1
+ export * from "./auth";
@@ -0,0 +1 @@
1
+ export * from "./auth";
@@ -1,5 +1,5 @@
1
- import { registry } from "./registry";
2
- import { logger } from "./commands/logger";
1
+ import { registry } from "../registry";
2
+ import { logger } from "../logger";
3
3
  const name = String(process.env.NEXT_PUBLIC_APP_NAME || "").toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "") + ".cavity";
4
4
  const storeName = "cache";
5
5
  const version = 1;
@@ -0,0 +1 @@
1
+ export * from "./cavity";
@@ -0,0 +1 @@
1
+ export * from "./cavity";
@@ -0,0 +1 @@
1
+ export * from "./cn";
@@ -0,0 +1 @@
1
+ export * from "./cn";
@@ -0,0 +1 @@
1
+ export * from "./conversion";
@@ -0,0 +1 @@
1
+ export * from "./conversion";
@@ -0,0 +1 @@
1
+ export * from "./encryption";
@@ -0,0 +1 @@
1
+ export * from "./encryption";
@@ -1,5 +1,5 @@
1
- import { ValidationRules } from "./validation.util";
2
- import { ApiType } from "./api.util";
1
+ import { ValidationRules } from "../validation";
2
+ import { ApiType } from "../api";
3
3
  type DBSchema = any;
4
4
  export interface FormRegisterType {
5
5
  name: string;
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import { useReducer, useEffect, useState } from "react";
3
- import { registry } from "./registry";
4
- import { validation } from "./validation.util";
5
- import { api } from "./api.util";
3
+ import { registry } from "../registry";
4
+ import { validation } from "../validation";
5
+ import { api } from "../api";
6
6
  const initialState = {
7
7
  formRegisters: [],
8
8
  formValues: [],
@@ -0,0 +1 @@
1
+ export * from "./form";
@@ -0,0 +1 @@
1
+ export * from "./form";
package/dist/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- export * from "./api.util";
2
- export * from "./auth.util";
3
- export * from "./cavity.util";
4
- export * from "./encryption.util";
5
- export * from "./cn.util";
6
- export * from "./form.util";
7
- export * from "./resource.util";
8
- export * from "./table.util";
9
- export * from "./validation.util";
10
- export * from "./conversion.util";
11
- export * from "./shortcut.util";
12
- export * from "./commands/logger";
1
+ export * from "./api";
2
+ export * from "./auth";
3
+ export * from "./cavity";
4
+ export * from "./encryption";
5
+ export * from "./cn";
6
+ export * from "./form";
7
+ export * from "./resource";
8
+ export * from "./table";
9
+ export * from "./validation";
10
+ export * from "./conversion";
11
+ export * from "./shortcut";
12
+ export * from "./logger";
13
13
  export * from "./registry";
14
14
  export declare const useResponsive: () => {
15
15
  isXs: boolean;
package/dist/index.js CHANGED
@@ -3,18 +3,18 @@ import { useEffect, useState } from "react";
3
3
  // ==============================>
4
4
  // ## Export all from core utils
5
5
  // ==============================>
6
- export * from "./api.util";
7
- export * from "./auth.util";
8
- export * from "./cavity.util";
9
- export * from "./encryption.util";
10
- export * from "./cn.util";
11
- export * from "./form.util";
12
- export * from "./resource.util";
13
- export * from "./table.util";
14
- export * from "./validation.util";
15
- export * from "./conversion.util";
16
- export * from "./shortcut.util";
17
- export * from "./commands/logger";
6
+ export * from "./api";
7
+ export * from "./auth";
8
+ export * from "./cavity";
9
+ export * from "./encryption";
10
+ export * from "./cn";
11
+ export * from "./form";
12
+ export * from "./resource";
13
+ export * from "./table";
14
+ export * from "./validation";
15
+ export * from "./conversion";
16
+ export * from "./shortcut";
17
+ export * from "./logger";
18
18
  export * from "./registry";
19
19
  // ==============================>
20
20
  // ## Detect device size
@@ -0,0 +1 @@
1
+ export * from "./resource";
@@ -0,0 +1 @@
1
+ export * from "./resource";
@@ -1,4 +1,4 @@
1
- import { ApiType } from "./api.util";
1
+ import { ApiType } from "../api";
2
2
  export type ResourceParams = {
3
3
  page?: number;
4
4
  paginate?: number;
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { useEffect, useState } from "react";
3
- import { useGetApi } from "./api.util";
4
- import { registry } from "./registry";
3
+ import { useGetApi } from "../api";
4
+ import { registry } from "../registry";
5
5
  export function useResource(props) {
6
6
  const isApi = "path" in props || "url" in props;
7
7
  const apiResult = useGetApi(isApi ? props : {}, !isApi);
@@ -0,0 +1 @@
1
+ export * from "./shortcut";
@@ -0,0 +1 @@
1
+ export * from "./shortcut";
@@ -0,0 +1 @@
1
+ export * from "./table";
@@ -0,0 +1 @@
1
+ export * from "./table";
@@ -1,5 +1,5 @@
1
- import { ApiFilterType, ApiParamsType } from "./api.util";
2
- import { ResourceParams, UseResourceProps } from "./resource.util";
1
+ import { ApiFilterType, ApiParamsType } from "../api";
2
+ import { ResourceParams, UseResourceProps } from "../resource";
3
3
  export type TableStateType = {
4
4
  params?: ApiParamsType;
5
5
  data?: Record<string, any>[];
@@ -2,8 +2,8 @@
2
2
  import { useEffect, useState } from "react";
3
3
  import { useRouter, useSearchParams } from "next/navigation";
4
4
  import LZString from "lz-string";
5
- import { conversion } from "./conversion.util";
6
- import { useResource } from "./resource.util";
5
+ import { conversion } from "../conversion";
6
+ import { useResource } from "../resource";
7
7
  export const useTable = (fetchControl, id = "", title = "", urlParam) => {
8
8
  const [state, setState] = useState({});
9
9
  const router = useRouter();
@@ -0,0 +1 @@
1
+ export * from "./validation";
@@ -0,0 +1 @@
1
+ export * from "./validation";
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { useEffect, useState } from "react";
3
3
  import validator from "validator";
4
- import { validationLangs } from "./langs";
4
+ import { validationLangs } from "./validation.langs";
5
5
  // ==========================>
6
6
  // ## Validation core
7
7
  // ==========================>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@skalfa/skalfa-app-core",
3
- "version": "1.0.0",
4
- "description": "Core utility functions for the Skalfa Next.js frontend framework.",
3
+ "version": "1.0.3",
4
+ "description": "Core framework engine and foundational utility hook library for the Skalfa Next.js frontend.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
@@ -42,6 +42,6 @@
42
42
  "next": "16.1.1",
43
43
  "react": "^19.2.1",
44
44
  "react-dom": "^19.2.1",
45
- "typescript": "^5.0.0"
45
+ "typescript": "^6.0.3"
46
46
  }
47
47
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,22 +0,0 @@
1
- import path from "path";
2
- import fs from "fs";
3
- import { exec } from "child_process";
4
- import { logger } from "./logger";
5
- const rootDir = path.resolve();
6
- const configText = fs.readFileSync("barrels.json", "utf8");
7
- const config = JSON.parse(configText);
8
- const directories = Array.isArray(config.directory) ? config.directory : [config.directory];
9
- directories.forEach((dir) => {
10
- const absoluteDir = path.join(rootDir, dir);
11
- if (!fs.existsSync(absoluteDir)) {
12
- logger.error(`Barrels error: ${absoluteDir} directory not found`);
13
- return;
14
- }
15
- fs.watch(absoluteDir, { recursive: true }, (_, filename) => {
16
- if (filename && (filename.endsWith(".ts") || filename.endsWith(".tsx")) && filename !== "index.ts") {
17
- exec("npx barrelsby -c barrels.json", { cwd: rootDir });
18
- logger.info("Barrels updated " + absoluteDir + "/index.ts");
19
- }
20
- });
21
- });
22
- logger.start("Barrels watched " + directories.join(", "));
@@ -1,3 +0,0 @@
1
- export declare function blueprint(options?: {
2
- only?: string[];
3
- }): Promise<void>;
@@ -1,306 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { logger } from "./logger";
4
- import { conversion } from "../conversion.util";
5
- const renderJS = (value, indent = 0) => {
6
- const pad = " ".repeat(indent);
7
- if (Array.isArray(value)) {
8
- if (!value.length)
9
- return "[]";
10
- if (value.every(v => typeof v === "string")) {
11
- return `[${value.map(v => JSON.stringify(v)).join(", ")}]`;
12
- }
13
- return `[\n${value
14
- .map(v => pad + " " + renderJS(v, indent + 2))
15
- .join(",\n")}\n${pad}]`;
16
- }
17
- if (value && typeof value === "object") {
18
- const entries = Object.entries(value);
19
- if (!entries.length)
20
- return "{}";
21
- return `{\n${entries
22
- .map(([k, v]) => `${pad} ${k}: ${renderJS(v, indent + 2)}`)
23
- .join(",\n")}\n${pad}}`;
24
- }
25
- if (typeof value === "string")
26
- return JSON.stringify(value);
27
- return String(value);
28
- };
29
- function extractValidationArray(def = "") {
30
- const rules = [];
31
- if (def.includes("required"))
32
- rules.push("required");
33
- if (def.includes("email"))
34
- rules.push("email");
35
- if (def.includes("url"))
36
- rules.push("url");
37
- const min = def.match(/min,(\d+)/);
38
- if (min)
39
- rules.push(`min:${min[1]}`);
40
- const max = def.match(/max,(\d+)/);
41
- if (max)
42
- rules.push(`max:${max[1]}`);
43
- return rules;
44
- }
45
- function extractFormType(rules) {
46
- const rule = rules.find(r => r.startsWith("form:"));
47
- return rule ? rule.replace("form:", "") : undefined;
48
- }
49
- function inferFormType(pageDef = "", modelDef = "") {
50
- const explicit = pageDef.split("|");
51
- if (explicit && explicit[0] && explicit[0] != "text")
52
- return explicit[0];
53
- if (modelDef.includes("type:integer") || modelDef.includes("type:float")) {
54
- return "number";
55
- }
56
- if (modelDef.includes("type:date"))
57
- return "date";
58
- if (modelDef.includes("type:datetime"))
59
- return "datetime";
60
- if (modelDef.includes("type:image"))
61
- return "image";
62
- return "default";
63
- }
64
- function parseFeatures(features) {
65
- const controlBar = [];
66
- const action = [];
67
- if (!features) {
68
- return { controlBar: ["CREATE"], action: ["EDIT", "DELETE"] };
69
- }
70
- const list = features.split(" ");
71
- if (list.includes("create"))
72
- controlBar.push("CREATE");
73
- controlBar.push("SEARCH", "SORT", "SELECTABLE");
74
- if (list.includes("import"))
75
- controlBar.push("IMPORT");
76
- if (list.includes("export"))
77
- controlBar.push("EXPORT");
78
- if (list.includes("print"))
79
- controlBar.push("PRINT");
80
- if (list.includes("update") || list.includes("edit"))
81
- action.push("EDIT");
82
- if (list.includes("delete"))
83
- action.push("DELETE");
84
- if (list.includes("detail"))
85
- action.push("DETAIL");
86
- return { controlBar, action };
87
- }
88
- function parseModelSchema(schema = {}) {
89
- const columns = [];
90
- const forms = [];
91
- const details = [];
92
- for (const [field, def] of Object.entries(schema)) {
93
- const label = conversion.strPascal(field, " ");
94
- if (def.includes("selectable")) {
95
- columns.push({ selector: field, label });
96
- details.push({ label, item: field });
97
- }
98
- if (def.includes("fillable")) {
99
- const fieldType = inferFormType("", def);
100
- forms.push({
101
- ...(fieldType != "default" ? { type: fieldType } : {}),
102
- construction: {
103
- name: field,
104
- label,
105
- placeholder: "Masukkan " + label.toLowerCase(),
106
- validations: extractValidationArray(def)
107
- }
108
- });
109
- }
110
- }
111
- return { columns, forms, details };
112
- }
113
- function resolvePath(page, controllers, model) {
114
- if (page.path)
115
- return page.path;
116
- if (Array.isArray(controllers)) {
117
- const match = controllers;
118
- if (match)
119
- return "/" + match[1];
120
- }
121
- return "/" + model.split("/").pop();
122
- }
123
- function parsePageSchema(pageSchema, modelSchema = {}) {
124
- const columns = [];
125
- const forms = [];
126
- const details = [];
127
- for (const [field, def] of Object.entries(pageSchema)) {
128
- const rules = def.replace(/\|/g, " ").split(" ").filter(Boolean);
129
- const defaultLabel = conversion.strPascal(field, " ");
130
- const colLabelRule = rules.find(r => r.includes("column:label,"));
131
- const colLabel = conversion.strPascal(colLabelRule ? colLabelRule.split(",")[1] : defaultLabel, " ");
132
- const formLabelRule = rules.find(r => r.includes("form:label,"));
133
- const formLabel = conversion.strPascal(formLabelRule ? formLabelRule.split(",")[1] : (colLabelRule ? colLabel : defaultLabel), " ");
134
- const detailLabel = colLabelRule ? colLabel : (formLabelRule ? formLabel : defaultLabel);
135
- const hasColumn = rules.some(r => r.includes("column:"));
136
- const hasForm = rules.some(r => r.includes("form:")) || rules.every(r => !r.includes("column:"));
137
- const hasDetail = rules.includes("detail");
138
- if (hasColumn) {
139
- columns.push({
140
- selector: field,
141
- label: colLabel,
142
- ...(rules.includes("column:sortable") || rules.includes("sortable") ? { sortable: true } : {})
143
- });
144
- if (!hasDetail)
145
- details.push({ label: detailLabel, item: field });
146
- }
147
- if (hasForm) {
148
- const typeRules = rules.filter(r => !r.startsWith("form:label,"));
149
- const typeRule = extractFormType(typeRules);
150
- let fieldType = inferFormType(typeRule, modelSchema[field] || "");
151
- let selectPath = "";
152
- const selectRule = rules.find(r => r.startsWith("select,") || r.startsWith("form:select,"));
153
- if (selectRule) {
154
- fieldType = "select";
155
- selectPath = selectRule.split(",")[1];
156
- }
157
- if (typeRule === "check")
158
- fieldType = "boolean";
159
- if (typeRule === "currency")
160
- fieldType = "currency";
161
- if (typeRule === "image")
162
- fieldType = "image";
163
- if (typeRule === "date")
164
- fieldType = "date";
165
- if (typeRule === "time")
166
- fieldType = "time";
167
- let col;
168
- const colRule = rules.find(r => /col,(\d+)/.test(r));
169
- if (colRule) {
170
- const n = Number(colRule.split(',').pop());
171
- if (n >= 1 && n <= 12)
172
- col = n;
173
- }
174
- forms.push({
175
- ...(fieldType != "default" && fieldType != "text" ? { type: fieldType } : {}),
176
- ...(col ? { col } : {}),
177
- construction: {
178
- name: field,
179
- label: formLabel,
180
- placeholder: "Masukkan " + formLabel.toLowerCase(),
181
- validations: extractValidationArray(modelSchema[field] || ""),
182
- ...(selectPath ? { serverOptionControl: { path: selectPath } } : {}),
183
- ...(rules.includes("wrap") ? { wrap: true } : {})
184
- }
185
- });
186
- }
187
- if (hasDetail)
188
- details.push({ label: detailLabel, item: field });
189
- }
190
- const formMap = new Map();
191
- forms.forEach(f => formMap.set(f.construction.name, f));
192
- const nestedForms = [];
193
- forms.forEach(f => {
194
- const name = f.construction.name;
195
- if (name.includes(".")) {
196
- const parts = name.split(".");
197
- const selfName = parts.pop();
198
- const parentName = parts.join(".");
199
- const parent = formMap.get(parentName);
200
- if (parent) {
201
- if (!parent.type)
202
- parent.type = "cluster";
203
- if (!parent.construction.fields)
204
- parent.construction.fields = [];
205
- f.construction.name = selfName;
206
- parent.construction.fields.push(f);
207
- }
208
- else {
209
- nestedForms.push(f);
210
- }
211
- }
212
- else {
213
- nestedForms.push(f);
214
- }
215
- });
216
- return { columns, forms: nestedForms, details };
217
- }
218
- function loadBlueprintFiles(dir = "blueprints") {
219
- const basePath = path.join(process.cwd(), dir);
220
- if (!fs.existsSync(basePath)) {
221
- throw new Error("Blueprint folder not found");
222
- }
223
- return fs.readdirSync(basePath)
224
- .filter(f => f.endsWith(".blueprint.json"))
225
- .map(file => {
226
- const fullPath = path.join(basePath, file);
227
- const content = JSON.parse(fs.readFileSync(fullPath, "utf-8"));
228
- if (!Array.isArray(content)) {
229
- throw new Error(`${file} must export array of blueprints`);
230
- }
231
- return {
232
- file: file.replace(".blueprint.json", ""),
233
- blueprints: content,
234
- };
235
- });
236
- }
237
- const blueprintMarker = `// ============================================
238
- // ## file THIS FILE IS AUTO-GENERATED BY BLUEPRINT
239
- // ?? Blueprint : {{ blueprint }}
240
- // !! If this comment is removed, blueprint engine WILL NOT override this file.
241
- // ============================================
242
-
243
-
244
- `;
245
- // ===============================
246
- // ## Main generator
247
- // ===============================
248
- export async function blueprint(options) {
249
- const stub = fs.readFileSync(path.join(process.cwd(), "/utils/commands/stubs/table-blueprint.stub"), "utf-8");
250
- const loaded = loadBlueprintFiles();
251
- for (const file of loaded) {
252
- for (const bp of file.blueprints) {
253
- const pagesToGenerate = { ...(bp.pages || {}) };
254
- for (const [key, val] of Object.entries(bp)) {
255
- if (typeof val === "object" && val["schema"]) {
256
- pagesToGenerate[key] = val;
257
- }
258
- }
259
- for (const [key, page] of Object.entries(pagesToGenerate)) {
260
- const route = key;
261
- const name = conversion.strPascal(route.split("/").pop());
262
- if (options?.only && !options.only.includes(name))
263
- continue;
264
- const outDir = path.join(process.cwd(), "app", route);
265
- fs.mkdirSync(outDir, { recursive: true });
266
- const filePath = path.join(outDir, "page.tsx");
267
- if (fs.existsSync(filePath)) {
268
- const content = fs.readFileSync(filePath, "utf-8");
269
- if (!content.includes("AUTO-GENERATED BY BLUEPRINT")) {
270
- logger.info(`Skip overridden file: ${filePath}`);
271
- continue;
272
- }
273
- }
274
- const schema = bp.schema ?? {};
275
- const parsed = page?.schema ? parsePageSchema(page.schema, schema) : parseModelSchema(schema);
276
- const { controlBar, action } = parseFeatures(page?.features);
277
- const fetchPath = resolvePath(page, bp.controllers, bp.model);
278
- let properties = `
279
- fetchControl={{
280
- path: "${fetchPath}"
281
- }}
282
- columnControl={${renderJS(parsed.columns, 8)}}
283
- formControl={{
284
- fields: ${renderJS(parsed.forms, 10)}
285
- }}
286
- `;
287
- if (parsed.details) {
288
- properties += ` detailControl={${renderJS(parsed.details, 8)}}\n`;
289
- }
290
- if (controlBar.length) {
291
- properties += ` controlBar={${JSON.stringify(controlBar)}}\n`;
292
- }
293
- if (action.length) {
294
- properties += ` actionControl={${JSON.stringify(action)}}\n`;
295
- }
296
- const content = stub
297
- .replace(/{{ marker }}/g, blueprintMarker.replace(/{{ blueprint }}/g, file.file + ".blueprint.json"))
298
- .replace(/{{ name }}/g, name)
299
- .replace(/{{ title }}/g, name)
300
- .replace(/{{ properties }}/g, properties);
301
- fs.writeFileSync(path.join(outDir, "page.tsx"), content);
302
- logger.info(`Generated: ${filePath}`);
303
- }
304
- }
305
- }
306
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- import { Command } from "commander";
2
- import { usePdf } from "./use-pdf";
3
- import { blueprint } from "./blueprint";
4
- import { logger } from "./logger";
5
- const program = new Command();
6
- program.name("light").description("Next Light CLI").version("1.0.0");
7
- program.command("use-pdf").description("Copy pdf.worker.min.mjs ke folder public/").action(usePdf);
8
- program.command("blueprint")
9
- .option("-o, --only <names...>", "Run only specific blueprints")
10
- .description("Generate blueprint")
11
- .action(async (opts) => {
12
- await blueprint({ only: opts.only });
13
- logger.info("Success run all blueprints!");
14
- process.exit(0);
15
- });
16
- program.parse();
@@ -1 +0,0 @@
1
- export declare function usePdf(): void;
@@ -1,17 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { fileURLToPath } from "url";
4
- import { logger } from "./logger";
5
- export function usePdf() {
6
- const __filename = fileURLToPath(import.meta.url);
7
- const __dirname = path.dirname(__filename);
8
- const projectRoot = path.join(__dirname, "..", "..");
9
- const source = path.join(projectRoot, "node_modules", "pdfjs-dist", "legacy", "build", "pdf.worker.min.mjs");
10
- const target = path.join(projectRoot, "public", "pdf.worker.min.mjs");
11
- if (!fs.existsSync(source)) {
12
- logger.error(`Gagal: pdf.worker.min.mjs tidak ditemukan.`);
13
- process.exit(1);
14
- }
15
- fs.copyFileSync(source, target);
16
- logger.info("Berhasil memindahkan worker ke public/pdf.worker.min.mjs");
17
- }
@@ -1 +0,0 @@
1
- export * from "./validation.langs";
@@ -1 +0,0 @@
1
- export * from "./validation.langs";
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes