@kdrgny/justjson 1.0.0 → 1.1.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/LICENSE +21 -0
- package/README.md +76 -0
- package/dist/cli.js +334 -14
- package/dist/editor/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/dist/editor/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/dist/editor/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/editor/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/editor/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/dist/editor/assets/index-B-aBBk0p.css +1 -0
- package/dist/editor/assets/index-DhyPvr9S.js +574 -0
- package/dist/editor/index.html +2 -2
- package/package.json +14 -3
- package/dist/editor/assets/index-BN_YWkOH.css +0 -1
- package/dist/editor/assets/index-DsfRA4dz.js +0 -400
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kadir Günay
|
|
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,76 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# JustJSON
|
|
4
|
+
|
|
5
|
+
**A tiny local-first CMS. Build your schema in a visual UI, edit content in a clean editor — everything stays on disk as plain JSON.**
|
|
6
|
+
|
|
7
|
+
No database · no account · no lock-in.
|
|
8
|
+
|
|
9
|
+
[Website](https://justjson-site.vercel.app) ·
|
|
10
|
+
[GitHub](https://github.com/kdrgny-dev/justjson) ·
|
|
11
|
+
MIT
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
JustJSON is the cleanest way to manage structured content **without writing config**. Design collections and fields by clicking, fill them in a real editor, and get plain JSON files you own — in your own repo, ready for your build.
|
|
18
|
+
|
|
19
|
+
It runs entirely on your machine. Nothing is uploaded anywhere; your content is just files on disk.
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
cd my-project/
|
|
25
|
+
npx @kdrgny/justjson # opens the editor in your browser
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
On an empty folder the editor greets you with a picker: start from a **template**, from **scratch**, or **import your own JSON** — an existing `_schema.json`, or plain content (say, an export from another tool) whose structure JustJSON figures out for you.
|
|
29
|
+
|
|
30
|
+
Design your schema, enter content, upload images. Everything is written to `content/*.json` in your folder. Commit it, deploy it, import it in your build — your flow.
|
|
31
|
+
|
|
32
|
+
## What you get
|
|
33
|
+
|
|
34
|
+
| | |
|
|
35
|
+
|---|---|
|
|
36
|
+
| **Start from a template** | Blog, CV, portfolio, docs or changelog — each card previews the collections and fields it creates. |
|
|
37
|
+
| **Bring your own JSON** | Paste any content JSON and JustJSON infers the structure: lists become collections, objects become singletons, HTML becomes rich text. |
|
|
38
|
+
| **Visual schema builder** | Define collections and fields in the UI. Pick a field type from icon cards — no config file to hand-write. |
|
|
39
|
+
| **Searchable content table** | Entries listed by title, slug and date. Search and edit instantly — content, not a pile of slugs. |
|
|
40
|
+
| **Rich-text editor** | Headings, bold, lists, quotes — WYSIWYG, saved to disk as clean, diffable Markdown. |
|
|
41
|
+
| **Image uploads** | Drop an image; it's resized to WebP in the browser and written under `content/media/`. |
|
|
42
|
+
| **Type-safe output** | Generates `types.ts` from your schema, so your content is fully typed in your project. |
|
|
43
|
+
| **Export any time** | One click downloads schema + content + types as a ZIP. Nothing is ever locked in. |
|
|
44
|
+
| **The endpoint is yours** | Wherever you put the JSON becomes your API — repo raw, jsDelivr, your build. |
|
|
45
|
+
|
|
46
|
+
Field types: `text` · `richtext` · `number` · `boolean` · `date` · `select` · `relation` (multi) · `image`.
|
|
47
|
+
|
|
48
|
+
## Commands
|
|
49
|
+
|
|
50
|
+
| Command | What it does |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `npx @kdrgny/justjson` (or `serve`) | Starts the local editor and opens it in your browser |
|
|
53
|
+
| `npx @kdrgny/justjson init [template]` | Scaffolds a schema from a template (`blog`, `cv`, `portfolio`, `docs`, `changelog`) |
|
|
54
|
+
| `npx @kdrgny/justjson types` | Generates `types.ts` from your schema |
|
|
55
|
+
| `npx @kdrgny/justjson export` | Exports a ZIP snapshot (schema + content + types) |
|
|
56
|
+
|
|
57
|
+
## How it works
|
|
58
|
+
|
|
59
|
+
Your project holds a `content/` folder. JustJSON reads and writes it — that's all.
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
content/
|
|
63
|
+
_schema.json ← your schema (built from the UI)
|
|
64
|
+
posts/
|
|
65
|
+
hello-world.json ← one file per entry
|
|
66
|
+
settings.json ← singletons
|
|
67
|
+
media/ ← uploaded images (WebP)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The editor is served locally by the CLI; it talks only to your disk. Delete `node_modules`, keep the JSON — your content is never trapped in a tool.
|
|
71
|
+
|
|
72
|
+
JustJSON is deliberately small. It does one thing — turn a schema into editable JSON content — and tries to do it well.
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
[MIT](https://github.com/kdrgny-dev/justjson/blob/main/LICENSE) © Kadir Günay
|
package/dist/cli.js
CHANGED
|
@@ -4314,6 +4314,98 @@ function buildExportManifest(input) {
|
|
|
4314
4314
|
}
|
|
4315
4315
|
return out;
|
|
4316
4316
|
}
|
|
4317
|
+
var HTML = /<[a-z!/][\s\S]*>/i;
|
|
4318
|
+
function inferType(value) {
|
|
4319
|
+
if (typeof value === "boolean") return "boolean";
|
|
4320
|
+
if (typeof value === "number") return "number";
|
|
4321
|
+
if (typeof value === "string") return HTML.test(value) ? "richtext" : "text";
|
|
4322
|
+
return null;
|
|
4323
|
+
}
|
|
4324
|
+
function isPlainObject(v) {
|
|
4325
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
4326
|
+
}
|
|
4327
|
+
function fieldsFromRows(rows) {
|
|
4328
|
+
const order = [];
|
|
4329
|
+
const types = /* @__PURE__ */ new Map();
|
|
4330
|
+
for (const row of rows) {
|
|
4331
|
+
for (const [key, value] of Object.entries(row)) {
|
|
4332
|
+
const t = inferType(value);
|
|
4333
|
+
if (t === null) continue;
|
|
4334
|
+
if (!types.has(key)) {
|
|
4335
|
+
types.set(key, t);
|
|
4336
|
+
order.push(key);
|
|
4337
|
+
} else if (types.get(key) === "text" && t === "richtext") {
|
|
4338
|
+
types.set(key, "richtext");
|
|
4339
|
+
}
|
|
4340
|
+
}
|
|
4341
|
+
}
|
|
4342
|
+
return order.map((key) => ({ key, label: key, type: types.get(key) }));
|
|
4343
|
+
}
|
|
4344
|
+
function inferProject(data) {
|
|
4345
|
+
if (!isPlainObject(data)) throw new Error("\u0130\xE7e aktar\u0131lan JSON bir nesne olmal\u0131.");
|
|
4346
|
+
const collections = [];
|
|
4347
|
+
const singletons = [];
|
|
4348
|
+
const entries = {};
|
|
4349
|
+
const singletonData = {};
|
|
4350
|
+
const generalFields = [];
|
|
4351
|
+
const generalData = {};
|
|
4352
|
+
const usedNames = /* @__PURE__ */ new Set();
|
|
4353
|
+
const uniqueName = (base) => {
|
|
4354
|
+
let name = base || "alan";
|
|
4355
|
+
let n = 2;
|
|
4356
|
+
while (usedNames.has(name)) name = `${base}-${n++}`;
|
|
4357
|
+
usedNames.add(name);
|
|
4358
|
+
return name;
|
|
4359
|
+
};
|
|
4360
|
+
const isRowList = (v) => Array.isArray(v) && v.length > 0 && v.every(isPlainObject);
|
|
4361
|
+
const addCollection = (key, list, label = key) => {
|
|
4362
|
+
const name = uniqueName(slugify(key));
|
|
4363
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4364
|
+
const rows = list.map((row, i) => {
|
|
4365
|
+
const firstText = Object.values(row).find((v) => typeof v === "string" && v.trim() !== "");
|
|
4366
|
+
const base = slugify(
|
|
4367
|
+
String(row.slug ?? row.title ?? row.name ?? row.label ?? firstText ?? `${name}-${i + 1}`)
|
|
4368
|
+
) || `${name}-${i + 1}`;
|
|
4369
|
+
let slug = base;
|
|
4370
|
+
let n = 2;
|
|
4371
|
+
while (seen.has(slug)) slug = `${base}-${n++}`;
|
|
4372
|
+
seen.add(slug);
|
|
4373
|
+
return { slug, ...row };
|
|
4374
|
+
});
|
|
4375
|
+
const fields = fieldsFromRows(rows);
|
|
4376
|
+
const keys = new Set(fields.map((f) => f.key));
|
|
4377
|
+
collections.push({ name, label, path: name, fields });
|
|
4378
|
+
entries[name] = rows.map(
|
|
4379
|
+
(row) => Object.fromEntries(Object.entries(row).filter(([k]) => keys.has(k)))
|
|
4380
|
+
);
|
|
4381
|
+
};
|
|
4382
|
+
for (const [key, value] of Object.entries(data)) {
|
|
4383
|
+
if (isRowList(value)) {
|
|
4384
|
+
addCollection(key, value);
|
|
4385
|
+
} else if (isPlainObject(value)) {
|
|
4386
|
+
const name = uniqueName(slugify(key));
|
|
4387
|
+
const flat = {};
|
|
4388
|
+
for (const [k, v] of Object.entries(value)) {
|
|
4389
|
+
if (isRowList(v)) addCollection(usedNames.has(slugify(k)) ? `${key}-${k}` : k, v, k);
|
|
4390
|
+
else if (inferType(v) !== null) flat[k] = v;
|
|
4391
|
+
}
|
|
4392
|
+
singletons.push({ name, label: key, path: `${name}.json`, fields: fieldsFromRows([flat]) });
|
|
4393
|
+
singletonData[name] = flat;
|
|
4394
|
+
} else {
|
|
4395
|
+
const t = inferType(value);
|
|
4396
|
+
if (t) {
|
|
4397
|
+
generalFields.push({ key, label: key, type: t });
|
|
4398
|
+
generalData[key] = value;
|
|
4399
|
+
}
|
|
4400
|
+
}
|
|
4401
|
+
}
|
|
4402
|
+
if (generalFields.length > 0) {
|
|
4403
|
+
const name = uniqueName("genel");
|
|
4404
|
+
singletons.push({ name, label: "Genel", path: `${name}.json`, fields: generalFields });
|
|
4405
|
+
singletonData[name] = generalData;
|
|
4406
|
+
}
|
|
4407
|
+
return { schema: { version: 1, collections, singletons }, entries, singletons: singletonData };
|
|
4408
|
+
}
|
|
4317
4409
|
|
|
4318
4410
|
// src/commands/export.ts
|
|
4319
4411
|
import { zipSync } from "fflate";
|
|
@@ -4387,9 +4479,7 @@ async function resolveContentDir(root2) {
|
|
|
4387
4479
|
}
|
|
4388
4480
|
|
|
4389
4481
|
// src/commands/export.ts
|
|
4390
|
-
async function
|
|
4391
|
-
const adapter = new FsAdapter(root2);
|
|
4392
|
-
const contentDir = await resolveContentDir(root2);
|
|
4482
|
+
async function collectExportZip(adapter, contentDir) {
|
|
4393
4483
|
const schema = await loadSchema(adapter, contentDir);
|
|
4394
4484
|
if (!schema) throw new Error("\u015Eema bulunamad\u0131. \xD6nce `justjson init` \xE7al\u0131\u015Ft\u0131r\u0131n.");
|
|
4395
4485
|
const store = new ContentStore(adapter, schema, contentDir);
|
|
@@ -4414,7 +4504,12 @@ async function exportZip(root2, outFile = "justjson-export.zip") {
|
|
|
4414
4504
|
for (const [path, content] of Object.entries(manifest)) {
|
|
4415
4505
|
zipInput[path] = typeof content === "string" ? encoder.encode(content) : content;
|
|
4416
4506
|
}
|
|
4417
|
-
|
|
4507
|
+
return zipSync(zipInput);
|
|
4508
|
+
}
|
|
4509
|
+
async function exportZip(root2, outFile = "justjson-export.zip") {
|
|
4510
|
+
const adapter = new FsAdapter(root2);
|
|
4511
|
+
const contentDir = await resolveContentDir(root2);
|
|
4512
|
+
const zipped = await collectExportZip(adapter, contentDir);
|
|
4418
4513
|
const outAbs = join(root2, outFile);
|
|
4419
4514
|
await writeFile2(outAbs, zipped);
|
|
4420
4515
|
return outAbs;
|
|
@@ -4422,6 +4517,8 @@ async function exportZip(root2, outFile = "justjson-export.zip") {
|
|
|
4422
4517
|
|
|
4423
4518
|
// src/templates/blog.json
|
|
4424
4519
|
var blog_default = {
|
|
4520
|
+
title: "Blog",
|
|
4521
|
+
description: "Rich-text i\xE7erikli yaz\u0131lar ve site ad\u0131 i\xE7in bir Ayarlar.",
|
|
4425
4522
|
schema: {
|
|
4426
4523
|
version: 1,
|
|
4427
4524
|
collections: [
|
|
@@ -4451,8 +4548,49 @@ var blog_default = {
|
|
|
4451
4548
|
}
|
|
4452
4549
|
};
|
|
4453
4550
|
|
|
4551
|
+
// src/templates/changelog.json
|
|
4552
|
+
var changelog_default = {
|
|
4553
|
+
title: "Changelog",
|
|
4554
|
+
description: "S\xFCr\xFCm notlar\u0131: versiyon, tarih, t\xFCr ve rich-text a\xE7\u0131klama.",
|
|
4555
|
+
schema: {
|
|
4556
|
+
version: 1,
|
|
4557
|
+
collections: [
|
|
4558
|
+
{
|
|
4559
|
+
name: "releases",
|
|
4560
|
+
label: "S\xFCr\xFCmler",
|
|
4561
|
+
path: "releases",
|
|
4562
|
+
fields: [
|
|
4563
|
+
{ key: "version", label: "Versiyon", type: "text", required: true },
|
|
4564
|
+
{ key: "slug", label: "Slug", type: "text", required: true },
|
|
4565
|
+
{ key: "date", label: "Tarih", type: "date" },
|
|
4566
|
+
{
|
|
4567
|
+
key: "type",
|
|
4568
|
+
label: "T\xFCr",
|
|
4569
|
+
type: "select",
|
|
4570
|
+
options: ["Eklendi", "De\u011Fi\u015Fti", "D\xFCzeltildi"]
|
|
4571
|
+
},
|
|
4572
|
+
{ key: "body", label: "Notlar", type: "richtext" }
|
|
4573
|
+
]
|
|
4574
|
+
}
|
|
4575
|
+
],
|
|
4576
|
+
singletons: []
|
|
4577
|
+
},
|
|
4578
|
+
samples: {
|
|
4579
|
+
releases: [
|
|
4580
|
+
{
|
|
4581
|
+
version: "1.0.0",
|
|
4582
|
+
slug: "1-0-0",
|
|
4583
|
+
type: "Eklendi",
|
|
4584
|
+
body: "\u0130lk s\xFCr\xFCm."
|
|
4585
|
+
}
|
|
4586
|
+
]
|
|
4587
|
+
}
|
|
4588
|
+
};
|
|
4589
|
+
|
|
4454
4590
|
// src/templates/cv.json
|
|
4455
4591
|
var cv_default = {
|
|
4592
|
+
title: "CV",
|
|
4593
|
+
description: "Deneyim koleksiyonu ve ki\u015Fisel bilgiler i\xE7in bir Profil.",
|
|
4456
4594
|
schema: {
|
|
4457
4595
|
version: 1,
|
|
4458
4596
|
collections: [
|
|
@@ -4484,22 +4622,128 @@ var cv_default = {
|
|
|
4484
4622
|
}
|
|
4485
4623
|
};
|
|
4486
4624
|
|
|
4625
|
+
// src/templates/docs.json
|
|
4626
|
+
var docs_default = {
|
|
4627
|
+
title: "Dok\xFCmantasyon",
|
|
4628
|
+
description: "S\u0131ralanabilir sayfalar ve rich-text i\xE7erik; site ba\u015Fl\u0131\u011F\u0131 i\xE7in bir Ayarlar.",
|
|
4629
|
+
schema: {
|
|
4630
|
+
version: 1,
|
|
4631
|
+
collections: [
|
|
4632
|
+
{
|
|
4633
|
+
name: "pages",
|
|
4634
|
+
label: "Sayfalar",
|
|
4635
|
+
path: "pages",
|
|
4636
|
+
fields: [
|
|
4637
|
+
{ key: "title", label: "Ba\u015Fl\u0131k", type: "text", required: true },
|
|
4638
|
+
{ key: "slug", label: "Slug", type: "text", required: true },
|
|
4639
|
+
{ key: "order", label: "S\u0131ra", type: "number" },
|
|
4640
|
+
{ key: "body", label: "\u0130\xE7erik", type: "richtext" }
|
|
4641
|
+
]
|
|
4642
|
+
}
|
|
4643
|
+
],
|
|
4644
|
+
singletons: [
|
|
4645
|
+
{
|
|
4646
|
+
name: "settings",
|
|
4647
|
+
label: "Ayarlar",
|
|
4648
|
+
path: "settings.json",
|
|
4649
|
+
fields: [
|
|
4650
|
+
{ key: "title", label: "Site ad\u0131", type: "text" },
|
|
4651
|
+
{ key: "tagline", label: "Slogan", type: "text" }
|
|
4652
|
+
]
|
|
4653
|
+
}
|
|
4654
|
+
]
|
|
4655
|
+
},
|
|
4656
|
+
samples: {
|
|
4657
|
+
pages: [
|
|
4658
|
+
{ title: "Ba\u015Flarken", slug: "baslarken", order: 1, body: "Kuruluma ho\u015F geldin." }
|
|
4659
|
+
]
|
|
4660
|
+
}
|
|
4661
|
+
};
|
|
4662
|
+
|
|
4663
|
+
// src/templates/portfolio.json
|
|
4664
|
+
var portfolio_default = {
|
|
4665
|
+
title: "Portfolyo",
|
|
4666
|
+
description: "Kapak g\xF6rseli, etiket ve rich-text i\xE7erikli projeler; bir de Hakk\u0131nda sayfas\u0131.",
|
|
4667
|
+
schema: {
|
|
4668
|
+
version: 1,
|
|
4669
|
+
collections: [
|
|
4670
|
+
{
|
|
4671
|
+
name: "projects",
|
|
4672
|
+
label: "Projeler",
|
|
4673
|
+
path: "projects",
|
|
4674
|
+
fields: [
|
|
4675
|
+
{ key: "title", label: "Ba\u015Fl\u0131k", type: "text", required: true },
|
|
4676
|
+
{ key: "slug", label: "Slug", type: "text", required: true },
|
|
4677
|
+
{ key: "summary", label: "\xD6zet", type: "text" },
|
|
4678
|
+
{ key: "cover", label: "Kapak", type: "image" },
|
|
4679
|
+
{ key: "url", label: "Ba\u011Flant\u0131", type: "text" },
|
|
4680
|
+
{
|
|
4681
|
+
key: "kind",
|
|
4682
|
+
label: "T\xFCr",
|
|
4683
|
+
type: "select",
|
|
4684
|
+
options: ["Web", "Mobil", "Tasar\u0131m"]
|
|
4685
|
+
},
|
|
4686
|
+
{ key: "body", label: "\u0130\xE7erik", type: "richtext" },
|
|
4687
|
+
{ key: "date", label: "Tarih", type: "date" }
|
|
4688
|
+
]
|
|
4689
|
+
}
|
|
4690
|
+
],
|
|
4691
|
+
singletons: [
|
|
4692
|
+
{
|
|
4693
|
+
name: "about",
|
|
4694
|
+
label: "Hakk\u0131nda",
|
|
4695
|
+
path: "about.json",
|
|
4696
|
+
fields: [
|
|
4697
|
+
{ key: "name", label: "Ad", type: "text", required: true },
|
|
4698
|
+
{ key: "avatar", label: "Avatar", type: "image" },
|
|
4699
|
+
{ key: "bio", label: "Biyografi", type: "richtext" }
|
|
4700
|
+
]
|
|
4701
|
+
}
|
|
4702
|
+
]
|
|
4703
|
+
},
|
|
4704
|
+
samples: {
|
|
4705
|
+
projects: [
|
|
4706
|
+
{
|
|
4707
|
+
title: "\xD6rnek Proje",
|
|
4708
|
+
slug: "ornek-proje",
|
|
4709
|
+
summary: "K\u0131sa bir a\xE7\u0131klama.",
|
|
4710
|
+
kind: "Web",
|
|
4711
|
+
body: "Proje detaylar\u0131 burada."
|
|
4712
|
+
}
|
|
4713
|
+
]
|
|
4714
|
+
}
|
|
4715
|
+
};
|
|
4716
|
+
|
|
4487
4717
|
// src/commands/init.ts
|
|
4488
4718
|
var templates = {
|
|
4489
4719
|
blog: blog_default,
|
|
4490
|
-
cv: cv_default
|
|
4720
|
+
cv: cv_default,
|
|
4721
|
+
portfolio: portfolio_default,
|
|
4722
|
+
docs: docs_default,
|
|
4723
|
+
changelog: changelog_default
|
|
4491
4724
|
};
|
|
4492
4725
|
function listTemplates() {
|
|
4493
4726
|
return Object.keys(templates);
|
|
4494
4727
|
}
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4728
|
+
function getTemplate(name) {
|
|
4729
|
+
return templates[name];
|
|
4730
|
+
}
|
|
4731
|
+
function templateList() {
|
|
4732
|
+
return Object.entries(templates).map(([id, t]) => {
|
|
4733
|
+
const s = t.schema;
|
|
4734
|
+
return {
|
|
4735
|
+
id,
|
|
4736
|
+
title: t.title,
|
|
4737
|
+
description: t.description,
|
|
4738
|
+
collections: s.collections.map((c) => ({
|
|
4739
|
+
label: c.label ?? c.name,
|
|
4740
|
+
fields: c.fields.length
|
|
4741
|
+
})),
|
|
4742
|
+
singletons: s.singletons.map((sg) => ({ label: sg.label ?? sg.name }))
|
|
4743
|
+
};
|
|
4744
|
+
});
|
|
4745
|
+
}
|
|
4746
|
+
async function applyTemplate(adapter, contentDir, template) {
|
|
4503
4747
|
const schema = parseSchema(template.schema);
|
|
4504
4748
|
await saveSchema(adapter, schema, contentDir);
|
|
4505
4749
|
const store = new ContentStore(adapter, schema, contentDir);
|
|
@@ -4509,6 +4753,17 @@ async function initProject(root2, templateName) {
|
|
|
4509
4753
|
await store.writeEntry(collection, slug, row);
|
|
4510
4754
|
}
|
|
4511
4755
|
}
|
|
4756
|
+
return schema;
|
|
4757
|
+
}
|
|
4758
|
+
async function initProject(root2, templateName) {
|
|
4759
|
+
const template = templates[templateName];
|
|
4760
|
+
if (!template) throw new Error(`Bilinmeyen template: ${templateName}`);
|
|
4761
|
+
const adapter = new FsAdapter(root2);
|
|
4762
|
+
const contentDir = await resolveContentDir(root2);
|
|
4763
|
+
if (await loadSchema(adapter, contentDir)) {
|
|
4764
|
+
throw new Error("Bu klas\xF6rde zaten bir \u015Fema var (content/_schema.json).");
|
|
4765
|
+
}
|
|
4766
|
+
await applyTemplate(adapter, contentDir, template);
|
|
4512
4767
|
}
|
|
4513
4768
|
|
|
4514
4769
|
// src/commands/types.ts
|
|
@@ -4525,7 +4780,7 @@ async function generateTypesFile(root2, outPath = "types.ts") {
|
|
|
4525
4780
|
// src/server.ts
|
|
4526
4781
|
import { exec } from "child_process";
|
|
4527
4782
|
import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile3 } from "fs/promises";
|
|
4528
|
-
import { dirname as dirname2, extname, join as join3, normalize } from "path";
|
|
4783
|
+
import { basename, dirname as dirname2, extname, join as join3, normalize } from "path";
|
|
4529
4784
|
import { fileURLToPath } from "url";
|
|
4530
4785
|
import { serve } from "@hono/node-server";
|
|
4531
4786
|
import { Hono } from "hono";
|
|
@@ -4553,6 +4808,71 @@ async function createServer(root2) {
|
|
|
4553
4808
|
if (msg.startsWith("G\xFCvensiz") || msg.startsWith("Yol")) return c.json({ error: msg }, 400);
|
|
4554
4809
|
return c.json({ error: "sunucu hatas\u0131" }, 500);
|
|
4555
4810
|
});
|
|
4811
|
+
app.get(
|
|
4812
|
+
"/api/_project",
|
|
4813
|
+
(c) => c.json({
|
|
4814
|
+
name: basename(root2) || "proje",
|
|
4815
|
+
path: root2,
|
|
4816
|
+
contentDir,
|
|
4817
|
+
collections: schema.collections.length,
|
|
4818
|
+
singletons: schema.singletons.length
|
|
4819
|
+
})
|
|
4820
|
+
);
|
|
4821
|
+
app.get("/api/_templates", (c) => c.json({ items: templateList() }));
|
|
4822
|
+
app.post("/api/_init", async (c) => {
|
|
4823
|
+
const { template: id } = await c.req.json();
|
|
4824
|
+
const t = id ? getTemplate(id) : void 0;
|
|
4825
|
+
if (!t) return c.json({ error: "Bilinmeyen template" }, 404);
|
|
4826
|
+
if (schema.collections.length > 0 || schema.singletons.length > 0) {
|
|
4827
|
+
return c.json({ error: "Bu klas\xF6rde zaten bir \u015Fema var." }, 400);
|
|
4828
|
+
}
|
|
4829
|
+
schema = await applyTemplate(adapter, contentDir, t);
|
|
4830
|
+
store = new ContentStore(adapter, schema, contentDir);
|
|
4831
|
+
return c.json({ ok: true });
|
|
4832
|
+
});
|
|
4833
|
+
app.post("/api/_import", async (c) => {
|
|
4834
|
+
if (schema.collections.length > 0 || schema.singletons.length > 0) {
|
|
4835
|
+
return c.json({ error: "Bu klas\xF6rde zaten bir \u015Fema var." }, 400);
|
|
4836
|
+
}
|
|
4837
|
+
const { raw } = await c.req.json();
|
|
4838
|
+
let next;
|
|
4839
|
+
let entries = {};
|
|
4840
|
+
let singletonData = {};
|
|
4841
|
+
try {
|
|
4842
|
+
next = parseSchema(raw);
|
|
4843
|
+
} catch {
|
|
4844
|
+
try {
|
|
4845
|
+
const inferred = inferProject(raw);
|
|
4846
|
+
next = parseSchema(inferred.schema);
|
|
4847
|
+
entries = inferred.entries;
|
|
4848
|
+
singletonData = inferred.singletons;
|
|
4849
|
+
} catch (e) {
|
|
4850
|
+
return c.json({ error: `\u0130\xE7e aktar\u0131lamad\u0131: ${e.message}` }, 400);
|
|
4851
|
+
}
|
|
4852
|
+
}
|
|
4853
|
+
await saveSchema(adapter, next, contentDir);
|
|
4854
|
+
schema = next;
|
|
4855
|
+
store = new ContentStore(adapter, schema, contentDir);
|
|
4856
|
+
for (const [collection, rows] of Object.entries(entries)) {
|
|
4857
|
+
for (const row of rows) {
|
|
4858
|
+
const slug = slugify(String(row.slug ?? row.title ?? "icerik")) || "icerik";
|
|
4859
|
+
await store.writeEntry(collection, slug, row);
|
|
4860
|
+
}
|
|
4861
|
+
}
|
|
4862
|
+
for (const [name, data] of Object.entries(singletonData)) {
|
|
4863
|
+
await store.writeSingleton(name, data);
|
|
4864
|
+
}
|
|
4865
|
+
return c.json({ ok: true });
|
|
4866
|
+
});
|
|
4867
|
+
app.get("/api/_export", async (c) => {
|
|
4868
|
+
const zipped = await collectExportZip(adapter, contentDir);
|
|
4869
|
+
return new Response(zipped, {
|
|
4870
|
+
headers: {
|
|
4871
|
+
"content-type": "application/zip",
|
|
4872
|
+
"content-disposition": 'attachment; filename="justjson-export.zip"'
|
|
4873
|
+
}
|
|
4874
|
+
});
|
|
4875
|
+
});
|
|
4556
4876
|
app.get("/api/_schema", (c) => c.json(schema));
|
|
4557
4877
|
app.put("/api/_schema", async (c) => {
|
|
4558
4878
|
let next;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|