cajyu 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.
Files changed (3) hide show
  1. package/README.md +59 -90
  2. package/bin/cajyu.js +157 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,57 +2,74 @@
2
2
 
3
3
  **A clean, practical programming language that transpiles to JavaScript.**
4
4
 
5
- Cajyu is designed for people who want a simpler syntax without leaving the JavaScript ecosystem. Write expressive code, get real JavaScript output, and use a growing set of official libraries.
5
+ Cajyu gives you a simpler, more expressive syntax while staying fully compatible with the JavaScript ecosystem.
6
6
 
7
7
  [![npm](https://img.shields.io/badge/npm-cajyu-blue)](https://www.npmjs.com/package/cajyu)
8
8
  [![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)
9
+ [![Version](https://img.shields.io/badge/version-1.1.0-brightgreen)](package.json)
9
10
 
10
11
  ---
11
12
 
12
13
  ## Features
13
14
 
14
- - **Familiar yet cleaner syntax** — variables, functions, classes, control flow, and loops that feel natural
15
- - **Transpiles to modern JavaScript** — runs anywhere Node.js runs
16
- - **Real HTTP server** — built-in `Server` class with POST handlers, sleep/wake, and static files
17
- - **Official libraries** — `serial`, `fs`, `math`, `http` (and more coming)
18
- - **Optional typing** — runtime type checks with `var x:Number = 10`
19
- - **Async support** — `sync fn` and `wait`
20
- - **One-liners & stacking** — concise style when you want it
21
- - **CLI** — `cajyu init`, `cajyu inst`, `cajyu run`
15
+ - Clean syntax for variables, functions, classes, loops and conditionals
16
+ - Transpiles to modern JavaScript
17
+ - Real HTTP server with POST handlers, sleep/wake
18
+ - Official libraries: `serial`, `fs`, `math`, `http`, `websocket`
19
+ - Optional runtime typing
20
+ - Async with `sync fn` and `wait`
21
+ - One-liners and stacking
22
+ - CLI with flags and multiple commands
22
23
 
23
24
  ---
24
25
 
25
26
  ## Quick Start
26
27
 
27
28
  ```bash
28
- # Install the CLI (once published)
29
+ # After publishing
29
30
  npm install -g cajyu
30
31
 
31
- # Or run directly from this repo
32
+ # Or from source
32
33
  node bin/cajyu.js --help
33
34
  ```
34
35
 
35
- Create a new project:
36
-
37
36
  ```bash
38
37
  cajyu init
38
+ cajyu inst serial
39
+ cajyu inst http
40
+ cajyu run examples/fatorial.cjy
39
41
  ```
40
42
 
41
- Run a file:
43
+ ---
42
44
 
43
- ```bash
44
- cajyu run examples/fatorial.cjy
45
+ ## CLI
46
+
47
+ ```
48
+ cajyu [flags]
49
+ cajyu <command> [options]
45
50
  ```
46
51
 
52
+ | Command | Description |
53
+ |------------------|--------------------------------------|
54
+ | `init` | Create a new project |
55
+ | `inst <lib>` | Install a library from CajyuLibs |
56
+ | `run <file.cjy>` | Compile and run a file |
57
+ | `list` | List installed libraries |
58
+ | `update` | Update libraries (planned) |
59
+
60
+ | Flag | Description |
61
+ |------------------|----------------------|
62
+ | `-h, --help` | Show help |
63
+ | `-v, --version` | Show version |
64
+
47
65
  ---
48
66
 
49
- ## Syntax Overview
67
+ ## Syntax
50
68
 
51
69
  ### Variables
52
70
  ```cajyu
53
71
  var name = "Cajyu"
54
72
  var age:Number = 17
55
- var items = [1, 2, 3]
56
73
  ```
57
74
 
58
75
  ### Functions
@@ -60,13 +77,9 @@ var items = [1, 2, 3]
60
77
  fn add a, b {
61
78
  return a + b
62
79
  }
63
-
64
- fn double x {
65
- return x * 2
66
- }
67
80
  ```
68
81
 
69
- ### Control Flow
82
+ ### Control flow & loops
70
83
  ```cajyu
71
84
  if x > 10 {
72
85
  print("big")
@@ -75,17 +88,10 @@ if x > 10 {
75
88
  } else {
76
89
  print("small")
77
90
  }
78
- ```
79
91
 
80
- ### Loops
81
- ```cajyu
82
92
  for i in range(10) {
83
93
  print(i)
84
94
  }
85
-
86
- while x < 100 {
87
- x = x * 2
88
- }
89
95
  ```
90
96
 
91
97
  ### Classes
@@ -96,26 +102,14 @@ class Person {
96
102
  Self.age = age
97
103
  }
98
104
  greet {
99
- return "Hello, I'm " + Self.name
105
+ return "Hello, " + Self.name
100
106
  }
101
107
  }
102
-
103
- var p = new Person("Ana", 17)
104
- print(p.greet())
105
- ```
106
-
107
- ### Async
108
- ```cajyu
109
- sync fn fetchData {
110
- wait someAsyncCall()
111
- return result
112
- }
113
108
  ```
114
109
 
115
- ### HTTP Server
110
+ ### HTTP
116
111
  ```cajyu
117
112
  import Server from CajyuLibs.http
118
- import print from CajyuLibs.serial
119
113
 
120
114
  var server = new Server(3000)
121
115
 
@@ -123,10 +117,20 @@ server.post(fn b {
123
117
  if !b.a and !b.b {
124
118
  return { code: 400 }
125
119
  }
126
- return {
127
- code: 200,
128
- result: b.a + b.b
129
- }
120
+ return { code: 200, result: b.a + b.b }
121
+ })
122
+ ```
123
+
124
+ ### WebSocket
125
+ ```cajyu
126
+ import WS from CajyuLibs.websocket
127
+
128
+ var wss = new WS.Server(8080)
129
+ wss.on("connection", fn client {
130
+ print("client connected")
131
+ })
132
+ wss.on("message", fn msg, client {
133
+ wss.broadcast(msg)
130
134
  })
131
135
  ```
132
136
 
@@ -134,56 +138,25 @@ server.post(fn b {
134
138
 
135
139
  ## Libraries
136
140
 
137
- Official libraries live in the [CajyuLibs](https://github.com/abs-js/CajyuLibs) repository.
138
-
139
- Install a library:
141
+ Official libraries: https://github.com/abs-js/CajyuLibs
140
142
 
141
143
  ```bash
142
144
  cajyu inst serial
145
+ cajyu inst fs
146
+ cajyu inst math
143
147
  cajyu inst http
144
- ```
145
-
146
- Import in your code:
147
-
148
- ```cajyu
149
- import print from CajyuLibs.serial
150
- import Server from CajyuLibs.http
151
- ```
152
-
153
- ---
154
-
155
- ## CLI Commands
156
-
157
- | Command | Description |
158
- |---------|-------------|
159
- | `cajyu init` | Create a new project (`package.json` + structure) |
160
- | `cajyu inst <name>` | Install a library from CajyuLibs |
161
- | `cajyu run <file.cjy>` | Compile and run a Cajyu file |
162
-
163
- ---
164
-
165
- ## Project Structure
166
-
167
- ```
168
- Cajyu/
169
- ├── bin/cajyu.js # CLI entry point
170
- ├── src/compiler.js # Transpiler
171
- ├── examples/ # Working examples
172
- │ ├── fatorial.cjy
173
- │ ├── classe.cjy
174
- │ └── servidor-post.cjy
175
- └── package.json
148
+ cajyu inst websocket
176
149
  ```
177
150
 
178
151
  ---
179
152
 
180
153
  ## Contributing
181
154
 
182
- Cajyu is early but intentional. Pull requests are welcome — especially for:
155
+ Pull requests are welcome. Priority areas:
183
156
 
184
- - A proper parser (currently regex-based)
157
+ - A proper parser (current one is regex-based)
185
158
  - More language features
186
- - New official libraries
159
+ - Additional libraries
187
160
  - Better error messages
188
161
 
189
162
  ---
@@ -191,7 +164,3 @@ Cajyu is early but intentional. Pull requests are welcome — especially for:
191
164
  ## License
192
165
 
193
166
  MIT
194
-
195
- ---
196
-
197
- **Built for people who like clean code and real results.**
package/bin/cajyu.js ADDED
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ import { execSync } from 'child_process';
6
+ import { compileAndRun } from '../src/compiler.js';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ const CAJYULIBS_REPO = 'https://github.com/abs-js/CajyuLibs.git';
12
+ const VERSION = '1.1.0';
13
+
14
+ const args = process.argv.slice(2);
15
+ const command = args[0];
16
+ const flags = args.filter(a => a.startsWith('-'));
17
+
18
+ function hasFlag(...names) {
19
+ return names.some(n => flags.includes(n) || flags.includes(`-${n}`) || flags.includes(`--${n}`));
20
+ }
21
+
22
+ async function main() {
23
+ if (hasFlag('v', 'version', '--version')) {
24
+ console.log(`Cajyu ${VERSION}`);
25
+ return;
26
+ }
27
+
28
+ if (hasFlag('h', 'help', '--help') || !command) {
29
+ showHelp();
30
+ return;
31
+ }
32
+
33
+ if (command === 'init') {
34
+ initProject();
35
+ } else if (command === 'inst' || command === 'install') {
36
+ const libName = args[1];
37
+ if (!libName || libName.startsWith('-')) {
38
+ console.error('Usage: cajyu inst <library>');
39
+ process.exit(1);
40
+ }
41
+ await installLib(libName);
42
+ } else if (command === 'run') {
43
+ const file = args.find(a => a.endsWith('.cjy') || (a !== 'run' && !a.startsWith('-')));
44
+ if (!file) {
45
+ console.error('Usage: cajyu run <file.cjy>');
46
+ process.exit(1);
47
+ }
48
+ await compileAndRun(file);
49
+ } else if (command === 'list') {
50
+ listInstalled();
51
+ } else if (command === 'update') {
52
+ console.log('Updating is not yet implemented. Re-run `cajyu inst <lib>` after deleting the folder.');
53
+ } else {
54
+ console.error(`Unknown command: ${command}`);
55
+ showHelp();
56
+ process.exit(1);
57
+ }
58
+ }
59
+
60
+ function showHelp() {
61
+ console.log(`
62
+ Cajyu ${VERSION} — a custom programming language that transpiles to JavaScript
63
+
64
+ Usage:
65
+ cajyu [flags]
66
+ cajyu <command> [options]
67
+
68
+ Commands:
69
+ init Create a new Cajyu project
70
+ inst <lib> Install a library from CajyuLibs
71
+ run <file.cjy> Compile and execute a Cajyu file
72
+ list List installed libraries
73
+ update Update installed libraries (coming soon)
74
+
75
+ Flags:
76
+ -h, --help Show this help
77
+ -v, --version Show version
78
+
79
+ Examples:
80
+ cajyu init
81
+ cajyu inst http
82
+ cajyu inst websocket
83
+ cajyu run examples/fatorial.cjy
84
+ cajyu list
85
+ `);
86
+ }
87
+
88
+ function initProject() {
89
+ const pkg = {
90
+ name: "cajyu-project",
91
+ version: "1.0.0",
92
+ description: "Cajyu project",
93
+ main: "index.cjy",
94
+ type: "module"
95
+ };
96
+ fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));
97
+ if (!fs.existsSync('CajyuLibs')) fs.mkdirSync('CajyuLibs');
98
+ console.log('Cajyu project initialized.');
99
+ }
100
+
101
+ async function installLib(libName) {
102
+ console.log(`Installing "${libName}" from CajyuLibs...`);
103
+
104
+ const targetDir = path.join(process.cwd(), 'CajyuLibs', libName);
105
+ if (fs.existsSync(targetDir)) {
106
+ console.log(`Library "${libName}" already installed.`);
107
+ return;
108
+ }
109
+
110
+ const tmpDir = path.join('/tmp', `cajyulibs-${Date.now()}`);
111
+ try {
112
+ console.log('Cloning CajyuLibs repository...');
113
+ execSync(`git clone --depth 1 ${CAJYULIBS_REPO} ${tmpDir}`, { stdio: 'inherit' });
114
+
115
+ const sourceLib = path.join(tmpDir, libName);
116
+ if (!fs.existsSync(sourceLib)) {
117
+ console.error(`Library "${libName}" not found in CajyuLibs.`);
118
+ process.exit(1);
119
+ }
120
+
121
+ fs.mkdirSync(path.dirname(targetDir), { recursive: true });
122
+ fs.cpSync(sourceLib, targetDir, { recursive: true });
123
+
124
+ const pkgPath = path.join(targetDir, 'package.json');
125
+ if (fs.existsSync(pkgPath)) {
126
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
127
+ if (pkg.dependencies && Object.keys(pkg.dependencies).length > 0) {
128
+ console.log('Installing library dependencies...');
129
+ execSync('npm install', { cwd: targetDir, stdio: 'inherit' });
130
+ }
131
+ }
132
+
133
+ console.log(`✓ Library "${libName}" installed to CajyuLibs/${libName}/`);
134
+ } catch (err) {
135
+ console.error('Failed to install library:', err.message);
136
+ process.exit(1);
137
+ } finally {
138
+ try { fs.rmSync(tmpDir, { recursive: true, force: true }); } catch {}
139
+ }
140
+ }
141
+
142
+ function listInstalled() {
143
+ const libsDir = path.join(process.cwd(), 'CajyuLibs');
144
+ if (!fs.existsSync(libsDir)) {
145
+ console.log('No libraries installed yet.');
146
+ return;
147
+ }
148
+ const libs = fs.readdirSync(libsDir).filter(d => fs.statSync(path.join(libsDir, d)).isDirectory());
149
+ if (libs.length === 0) {
150
+ console.log('No libraries installed.');
151
+ } else {
152
+ console.log('Installed libraries:');
153
+ libs.forEach(l => console.log(` - ${l}`));
154
+ }
155
+ }
156
+
157
+ main().catch(console.error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cajyu",
3
- "version": "1.0.0",
3
+ "version": "1.0.01",
4
4
  "description": "Cajyu programming language - a custom language that compiles to JavaScript",
5
5
  "main": "src/compiler.js",
6
6
  "bin": {