coloco 0.4.7__tar.gz → 0.4.8__tar.gz
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.
- {coloco-0.4.7 → coloco-0.4.8}/PKG-INFO +1 -1
- {coloco-0.4.7 → coloco-0.4.8}/pyproject.toml +1 -1
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/cli/createapp.py +3 -5
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/cli/dev.py +2 -2
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/cli/node.py +2 -2
- coloco-0.4.8/src/coloco/codegen.py +92 -0
- coloco-0.4.8/src/coloco/config.py +22 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/exceptions.py +1 -0
- coloco-0.4.8/src/coloco/templates/standard/.gitignore-tpl +20 -0
- coloco-0.4.8/src/coloco/templates/standard/README.md-tpl +3 -0
- {coloco-0.4.7/src/coloco/templates/standard/+node → coloco-0.4.8/src/coloco/templates/standard}/package.json-tpl +10 -5
- coloco-0.4.8/src/coloco/templates/standard/pyproject.toml-tpl +17 -0
- coloco-0.4.8/src/coloco/templates/standard/src/app/example/index.svelte-tpl +13 -0
- coloco-0.4.8/src/coloco/templates/standard/src/app/index.svelte-tpl +1 -0
- coloco-0.4.8/src/coloco/templates/standard/src/app.svelte-tpl +38 -0
- coloco-0.4.8/src/coloco/templates/standard/src/assets/favicon.png-tpl +0 -0
- coloco-0.4.8/src/coloco/templates/standard/src/lib/client.ts-tpl +15 -0
- coloco-0.4.8/src/coloco/templates/standard/src/main.py-tpl +6 -0
- {coloco-0.4.7/src/coloco/templates/standard/+app → coloco-0.4.8/src/coloco/templates/standard/src}/main.ts-tpl +1 -2
- coloco-0.4.8/src/coloco/templates/standard/tsconfig.json-tpl +36 -0
- coloco-0.4.8/src/coloco/templates/standard/vite-env.d.ts-tpl +11 -0
- coloco-0.4.8/src/coloco/templates/standard/vite.config.ts-tpl +30 -0
- coloco-0.4.7/src/coloco/codegen.py +0 -62
- coloco-0.4.7/src/coloco/config.py +0 -18
- coloco-0.4.7/src/coloco/templates/standard/+app/app.svelte-tpl +0 -29
- coloco-0.4.7/src/coloco/templates/standard/+app/index.svelte-tpl +0 -1
- coloco-0.4.7/src/coloco/templates/standard/+node/openapi-ts.config.ts-tpl +0 -10
- coloco-0.4.7/src/coloco/templates/standard/+node/tsconfig.json-tpl +0 -43
- coloco-0.4.7/src/coloco/templates/standard/+node/vite-env.d.ts-tpl +0 -2
- coloco-0.4.7/src/coloco/templates/standard/+node/vite.config.ts-tpl +0 -48
- coloco-0.4.7/src/coloco/templates/standard/.gitignore-tpl +0 -6
- coloco-0.4.7/src/coloco/templates/standard/README.md-tpl +0 -3
- coloco-0.4.7/src/coloco/templates/standard/example/index.svelte-tpl +0 -7
- coloco-0.4.7/src/coloco/templates/standard/main.py-tpl +0 -3
- coloco-0.4.7/src/coloco/templates/standard/pyproject.toml-tpl +0 -13
- coloco-0.4.7/src/coloco/templates/standard/tsconfig.json-tpl +0 -3
- {coloco-0.4.7 → coloco-0.4.8}/LICENSE +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/README.md +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/__init__.py +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/__main__.py +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/api.py +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/app.py +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/cli/api.py +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/cli/build.py +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/cli/db.py +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/cli/package.py +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/cli/serve.py +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/db.py +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/dependencies.py +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/lifespan.py +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/static.py +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/templates/docker/.dockerignore-tpl +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/templates/docker/Dockerfile-tpl +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/src/coloco/templates/docker/docker-compose.yml-tpl +0 -0
- {coloco-0.4.7/src/coloco/templates/standard/+app → coloco-0.4.8/src/coloco/templates/standard/src/app}/404.svelte-tpl +0 -0
- {coloco-0.4.7/src/coloco/templates/standard → coloco-0.4.8/src/coloco/templates/standard/src/app}/example/api.py-tpl +0 -0
- {coloco-0.4.7/src/coloco/templates/standard/+app → coloco-0.4.8/src/coloco/templates/standard/src}/app.css-tpl +0 -0
- {coloco-0.4.7/src/coloco/templates/standard/+app → coloco-0.4.8/src/coloco/templates/standard/src}/index.html-tpl +0 -0
- {coloco-0.4.7/src/coloco/templates/standard/+node → coloco-0.4.8/src/coloco/templates/standard}/svelte.config.js-tpl +0 -0
- {coloco-0.4.7 → coloco-0.4.8}/tests/__init__.py +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
from rich import print
|
|
2
|
-
from .node import install
|
|
3
1
|
import os
|
|
2
|
+
from rich import print
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
def createapp(name: str):
|
|
@@ -11,6 +10,7 @@ def createapp(name: str):
|
|
|
11
10
|
|
|
12
11
|
template_vars = {
|
|
13
12
|
"project_name": name,
|
|
13
|
+
"coloco_version": "0.4.8",
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
# Create directory
|
|
@@ -28,9 +28,7 @@ def createapp(name: str):
|
|
|
28
28
|
content = f.read()
|
|
29
29
|
for key, value in template_vars.items():
|
|
30
30
|
content = content.replace(f"{{{{ {key} }}}}", value)
|
|
31
|
-
with open(
|
|
32
|
-
os.path.join(install_dir, relative_path, file[:-4]), "w"
|
|
33
|
-
) as f:
|
|
31
|
+
with open(os.path.join(install_dir, relative_path, file[:-4]), "w") as f:
|
|
34
32
|
f.write(content)
|
|
35
33
|
|
|
36
34
|
print(f"App created in {install_dir}")
|
|
@@ -10,7 +10,7 @@ app = cyclopts.App()
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
@app.default()
|
|
13
|
-
def dev(app: str | None = None, host: str = "127.0.0.1"):
|
|
13
|
+
def dev(app: str | None = None, host: str = "127.0.0.1", port: int = 5172):
|
|
14
14
|
if not app:
|
|
15
15
|
app = get_coloco_config().get("app") or "src.main.app"
|
|
16
16
|
|
|
@@ -26,7 +26,7 @@ def dev(app: str | None = None, host: str = "127.0.0.1"):
|
|
|
26
26
|
_serve(
|
|
27
27
|
app=app,
|
|
28
28
|
host=host,
|
|
29
|
-
port=
|
|
29
|
+
port=port,
|
|
30
30
|
log_level="debug",
|
|
31
31
|
mode="dev",
|
|
32
32
|
reload=True,
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from contextlib import contextmanager
|
|
2
|
+
from fastapi import FastAPI
|
|
3
|
+
from fastapi.routing import APIRoute
|
|
4
|
+
import json
|
|
5
|
+
from subprocess import run
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import shutil
|
|
9
|
+
import filecmp
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def compare_and_copy(source_dir, target_dir):
|
|
13
|
+
"""
|
|
14
|
+
Compares files in two directories and copies files from source to target if they differ, creating target directories if needed.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
source_dir (str): Path to the source directory.
|
|
18
|
+
target_dir (str): Path to the target directory.
|
|
19
|
+
"""
|
|
20
|
+
for root, _, files in os.walk(source_dir):
|
|
21
|
+
rel_path = os.path.relpath(root, source_dir) # Get relative path from source
|
|
22
|
+
target_path = os.path.join(target_dir, rel_path)
|
|
23
|
+
os.makedirs(target_path, exist_ok=True) # Create target directory if it doesn't exist
|
|
24
|
+
|
|
25
|
+
for file in files:
|
|
26
|
+
source_file = os.path.join(root, file)
|
|
27
|
+
target_file = os.path.join(target_path, file)
|
|
28
|
+
|
|
29
|
+
if not os.path.exists(target_file) or not filecmp.cmp(source_file, target_file):
|
|
30
|
+
shutil.copy2(source_file, target_file)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def custom_generate_unique_id(route: APIRoute) -> str:
|
|
34
|
+
return f"{route.name}"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def generate_openapi_schema(app: FastAPI, path="/tmp/openapi.json"):
|
|
38
|
+
with open(path, "w") as f:
|
|
39
|
+
json.dump(app.openapi(), f)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@contextmanager
|
|
43
|
+
def ensure_openapi_ts_config(config_path="./openapi-ts.config.ts", output_path="./api/app"):
|
|
44
|
+
"""
|
|
45
|
+
Ensures an openapi-ts config file is present, otherwise temporarily generates one
|
|
46
|
+
"""
|
|
47
|
+
generated = False
|
|
48
|
+
try:
|
|
49
|
+
if not os.path.exists(config_path):
|
|
50
|
+
with open(config_path, "w") as f:
|
|
51
|
+
generated = True
|
|
52
|
+
f.write(
|
|
53
|
+
f"""
|
|
54
|
+
import {{ defaultPlugins }} from '@hey-api/openapi-ts';
|
|
55
|
+
import {{ codegenConfig }} from '@coloco/api-client-svelte';
|
|
56
|
+
|
|
57
|
+
export default {{
|
|
58
|
+
plugins: [
|
|
59
|
+
...defaultPlugins,
|
|
60
|
+
'@hey-api/client-fetch',
|
|
61
|
+
codegenConfig({{ name: 'coloco-codegen', outputPath: '{output_path}' }}),
|
|
62
|
+
],
|
|
63
|
+
}};
|
|
64
|
+
"""
|
|
65
|
+
)
|
|
66
|
+
yield
|
|
67
|
+
finally:
|
|
68
|
+
if generated:
|
|
69
|
+
os.remove(config_path)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def generate_openapi_code(
|
|
73
|
+
host,
|
|
74
|
+
spec_path="/tmp/openapi.json",
|
|
75
|
+
output_dir="./src/app/.generated/client",
|
|
76
|
+
config_path="./openapi-ts.config.ts",
|
|
77
|
+
diff_files=False,
|
|
78
|
+
):
|
|
79
|
+
temp_dir = "/tmp/backend_api"
|
|
80
|
+
output_path = os.path.join(os.getcwd(), output_dir)
|
|
81
|
+
|
|
82
|
+
with ensure_openapi_ts_config(config_path):
|
|
83
|
+
run(
|
|
84
|
+
f"npx openapi-ts "
|
|
85
|
+
f"--base {host} "
|
|
86
|
+
f"--file {config_path} "
|
|
87
|
+
f"--input {spec_path} "
|
|
88
|
+
f"--output {temp_dir if diff_files else output_path} ".split(),
|
|
89
|
+
cwd=os.getcwd(),
|
|
90
|
+
)
|
|
91
|
+
if diff_files:
|
|
92
|
+
compare_and_copy(temp_dir, output_dir)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import tomllib
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def get_pyproject_config(path: str = "pyproject.toml"):
|
|
6
|
+
# Read project toml
|
|
7
|
+
if not os.path.exists(path):
|
|
8
|
+
raise LookupError(f"{path} not found")
|
|
9
|
+
with open(path, "rb") as f:
|
|
10
|
+
config = tomllib.load(f)
|
|
11
|
+
return config
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_coloco_config():
|
|
15
|
+
# Read project toml
|
|
16
|
+
config = get_pyproject_config()
|
|
17
|
+
|
|
18
|
+
# Get coloco config
|
|
19
|
+
coloco_config = config.get("tool", {}).get("coloco")
|
|
20
|
+
if not coloco_config:
|
|
21
|
+
raise LookupError("coloco config not found in pyproject.toml under [tool.coloco]")
|
|
22
|
+
return coloco_config
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
2
|
+
"name": "couchquest",
|
|
3
3
|
"private": true,
|
|
4
4
|
"version": "1.0.0",
|
|
5
5
|
"type": "module",
|
|
@@ -10,16 +10,21 @@
|
|
|
10
10
|
"check": "svelte-check --tsconfig ./tsconfig.app.json && tsc -p tsconfig.node.json"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@coloco/api-client-svelte": "^0.4.
|
|
14
|
-
"@coloco/router": "^0.1.
|
|
13
|
+
"@coloco/api-client-svelte": "^0.4.12",
|
|
14
|
+
"@coloco/router": "^0.1.18",
|
|
15
|
+
"@coloco/vite": "^0.1.1",
|
|
15
16
|
"@hey-api/client-fetch": "^0.8.2",
|
|
16
17
|
"@hey-api/openapi-ts": "^0.64.7",
|
|
17
18
|
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
|
18
19
|
"@tsconfig/svelte": "^5.0.4",
|
|
19
20
|
"@types/node": "^22.13.4",
|
|
21
|
+
"autoprefixer": "^10.4.20",
|
|
20
22
|
"svelte": "^5.19.6",
|
|
21
23
|
"svelte-check": "^4.1.4",
|
|
22
|
-
"typescript": "~5.
|
|
23
|
-
"vite": "^6.
|
|
24
|
+
"typescript": "~5.8.2",
|
|
25
|
+
"vite": "^6.3.3"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@mateothegreat/svelte5-router": "^2.14.1"
|
|
24
29
|
}
|
|
25
30
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "{{ project_name }}"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Your project description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.13"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"coloco>={{ coloco_version }}",
|
|
9
|
+
"tortoise-pathway>=0.2.0",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[tool.coloco]
|
|
13
|
+
app = "src.main.app"
|
|
14
|
+
migrations_dir = "+migrations"
|
|
15
|
+
|
|
16
|
+
[tool.uv.sources]
|
|
17
|
+
tortoise-pathway = { git = "https://github.com/channelcat/tortoise-pathway", rev = "iterate-migration-apply" }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { test } from "./api";
|
|
3
|
+
|
|
4
|
+
const results = test({ name: "Testy McTesterson" });
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
{#await results}
|
|
8
|
+
<p>Loading...</p>
|
|
9
|
+
{:then response}
|
|
10
|
+
<p>Hello {response.data}</p>
|
|
11
|
+
{:catch error}
|
|
12
|
+
<p>Error: {error}</p>
|
|
13
|
+
{/await}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
I am the home page!
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import "./app.css";
|
|
3
|
+
|
|
4
|
+
import { Router, getRoutes, route } from "@coloco/router";
|
|
5
|
+
import { setDefaultClient } from "@coloco/api-client-svelte";
|
|
6
|
+
|
|
7
|
+
import FavIcon from "@/assets/favicon.png";
|
|
8
|
+
|
|
9
|
+
import Index from "@app/index.svelte";
|
|
10
|
+
import NotFound from "@app/404.svelte";
|
|
11
|
+
|
|
12
|
+
import { client } from "./lib/client";
|
|
13
|
+
|
|
14
|
+
setDefaultClient(client);
|
|
15
|
+
|
|
16
|
+
const routes = getRoutes({
|
|
17
|
+
index: Index,
|
|
18
|
+
notFound: NotFound,
|
|
19
|
+
});
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<svelte:head>
|
|
23
|
+
<link rel="icon" type="image/x-icon" href={FavIcon} />
|
|
24
|
+
</svelte:head>
|
|
25
|
+
|
|
26
|
+
<main>
|
|
27
|
+
Main Page
|
|
28
|
+
|
|
29
|
+
<br /><br />
|
|
30
|
+
|
|
31
|
+
<a use:route href="/">Home</a><br />
|
|
32
|
+
<a use:route href="/example">Example</a><br />
|
|
33
|
+
<a use:route href="/missing">Missing</a>
|
|
34
|
+
|
|
35
|
+
<br /><br />
|
|
36
|
+
|
|
37
|
+
<Router basePath="/" {routes} />
|
|
38
|
+
</main>
|
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { makeClient } from "@coloco/api-client-svelte";
|
|
2
|
+
|
|
3
|
+
export const client = makeClient({
|
|
4
|
+
baseUrl: import.meta.env.VITE_API_HOST,
|
|
5
|
+
throwOnError: true,
|
|
6
|
+
fetch: (request) => {
|
|
7
|
+
return fetch(request, {
|
|
8
|
+
credentials: "include",
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
errorHandler: (error) => {
|
|
12
|
+
console.error(error.stack);
|
|
13
|
+
alert(error.message);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Coloco auto-generated APIs
|
|
4
|
+
"rootDirs": ["./src", "./src/app/.generated/client/api"],
|
|
5
|
+
"verbatimModuleSyntax": true,
|
|
6
|
+
"isolatedModules": true,
|
|
7
|
+
"lib": ["esnext", "DOM", "DOM.Iterable"],
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"module": "esnext",
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"target": "esnext",
|
|
12
|
+
// Project
|
|
13
|
+
"allowJs": true,
|
|
14
|
+
"checkJs": true,
|
|
15
|
+
"esModuleInterop": true,
|
|
16
|
+
"forceConsistentCasingInFileNames": true,
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"skipLibCheck": true,
|
|
19
|
+
"sourceMap": true,
|
|
20
|
+
"strict": true,
|
|
21
|
+
// Coloco Paths
|
|
22
|
+
"paths": {
|
|
23
|
+
"@api/*": ["./src/app/.generated/client/api/app/*"],
|
|
24
|
+
"@app/*": ["./src/app/*"],
|
|
25
|
+
"@client/*": ["./src/app/.generated/client/*"],
|
|
26
|
+
"@/*": ["./src/*", "./src/app/.generated/client/api/*"]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"include": [
|
|
30
|
+
"./src/**/*.ts",
|
|
31
|
+
"./src/**/*.js",
|
|
32
|
+
"./src/**/*.svelte",
|
|
33
|
+
"./vite.config.ts",
|
|
34
|
+
"./vite-env.d.ts"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import path, { dirname, resolve, relative } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { defineConfig } from "vite";
|
|
4
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
5
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
6
|
+
import { coloco, colocoAliases } from "@coloco/vite";
|
|
7
|
+
|
|
8
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const root = resolve(__dirname, "./src");
|
|
10
|
+
|
|
11
|
+
// https://vite.dev/config/
|
|
12
|
+
export default defineConfig({
|
|
13
|
+
plugins: [tailwindcss(), svelte(), coloco()],
|
|
14
|
+
root: root,
|
|
15
|
+
server: {
|
|
16
|
+
host: "0.0.0.0",
|
|
17
|
+
port: 5173,
|
|
18
|
+
},
|
|
19
|
+
build: {
|
|
20
|
+
outDir: "../dist/app",
|
|
21
|
+
emptyOutDir: true,
|
|
22
|
+
},
|
|
23
|
+
clearScreen: false,
|
|
24
|
+
resolve: {
|
|
25
|
+
alias: [
|
|
26
|
+
...colocoAliases(),
|
|
27
|
+
{ find: "$lib", replacement: path.resolve("./src/lib") },
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
from fastapi import FastAPI
|
|
2
|
-
from fastapi.routing import APIRoute
|
|
3
|
-
import json
|
|
4
|
-
from subprocess import run
|
|
5
|
-
|
|
6
|
-
import os
|
|
7
|
-
import shutil
|
|
8
|
-
import filecmp
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def compare_and_copy(source_dir, target_dir):
|
|
12
|
-
"""
|
|
13
|
-
Compares files in two directories and copies files from source to target if they differ, creating target directories if needed.
|
|
14
|
-
|
|
15
|
-
Args:
|
|
16
|
-
source_dir (str): Path to the source directory.
|
|
17
|
-
target_dir (str): Path to the target directory.
|
|
18
|
-
"""
|
|
19
|
-
for root, _, files in os.walk(source_dir):
|
|
20
|
-
rel_path = os.path.relpath(root, source_dir) # Get relative path from source
|
|
21
|
-
target_path = os.path.join(target_dir, rel_path)
|
|
22
|
-
os.makedirs(
|
|
23
|
-
target_path, exist_ok=True
|
|
24
|
-
) # Create target directory if it doesn't exist
|
|
25
|
-
|
|
26
|
-
for file in files:
|
|
27
|
-
source_file = os.path.join(root, file)
|
|
28
|
-
target_file = os.path.join(target_path, file)
|
|
29
|
-
|
|
30
|
-
if not os.path.exists(target_file) or not filecmp.cmp(
|
|
31
|
-
source_file, target_file
|
|
32
|
-
):
|
|
33
|
-
shutil.copy2(source_file, target_file)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def custom_generate_unique_id(route: APIRoute) -> str:
|
|
37
|
-
return f"{route.name}"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def generate_openapi_schema(app: FastAPI, path="/tmp/openapi.json"):
|
|
41
|
-
with open(path, "w") as f:
|
|
42
|
-
json.dump(app.openapi(), f)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def generate_openapi_code(
|
|
46
|
-
host,
|
|
47
|
-
spec_path="/tmp/openapi.json",
|
|
48
|
-
output_dir="./src/app/.generated/client",
|
|
49
|
-
diff_files=False,
|
|
50
|
-
):
|
|
51
|
-
temp_dir = "/tmp/backend_api"
|
|
52
|
-
output_path = os.path.join(os.getcwd(), output_dir)
|
|
53
|
-
|
|
54
|
-
run(
|
|
55
|
-
f"npx openapi-ts "
|
|
56
|
-
f"--base {host} "
|
|
57
|
-
f"--input {spec_path} "
|
|
58
|
-
f"--output {temp_dir if diff_files else output_path} ".split(),
|
|
59
|
-
cwd=os.getcwd(),
|
|
60
|
-
)
|
|
61
|
-
if diff_files:
|
|
62
|
-
compare_and_copy(temp_dir, output_dir)
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import tomllib
|
|
2
|
-
import os
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def get_coloco_config():
|
|
6
|
-
# Read project toml
|
|
7
|
-
if not os.path.exists("pyproject.toml"):
|
|
8
|
-
raise LookupError("pyproject.toml not found")
|
|
9
|
-
with open("pyproject.toml", "rb") as f:
|
|
10
|
-
config = tomllib.load(f)
|
|
11
|
-
|
|
12
|
-
# Get coloco config
|
|
13
|
-
coloco_config = config.get("tool", {}).get("coloco")
|
|
14
|
-
if not coloco_config:
|
|
15
|
-
raise LookupError(
|
|
16
|
-
"coloco config not found in pyproject.toml under [tool.coloco]"
|
|
17
|
-
)
|
|
18
|
-
return coloco_config
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { makeClient, setDefaultClient } from "@coloco/api-client-svelte";
|
|
3
|
-
import { route, Router, getRoutes } from "@coloco/router";
|
|
4
|
-
|
|
5
|
-
import Index from "./index.svelte";
|
|
6
|
-
import NotFound from "./404.svelte";
|
|
7
|
-
|
|
8
|
-
const client = makeClient({ baseUrl: import.meta.env.API_HOST });
|
|
9
|
-
const routes = getRoutes({
|
|
10
|
-
index: Index,
|
|
11
|
-
notFound: NotFound,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
setDefaultClient(client);
|
|
15
|
-
</script>
|
|
16
|
-
|
|
17
|
-
<main>
|
|
18
|
-
Main Page
|
|
19
|
-
|
|
20
|
-
<br /><br />
|
|
21
|
-
|
|
22
|
-
<a use:route href="/">Home</a><br />
|
|
23
|
-
<a use:route href="/example">Example</a><br />
|
|
24
|
-
<a use:route href="/missing">Missing</a>
|
|
25
|
-
|
|
26
|
-
<br /><br />
|
|
27
|
-
|
|
28
|
-
<Router basePath="/" {routes} />
|
|
29
|
-
</main>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
I am the home page!
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { defaultPlugins } from '@hey-api/openapi-ts';
|
|
2
|
-
import { codegenConfig } from '@coloco/api-client-svelte';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
plugins: [
|
|
6
|
-
...defaultPlugins,
|
|
7
|
-
'@hey-api/client-fetch',
|
|
8
|
-
codegenConfig({ name: 'coloco-codegen', outputPath: './api' }),
|
|
9
|
-
],
|
|
10
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"rootDirs": [
|
|
4
|
-
"..",
|
|
5
|
-
"../+app/.generated/client/api"
|
|
6
|
-
],
|
|
7
|
-
"verbatimModuleSyntax": true,
|
|
8
|
-
"isolatedModules": true,
|
|
9
|
-
"lib": [
|
|
10
|
-
"esnext",
|
|
11
|
-
"DOM",
|
|
12
|
-
"DOM.Iterable"
|
|
13
|
-
],
|
|
14
|
-
"moduleResolution": "bundler",
|
|
15
|
-
"module": "esnext",
|
|
16
|
-
"noEmit": true,
|
|
17
|
-
"target": "esnext",
|
|
18
|
-
// Project
|
|
19
|
-
"allowJs": true,
|
|
20
|
-
"checkJs": true,
|
|
21
|
-
"esModuleInterop": true,
|
|
22
|
-
"forceConsistentCasingInFileNames": true,
|
|
23
|
-
"resolveJsonModule": true,
|
|
24
|
-
"skipLibCheck": true,
|
|
25
|
-
"sourceMap": true,
|
|
26
|
-
"strict": true,
|
|
27
|
-
"paths": {
|
|
28
|
-
"@api/*": [
|
|
29
|
-
"../+app/.generated/client/api/*"
|
|
30
|
-
]
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
"include": [
|
|
34
|
-
"../**/*.ts",
|
|
35
|
-
"../**/*.js",
|
|
36
|
-
"../**/*.svelte",
|
|
37
|
-
"./vite.config.ts"
|
|
38
|
-
],
|
|
39
|
-
"exclude": [
|
|
40
|
-
"../node_modules/**",
|
|
41
|
-
"../dist/**"
|
|
42
|
-
]
|
|
43
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import path, { dirname, resolve, relative } from 'node:path'
|
|
2
|
-
import { fileURLToPath } from 'node:url'
|
|
3
|
-
import { defineConfig } from 'vite'
|
|
4
|
-
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
|
5
|
-
|
|
6
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
const root = resolve(__dirname, '../');
|
|
8
|
-
|
|
9
|
-
// https://vite.dev/config/
|
|
10
|
-
export default defineConfig({
|
|
11
|
-
plugins: [svelte()],
|
|
12
|
-
root: resolve(root, '+app'),
|
|
13
|
-
server: {
|
|
14
|
-
host: "0.0.0.0",
|
|
15
|
-
port: 5173,
|
|
16
|
-
},
|
|
17
|
-
build: {
|
|
18
|
-
outDir: '../dist/app',
|
|
19
|
-
emptyOutDir: true, // also necessary
|
|
20
|
-
},
|
|
21
|
-
clearScreen: false,
|
|
22
|
-
resolve: {
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
alias: [{
|
|
25
|
-
find: './api',
|
|
26
|
-
customResolver: (_, filePath: string) => {
|
|
27
|
-
const subFolder = path.relative(root, dirname(filePath));
|
|
28
|
-
const apiFile = resolve(root, `+app/.generated/client/api/${subFolder}/api.ts`);
|
|
29
|
-
return apiFile;
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
{
|
|
34
|
-
find: '@api',
|
|
35
|
-
replacement: '/.generated/client/api'
|
|
36
|
-
},
|
|
37
|
-
// @ts-ignore
|
|
38
|
-
{
|
|
39
|
-
find: '@app/',
|
|
40
|
-
replacement: '/'
|
|
41
|
-
},
|
|
42
|
-
// @ts-ignore
|
|
43
|
-
{
|
|
44
|
-
find: '@root',
|
|
45
|
-
replacement: '/..'
|
|
46
|
-
}]
|
|
47
|
-
}
|
|
48
|
-
})
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
[project]
|
|
2
|
-
name = "{{ project_name }}"
|
|
3
|
-
version = "0.1.0"
|
|
4
|
-
description = "Your project description here"
|
|
5
|
-
readme = "README.md"
|
|
6
|
-
requires-python = ">=3.11"
|
|
7
|
-
dependencies = [
|
|
8
|
-
"coloco>=0.2.0",
|
|
9
|
-
]
|
|
10
|
-
|
|
11
|
-
[tool.coloco]
|
|
12
|
-
app = "main.app"
|
|
13
|
-
migrations_dir = "./+migrations"
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|