jac-client 0.2.8__py3-none-any.whl → 0.2.10__py3-none-any.whl
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.
- jac_client/examples/all-in-one/{app.jac → main.jac} +5 -5
- jac_client/examples/all-in-one/pages/BudgetPlanner.jac +8 -1
- jac_client/examples/all-in-one/pages/FeaturesTest.jac +16 -1
- jac_client/examples/all-in-one/pages/{FeaturesTest.cl.jac → features_test_ui.cl.jac} +11 -0
- jac_client/examples/all-in-one/pages/nestedDemo.jac +1 -1
- jac_client/examples/all-in-one/pages/notFound.jac +2 -7
- jac_client/plugin/cli.jac +491 -411
- jac_client/plugin/client.jac +25 -0
- jac_client/plugin/client_runtime.cl.jac +5 -1
- jac_client/plugin/impl/client.impl.jac +96 -55
- jac_client/plugin/impl/client_runtime.impl.jac +154 -0
- jac_client/plugin/plugin_config.jac +243 -15
- jac_client/plugin/src/config_loader.jac +1 -0
- jac_client/plugin/src/desktop_config.jac +31 -0
- jac_client/plugin/src/impl/compiler.impl.jac +1 -1
- jac_client/plugin/src/impl/config_loader.impl.jac +8 -0
- jac_client/plugin/src/impl/desktop_config.impl.jac +191 -0
- jac_client/plugin/src/impl/vite_bundler.impl.jac +97 -16
- jac_client/plugin/src/targets/desktop/sidecar/main.py +144 -0
- jac_client/plugin/src/targets/desktop_target.jac +37 -0
- jac_client/plugin/src/targets/impl/desktop_target.impl.jac +2334 -0
- jac_client/plugin/src/targets/impl/registry.impl.jac +64 -0
- jac_client/plugin/src/targets/impl/web_target.impl.jac +157 -0
- jac_client/plugin/src/targets/register.jac +21 -0
- jac_client/plugin/src/targets/registry.jac +87 -0
- jac_client/plugin/src/targets/web_target.jac +35 -0
- jac_client/plugin/src/vite_bundler.jac +6 -0
- jac_client/plugin/utils/__init__.jac +1 -0
- jac_client/plugin/utils/impl/node_installer.impl.jac +249 -0
- jac_client/plugin/utils/node_installer.jac +41 -0
- jac_client/templates/client.jacpack +72 -0
- jac_client/templates/fullstack.jacpack +61 -0
- jac_client/tests/conftest.py +48 -7
- jac_client/tests/test_cli.py +184 -70
- jac_client/tests/test_e2e.py +232 -0
- jac_client/tests/test_helpers.py +65 -0
- jac_client/tests/test_it.py +91 -135
- jac_client/tests/test_it_desktop.py +891 -0
- {jac_client-0.2.8.dist-info → jac_client-0.2.10.dist-info}/METADATA +4 -4
- jac_client-0.2.10.dist-info/RECORD +115 -0
- {jac_client-0.2.8.dist-info → jac_client-0.2.10.dist-info}/WHEEL +1 -1
- jac_client-0.2.8.dist-info/RECORD +0 -97
- /jac_client/examples/all-in-one/pages/{BudgetPlanner.cl.jac → budget_planner_ui.cl.jac} +0 -0
- /jac_client/examples/asset-serving/css-with-image/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/asset-serving/image-asset/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/asset-serving/import-alias/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/basic/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/basic-auth/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/basic-auth-with-router/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/basic-full-stack/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/css-styling/js-styling/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/css-styling/material-ui/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/css-styling/pure-css/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/css-styling/sass-example/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/css-styling/styled-components/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/css-styling/tailwind-example/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/full-stack-with-auth/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/little-x/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/nested-folders/nested-advance/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/nested-folders/nested-basic/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/ts-support/{src/app.jac → main.jac} +0 -0
- /jac_client/examples/with-router/{src/app.jac → main.jac} +0 -0
- {jac_client-0.2.8.dist-info → jac_client-0.2.10.dist-info}/entry_points.txt +0 -0
- {jac_client-0.2.8.dist-info → jac_client-0.2.10.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Implementation of target registry."""
|
|
2
|
+
|
|
3
|
+
"""Register a new build target."""
|
|
4
|
+
impl TargetRegistry.register(target: ClientTarget) -> None {
|
|
5
|
+
self._targets[target.name] = target;
|
|
6
|
+
if target.default {
|
|
7
|
+
self._default_target = target.name;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
"""Get a target by name."""
|
|
12
|
+
impl TargetRegistry.get(name: str) -> Optional[ClientTarget] {
|
|
13
|
+
return self._targets.get(name);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
"""Get the default target."""
|
|
17
|
+
impl TargetRegistry.get_default -> Optional[ClientTarget] {
|
|
18
|
+
if self._default_target {
|
|
19
|
+
return self._targets.get(self._default_target);
|
|
20
|
+
}
|
|
21
|
+
# Find first target marked as default
|
|
22
|
+
for target in self._targets.values() {
|
|
23
|
+
if target.default {
|
|
24
|
+
return target;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return None;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
"""Get all registered targets."""
|
|
31
|
+
impl TargetRegistry.get_all -> list[ClientTarget] {
|
|
32
|
+
return list(self._targets.values());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
"""Check if a target is registered."""
|
|
36
|
+
impl TargetRegistry.has(name: str) -> bool {
|
|
37
|
+
return name in self._targets;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
"""Set the default target."""
|
|
41
|
+
impl TargetRegistry.set_default(name: str) -> None {
|
|
42
|
+
if name not in self._targets {
|
|
43
|
+
raise ValueError(f"ClientTarget '{name}' is not registered") ;
|
|
44
|
+
}
|
|
45
|
+
# Unset previous default
|
|
46
|
+
if self._default_target {
|
|
47
|
+
prev_target = self._targets.get(self._default_target);
|
|
48
|
+
if prev_target {
|
|
49
|
+
prev_target.default = False;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
# Set new default
|
|
53
|
+
self._default_target = name;
|
|
54
|
+
target = self._targets.get(name);
|
|
55
|
+
if target {
|
|
56
|
+
target.default = True;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
"""Clear all registered targets (for testing)."""
|
|
61
|
+
impl TargetRegistry.clear -> None {
|
|
62
|
+
self._targets.clear();
|
|
63
|
+
self._default_target = None;
|
|
64
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""Implementation of WebTarget methods."""
|
|
2
|
+
import types;
|
|
3
|
+
import from pathlib { Path }
|
|
4
|
+
import from typing { Optional }
|
|
5
|
+
import from jac_client.plugin.src.vite_bundler { ViteBundler }
|
|
6
|
+
|
|
7
|
+
"""Build web bundle using existing Vite pipeline."""
|
|
8
|
+
impl WebTarget.build(
|
|
9
|
+
self: WebTarget,
|
|
10
|
+
entry_file: Path,
|
|
11
|
+
project_dir: Path,
|
|
12
|
+
platform: Optional[str] = None
|
|
13
|
+
) -> Path {
|
|
14
|
+
import os;
|
|
15
|
+
import shutil;
|
|
16
|
+
import from jaclang.pycore.runtime { JacRuntime as Jac }
|
|
17
|
+
import from jac_client.plugin.client { JacClient }
|
|
18
|
+
bundler = ViteBundler(project_dir=project_dir);
|
|
19
|
+
# Clean dist directory for fresh build
|
|
20
|
+
dist_dir = bundler.output_dir;
|
|
21
|
+
if dist_dir.exists() {
|
|
22
|
+
shutil.rmtree(dist_dir);
|
|
23
|
+
}
|
|
24
|
+
dist_dir.mkdir(parents=True, exist_ok=True);
|
|
25
|
+
# Load the module (same as jac start does via _proc_file + jac_import)
|
|
26
|
+
(base, mod) = os.path.split(str(entry_file));
|
|
27
|
+
base = base or "./";
|
|
28
|
+
if entry_file.name.endswith('.jac') {
|
|
29
|
+
mod = mod[:-4];
|
|
30
|
+
}
|
|
31
|
+
# Import the module (Jac.jac_import handles context creation internally)
|
|
32
|
+
Jac.jac_import(target=mod, base_path=base, lng='jac');
|
|
33
|
+
if Jac.program.errors_had {
|
|
34
|
+
errors = '\n'.join(Jac.program.errors_had);
|
|
35
|
+
raise RuntimeError(f"Failed to compile {entry_file}:\n{errors}") ;
|
|
36
|
+
}
|
|
37
|
+
# Get the loaded module
|
|
38
|
+
loaded_mod = Jac.loaded_modules.get(mod);
|
|
39
|
+
if not loaded_mod {
|
|
40
|
+
raise RuntimeError(f"Module '{mod}' not found after import") ;
|
|
41
|
+
}
|
|
42
|
+
# Type assertion: loaded_mod is guaranteed to be not None here
|
|
43
|
+
if not isinstance(loaded_mod, types.ModuleType) {
|
|
44
|
+
raise RuntimeError(f"Module '{mod}' is not a valid module type") ;
|
|
45
|
+
}
|
|
46
|
+
# Build bundle using ViteClientBundleBuilder (same as jac start's introspector.ensure_bundle)
|
|
47
|
+
builder = JacClient.get_client_bundle_builder();
|
|
48
|
+
bundle = builder.build(loaded_mod, force=True);
|
|
49
|
+
# Find the bundle file
|
|
50
|
+
bundle_path = bundler.find_bundle();
|
|
51
|
+
if not bundle_path {
|
|
52
|
+
raise RuntimeError("Web build failed: bundle not found") ;
|
|
53
|
+
}
|
|
54
|
+
# Always generate static index.html for static serving
|
|
55
|
+
_generate_index_html(
|
|
56
|
+
bundle_path=bundle_path,
|
|
57
|
+
bundler=bundler,
|
|
58
|
+
loaded_mod=loaded_mod,
|
|
59
|
+
project_dir=project_dir
|
|
60
|
+
);
|
|
61
|
+
return bundle_path;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
"""Generate static index.html file for the built bundle."""
|
|
65
|
+
def _generate_index_html(
|
|
66
|
+
bundle_path: Path,
|
|
67
|
+
bundler: ViteBundler,
|
|
68
|
+
loaded_mod: types.ModuleType,
|
|
69
|
+
project_dir: Path
|
|
70
|
+
) -> None {
|
|
71
|
+
import html;
|
|
72
|
+
import hashlib;
|
|
73
|
+
import from jaclang.project.config { get_config }
|
|
74
|
+
import from jac_client.plugin.client { HeaderBuilder }
|
|
75
|
+
import from jaclang.pycore.runtime { JacRuntime as Jac }
|
|
76
|
+
|
|
77
|
+
# Get the first client export function (or default to 'app')
|
|
78
|
+
mod_path = getattr(loaded_mod, '__file__', None);
|
|
79
|
+
if mod_path {
|
|
80
|
+
mod = Jac.program.mod.hub.get(mod_path);
|
|
81
|
+
if mod and mod.gen.client_manifest {
|
|
82
|
+
client_exports = mod.gen.client_manifest.exports;
|
|
83
|
+
# client_exports is a list[str], not a dict
|
|
84
|
+
if client_exports and len(client_exports) > 0 {
|
|
85
|
+
function_name = client_exports[0];
|
|
86
|
+
} else {
|
|
87
|
+
function_name = 'app';
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
function_name = 'app';
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
function_name = 'app';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
# Get module name
|
|
97
|
+
module_name = loaded_mod.__name__;
|
|
98
|
+
|
|
99
|
+
# Get dist directory (output_dir is already a Path)
|
|
100
|
+
dist_dir = Path(bundler.output_dir);
|
|
101
|
+
|
|
102
|
+
# Check for CSS file
|
|
103
|
+
css_link = '';
|
|
104
|
+
css_file = bundler.find_css();
|
|
105
|
+
if css_file {
|
|
106
|
+
css_hash = hashlib.sha256(css_file.read_bytes()).hexdigest()[:8];
|
|
107
|
+
css_filename = css_file.name;
|
|
108
|
+
css_link = f'<link rel="stylesheet" href="{css_filename}?hash={css_hash}"/>';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
# Get meta data from config
|
|
112
|
+
config = get_config();
|
|
113
|
+
meta_data = {};
|
|
114
|
+
if config {
|
|
115
|
+
client_cfg = config.get_plugin_config("client");
|
|
116
|
+
if client_cfg {
|
|
117
|
+
meta_data = client_cfg.get("app_meta_data", {});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
# Build HTML head using HeaderBuilder (same as render_page)
|
|
122
|
+
head_builder = HeaderBuilder(meta_data, function_name);
|
|
123
|
+
head_content = head_builder.build_head();
|
|
124
|
+
if css_link {
|
|
125
|
+
head_content += f"\n {css_link}";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
# Get bundle filename (relative to dist_dir)
|
|
129
|
+
bundle_filename = bundle_path.name;
|
|
130
|
+
|
|
131
|
+
# Generate HTML with __jac_init__ script tag for client runtime
|
|
132
|
+
init_payload = {
|
|
133
|
+
"module": module_name,
|
|
134
|
+
"function": function_name,
|
|
135
|
+
"args": {},
|
|
136
|
+
"argOrder": [],
|
|
137
|
+
"globals": {}
|
|
138
|
+
};
|
|
139
|
+
import json;
|
|
140
|
+
init_json = json.dumps(init_payload);
|
|
141
|
+
|
|
142
|
+
html_content = f'''<!DOCTYPE html>
|
|
143
|
+
<html lang="en">
|
|
144
|
+
<head>
|
|
145
|
+
{head_content}
|
|
146
|
+
</head>
|
|
147
|
+
<body>
|
|
148
|
+
<div id="root"></div>
|
|
149
|
+
<script id="__jac_init__" type="application/json">{html.escape(init_json)}</script>
|
|
150
|
+
<script src="{bundle_filename}" defer></script>
|
|
151
|
+
</body>
|
|
152
|
+
</html>''';
|
|
153
|
+
|
|
154
|
+
# Write index.html to dist directory
|
|
155
|
+
index_html = dist_dir / 'index.html';
|
|
156
|
+
index_html.write_text(html_content, encoding='utf-8');
|
|
157
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Register all build targets.
|
|
2
|
+
|
|
3
|
+
This module registers all available build targets when the plugin loads.
|
|
4
|
+
"""
|
|
5
|
+
import from jac_client.plugin.src.targets.registry { get_target_registry }
|
|
6
|
+
import from jac_client.plugin.src.targets.web_target { WebTarget }
|
|
7
|
+
import from jac_client.plugin.src.targets.desktop_target { DesktopTarget }
|
|
8
|
+
# Note: Jac's annex pass should auto-discover .impl.jac files automatically
|
|
9
|
+
# The impl files in impl/ directory should be loaded when the base classes are imported
|
|
10
|
+
"""Register all available targets."""
|
|
11
|
+
def register_targets -> None {
|
|
12
|
+
registry = get_target_registry();
|
|
13
|
+
|
|
14
|
+
# Register web target (default)
|
|
15
|
+
web_target = WebTarget();
|
|
16
|
+
registry.register(web_target);
|
|
17
|
+
|
|
18
|
+
# Register desktop target (placeholder for Phase 2)
|
|
19
|
+
desktop_target = DesktopTarget();
|
|
20
|
+
registry.register(desktop_target);
|
|
21
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Target registry for build targets (web, desktop, mobile, etc.).
|
|
2
|
+
|
|
3
|
+
This module provides a registry system for managing different build targets.
|
|
4
|
+
Each target is a class that inherits from the base ClientTarget class.
|
|
5
|
+
"""
|
|
6
|
+
import from typing { Optional }
|
|
7
|
+
import from pathlib { Path }
|
|
8
|
+
|
|
9
|
+
"""Base class for all build targets.
|
|
10
|
+
|
|
11
|
+
All targets must inherit from this class and implement the required methods.
|
|
12
|
+
"""
|
|
13
|
+
class ClientTarget {
|
|
14
|
+
has name: str,
|
|
15
|
+
default: bool = False,
|
|
16
|
+
requires_setup: bool = False,
|
|
17
|
+
config_section: str = "",
|
|
18
|
+
required_dependencies: list[str] = [],
|
|
19
|
+
output_dir: Optional[Path] = None;
|
|
20
|
+
|
|
21
|
+
"""Setup the target (one-time initialization)."""
|
|
22
|
+
def setup(self: ClientTarget, project_dir: Path) -> None abs;
|
|
23
|
+
|
|
24
|
+
"""Build the target."""
|
|
25
|
+
def build(
|
|
26
|
+
self: ClientTarget,
|
|
27
|
+
entry_file: Path,
|
|
28
|
+
project_dir: Path,
|
|
29
|
+
platform: Optional[str] = None
|
|
30
|
+
) -> Path abs;
|
|
31
|
+
|
|
32
|
+
"""Start dev server for the target."""
|
|
33
|
+
def dev(self: ClientTarget, entry_file: Path, project_dir: Path) -> None abs;
|
|
34
|
+
|
|
35
|
+
"""Start the target (production mode - build and run)."""
|
|
36
|
+
def start(self: ClientTarget, entry_file: Path, project_dir: Path) -> None abs;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
"""Central registry for build targets.
|
|
40
|
+
|
|
41
|
+
This is a singleton that collects all build targets registered by plugins.
|
|
42
|
+
The CLI uses this registry to delegate build operations to the appropriate target.
|
|
43
|
+
"""
|
|
44
|
+
obj TargetRegistry {
|
|
45
|
+
has _targets: dict[str, ClientTarget] = {},
|
|
46
|
+
_default_target: Optional[str] = None;
|
|
47
|
+
|
|
48
|
+
"""Register a new build target."""
|
|
49
|
+
def register(target: ClientTarget) -> None;
|
|
50
|
+
|
|
51
|
+
"""Get a target by name."""
|
|
52
|
+
def get(name: str) -> Optional[ClientTarget];
|
|
53
|
+
|
|
54
|
+
"""Get the default target."""
|
|
55
|
+
def get_default -> Optional[ClientTarget];
|
|
56
|
+
|
|
57
|
+
"""Get all registered targets."""
|
|
58
|
+
def get_all -> list[ClientTarget];
|
|
59
|
+
|
|
60
|
+
"""Check if a target is registered."""
|
|
61
|
+
def has(name: str) -> bool;
|
|
62
|
+
|
|
63
|
+
"""Set the default target."""
|
|
64
|
+
def set_default(name: str) -> None;
|
|
65
|
+
|
|
66
|
+
"""Clear all registered targets (for testing)."""
|
|
67
|
+
def clear -> None;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
# Global singleton instance
|
|
71
|
+
glob _registry: TargetRegistry | None = None;
|
|
72
|
+
|
|
73
|
+
"""Get or create the global target registry."""
|
|
74
|
+
def get_target_registry -> TargetRegistry {
|
|
75
|
+
import from jac_client.plugin.src.targets.registry { TargetRegistry }
|
|
76
|
+
global _registry;
|
|
77
|
+
if _registry is None {
|
|
78
|
+
_registry = TargetRegistry();
|
|
79
|
+
}
|
|
80
|
+
return _registry;
|
|
81
|
+
}
|
|
82
|
+
# Target name: "web", "desktop", "android", "ios"
|
|
83
|
+
# Is this the default target?
|
|
84
|
+
# Does this target need setup?
|
|
85
|
+
# Section in jac.toml (e.g., "desktop")
|
|
86
|
+
# Required npm/system dependencies
|
|
87
|
+
# Where build outputs go
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Web target implementation.
|
|
2
|
+
|
|
3
|
+
This is the default target for building web applications.
|
|
4
|
+
"""
|
|
5
|
+
import from pathlib { Path }
|
|
6
|
+
import from typing { Optional }
|
|
7
|
+
import from jac_client.plugin.src.targets.registry { ClientTarget }
|
|
8
|
+
|
|
9
|
+
"""Web build target."""
|
|
10
|
+
class WebTarget(ClientTarget) {
|
|
11
|
+
def init(self: WebTarget) {
|
|
12
|
+
self.name = "web";
|
|
13
|
+
self.default = True;
|
|
14
|
+
self.requires_setup = False;
|
|
15
|
+
self.config_section = "plugin.client";
|
|
16
|
+
self.output_dir = Path(".jac/client/dist");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
"""Setup web target (no-op for web, already set up by default)."""
|
|
20
|
+
override def setup(self: WebTarget, project_dir: Path) -> None;
|
|
21
|
+
|
|
22
|
+
"""Build web bundle using existing Vite pipeline."""
|
|
23
|
+
override def build(
|
|
24
|
+
self: WebTarget,
|
|
25
|
+
entry_file: Path,
|
|
26
|
+
project_dir: Path,
|
|
27
|
+
platform: Optional[str] = None
|
|
28
|
+
) -> Path;
|
|
29
|
+
|
|
30
|
+
"""Start web dev server."""
|
|
31
|
+
override def dev(self: WebTarget, entry_file: Path, project_dir: Path) -> None;
|
|
32
|
+
|
|
33
|
+
"""Start web target (no-op for web, handled by jac start)."""
|
|
34
|
+
override def start(self: WebTarget, entry_file: Path, project_dir: Path) -> None;
|
|
35
|
+
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"""Vite bundling module."""
|
|
2
2
|
import hashlib;
|
|
3
3
|
import json;
|
|
4
|
+
import logging;
|
|
4
5
|
import shutil;
|
|
5
6
|
import subprocess;
|
|
6
7
|
import from pathlib { Path }
|
|
7
8
|
import from typing { Any, Optional }
|
|
8
9
|
import from jaclang.runtimelib.client_bundle { ClientBundleError }
|
|
9
10
|
import from .config_loader { JacClientConfig }
|
|
11
|
+
|
|
12
|
+
glob logger = logging.getLogger(__name__);
|
|
10
13
|
"""Handles Vite bundling operations."""
|
|
11
14
|
class ViteBundler {
|
|
12
15
|
def init(
|
|
@@ -34,6 +37,9 @@ class ViteBundler {
|
|
|
34
37
|
) -> Path;
|
|
35
38
|
|
|
36
39
|
def create_tsconfig(self: ViteBundler) -> Path;
|
|
40
|
+
"""Create config files from jac.toml [plugins.client.configs]."""
|
|
41
|
+
def create_config_files(self: ViteBundler) -> list[Path];
|
|
42
|
+
|
|
37
43
|
"""Create a dev-mode vite config with API proxy for HMR."""
|
|
38
44
|
def create_dev_vite_config(
|
|
39
45
|
self: ViteBundler, entry_file: Path, api_port: int = 8000
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Utility modules for jac-client plugin."""
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"""Implementation of Node.js installer methods."""
|
|
2
|
+
|
|
3
|
+
"""Check if Node.js is installed and accessible."""
|
|
4
|
+
impl NodeInstaller.is_node_installed -> bool {
|
|
5
|
+
try {
|
|
6
|
+
result = subprocess.run(
|
|
7
|
+
['node', '--version'], capture_output=True, text=True, timeout=5
|
|
8
|
+
);
|
|
9
|
+
return result.returncode == 0;
|
|
10
|
+
} except (FileNotFoundError, subprocess.TimeoutExpired) {
|
|
11
|
+
return False;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
"""Check if npm is installed and accessible."""
|
|
16
|
+
impl NodeInstaller.is_npm_installed -> bool {
|
|
17
|
+
try {
|
|
18
|
+
result = subprocess.run(
|
|
19
|
+
['npm', '--version'], capture_output=True, text=True, timeout=5
|
|
20
|
+
);
|
|
21
|
+
return result.returncode == 0;
|
|
22
|
+
} except (FileNotFoundError, subprocess.TimeoutExpired) {
|
|
23
|
+
return False;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
"""Check if NVM is installed."""
|
|
28
|
+
impl NodeInstaller.is_nvm_installed -> bool {
|
|
29
|
+
nvm_dir = Path.home() / '.nvm';
|
|
30
|
+
return nvm_dir.exists() and (nvm_dir / 'nvm.sh').exists();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
"""Get the currently installed Node.js version."""
|
|
34
|
+
impl NodeInstaller.get_node_version -> (str | None) {
|
|
35
|
+
try {
|
|
36
|
+
result = subprocess.run(
|
|
37
|
+
['node', '--version'], capture_output=True, text=True, timeout=5
|
|
38
|
+
);
|
|
39
|
+
if result.returncode == 0 {
|
|
40
|
+
return result.stdout.strip();
|
|
41
|
+
}
|
|
42
|
+
} except (FileNotFoundError, subprocess.TimeoutExpired) { }
|
|
43
|
+
return None;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
"""Install NVM (Node Version Manager)."""
|
|
47
|
+
impl NodeInstaller.install_nvm -> tuple[bool, str] {
|
|
48
|
+
system = platform.system();
|
|
49
|
+
if system == 'Windows' {
|
|
50
|
+
return (
|
|
51
|
+
False,
|
|
52
|
+
'Windows detected. Please install Node.js manually:\n' + ' 1. Download from: https://nodejs.org/\n' + ' 2. Or use nvm-windows: https://github.com/coreybutler/nvm-windows\n' + ' After installation, run "jac add --cl" again.'
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
print('Installing NVM (Node Version Manager)...');
|
|
56
|
+
try {
|
|
57
|
+
# Download and run NVM installation script
|
|
58
|
+
install_script = subprocess.run(
|
|
59
|
+
['curl', '-o-', NodeInstaller.NVM_INSTALL_URL],
|
|
60
|
+
capture_output=True,
|
|
61
|
+
text=True,
|
|
62
|
+
timeout=30
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
if install_script.returncode != 0 {
|
|
66
|
+
return (
|
|
67
|
+
False,
|
|
68
|
+
f'Failed to download NVM installer: {install_script.stderr}'
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
# Execute the installation script
|
|
73
|
+
result = subprocess.run(
|
|
74
|
+
['bash', '-c', install_script.stdout],
|
|
75
|
+
capture_output=True,
|
|
76
|
+
text=True,
|
|
77
|
+
timeout=60
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
if result.returncode != 0 {
|
|
81
|
+
return (False, f'NVM installation failed: {result.stderr}');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
print('NVM installed successfully!');
|
|
85
|
+
return (True, 'NVM installed successfully');
|
|
86
|
+
} except subprocess.TimeoutExpired {
|
|
87
|
+
return (
|
|
88
|
+
False,
|
|
89
|
+
'NVM installation timed out. Please check your internet connection.'
|
|
90
|
+
);
|
|
91
|
+
} except FileNotFoundError as e {
|
|
92
|
+
if 'curl' in str(e) {
|
|
93
|
+
return (
|
|
94
|
+
False,
|
|
95
|
+
'curl command not found. Please install curl first:\n' + ' Ubuntu/Debian: sudo apt-get install curl\n' + ' macOS: curl is pre-installed\n' + ' Fedora/RHEL: sudo dnf install curl'
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return (False, f'Required command not found: {e}');
|
|
99
|
+
} except Exception as e {
|
|
100
|
+
return (False, f'Unexpected error during NVM installation: {e}');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
"""Install Node.js using NVM."""
|
|
105
|
+
impl NodeInstaller.install_node_via_nvm(version: str = "20") -> tuple[bool, str] {
|
|
106
|
+
print(f'Installing Node.js v{version} via NVM...');
|
|
107
|
+
nvm_dir = Path.home() / '.nvm';
|
|
108
|
+
nvm_script = nvm_dir / 'nvm.sh';
|
|
109
|
+
if not nvm_script.exists() {
|
|
110
|
+
return (False, 'NVM is not installed or nvm.sh not found');
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
# Source NVM and install Node.js
|
|
114
|
+
command = (
|
|
115
|
+
'export NVM_DIR="$HOME/.nvm"\n' + '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"\n' + f'nvm install {version}\n' + f'nvm use {version}\n' + f'nvm alias default {version}\n'
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
result = subprocess.run(
|
|
119
|
+
['bash', '-c', command], capture_output=True, text=True, timeout=300
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
if result.returncode != 0 {
|
|
123
|
+
return (False, f'Node.js installation failed: {result.stderr}');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
print(f'Node.js v{version} installed successfully!');
|
|
127
|
+
return (True, f'Node.js v{version} installed successfully');
|
|
128
|
+
} except subprocess.TimeoutExpired {
|
|
129
|
+
return (False, 'Node.js installation timed out. Please try again.');
|
|
130
|
+
} except Exception as e {
|
|
131
|
+
return (False, f'Unexpected error during Node.js installation: {e}');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
"""Ensure Node.js is installed, installing automatically if needed.
|
|
136
|
+
|
|
137
|
+
Returns tuple of (success: bool, message: str, was_just_installed: bool)
|
|
138
|
+
"""
|
|
139
|
+
impl NodeInstaller.ensure_node_installed(
|
|
140
|
+
interactive: bool = True
|
|
141
|
+
) -> tuple[bool, str, bool] {
|
|
142
|
+
# Common fallback message for manual installation
|
|
143
|
+
manual_install_msg = (
|
|
144
|
+
'Please install Node.js manually:\n' + ' • Download from: https://nodejs.org/\n' + ' • Or install NVM: https://github.com/nvm-sh/nvm\n' + ' After installation, run "jac add --cl" again.'
|
|
145
|
+
);
|
|
146
|
+
# Check if Node.js is already available
|
|
147
|
+
if NodeInstaller.is_node_installed() and NodeInstaller.is_npm_installed() {
|
|
148
|
+
version = NodeInstaller.get_node_version();
|
|
149
|
+
return (True, f'Node.js {version} is already installed', False);
|
|
150
|
+
}
|
|
151
|
+
print('\nNode.js is not installed or not found in PATH.');
|
|
152
|
+
# Check for interactive mode
|
|
153
|
+
if interactive {
|
|
154
|
+
print(
|
|
155
|
+
'\nJac client requires Node.js to build and run client-side applications.'
|
|
156
|
+
);
|
|
157
|
+
print(
|
|
158
|
+
f'Would you like to automatically install Node.js v{NodeInstaller.DEFAULT_NODE_VERSION} using NVM?'
|
|
159
|
+
);
|
|
160
|
+
response = input('Install Node.js? [Y/n]: ').strip().lower();
|
|
161
|
+
if response and response not in ('y', 'yes') {
|
|
162
|
+
return (
|
|
163
|
+
False,
|
|
164
|
+
f'Node.js installation cancelled. {manual_install_msg}',
|
|
165
|
+
False
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
# Wrap entire installation process in error handling
|
|
170
|
+
try {
|
|
171
|
+
# Check if NVM is installed
|
|
172
|
+
if not NodeInstaller.is_nvm_installed() {
|
|
173
|
+
success_nvm = NodeInstaller.install_nvm();
|
|
174
|
+
if not success_nvm[0] {
|
|
175
|
+
return (
|
|
176
|
+
False,
|
|
177
|
+
f'Unable to automatically install Node.js.\n\nError: {success_nvm[
|
|
178
|
+
1
|
|
179
|
+
]}\n\n{manual_install_msg}',
|
|
180
|
+
False
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
# Install Node.js via NVM
|
|
186
|
+
success_node = NodeInstaller.install_node_via_nvm();
|
|
187
|
+
if not success_node[0] {
|
|
188
|
+
return (
|
|
189
|
+
False,
|
|
190
|
+
f'Unable to automatically install Node.js.\n\nError: {success_node[1]}\n\n{manual_install_msg}',
|
|
191
|
+
False
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
# Node.js is now available via NVM sourcing in subprocesses
|
|
196
|
+
print('\n' + '=' * 70);
|
|
197
|
+
print('Node.js has been installed successfully!');
|
|
198
|
+
print('Continuing with package installation...');
|
|
199
|
+
print('=' * 70 + '\n');
|
|
200
|
+
|
|
201
|
+
return (
|
|
202
|
+
True,
|
|
203
|
+
f'Node.js {NodeInstaller.DEFAULT_NODE_VERSION} installed successfully',
|
|
204
|
+
True
|
|
205
|
+
);
|
|
206
|
+
} except Exception as e {
|
|
207
|
+
# Catch any unexpected errors during installation
|
|
208
|
+
return (
|
|
209
|
+
False,
|
|
210
|
+
f'Unable to automatically install Node.js.\n\nUnexpected error: {str(e)}\n\n{manual_install_msg}',
|
|
211
|
+
False
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
"""Run npm command with NVM environment properly sourced.
|
|
217
|
+
|
|
218
|
+
This method automatically sources NVM in a subprocess, so npm commands work
|
|
219
|
+
immediately after NVM installation without requiring the user to reload their shell.
|
|
220
|
+
"""
|
|
221
|
+
impl NodeInstaller.run_npm_with_nvm(
|
|
222
|
+
args: list, cwd: Path, timeout: int = 300
|
|
223
|
+
) -> object {
|
|
224
|
+
# First, try running npm directly (in case it's already in PATH)
|
|
225
|
+
try {
|
|
226
|
+
return subprocess.run(
|
|
227
|
+
['npm'] + args,
|
|
228
|
+
cwd=cwd,
|
|
229
|
+
capture_output=True,
|
|
230
|
+
text=True,
|
|
231
|
+
timeout=timeout,
|
|
232
|
+
check=True
|
|
233
|
+
);
|
|
234
|
+
} except FileNotFoundError { }
|
|
235
|
+
# If npm is not in PATH, source NVM and run npm in a subprocess
|
|
236
|
+
# This allows npm to work immediately after installation without shell reload
|
|
237
|
+
args_str = ' '.join(args);
|
|
238
|
+
command = (
|
|
239
|
+
'export NVM_DIR="$HOME/.nvm"\n' + '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"\n' + f'npm {args_str}\n'
|
|
240
|
+
);
|
|
241
|
+
return subprocess.run(
|
|
242
|
+
['bash', '-c', command],
|
|
243
|
+
cwd=cwd,
|
|
244
|
+
capture_output=True,
|
|
245
|
+
text=True,
|
|
246
|
+
timeout=timeout,
|
|
247
|
+
check=True
|
|
248
|
+
);
|
|
249
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Automatic Node.js installation utility using NVM."""
|
|
2
|
+
|
|
3
|
+
import os;
|
|
4
|
+
import platform;
|
|
5
|
+
import subprocess;
|
|
6
|
+
import from pathlib { Path }
|
|
7
|
+
|
|
8
|
+
"""Handles Node.js installation and detection."""
|
|
9
|
+
obj NodeInstaller {
|
|
10
|
+
static has DEFAULT_NODE_VERSION: str = "20",
|
|
11
|
+
NVM_INSTALL_URL: str = "https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh";
|
|
12
|
+
|
|
13
|
+
"""Check if Node.js is installed and accessible."""
|
|
14
|
+
static def is_node_installed -> bool;
|
|
15
|
+
|
|
16
|
+
"""Check if npm is installed and accessible."""
|
|
17
|
+
static def is_npm_installed -> bool;
|
|
18
|
+
|
|
19
|
+
"""Check if NVM is installed."""
|
|
20
|
+
static def is_nvm_installed -> bool;
|
|
21
|
+
|
|
22
|
+
"""Get the currently installed Node.js version."""
|
|
23
|
+
static def get_node_version -> (str | None);
|
|
24
|
+
|
|
25
|
+
"""Install NVM (Node Version Manager)."""
|
|
26
|
+
static def install_nvm -> tuple[bool, str];
|
|
27
|
+
|
|
28
|
+
"""Install Node.js using NVM."""
|
|
29
|
+
static def install_node_via_nvm(version: str = "20") -> tuple[bool, str];
|
|
30
|
+
|
|
31
|
+
"""Ensure Node.js is installed, installing automatically if needed.
|
|
32
|
+
|
|
33
|
+
Returns tuple of (success: bool, message: str, was_just_installed: bool)
|
|
34
|
+
"""
|
|
35
|
+
static def ensure_node_installed(
|
|
36
|
+
interactive: bool = True
|
|
37
|
+
) -> tuple[bool, str, bool];
|
|
38
|
+
|
|
39
|
+
"""Run npm command with NVM environment properly sourced."""
|
|
40
|
+
static def run_npm_with_nvm(args: list, cwd: Path, timeout: int = 300) -> object;
|
|
41
|
+
}
|