juxscript 1.0.89 โ 1.0.90
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/bin/cli.js +243 -92
- package/index.js +21 -0
- package/machinery/build3.js +21 -0
- package/machinery/compiler3.js +638 -0
- package/machinery/serve.js +255 -0
- package/machinery/watcher.js +53 -64
- package/package.json +11 -3
- package/lib/componentsv2/index.d.ts +0 -39
- package/lib/componentsv2/index.d.ts.map +0 -1
- package/lib/componentsv2/index.js +0 -221
- package/lib/componentsv2/index.js.map +0 -1
- package/lib/componentsv2/index.ts +0 -253
- package/machinery/ast.js +0 -347
- package/machinery/compiler.js +0 -706
- package/machinery/diagnose.js +0 -72
- package/machinery/doc-generator.js +0 -136
- package/machinery/imports.js +0 -155
- package/machinery/jux-module-pattern.md +0 -118
- package/machinery/server.js +0 -86
- package/machinery/ts-shim.js +0 -46
- package/machinery/verifier.js +0 -135
- package/tests/dropdown-test.js +0 -25
- package/tests/juxerrors/bad_syntax.jux +0 -8
- package/tests/juxerrors/ghost_dep.jux +0 -10
- package/tests/server_plugin_test.ts +0 -191
package/machinery/diagnose.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
import { bundleJuxFilesToRouter, generateIndexHtml } from './compiler.js';
|
|
5
|
-
import { verifyStaticBuild } from './verifier.js';
|
|
6
|
-
|
|
7
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
const FIXTURES_DIR = path.join(__dirname, 'fixtures');
|
|
9
|
-
const DIST_DIR = path.join(__dirname, '.temp_dist_test');
|
|
10
|
-
|
|
11
|
-
// Setup temp dir
|
|
12
|
-
if (!fs.existsSync(DIST_DIR)) fs.mkdirSync(DIST_DIR);
|
|
13
|
-
|
|
14
|
-
async function runTest(fileName, description) {
|
|
15
|
-
console.log(`\n๐งช TEST: ${description} (${fileName})`);
|
|
16
|
-
console.log(' Context: Trying to build a broken file...');
|
|
17
|
-
|
|
18
|
-
const srcFile = path.join(FIXTURES_DIR, fileName);
|
|
19
|
-
|
|
20
|
-
// Mock finding files by explicitly passing our bad file as the "source"
|
|
21
|
-
// Since bundleJuxFilesToRouter takes a directory, we need to create a temp source dir
|
|
22
|
-
const tempSrcDir = path.join(__dirname, '.temp_src_' + Date.now());
|
|
23
|
-
fs.mkdirSync(tempSrcDir);
|
|
24
|
-
fs.copyFileSync(srcFile, path.join(tempSrcDir, 'index.jux'));
|
|
25
|
-
|
|
26
|
-
let buildSuccess = false;
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
// 1. Attempt Bundle
|
|
30
|
-
const result = await bundleJuxFilesToRouter(tempSrcDir, DIST_DIR, { routePrefix: '' });
|
|
31
|
-
|
|
32
|
-
// 2. Generate HTML (needed for verifier to check import map)
|
|
33
|
-
generateIndexHtml(DIST_DIR, result);
|
|
34
|
-
|
|
35
|
-
// 3. Run Verifier
|
|
36
|
-
const verified = verifyStaticBuild(DIST_DIR);
|
|
37
|
-
|
|
38
|
-
if (!verified) {
|
|
39
|
-
console.log(' โ
SUCCESS: Verifier correctly caught the error!');
|
|
40
|
-
buildSuccess = false;
|
|
41
|
-
} else {
|
|
42
|
-
console.log(' โ FAILURE: Build passed but should have failed verification.');
|
|
43
|
-
buildSuccess = true;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
} catch (e) {
|
|
47
|
-
console.log(` โ
SUCCESS: Compiler threw error as expected:`);
|
|
48
|
-
console.log(` "${e.message.split('\n')[0]}"`);
|
|
49
|
-
buildSuccess = false;
|
|
50
|
-
} finally {
|
|
51
|
-
// Cleanup
|
|
52
|
-
fs.rmSync(tempSrcDir, { recursive: true, force: true });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return !buildSuccess;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async function main() {
|
|
59
|
-
console.log('๐ฉบ JUX FAILURE DIAGNOSTICS\n');
|
|
60
|
-
|
|
61
|
-
// Test 1: bad_syntax.jux (Should throw during compile)
|
|
62
|
-
await runTest('bad_syntax.jux', 'Syntax Error Detection');
|
|
63
|
-
|
|
64
|
-
// Test 2: ghost_dep.jux (Should pass compile, fail verification)
|
|
65
|
-
await runTest('ghost_dep.jux', 'Ghost Dependency Detection');
|
|
66
|
-
|
|
67
|
-
// Cleanup Dist
|
|
68
|
-
fs.rmSync(DIST_DIR, { recursive: true, force: true });
|
|
69
|
-
console.log('\n๐ Diagnostics Complete');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
main();
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { glob } from 'glob';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generate documentation from TypeScript component files
|
|
7
|
-
*
|
|
8
|
-
* @param {string} juxLibPath - Absolute path to jux/lib directory
|
|
9
|
-
*/
|
|
10
|
-
export async function generateDocs(juxLibPath) {
|
|
11
|
-
const componentsDir = path.join(juxLibPath, 'components');
|
|
12
|
-
|
|
13
|
-
if (!fs.existsSync(componentsDir)) {
|
|
14
|
-
throw new Error(`Components directory not found: ${componentsDir}`);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
console.log(` Scanning: ${componentsDir}`);
|
|
18
|
-
|
|
19
|
-
// Find all component TypeScript files
|
|
20
|
-
const componentFiles = glob.sync('*.ts', {
|
|
21
|
-
cwd: componentsDir,
|
|
22
|
-
absolute: true,
|
|
23
|
-
ignore: ['reactivity.ts', 'error-handler.ts']
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
console.log(` Found ${componentFiles.length} component files`);
|
|
27
|
-
|
|
28
|
-
const components = [];
|
|
29
|
-
|
|
30
|
-
for (const filePath of componentFiles) {
|
|
31
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
32
|
-
const componentDoc = parseComponentFile(content, filePath);
|
|
33
|
-
|
|
34
|
-
if (componentDoc) {
|
|
35
|
-
components.push(componentDoc);
|
|
36
|
-
console.log(` โ ${componentDoc.name}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Sort by category and name
|
|
41
|
-
components.sort((a, b) => {
|
|
42
|
-
const categoryCompare = (a.category || 'ZZZ').localeCompare(b.category || 'ZZZ');
|
|
43
|
-
if (categoryCompare !== 0) return categoryCompare;
|
|
44
|
-
return a.name.localeCompare(b.name);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// Generate the docs data
|
|
48
|
-
const docsData = {
|
|
49
|
-
components,
|
|
50
|
-
version: '1.0.0',
|
|
51
|
-
lastUpdated: new Date().toISOString()
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// Write to JSON file
|
|
55
|
-
const outputPath = path.join(componentsDir, 'docs-data.json');
|
|
56
|
-
fs.writeFileSync(outputPath, JSON.stringify(docsData, null, 2));
|
|
57
|
-
|
|
58
|
-
console.log(` Generated: ${outputPath}`);
|
|
59
|
-
|
|
60
|
-
return docsData;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Parse a single component file
|
|
65
|
-
*/
|
|
66
|
-
function parseComponentFile(content, filePath) {
|
|
67
|
-
const fileName = path.basename(filePath, '.ts');
|
|
68
|
-
const className = fileName.charAt(0).toUpperCase() + fileName.slice(1);
|
|
69
|
-
|
|
70
|
-
const category = inferCategory(className, content);
|
|
71
|
-
const descMatch = content.match(/\/\*\*\s*\n\s*\*\s*([^\n*]+)/);
|
|
72
|
-
const description = descMatch ? descMatch[1].trim() : `${className} component`;
|
|
73
|
-
const factoryMatch = content.match(/export function\s+\w+\(([^)]*)\)/);
|
|
74
|
-
const constructorSig = factoryMatch
|
|
75
|
-
? `jux.${fileName}(${factoryMatch[1]})`
|
|
76
|
-
: `new ${className}()`;
|
|
77
|
-
const fluentMethods = extractFluentMethods(content, className);
|
|
78
|
-
const exampleMatch = content.match(/\*\s+Usage:\s*\n\s*\*\s+(.+?)(?:\n|$)/);
|
|
79
|
-
let example = exampleMatch
|
|
80
|
-
? exampleMatch[1].trim()
|
|
81
|
-
: `jux.${fileName}('id').render()`;
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
name: className,
|
|
85
|
-
category,
|
|
86
|
-
description,
|
|
87
|
-
constructor: constructorSig,
|
|
88
|
-
fluentMethods,
|
|
89
|
-
example
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Extract fluent API methods from class
|
|
95
|
-
*/
|
|
96
|
-
function extractFluentMethods(content, className) {
|
|
97
|
-
const methods = [];
|
|
98
|
-
const methodRegex = /^\s*(\w+)\(([^)]*)\):\s*this\s*\{/gm;
|
|
99
|
-
let match;
|
|
100
|
-
|
|
101
|
-
while ((match = methodRegex.exec(content)) !== null) {
|
|
102
|
-
const methodName = match[1];
|
|
103
|
-
const params = match[2];
|
|
104
|
-
if (methodName.startsWith('_') || methodName === 'constructor') continue;
|
|
105
|
-
const cleanParams = params.split(',').map(p => p.trim().split(':')[0].trim()).filter(p => p).join(', ');
|
|
106
|
-
methods.push({
|
|
107
|
-
name: methodName,
|
|
108
|
-
params: cleanParams ? `(${cleanParams})` : '()',
|
|
109
|
-
returns: 'this',
|
|
110
|
-
description: `Set ${methodName}`
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const renderMatch = content.match(/^\s*render\(([^)]*)\):\s*(\w+)/m);
|
|
115
|
-
if (renderMatch && !methods.find(m => m.name === 'render')) {
|
|
116
|
-
methods.push({
|
|
117
|
-
name: 'render',
|
|
118
|
-
params: renderMatch[1] ? `(${renderMatch[1]})` : '()',
|
|
119
|
-
returns: renderMatch[2],
|
|
120
|
-
description: 'Render component to DOM'
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return methods;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Infer category from component name or content
|
|
129
|
-
*/
|
|
130
|
-
function inferCategory(name, content) {
|
|
131
|
-
const dataComponents = ['Table', 'List', 'Chart', 'Data'];
|
|
132
|
-
const coreComponents = ['App', 'Layout', 'Theme', 'Style', 'Script', 'Import'];
|
|
133
|
-
if (dataComponents.some(dc => name.includes(dc))) return 'Data Components';
|
|
134
|
-
if (coreComponents.includes(name)) return 'Core';
|
|
135
|
-
return 'UI Components';
|
|
136
|
-
}
|
package/machinery/imports.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
|
|
5
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
-
const __dirname = path.dirname(__filename);
|
|
7
|
-
const REGISTRY_PATH = path.join(__dirname, '../lib/registry/packages.json');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Load package registry
|
|
11
|
-
*/
|
|
12
|
-
function loadRegistry() {
|
|
13
|
-
if (!fs.existsSync(REGISTRY_PATH)) {
|
|
14
|
-
return {};
|
|
15
|
-
}
|
|
16
|
-
return JSON.parse(fs.readFileSync(REGISTRY_PATH, 'utf-8'));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Parse @import directives from Jux code
|
|
21
|
-
*/
|
|
22
|
-
export function parseImports(juxCode) {
|
|
23
|
-
const imports = [];
|
|
24
|
-
const lines = juxCode.split('\n');
|
|
25
|
-
|
|
26
|
-
for (let i = 0; i < lines.length; i++) {
|
|
27
|
-
const line = lines[i].trim();
|
|
28
|
-
|
|
29
|
-
// Stop parsing when we hit actual code (non-directive, non-comment)
|
|
30
|
-
if (line && !line.startsWith('@') && !line.startsWith('//') && !line.startsWith('/*')) {
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Match @import directive
|
|
35
|
-
const importMatch = line.match(/^@import\s+(.+)$/);
|
|
36
|
-
if (importMatch) {
|
|
37
|
-
const importSpec = importMatch[1].trim();
|
|
38
|
-
imports.push({
|
|
39
|
-
line: i + 1,
|
|
40
|
-
raw: importSpec,
|
|
41
|
-
resolved: resolveImport(importSpec)
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
if (process.env.JUX_VERBOSE) {
|
|
45
|
-
console.log(` [Line ${i + 1}] Found @import: ${importSpec}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return imports;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Resolve import specification to URL/path
|
|
55
|
-
*/
|
|
56
|
-
export function resolveImport(importSpec) {
|
|
57
|
-
// Remove quotes if present
|
|
58
|
-
const cleaned = importSpec.replace(/^['"]|['"]$/g, '');
|
|
59
|
-
|
|
60
|
-
// Direct URL (starts with http:// or https://)
|
|
61
|
-
if (cleaned.startsWith('http://') || cleaned.startsWith('https://')) {
|
|
62
|
-
return {
|
|
63
|
-
type: 'cdn',
|
|
64
|
-
url: cleaned,
|
|
65
|
-
source: 'direct'
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Local file (starts with ./ or ../ or /)
|
|
70
|
-
if (cleaned.startsWith('./') || cleaned.startsWith('../') || cleaned.startsWith('/')) {
|
|
71
|
-
return {
|
|
72
|
-
type: 'local',
|
|
73
|
-
path: cleaned,
|
|
74
|
-
source: 'file'
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Unknown/unsupported
|
|
79
|
-
return {
|
|
80
|
-
type: 'unknown',
|
|
81
|
-
name: cleaned,
|
|
82
|
-
error: `Import "${cleaned}" must be a URL (https://...) or relative path (./...)`
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Auto-detect component dependencies
|
|
88
|
-
*/
|
|
89
|
-
function detectComponentDependencies(usedComponents) {
|
|
90
|
-
const componentDeps = {
|
|
91
|
-
'chart': 'chart.js'
|
|
92
|
-
// Add more mappings as needed
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const deps = new Set();
|
|
96
|
-
|
|
97
|
-
usedComponents.forEach(comp => {
|
|
98
|
-
if (componentDeps[comp]) {
|
|
99
|
-
deps.add(componentDeps[comp]);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
return Array.from(deps).map(pkg => ({
|
|
104
|
-
auto: true,
|
|
105
|
-
resolved: resolveImport(pkg)
|
|
106
|
-
}));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Generate HTML script tags from resolved imports
|
|
111
|
-
*/
|
|
112
|
-
export function generateImportTags(imports) {
|
|
113
|
-
const tags = [];
|
|
114
|
-
const seen = new Set();
|
|
115
|
-
|
|
116
|
-
for (const imp of imports) {
|
|
117
|
-
const resolved = imp.resolved;
|
|
118
|
-
|
|
119
|
-
if (resolved.type === 'unknown') {
|
|
120
|
-
tags.push(`<!-- ERROR: ${resolved.error} -->`);
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const key = resolved.url || resolved.path;
|
|
125
|
-
if (seen.has(key)) continue;
|
|
126
|
-
seen.add(key);
|
|
127
|
-
|
|
128
|
-
if (resolved.type === 'cdn') {
|
|
129
|
-
tags.push(` <script src="${resolved.url}"></script>`);
|
|
130
|
-
} else if (resolved.type === 'local') {
|
|
131
|
-
tags.push(` <script type="module" src="${resolved.path}"></script>`);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return tags.join('\n');
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Validate all imports are resolvable
|
|
140
|
-
*/
|
|
141
|
-
export function validateImports(imports) {
|
|
142
|
-
const errors = [];
|
|
143
|
-
|
|
144
|
-
imports.forEach(imp => {
|
|
145
|
-
if (imp.resolved.type === 'unknown') {
|
|
146
|
-
errors.push({
|
|
147
|
-
line: imp.line,
|
|
148
|
-
message: imp.resolved.error,
|
|
149
|
-
raw: imp.raw
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
return errors;
|
|
155
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
# JUX Module Pattern
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
A `.jux` file can export a component-like interface with:
|
|
5
|
-
- Configuration options
|
|
6
|
-
- Public API methods
|
|
7
|
-
- Event emissions (EDR pattern)
|
|
8
|
-
- Internal/shared state
|
|
9
|
-
- Props (getters)
|
|
10
|
-
|
|
11
|
-
## Pattern Structure
|
|
12
|
-
|
|
13
|
-
```javascript
|
|
14
|
-
// calendar.jux
|
|
15
|
-
import { jux, state } from 'juxscript';
|
|
16
|
-
|
|
17
|
-
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
18
|
-
// MODULE DEFINITION
|
|
19
|
-
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
20
|
-
|
|
21
|
-
export default function Calendar(id, options = {}) {
|
|
22
|
-
// Internal state
|
|
23
|
-
const today = new Date();
|
|
24
|
-
const currentMonth = state(options.initialMonth ?? today.getMonth());
|
|
25
|
-
const currentYear = state(options.initialYear ?? today.getFullYear());
|
|
26
|
-
const selectedDate = state(null);
|
|
27
|
-
|
|
28
|
-
// Event emitters (EDR pattern)
|
|
29
|
-
const events = {
|
|
30
|
-
dateSelect: [],
|
|
31
|
-
monthChange: [],
|
|
32
|
-
yearChange: []
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// Emit helper
|
|
36
|
-
const emit = (eventName, data) => {
|
|
37
|
-
events[eventName]?.forEach(handler => handler(data));
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// Public API
|
|
41
|
-
const api = {
|
|
42
|
-
// Props (getters)
|
|
43
|
-
get currentMonth() { return currentMonth.value; },
|
|
44
|
-
get currentYear() { return currentYear.value; },
|
|
45
|
-
get selectedDate() { return selectedDate.value; },
|
|
46
|
-
|
|
47
|
-
// Methods
|
|
48
|
-
nextMonth() {
|
|
49
|
-
let month = currentMonth.value + 1;
|
|
50
|
-
let year = currentYear.value;
|
|
51
|
-
if (month > 11) { month = 0; year++; }
|
|
52
|
-
currentMonth.set(month);
|
|
53
|
-
currentYear.set(year);
|
|
54
|
-
emit('monthChange', { month, year });
|
|
55
|
-
return api;
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
prevMonth() {
|
|
59
|
-
let month = currentMonth.value - 1;
|
|
60
|
-
let year = currentYear.value;
|
|
61
|
-
if (month < 0) { month = 11; year--; }
|
|
62
|
-
currentMonth.set(month);
|
|
63
|
-
currentYear.set(year);
|
|
64
|
-
emit('monthChange', { month, year });
|
|
65
|
-
return api;
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
selectDate(date) {
|
|
69
|
-
selectedDate.set(date);
|
|
70
|
-
emit('dateSelect', { date });
|
|
71
|
-
return api;
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
// Event binding (EDR consumer registration)
|
|
75
|
-
on(eventName, handler) {
|
|
76
|
-
if (events[eventName]) {
|
|
77
|
-
events[eventName].push(handler);
|
|
78
|
-
}
|
|
79
|
-
return api;
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
// Render
|
|
83
|
-
render(targetId) {
|
|
84
|
-
// Build UI components...
|
|
85
|
-
return api;
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
// Expose for chaining
|
|
89
|
-
id
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
return api;
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## Usage
|
|
97
|
-
|
|
98
|
-
```javascript
|
|
99
|
-
// app.jux
|
|
100
|
-
import Calendar from './calendar.jux';
|
|
101
|
-
|
|
102
|
-
const cal = Calendar('my-calendar', {
|
|
103
|
-
initialMonth: 11,
|
|
104
|
-
initialYear: 2024
|
|
105
|
-
})
|
|
106
|
-
.on('dateSelect', ({ date }) => {
|
|
107
|
-
console.log('Date selected:', date);
|
|
108
|
-
})
|
|
109
|
-
.on('monthChange', ({ month, year }) => {
|
|
110
|
-
console.log('Month changed:', month, year);
|
|
111
|
-
})
|
|
112
|
-
.render('#app');
|
|
113
|
-
|
|
114
|
-
// Public API
|
|
115
|
-
cal.nextMonth();
|
|
116
|
-
cal.prevMonth();
|
|
117
|
-
console.log(cal.currentMonth); // getter
|
|
118
|
-
```
|
package/machinery/server.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import http from 'http';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
6
|
-
import { startWatcher } from './watcher.js';
|
|
7
|
-
import { verifyRuntime } from './verifier.js';
|
|
8
|
-
import { WebSocketServer } from 'ws';
|
|
9
|
-
|
|
10
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Try to start a server on a port, with fallback to next port if busy
|
|
14
|
-
* Returns the actual port that was successfully allocated
|
|
15
|
-
*/
|
|
16
|
-
async function tryPort(startPort, maxAttempts = 5, reservedPorts = []) {
|
|
17
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
18
|
-
const port = startPort + attempt;
|
|
19
|
-
if (reservedPorts.includes(port)) continue;
|
|
20
|
-
try {
|
|
21
|
-
await new Promise((resolve, reject) => {
|
|
22
|
-
const testServer = http.createServer();
|
|
23
|
-
testServer.once('error', reject);
|
|
24
|
-
testServer.once('listening', () => { testServer.close(); resolve(port); });
|
|
25
|
-
testServer.listen(port);
|
|
26
|
-
});
|
|
27
|
-
return port;
|
|
28
|
-
} catch (err) { if (err.code !== 'EADDRINUSE') throw err; }
|
|
29
|
-
}
|
|
30
|
-
throw new Error(`Could not find available port`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async function serve(httpPort = 3000, wsPort = 3001, distDir = './.jux-dist', config = {}) {
|
|
34
|
-
const app = express();
|
|
35
|
-
const absoluteDistDir = path.resolve(distDir);
|
|
36
|
-
const projectRoot = path.resolve('.');
|
|
37
|
-
|
|
38
|
-
app.use(express.json());
|
|
39
|
-
if (!fs.existsSync(absoluteDistDir)) { process.exit(1); }
|
|
40
|
-
|
|
41
|
-
app.use((req, res, next) => {
|
|
42
|
-
res.setHeader('Cache-Control', 'no-store');
|
|
43
|
-
if (req.path.endsWith('.js')) res.setHeader('Content-Type', 'application/javascript; charset=utf-8');
|
|
44
|
-
next();
|
|
45
|
-
});
|
|
46
|
-
app.get('/favicon.ico', (req, res) => res.status(204).end());
|
|
47
|
-
app.use(express.static(absoluteDistDir));
|
|
48
|
-
app.use((req, res) => {
|
|
49
|
-
if (/\.[a-zA-Z0-9]+$/.test(req.path)) return res.status(404).send('Not found');
|
|
50
|
-
if (req.accepts('html')) res.sendFile(path.join(absoluteDistDir, 'index.html'));
|
|
51
|
-
else res.status(404).send('Not found');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const availableHttpPort = await tryPort(httpPort);
|
|
55
|
-
const availableWsPort = await tryPort(wsPort, 5, [availableHttpPort]);
|
|
56
|
-
const server = http.createServer(app);
|
|
57
|
-
const wss = new WebSocketServer({ port: availableWsPort });
|
|
58
|
-
const clients = [];
|
|
59
|
-
|
|
60
|
-
wss.on('connection', (ws) => {
|
|
61
|
-
clients.push(ws);
|
|
62
|
-
ws.on('close', () => { const i = clients.indexOf(ws); if (i > -1) clients.splice(i, 1); });
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
server.listen(availableHttpPort, async () => {
|
|
66
|
-
console.log(`๐ Server: http://localhost:${availableHttpPort}`);
|
|
67
|
-
const isHealthy = await verifyRuntime(availableHttpPort);
|
|
68
|
-
if (!isHealthy) { console.error('๐ Runtime Check Failed.'); process.exit(1); }
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const sourceName = config?.directories?.source || 'jux';
|
|
72
|
-
const juxSource = path.join(projectRoot, sourceName);
|
|
73
|
-
if (fs.existsSync(juxSource)) {
|
|
74
|
-
startWatcher(juxSource, absoluteDistDir, clients, config, availableWsPort);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const shutdown = async () => { wss.close(); server.close(); process.exit(0); };
|
|
78
|
-
process.on('SIGINT', shutdown);
|
|
79
|
-
process.on('SIGTERM', shutdown);
|
|
80
|
-
|
|
81
|
-
return { server, httpPort: availableHttpPort, wsPort: availableWsPort };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export async function start(httpPort = 3000, wsPort = 3001, distDir = './.jux-dist', config = {}) {
|
|
85
|
-
return serve(httpPort, wsPort, distDir, config);
|
|
86
|
-
}
|
package/machinery/ts-shim.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import esbuild from 'esbuild';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* TypeScript Shim - Strips type annotations using esbuild
|
|
5
|
-
* This is rock-solid and handles ALL TypeScript syntax correctly
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Strip TypeScript type annotations from code using esbuild
|
|
10
|
-
*
|
|
11
|
-
* @param {string} code - TypeScript source code
|
|
12
|
-
* @returns {string} - JavaScript code with types removed
|
|
13
|
-
*/
|
|
14
|
-
export function stripTypes(code) {
|
|
15
|
-
try {
|
|
16
|
-
// โ
Use esbuild to transform TypeScript โ JavaScript
|
|
17
|
-
const result = esbuild.transformSync(code, {
|
|
18
|
-
loader: 'ts',
|
|
19
|
-
format: 'esm',
|
|
20
|
-
target: 'es2020'
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
return result.code;
|
|
24
|
-
} catch (err) {
|
|
25
|
-
console.error('โ Failed to strip TypeScript:', err.message);
|
|
26
|
-
// Return original code if transformation fails
|
|
27
|
-
return code;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Check if a file is TypeScript based on extension
|
|
33
|
-
*/
|
|
34
|
-
export function isTypeScript(filePath) {
|
|
35
|
-
return filePath.endsWith('.ts') || filePath.endsWith('.tsx');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Load and parse a file, automatically stripping types if it's TypeScript
|
|
40
|
-
*/
|
|
41
|
-
export function loadAndStripTypes(filePath, fileContent) {
|
|
42
|
-
if (isTypeScript(filePath)) {
|
|
43
|
-
return stripTypes(fileContent);
|
|
44
|
-
}
|
|
45
|
-
return fileContent;
|
|
46
|
-
}
|