jpsx 0.1.16 → 0.1.19

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/README.md CHANGED
@@ -1,242 +1,143 @@
1
- # JPS (Just Python Script)
2
-
3
- A Python-like language that compiles to JavaScript, designed to integrate seamlessly with **any frontend framework**.
4
-
5
- [![npm version](https://img.shields.io/npm/v/jps.svg)](https://www.npmjs.com/package/jps)
6
- [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](LICENSE)
7
-
8
- ## Features
9
-
10
- - 🐍 **Python-like syntax** that compiles to clean JavaScript
11
- - ⚡ **Standalone file integration** - Import `.jps` files like `.jsx/.tsx` files!
12
- - 🔥 **Hot Module Replacement (HMR)** - Instant feedback during development
13
- - ⚡ **Zero-config integration** with React, Vue, Svelte, Angular, and more
14
- - 📦 **Multiple output formats**: ESM, CommonJS, IIFE, UMD
15
- - 🔌 **Flexible runtime modes**: Inline, external, CDN, or custom
16
- - 🛠️ **Build tool plugins** for Vite, Webpack, Rollup, esbuild
17
- - 🌐 **Browser-ready**: Works without any build step
18
- - 📝 **TypeScript support** with auto-generated declarations
19
-
20
- ## 🚀 Quick Start
21
-
22
- ### Standalone File Integration (⚡ Recommended)
23
-
24
- Import `.jps` files directly in your code - just like `.tsx` files!
25
-
26
- ```python
27
- # math.jps - a real file!
28
- def add(a, b):
29
- return a + b
30
-
31
- class Calculator:
32
- def __init__(self):
33
- self.value = 0
34
- ```
35
-
36
- ```typescript
37
- // App.tsx - just import and use!
38
- import { add, Calculator } from './math.jps';
39
-
40
- const sum = add(10, 20);
41
- const calc = new Calculator();
42
- ```
43
-
44
- **[See full example →](examples/react-vite-standalone/)**
45
-
46
- ---
47
-
48
- ### As a CLI Tool
49
-
50
- ```bash
51
- # Install globally
52
- npm install -g jps
53
-
54
- # Create a new project
55
- jps init my-project
56
- cd my-project
57
- jps run main.jps
58
- ```
59
-
60
- ### As a Library (Runtime Compilation)
61
-
62
- ```bash
63
- # Install in your project
64
- npm install jps
65
- ```
66
-
67
- #### React
68
-
69
- ```javascript
70
- import { compile } from 'jps';
71
-
72
- function App() {
73
- const jpsCode = `
74
- def greet(name):
75
- return "Hello, " + name
76
-
77
- print(greet("React"))
78
- `;
79
-
80
- const result = compile(jpsCode, {
81
- format: 'iife',
82
- runtimeMode: 'inline'
83
- });
84
-
85
- eval(result.code); // Outputs: Hello, React
86
- }
87
- ```
88
-
89
- #### Vue
90
-
91
- ```vue
92
- <script setup>
93
- import { compile } from 'jps';
94
- const result = compile('print("Hello Vue!")', {
95
- format: 'iife',
96
- runtimeMode: 'inline'
97
- });
98
- eval(result.code);
99
- </script>
100
- ```
101
-
102
- #### Browser (No Build Step)
103
-
104
- ```html
105
- <script type="module">
106
- import { compile } from 'https://cdn.jsdelivr.net/npm/jps@latest/dist/api/index.js';
107
- const result = compile('print("Hello Browser!")', {
108
- format: 'iife',
109
- runtimeMode: 'inline'
110
- });
111
- eval(result.code);
112
- </script>
113
- ```
114
-
115
- ## 📖 Documentation
116
-
117
- - **[Standalone File Integration](docs/STANDALONE_INTEGRATION.md)** - ⚡ Import .jps like .tsx (recommended!)
118
- - **[Integration Guide](docs/INTEGRATION.md)** - Complete guide for all frameworks
119
- - **[Quick Start](docs/QUICKSTART.md)** - 30-second integration examples
120
- - **[Syntax Guide](docs/syntax.md)** - JPS language syntax
121
- - **[Standard Library](docs/stdlib.md)** - Built-in functions
122
- - **[API Reference](docs/API.md)** - Programmatic API
123
-
124
- ## 🎯 Use Cases
125
-
126
- - **Code Playgrounds**: Build interactive Python-like editors
127
- - **Educational Tools**: Teach Python concepts in the browser
128
- - **Scripting**: Add Python-like scripting to your JavaScript app
129
- - **DSL**: Create domain-specific languages with Python syntax
130
- - **Prototyping**: Rapid development with Python-like syntax
131
-
132
- ## 📦 CLI Commands
133
-
134
- - `jps build <file>` - Compile JPS to JavaScript
135
- - `jps run <file>` - Compile and execute
136
- - `jps watch <file>` - Watch for changes and recompile
137
- - `jps init [name]` - Initialize a new JPS project
138
- - `jps doctor` - Verify environment setup
139
-
140
- ## 🔧 Programmatic API
141
-
142
- ```javascript
143
- import { compile, compileToJS, getRuntime } from 'jps';
144
-
145
- // Full API with metadata
146
- const result = compile(source, {
147
- format: 'esm', // Output format: 'esm' | 'cjs' | 'iife' | 'umd'
148
- runtimeMode: 'inline', // Runtime: 'inline' | 'external' | 'cdn' | 'none'
149
- moduleName: 'MyApp', // For IIFE/UMD
150
- sourceMap: true, // Include source maps
151
- standalone: false // Bundle everything
152
- });
153
-
154
- // Simple API (just returns code)
155
- const jsCode = compileToJS(source);
156
-
157
- // Get runtime library code
158
- const runtime = getRuntime();
159
- ```
160
-
161
- ## 🎨 Framework Examples
162
-
163
- Check out the [examples/](examples/) directory for complete working examples:
164
-
165
- - **React** - Vite plugin, Webpack loader, runtime compilation
166
- - **Vue 3** - Composition API integration
167
- - **Svelte** - Component integration
168
- - **Angular** - Service integration
169
- - **Next.js** - App Router and Pages Router
170
- - **Vanilla Browser** - No build step required
171
-
172
- ## 🛠️ Build Tool Plugins
173
-
174
- ### Vite
175
-
176
- ```javascript
177
- // vite.config.js
178
- import { jpsPlugin } from './vite-plugin-jps';
179
-
180
- export default {
181
- plugins: [jpsPlugin()]
182
- };
183
- ```
184
-
185
- ### Webpack
186
-
187
- ```javascript
188
- // webpack.config.js
189
- module.exports = {
190
- module: {
191
- rules: [
192
- { test: /\.jps$/, use: 'jps-loader' }
193
- ]
194
- }
195
- };
196
- ```
197
-
198
- See [INTEGRATION.md](docs/INTEGRATION.md) for Rollup, esbuild, and more.
199
-
200
- ## 🌟 Why JPS?
201
-
202
- 1. **Framework Agnostic**: Works with React, Vue, Svelte, Angular, and vanilla JS
203
- 2. **Flexible Output**: Choose the format that fits your needs
204
- 3. **Modern & Production-Ready**: Built with TypeScript, full test coverage
205
- 4. **Developer Friendly**: Simple API, great error messages, comprehensive docs
206
- 5. **Lightweight**: Minimal dependencies, tree-shakeable
207
-
208
- ## 🏗️ Development
209
-
210
- Prerequisites: Node.js 18+
211
-
212
- ```bash
213
- # Clone the repository
214
- git clone https://github.com/your-repo/jps.git
215
- cd jps
216
-
217
- # Install dependencies
218
- npm install
219
-
220
- # Build the project
221
- npm run build
222
-
223
- # Run tests
224
- npm test
225
- ```
226
-
227
- ## 📄 License
228
-
229
- ISC - See [LICENSE](LICENSE) file for details
230
-
231
- ## 🤝 Contributing
232
-
233
- Contributions are welcome! Please read our contributing guidelines first.
234
-
235
- ## 📮 Support
236
-
237
- - **Issues**: [GitHub Issues](https://github.com/your-repo/jps/issues)
238
- - **Discussions**: [GitHub Discussions](https://github.com/your-repo/jps/discussions)
239
-
240
- ---
241
-
242
- **Made with ❤️ by Loaii abdalslam**
1
+ # JPS (Just Python Script)
2
+ ![unnamed (8)](https://github.com/user-attachments/assets/bb92dc31-d62f-4560-8cf0-6935de1ed70a)
3
+
4
+ A Python-like language that compiles to JavaScript, designed to integrate seamlessly with **any frontend framework**.
5
+
6
+ [![npm version](https://img.shields.io/npm/v/jpsx.svg)](https://www.npmjs.com/package/jpsx)
7
+ [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](LICENSE)
8
+ <a href="https://www.producthunt.com/products/jps?embed=true&utm_source=badge-featured&utm_medium=badge&utm_campaign=badge-jps" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=1067365&theme=light" alt="JPS - New Programming Language | Write Python-like in Javascript | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
9
+
10
+ ---
11
+
12
+ ## 🚀 Quick Start
13
+
14
+ ### Installation
15
+
16
+ ```bash
17
+ # Install as a library in your project
18
+ npm install jpsx
19
+
20
+ # Or install globally as a CLI tool
21
+ npm install -g jpsx
22
+ ```
23
+
24
+ ### Standalone File Integration (Recommended)
25
+
26
+ Import `.jps` files directly in your code - just like `.tsx` files!
27
+
28
+ **math.jps**
29
+ ```python
30
+ def add(a, b):
31
+ return a + b
32
+
33
+ class Calculator:
34
+ def __init__(self):
35
+ self.value = 0
36
+ ```
37
+
38
+ **App.tsx**
39
+ ```typescript
40
+ import { add, Calculator } from './math.jps';
41
+
42
+ const sum = add(10, 20);
43
+ const calc = new Calculator();
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Features
49
+
50
+ - 🐍 **Python-like syntax** that compiles to clean JavaScript
51
+ - **Standalone file integration** - Import `.jps` files like `.jsx/.tsx` files!
52
+ - 🔥 **Hot Module Replacement (HMR)** - Instant feedback during development
53
+ - ⚡ **Zero-config integration** with React, Vue, Svelte, Angular, and more
54
+ - 📦 **Multiple output formats**: ESM, CommonJS, IIFE, UMD
55
+ - 🔌 **Flexible runtime modes**: Inline, external, CDN, or custom
56
+ - 🛠️ **Build tool plugins** for Vite, Webpack, Rollup, esbuild
57
+ - 🌐 **Browser-ready**: Works without any build step
58
+ - 📝 **TypeScript support** with auto-generated declarations
59
+
60
+ ---
61
+
62
+ ## 📖 Documentation & Guidelines
63
+
64
+ ### 1. Language Syntax
65
+ JPS supports core Python syntax tailored for the JavaScript ecosystem.
66
+
67
+ | Feature | JPS Syntax | Compiles to JS |
68
+ |---------|------------|----------------|
69
+ | **Function** | `def foo(a): return a` | `function foo(a) { return a; }` |
70
+ | **Class** | `class User: ...` | `class User { ... }` |
71
+ | **Loop** | `for i in range(5): ...` | `for (let i = 0; i < 5; i++) ...` |
72
+ | **List Comp** | `[x*2 for x in nums]` | `nums.map(x => x * 2)` |
73
+
74
+ ### 2. Runtime Functions
75
+ Built-in Python-like functions available globally:
76
+ - `print(args)`
77
+ - `len(obj)`
78
+ - `range(start, stop, step)`
79
+ - `sum(iterable)`
80
+ - `min() / max()`
81
+ - `sorted(iterable)`
82
+
83
+ ### 3. CLI Usage
84
+
85
+ ```bash
86
+ # Initialize a new JPS project
87
+ jps init my-project
88
+ cd my-project
89
+
90
+ # Run a JPS file directly
91
+ jps run main.jps
92
+
93
+ # Build for production
94
+ jps build main.jps --format esm
95
+ ```
96
+
97
+ ### 4. Integration Guide
98
+
99
+ **Vite Plugin**
100
+ ```javascript
101
+ // vite.config.js
102
+ import { jpsPlugin } from 'vite-plugin-jpsx';
103
+
104
+ export default {
105
+ plugins: [jpsPlugin()]
106
+ };
107
+ ```
108
+
109
+ **Webpack Loader**
110
+ ```javascript
111
+ // webpack.config.js
112
+ module.exports = {
113
+ module: {
114
+ rules: [
115
+ { test: /\.jps$/, use: 'jpsx-loader' }
116
+ ]
117
+ }
118
+ };
119
+ ```
120
+
121
+ ---
122
+
123
+ ## 🌟 Support Us
124
+
125
+ We are live on Product Hunt! If you like JPS, please support us:
126
+
127
+ <div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; border: 1px solid rgb(224, 224, 224); border-radius: 12px; padding: 20px; max-width: 500px; background: rgb(255, 255, 255); box-shadow: rgba(0, 0, 0, 0.05) 0px 2px 8px;">
128
+ <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 12px;">
129
+ <img alt="JPS" src="https://ph-files.imgix.net/99b42643-283d-47de-970f-27ae2be5a99a.jpeg?auto=format&fit=crop&w=80&h=80" style="width: 64px; height: 64px; border-radius: 8px; object-fit: cover; flex-shrink: 0;">
130
+ <div style="flex: 1 1 0%; min-width: 0px;">
131
+ <h3 style="margin: 0px; font-size: 18px; font-weight: 600; color: rgb(26, 26, 26); line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">JPS</h3>
132
+ <p style="margin: 4px 0px 0px; font-size: 14px; color: rgb(102, 102, 102); line-height: 1.4; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;">New Programming Language | Write Python-like in Javascript</p>
133
+ </div>
134
+ </div>
135
+ <a href="https://www.producthunt.com/products/jps?embed=true&utm_source=embed&utm_medium=post_embed" target="_blank" rel="noopener" style="display: inline-flex; align-items: center; gap: 4px; margin-top: 12px; padding: 8px 16px; background: rgb(255, 97, 84); color: rgb(255, 255, 255); text-decoration: none; border-radius: 8px; font-size: 14px; font-weight: 600;">Check it out on Product Hunt →</a>
136
+ </div>
137
+
138
+ ---
139
+
140
+ ## 📄 License
141
+ ISC - See [LICENSE](LICENSE)
142
+
143
+ **Made with ❤️ by Loaii abdalslam**
@@ -75,11 +75,11 @@ describe("compile() - Runtime Modes", () => {
75
75
  const source = 'print("test")';
76
76
  test("should use external runtime by default", () => {
77
77
  const result = compile(source);
78
- expect(result.code).toContain("./jps_runtime.js");
78
+ expect(result.code).toContain("jps/runtime");
79
79
  });
80
80
  test("should use external runtime mode", () => {
81
81
  const result = compile(source, { runtimeMode: "external" });
82
- expect(result.code).toContain("jps_runtime");
82
+ expect(result.code).toContain("jps/runtime");
83
83
  });
84
84
  test("should inline runtime code", () => {
85
85
  const result = compile(source, { runtimeMode: "inline" });