english-lang 0.1.1 → 0.2.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/README.md +9 -17
- package/dist/cli/engc.js +141 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,10 +17,10 @@ npm install -g english-lang
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
#
|
|
21
|
-
engc
|
|
20
|
+
# Scaffold a new project (React Native app + screens/ folder)
|
|
21
|
+
engc init my-app
|
|
22
22
|
|
|
23
|
-
# Compile a single file
|
|
23
|
+
# Compile a single file
|
|
24
24
|
engc screens/HomeScreen.eng --out rn/src/
|
|
25
25
|
|
|
26
26
|
# Compile all .eng files in a directory
|
|
@@ -108,22 +108,14 @@ my-app/
|
|
|
108
108
|
**Quick start:**
|
|
109
109
|
|
|
110
110
|
```bash
|
|
111
|
-
#
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
npm install --save-dev english-lang
|
|
115
|
-
|
|
116
|
-
# 2. Create the React Native app
|
|
117
|
-
npx @react-native-community/cli init rn
|
|
111
|
+
# One command sets everything up
|
|
112
|
+
engc init my-app
|
|
113
|
+
cd my-app
|
|
118
114
|
|
|
119
|
-
#
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
# 4. Write .eng files in screens/
|
|
123
|
-
# 5. Watch and compile
|
|
124
|
-
engc watch screens/ --out rn/src/
|
|
115
|
+
# Watch .eng files and compile to rn/src/ on every save
|
|
116
|
+
npm run watch
|
|
125
117
|
|
|
126
|
-
#
|
|
118
|
+
# In a separate terminal, run the app
|
|
127
119
|
cd rn && npx react-native run-ios
|
|
128
120
|
```
|
|
129
121
|
|
package/dist/cli/engc.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// engc — English (.eng) compiler CLI
|
|
5
5
|
//
|
|
6
6
|
// Usage:
|
|
7
|
+
// engc init <name> scaffold a new project
|
|
7
8
|
// engc <file.eng> compile → .tsx alongside source
|
|
8
9
|
// engc <file.eng> --out <dir> compile → specific output dir
|
|
9
10
|
// engc <file.eng> -o <output.tsx> compile → specific output file
|
|
@@ -47,8 +48,127 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
47
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
49
|
const fs = __importStar(require("fs"));
|
|
49
50
|
const path = __importStar(require("path"));
|
|
51
|
+
const childProcess = __importStar(require("child_process"));
|
|
50
52
|
const index_1 = require("../index");
|
|
51
|
-
// ──
|
|
53
|
+
// ── Starter .eng file ─────────────────────────────────────────
|
|
54
|
+
const STARTER_ENG = `\
|
|
55
|
+
screen HomeScreen:
|
|
56
|
+
title is "Home"
|
|
57
|
+
|
|
58
|
+
state:
|
|
59
|
+
message is "Hello from English!"
|
|
60
|
+
count is 0
|
|
61
|
+
|
|
62
|
+
when screen opens:
|
|
63
|
+
set count to 1
|
|
64
|
+
|
|
65
|
+
when "Say Hello" is pressed:
|
|
66
|
+
set message to "Hello!"
|
|
67
|
+
|
|
68
|
+
when "Reset" is pressed:
|
|
69
|
+
set message to "Hello from English!"
|
|
70
|
+
set count to 0
|
|
71
|
+
|
|
72
|
+
layout:
|
|
73
|
+
vertical stack spacing 16 padding 16:
|
|
74
|
+
show "Welcome" as heading
|
|
75
|
+
show message as body
|
|
76
|
+
show count
|
|
77
|
+
button "Say Hello"
|
|
78
|
+
button "Reset"
|
|
79
|
+
`;
|
|
80
|
+
// ── Dev ───────────────────────────────────────────────────────
|
|
81
|
+
function devProject(projectDir) {
|
|
82
|
+
const screensDir = path.join(projectDir, 'screens');
|
|
83
|
+
const rnDir = path.join(projectDir, 'rn');
|
|
84
|
+
const rnSrcDir = path.join(rnDir, 'src');
|
|
85
|
+
if (!fs.existsSync(screensDir) || !fs.existsSync(rnDir)) {
|
|
86
|
+
console.error('[engc] Not an english-lang project. Run engc init <name> first.');
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
console.log('[engc] Starting dev mode ...\n');
|
|
90
|
+
// Spawn Metro bundler
|
|
91
|
+
const metro = childProcess.spawn('npx', ['react-native', 'start'], {
|
|
92
|
+
cwd: rnDir,
|
|
93
|
+
stdio: 'inherit',
|
|
94
|
+
shell: true,
|
|
95
|
+
});
|
|
96
|
+
metro.on('error', (err) => {
|
|
97
|
+
console.error('[engc] Metro error:', err.message);
|
|
98
|
+
});
|
|
99
|
+
// Watch .eng files
|
|
100
|
+
compileDir(screensDir, rnSrcDir);
|
|
101
|
+
console.log(`[engc] Watching screens/ ...\n`);
|
|
102
|
+
fs.watch(screensDir, { recursive: false }, (event, filename) => {
|
|
103
|
+
if (!filename || !filename.endsWith('.eng'))
|
|
104
|
+
return;
|
|
105
|
+
const filePath = path.join(screensDir, filename);
|
|
106
|
+
if (!fs.existsSync(filePath))
|
|
107
|
+
return;
|
|
108
|
+
compileFile(filePath, rnSrcDir);
|
|
109
|
+
});
|
|
110
|
+
// Keep alive — exit both on Ctrl+C
|
|
111
|
+
process.on('SIGINT', () => {
|
|
112
|
+
metro.kill();
|
|
113
|
+
process.exit(0);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
// ── Init ──────────────────────────────────────────────────────
|
|
117
|
+
function initProject(name) {
|
|
118
|
+
const projectDir = path.resolve(name);
|
|
119
|
+
if (fs.existsSync(projectDir)) {
|
|
120
|
+
console.error(`[engc] Directory already exists: ${projectDir}`);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
console.log(`[engc] Creating project ${name} ...`);
|
|
124
|
+
// Create folder structure
|
|
125
|
+
const screensDir = path.join(projectDir, 'screens');
|
|
126
|
+
const rnSrcDir = path.join(projectDir, 'rn', 'src');
|
|
127
|
+
fs.mkdirSync(screensDir, { recursive: true });
|
|
128
|
+
fs.mkdirSync(rnSrcDir, { recursive: true });
|
|
129
|
+
// Write starter .eng file
|
|
130
|
+
fs.writeFileSync(path.join(screensDir, 'HomeScreen.eng'), STARTER_ENG, 'utf8');
|
|
131
|
+
console.log('[engc] Created screens/HomeScreen.eng');
|
|
132
|
+
// Write root package.json
|
|
133
|
+
const pkg = {
|
|
134
|
+
name,
|
|
135
|
+
version: '0.0.1',
|
|
136
|
+
private: true,
|
|
137
|
+
scripts: {
|
|
138
|
+
'dev': 'engc dev',
|
|
139
|
+
'compile': 'engc compile screens/ --out rn/src/',
|
|
140
|
+
'watch': 'engc watch screens/ --out rn/src/',
|
|
141
|
+
},
|
|
142
|
+
devDependencies: {
|
|
143
|
+
'english-lang': 'latest',
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
fs.writeFileSync(path.join(projectDir, 'package.json'), JSON.stringify(pkg, null, 2) + '\n', 'utf8');
|
|
147
|
+
console.log('[engc] Created package.json');
|
|
148
|
+
// Scaffold React Native app inside rn/
|
|
149
|
+
console.log('[engc] Scaffolding React Native app in rn/ (this takes a minute) ...');
|
|
150
|
+
try {
|
|
151
|
+
childProcess.execSync('npx @react-native-community/cli init rn --skip-install', { cwd: projectDir, stdio: 'inherit' });
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
console.error('[engc] Failed to scaffold React Native app. Make sure Node and npx are available.');
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
// Install rn dependencies
|
|
158
|
+
console.log('[engc] Installing React Native dependencies ...');
|
|
159
|
+
childProcess.execSync('npm install', { cwd: path.join(projectDir, 'rn'), stdio: 'inherit' });
|
|
160
|
+
// Compile the starter screen
|
|
161
|
+
console.log('[engc] Compiling starter screens ...');
|
|
162
|
+
compileDir(screensDir, rnSrcDir);
|
|
163
|
+
console.log(`
|
|
164
|
+
[engc] Done! Your project is ready.
|
|
165
|
+
|
|
166
|
+
cd ${name}
|
|
167
|
+
npm run dev ← starts Metro + watches .eng files
|
|
168
|
+
cd rn && npx react-native run-ios
|
|
169
|
+
`);
|
|
170
|
+
}
|
|
171
|
+
// ── Compile helpers ───────────────────────────────────────────
|
|
52
172
|
function compileFile(inputPath, outDir) {
|
|
53
173
|
const source = fs.readFileSync(inputPath, 'utf8');
|
|
54
174
|
const sourceFile = path.basename(inputPath);
|
|
@@ -80,7 +200,6 @@ function compileDir(srcDir, outDir) {
|
|
|
80
200
|
}
|
|
81
201
|
}
|
|
82
202
|
function watchDir(srcDir, outDir) {
|
|
83
|
-
// Run once on start
|
|
84
203
|
compileDir(srcDir, outDir);
|
|
85
204
|
console.log(`[engc] Watching ${srcDir} ...`);
|
|
86
205
|
fs.watch(srcDir, { recursive: false }, (event, filename) => {
|
|
@@ -100,6 +219,8 @@ function main() {
|
|
|
100
219
|
English Compiler (engc)
|
|
101
220
|
|
|
102
221
|
Usage:
|
|
222
|
+
engc init <name> scaffold a new project
|
|
223
|
+
engc dev start Metro + watch .eng files
|
|
103
224
|
engc <file.eng> compile → .tsx alongside source
|
|
104
225
|
engc <file.eng> --out <dir> compile → specific output directory
|
|
105
226
|
engc <file.eng> -o <output.tsx> compile → specific output file
|
|
@@ -110,14 +231,30 @@ Usage:
|
|
|
110
231
|
engc watch <dir> [--out <dir>] watch directory, recompile on save
|
|
111
232
|
|
|
112
233
|
Examples:
|
|
113
|
-
engc
|
|
234
|
+
engc init my-app
|
|
235
|
+
engc dev
|
|
114
236
|
engc screens/HomeScreen.eng --out rn/src/
|
|
115
237
|
engc compile screens/ --out rn/src/
|
|
116
238
|
engc watch screens/ --out rn/src/
|
|
117
239
|
`.trim());
|
|
118
240
|
process.exit(0);
|
|
119
241
|
}
|
|
120
|
-
//
|
|
242
|
+
// engc dev
|
|
243
|
+
if (args[0] === 'dev') {
|
|
244
|
+
devProject(process.cwd());
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
// engc init <name>
|
|
248
|
+
if (args[0] === 'init') {
|
|
249
|
+
const name = args[1];
|
|
250
|
+
if (!name) {
|
|
251
|
+
console.error('[engc] Usage: engc init <project-name>');
|
|
252
|
+
process.exit(1);
|
|
253
|
+
}
|
|
254
|
+
initProject(name);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
// engc compile <dir> | engc watch <dir>
|
|
121
258
|
if (args[0] === 'compile' || args[0] === 'watch') {
|
|
122
259
|
const cmd = args[0];
|
|
123
260
|
const srcDir = args[1] ? path.resolve(args[1]) : process.cwd();
|
|
@@ -151,7 +288,6 @@ Examples:
|
|
|
151
288
|
}
|
|
152
289
|
const source = fs.readFileSync(inputPath, 'utf8');
|
|
153
290
|
const sourceFile = path.basename(inputPath);
|
|
154
|
-
// Debug modes — need raw Lexer/Parser
|
|
155
291
|
if (dumpTokens || dumpAST) {
|
|
156
292
|
const { Lexer } = require('../src/lexer/Lexer');
|
|
157
293
|
const { Parser } = require('../src/parser/Parser');
|