kuza-lang 0.3.0 → 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.
- package/README.md +41 -12
- package/dist/index.js +125 -11
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -52,25 +52,52 @@ log >> "Осталось: {len >> users}";
|
|
|
52
52
|
- строки с подстановками `"Привет, {name}!"`, лямбды `(x) -> x * 2`, цепочки `|>`;
|
|
53
53
|
- 100+ встроенных команд: строки, массивы, JSON, файлы, HTTP, время, DOM;
|
|
54
54
|
- таблицы: `table<...>`, `select`, `update`, `delete`, сохранение в JSON;
|
|
55
|
-
- сайты: `
|
|
55
|
+
- сайты: `body`, `box`, `row`, `column`, `card`, `section`, `nav` (вложенные блоки),
|
|
56
|
+
а внутри — `heading`, `para`, `button`, `field`, `list`, `link`, `image`, `render`;
|
|
56
57
|
- модули `use math;`, `use time;`, `use "./helpers.kuza";`.
|
|
57
58
|
|
|
58
59
|
Полный список команд: `docs/commands.md` в репозитории языка.
|
|
59
60
|
|
|
60
61
|
## Сайты прямо на Kuza
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
Каркас — обычный `index.html`, а в `body` стоит метка, куда попадёт программа:
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<body>
|
|
67
|
+
{main.kuza}
|
|
68
|
+
</body>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Создать такой проект: `kuza init --web`. Дальше страница собирается из вложенных блоков —
|
|
72
|
+
как компоненты в React, только без сборщика и зависимостей:
|
|
63
73
|
|
|
64
74
|
```kuza
|
|
65
75
|
:count = 0;
|
|
66
76
|
|
|
77
|
+
func Card<t> >> [
|
|
78
|
+
card >> [
|
|
79
|
+
heading >> t;
|
|
80
|
+
para >> "Компонент — обычная функция Kuza.";
|
|
81
|
+
];
|
|
82
|
+
];
|
|
83
|
+
|
|
67
84
|
func draw<> >> [
|
|
68
|
-
page >> "Мой сайт
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
85
|
+
page >> "Мой сайт";
|
|
86
|
+
|
|
87
|
+
body >> [
|
|
88
|
+
heading >> "Привет! Это сайт на Kuza";
|
|
89
|
+
|
|
90
|
+
row >> [
|
|
91
|
+
Card<"Первый">;
|
|
92
|
+
Card<"Второй">;
|
|
93
|
+
];
|
|
94
|
+
|
|
95
|
+
column >> [
|
|
96
|
+
heading >> "Счётчик: {count}";
|
|
97
|
+
button >> <"Прибавить", increase>;
|
|
98
|
+
];
|
|
99
|
+
];
|
|
100
|
+
|
|
74
101
|
render;
|
|
75
102
|
];
|
|
76
103
|
|
|
@@ -83,12 +110,14 @@ draw<>;
|
|
|
83
110
|
```
|
|
84
111
|
|
|
85
112
|
```bash
|
|
86
|
-
kuza build
|
|
87
|
-
kuza watch
|
|
113
|
+
kuza build main.kuza --web # → main.html, код вставляется в метку {main.kuza}
|
|
114
|
+
kuza watch main.kuza --web # пересборка при каждом сохранении
|
|
88
115
|
```
|
|
89
116
|
|
|
90
|
-
|
|
91
|
-
`button`, `field` + `fieldValue
|
|
117
|
+
Контейнеры: `body`, `section`, `nav`, `row`, `column` (алиас `col`), `box`, `card`.
|
|
118
|
+
Внутри — `heading`, `para`, `list`, `button`, `field` + `fieldValue`, `link`, `image`.
|
|
119
|
+
`page` задаёт заголовок вкладки, `render` рисует собранное после изменения состояния.
|
|
120
|
+
Обычный консольный код (`log`, `for`, `try`) работает в том же файле.
|
|
92
121
|
|
|
93
122
|
## Сборка
|
|
94
123
|
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,7 @@ function usage() {
|
|
|
44
44
|
console.log(` ${primary("kuza")} build ${ex} --web ${dim("собрать страницу в main.html")}`);
|
|
45
45
|
console.log(` ${primary("kuza")} watch ${ex} ${dim("пересобирать при сохранении")}`);
|
|
46
46
|
console.log(` ${primary("kuza")} init ${dim("создать main" + FILE_EXT)}`);
|
|
47
|
+
console.log(` ${primary("kuza")} init --web ${dim("создать сайт: main" + FILE_EXT + " + index.html")}`);
|
|
47
48
|
console.log(` ${primary("kuza")} help ${dim("эта справка")}`);
|
|
48
49
|
console.log("");
|
|
49
50
|
console.log(dim("Пример: ") + code(`${NAME.toLowerCase()} init && ${NAME.toLowerCase()} run ${ex}`));
|
|
@@ -78,9 +79,29 @@ async function runFile(file) {
|
|
|
78
79
|
printEntry(entry);
|
|
79
80
|
process.exitCode = result.ok ? 0 : 1;
|
|
80
81
|
}
|
|
81
|
-
/**
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Куда вставить собранный код: в свой каркас index.html или в готовую страницу.
|
|
84
|
+
*
|
|
85
|
+
* Каркас — обычный HTML, внутри body которого стоит метка `{main.kuza}`.
|
|
86
|
+
* Если каркаса нет, генерируем минимальный сами.
|
|
87
|
+
*/
|
|
88
|
+
function pageHtml(code, scriptName, dir) {
|
|
89
|
+
const tag = `<script>\n${code}</script>`;
|
|
90
|
+
const shellPath = join(dir, "index.html");
|
|
91
|
+
if (existsSync(shellPath)) {
|
|
92
|
+
const shell = readFileSync(shellPath, "utf8");
|
|
93
|
+
const marker = `{${scriptName}}`;
|
|
94
|
+
if (shell.includes(marker))
|
|
95
|
+
return { html: shell.split(marker).join(tag), shell: "index.html" };
|
|
96
|
+
if (shell.includes("{kuza}"))
|
|
97
|
+
return { html: shell.split("{kuza}").join(tag), shell: "index.html" };
|
|
98
|
+
if (shell.includes("</body>")) {
|
|
99
|
+
return { html: shell.replace("</body>", `${tag}\n</body>`), shell: "index.html" };
|
|
100
|
+
}
|
|
101
|
+
return { html: `${shell}\n${tag}\n`, shell: "index.html" };
|
|
102
|
+
}
|
|
103
|
+
const fallback = `<!doctype html>\n<html lang="ru">\n<head>\n<meta charset="utf-8">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n<title>${NAME}</title>\n</head>\n<body>\n${tag}\n</body>\n</html>\n`;
|
|
104
|
+
return { html: fallback };
|
|
84
105
|
}
|
|
85
106
|
function buildFile(file, web) {
|
|
86
107
|
const path = resolve(file);
|
|
@@ -102,11 +123,18 @@ function buildFile(file, web) {
|
|
|
102
123
|
}
|
|
103
124
|
const base = path.slice(0, path.length - extname(path).length);
|
|
104
125
|
const outPath = web ? `${base}.html` : `${base}.js`;
|
|
105
|
-
|
|
126
|
+
if (web) {
|
|
127
|
+
const page = pageHtml(compiled.code, basename(path), dirname(path));
|
|
128
|
+
writeFileSync(outPath, page.html, "utf8");
|
|
129
|
+
console.log(success(`✓ ${t("built")} ${outPath}`));
|
|
130
|
+
if (page.shell)
|
|
131
|
+
console.log(dim(`Каркас: ${page.shell}`));
|
|
132
|
+
console.log(dim(`${t("openInBrowser")}: `) + code(`"${basename(outPath)}"`));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
writeFileSync(outPath, compiled.code, "utf8");
|
|
106
136
|
console.log(success(`✓ ${t("built")} ${outPath}`));
|
|
107
|
-
console.log(
|
|
108
|
-
? dim(`${t("openInBrowser")}: `) + code(`"${basename(outPath)}"`)
|
|
109
|
-
: dim(`${t("runWithNode")}: `) + code(`node "${basename(outPath)}"`));
|
|
137
|
+
console.log(dim(`${t("runWithNode")}: `) + code(`node "${basename(outPath)}"`));
|
|
110
138
|
}
|
|
111
139
|
/** Пересобирать файл при каждом сохранении. */
|
|
112
140
|
function watchProject(file, web) {
|
|
@@ -143,22 +171,108 @@ log >> "Сумма: " + sum >> numbers;
|
|
|
143
171
|
log >> "Чисел мало";
|
|
144
172
|
]
|
|
145
173
|
`;
|
|
146
|
-
|
|
174
|
+
/** Шаблон сайта: каркас index.html + компоненты в Kuza. */
|
|
175
|
+
const SITE_SAMPLE = `## main${FILE_EXT} — сайт на ${NAME}
|
|
176
|
+
## Сборка: ${NAME.toLowerCase()} build main${FILE_EXT} --web → main.html
|
|
177
|
+
## Живая пересборка: ${NAME.toLowerCase()} watch main${FILE_EXT} --web
|
|
178
|
+
|
|
179
|
+
:count = 0;
|
|
180
|
+
:greeting = "";
|
|
181
|
+
|
|
182
|
+
func Card<t> >> [
|
|
183
|
+
card >> [
|
|
184
|
+
heading >> t;
|
|
185
|
+
para >> "Компонент — обычная функция ${NAME}.";
|
|
186
|
+
];
|
|
187
|
+
];
|
|
188
|
+
|
|
189
|
+
func draw<> >> [
|
|
190
|
+
page >> "Мой сайт на ${NAME}";
|
|
191
|
+
|
|
192
|
+
body >> [
|
|
193
|
+
heading >> "Привет! Это сайт на ${NAME}";
|
|
194
|
+
para >> "Страница собирается из вложенных блоков, как в React, только без сборщика.";
|
|
195
|
+
|
|
196
|
+
row >> [
|
|
197
|
+
Card<"Первый">;
|
|
198
|
+
Card<"Второй">;
|
|
199
|
+
Card<"Третий">;
|
|
200
|
+
];
|
|
201
|
+
|
|
202
|
+
column >> [
|
|
203
|
+
heading >> "Счётчик: {count}";
|
|
204
|
+
button >> <"Прибавить", increase>;
|
|
205
|
+
button >> <"Сбросить", reset>;
|
|
206
|
+
];
|
|
207
|
+
|
|
208
|
+
field >> <"Как тебя зовут?", "name">;
|
|
209
|
+
button >> <"Поздороваться", greet>;
|
|
210
|
+
|
|
211
|
+
?greeting != "" >> [
|
|
212
|
+
card >> [ para >> greeting; ];
|
|
213
|
+
];
|
|
214
|
+
];
|
|
215
|
+
|
|
216
|
+
render;
|
|
217
|
+
];
|
|
218
|
+
|
|
219
|
+
func increase<> >> [
|
|
220
|
+
count = count + 1;
|
|
221
|
+
draw<>;
|
|
222
|
+
];
|
|
223
|
+
|
|
224
|
+
func reset<> >> [
|
|
225
|
+
count = 0;
|
|
226
|
+
draw<>;
|
|
227
|
+
];
|
|
228
|
+
|
|
229
|
+
func greet<> >> [
|
|
230
|
+
:name = fieldValue >> "name";
|
|
231
|
+
?len >> name > 0 >> [
|
|
232
|
+
greeting = "Привет, " + name + "!";
|
|
233
|
+
];
|
|
234
|
+
draw<>;
|
|
235
|
+
];
|
|
236
|
+
|
|
237
|
+
draw<>;
|
|
238
|
+
`;
|
|
239
|
+
/** Каркас страницы: почти пустой HTML с точкой вставки {main.kuza}. */
|
|
240
|
+
const SHELL_SAMPLE = `<!doctype html>
|
|
241
|
+
<html lang="ru">
|
|
242
|
+
<head>
|
|
243
|
+
<meta charset="utf-8">
|
|
244
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
245
|
+
<title>Мой сайт на ${NAME}</title>
|
|
246
|
+
</head>
|
|
247
|
+
<body>
|
|
248
|
+
<!-- Сюда попадёт собранный ${NAME}. Метку не удаляй. -->
|
|
249
|
+
{main${FILE_EXT}}
|
|
250
|
+
</body>
|
|
251
|
+
</html>
|
|
252
|
+
`;
|
|
253
|
+
function initProject(target, web) {
|
|
147
254
|
const dir = target ? resolve(target) : process.cwd();
|
|
148
255
|
const file = join(dir, `main${FILE_EXT}`);
|
|
256
|
+
const shellFile = join(dir, "index.html");
|
|
149
257
|
if (existsSync(file)) {
|
|
150
258
|
console.log(warning(`${t("initExists")}: ${file}`));
|
|
151
259
|
return;
|
|
152
260
|
}
|
|
153
261
|
try {
|
|
154
|
-
writeFileSync(file, SAMPLE, { encoding: "utf8", flag: "wx" });
|
|
262
|
+
writeFileSync(file, web ? SITE_SAMPLE : SAMPLE, { encoding: "utf8", flag: "wx" });
|
|
263
|
+
if (web && !existsSync(shellFile))
|
|
264
|
+
writeFileSync(shellFile, SHELL_SAMPLE, "utf8");
|
|
155
265
|
}
|
|
156
266
|
catch {
|
|
157
267
|
fail(`Не удалось создать ${file}. Проверь, что папка существует: ${dir}`);
|
|
158
268
|
return;
|
|
159
269
|
}
|
|
160
270
|
console.log(success(`✓ ${t("initCreated")} ${file}`));
|
|
161
|
-
|
|
271
|
+
if (web && existsSync(shellFile)) {
|
|
272
|
+
console.log(dim("Каркас страницы: ") + code("index.html") + dim(` — внутри body метка {main${FILE_EXT}}`));
|
|
273
|
+
}
|
|
274
|
+
console.log(dim(`${t("initNext")}: `) +
|
|
275
|
+
code(web ? `${NAME.toLowerCase()} build main${FILE_EXT} --web` : `${NAME.toLowerCase()} run main${FILE_EXT}`));
|
|
162
276
|
}
|
|
163
277
|
async function main() {
|
|
164
278
|
const [first, ...rest] = argv;
|
|
@@ -204,7 +318,7 @@ async function main() {
|
|
|
204
318
|
return;
|
|
205
319
|
}
|
|
206
320
|
if (first === "init") {
|
|
207
|
-
initProject(rest
|
|
321
|
+
initProject(rest.find((arg) => !arg.startsWith("--")), rest.includes("--web"));
|
|
208
322
|
return;
|
|
209
323
|
}
|
|
210
324
|
if (first.endsWith(FILE_EXT)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kuza-lang",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Kuza — консоль языка: запуск, сборка, REPL и ИИ-помощник",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"start": "node dist/index.js"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"kuza-core": "^0.
|
|
30
|
+
"kuza-core": "^0.4.0",
|
|
31
31
|
"boxen": "^8.0.1",
|
|
32
32
|
"chalk": "^5.3.0",
|
|
33
33
|
"gradient-string": "^3.0.0"
|