@codespark/framework 1.0.0 → 1.0.1
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 +129 -0
- package/dist/react.js +2 -2
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 TonyL1u
|
|
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,129 @@
|
|
|
1
|
+
# @codespark/framework
|
|
2
|
+
|
|
3
|
+
Core framework abstraction for the [Codespark](https://codesparkjs.com) ecosystem. Provides a unified API for analyzing and compiling code across different frameworks (React, HTML, Markdown).
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
Visit [https://codesparkjs.com/docs/framework](https://codesparkjs.com/docs/framework) to view the documentation.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @codespark/framework
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @codespark/framework
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Using Built-in Frameworks
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { react } from '@codespark/framework/react';
|
|
23
|
+
import { html } from '@codespark/framework/html';
|
|
24
|
+
import { markdown } from '@codespark/framework/markdown';
|
|
25
|
+
|
|
26
|
+
// Analyze and compile React code
|
|
27
|
+
const files = {
|
|
28
|
+
'./App.tsx': `
|
|
29
|
+
export default function App() {
|
|
30
|
+
return <h1>Hello World</h1>;
|
|
31
|
+
}
|
|
32
|
+
`
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
react.analyze('./App.tsx', files);
|
|
36
|
+
const compiled = react.compile();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Registering Frameworks
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { registerFramework, registry } from '@codespark/framework';
|
|
43
|
+
import { react } from '@codespark/framework/react';
|
|
44
|
+
|
|
45
|
+
// Register a framework
|
|
46
|
+
registerFramework(react);
|
|
47
|
+
|
|
48
|
+
// Get a registered framework
|
|
49
|
+
const framework = registry.get('react');
|
|
50
|
+
|
|
51
|
+
// List all registered frameworks
|
|
52
|
+
const frameworks = registry.list(); // ['react']
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Creating Custom Frameworks
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { Framework, type Outputs } from '@codespark/framework';
|
|
59
|
+
|
|
60
|
+
class MyFramework extends Framework {
|
|
61
|
+
readonly name = 'my-framework';
|
|
62
|
+
readonly imports = {
|
|
63
|
+
'my-lib': 'https://esm.sh/my-lib'
|
|
64
|
+
};
|
|
65
|
+
outputs: Outputs = new Map();
|
|
66
|
+
|
|
67
|
+
analyze(entry: string, files: Record<string, string>) {
|
|
68
|
+
// Analyze dependencies and populate outputs
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
compile(): string {
|
|
72
|
+
const builder = this.createBuilder();
|
|
73
|
+
// Build runtime code
|
|
74
|
+
return builder.toString();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## API
|
|
80
|
+
|
|
81
|
+
### `Framework` (Abstract Class)
|
|
82
|
+
|
|
83
|
+
Base class for all framework implementations.
|
|
84
|
+
|
|
85
|
+
| Property/Method | Description |
|
|
86
|
+
|-----------------|-------------|
|
|
87
|
+
| `name` | Framework identifier |
|
|
88
|
+
| `imports` | Import map for external dependencies |
|
|
89
|
+
| `outputs` | Analyzed outputs by loader type |
|
|
90
|
+
| `analyze(entry, files)` | Analyze entry file and its dependencies |
|
|
91
|
+
| `compile()` | Compile analyzed code to executable string |
|
|
92
|
+
| `getOutput(type)` | Get outputs for a specific loader type |
|
|
93
|
+
|
|
94
|
+
### `registerFramework(framework, name?)`
|
|
95
|
+
|
|
96
|
+
Register a framework instance to the global registry.
|
|
97
|
+
|
|
98
|
+
### `registry`
|
|
99
|
+
|
|
100
|
+
Global framework registry instance.
|
|
101
|
+
|
|
102
|
+
| Method | Description |
|
|
103
|
+
|--------|-------------|
|
|
104
|
+
| `get(name)` | Get a framework by name |
|
|
105
|
+
| `list()` | List all registered framework names |
|
|
106
|
+
| `register(framework, name?)` | Register a framework |
|
|
107
|
+
|
|
108
|
+
### Loader Types
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
enum LoaderType {
|
|
112
|
+
ESModule = 'esmodule', // JavaScript/TypeScript modules
|
|
113
|
+
Style = 'style', // CSS stylesheets
|
|
114
|
+
Script = 'script', // Script tags
|
|
115
|
+
Asset = 'asset' // HTML and other assets
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Built-in Frameworks
|
|
120
|
+
|
|
121
|
+
| Framework | Import Path | Description |
|
|
122
|
+
|-----------|-------------|-------------|
|
|
123
|
+
| React | `@codespark/framework/react` | React with JSX/TSX support |
|
|
124
|
+
| HTML | `@codespark/framework/html` | HTML with inline scripts and styles |
|
|
125
|
+
| Markdown | `@codespark/framework/markdown` | Markdown to HTML |
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT
|
package/dist/react.js
CHANGED
|
@@ -233,13 +233,13 @@ function processFile(path, files, outputs, visited) {
|
|
|
233
233
|
switch (output.type) {
|
|
234
234
|
case LoaderType.ESModule: {
|
|
235
235
|
const { content, dependencies, externals } = output;
|
|
236
|
+
for (const depPath of Object.values(dependencies)) processFile(depPath, files, outputs, visited);
|
|
236
237
|
getOutputList(outputs, LoaderType.ESModule).push({
|
|
237
238
|
path,
|
|
238
239
|
content,
|
|
239
240
|
dependencies,
|
|
240
241
|
externals
|
|
241
242
|
});
|
|
242
|
-
for (const depPath of Object.values(dependencies)) processFile(depPath, files, outputs, visited);
|
|
243
243
|
break;
|
|
244
244
|
}
|
|
245
245
|
case LoaderType.Style: {
|
|
@@ -288,7 +288,7 @@ var Framework = class extends Framework$1 {
|
|
|
288
288
|
this.outputs = analyze(entry, files);
|
|
289
289
|
}
|
|
290
290
|
compile() {
|
|
291
|
-
const transformed = this.transformModulesToBlob([...this.getOutput(LoaderType.ESModule)]
|
|
291
|
+
const transformed = this.transformModulesToBlob([...this.getOutput(LoaderType.ESModule)]);
|
|
292
292
|
const builder = this.createBuilder(transformed);
|
|
293
293
|
const ast = parse(transformed, {
|
|
294
294
|
sourceType: "module",
|