english-lang 0.1.1 → 0.2.0
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 +97 -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,90 @@ 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
|
+
// ── Init ──────────────────────────────────────────────────────
|
|
81
|
+
function initProject(name) {
|
|
82
|
+
const projectDir = path.resolve(name);
|
|
83
|
+
if (fs.existsSync(projectDir)) {
|
|
84
|
+
console.error(`[engc] Directory already exists: ${projectDir}`);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
console.log(`[engc] Creating project ${name} ...`);
|
|
88
|
+
// Create folder structure
|
|
89
|
+
const screensDir = path.join(projectDir, 'screens');
|
|
90
|
+
const rnSrcDir = path.join(projectDir, 'rn', 'src');
|
|
91
|
+
fs.mkdirSync(screensDir, { recursive: true });
|
|
92
|
+
fs.mkdirSync(rnSrcDir, { recursive: true });
|
|
93
|
+
// Write starter .eng file
|
|
94
|
+
fs.writeFileSync(path.join(screensDir, 'HomeScreen.eng'), STARTER_ENG, 'utf8');
|
|
95
|
+
console.log('[engc] Created screens/HomeScreen.eng');
|
|
96
|
+
// Write root package.json
|
|
97
|
+
const pkg = {
|
|
98
|
+
name,
|
|
99
|
+
version: '0.0.1',
|
|
100
|
+
private: true,
|
|
101
|
+
scripts: {
|
|
102
|
+
'compile': 'engc compile screens/ --out rn/src/',
|
|
103
|
+
'watch': 'engc watch screens/ --out rn/src/',
|
|
104
|
+
},
|
|
105
|
+
devDependencies: {
|
|
106
|
+
'english-lang': 'latest',
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
fs.writeFileSync(path.join(projectDir, 'package.json'), JSON.stringify(pkg, null, 2) + '\n', 'utf8');
|
|
110
|
+
console.log('[engc] Created package.json');
|
|
111
|
+
// Scaffold React Native app inside rn/
|
|
112
|
+
console.log('[engc] Scaffolding React Native app in rn/ (this takes a minute) ...');
|
|
113
|
+
try {
|
|
114
|
+
childProcess.execSync('npx @react-native-community/cli init rn --skip-install', { cwd: projectDir, stdio: 'inherit' });
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
console.error('[engc] Failed to scaffold React Native app. Make sure Node and npx are available.');
|
|
118
|
+
process.exit(1);
|
|
119
|
+
}
|
|
120
|
+
// Install rn dependencies
|
|
121
|
+
console.log('[engc] Installing React Native dependencies ...');
|
|
122
|
+
childProcess.execSync('npm install', { cwd: path.join(projectDir, 'rn'), stdio: 'inherit' });
|
|
123
|
+
// Compile the starter screen
|
|
124
|
+
console.log('[engc] Compiling starter screens ...');
|
|
125
|
+
compileDir(screensDir, rnSrcDir);
|
|
126
|
+
console.log(`
|
|
127
|
+
[engc] Done! Your project is ready.
|
|
128
|
+
|
|
129
|
+
cd ${name}
|
|
130
|
+
npm run watch ← recompiles .eng files on save
|
|
131
|
+
cd rn && npx react-native run-ios
|
|
132
|
+
`);
|
|
133
|
+
}
|
|
134
|
+
// ── Compile helpers ───────────────────────────────────────────
|
|
52
135
|
function compileFile(inputPath, outDir) {
|
|
53
136
|
const source = fs.readFileSync(inputPath, 'utf8');
|
|
54
137
|
const sourceFile = path.basename(inputPath);
|
|
@@ -80,7 +163,6 @@ function compileDir(srcDir, outDir) {
|
|
|
80
163
|
}
|
|
81
164
|
}
|
|
82
165
|
function watchDir(srcDir, outDir) {
|
|
83
|
-
// Run once on start
|
|
84
166
|
compileDir(srcDir, outDir);
|
|
85
167
|
console.log(`[engc] Watching ${srcDir} ...`);
|
|
86
168
|
fs.watch(srcDir, { recursive: false }, (event, filename) => {
|
|
@@ -100,6 +182,7 @@ function main() {
|
|
|
100
182
|
English Compiler (engc)
|
|
101
183
|
|
|
102
184
|
Usage:
|
|
185
|
+
engc init <name> scaffold a new project
|
|
103
186
|
engc <file.eng> compile → .tsx alongside source
|
|
104
187
|
engc <file.eng> --out <dir> compile → specific output directory
|
|
105
188
|
engc <file.eng> -o <output.tsx> compile → specific output file
|
|
@@ -110,14 +193,24 @@ Usage:
|
|
|
110
193
|
engc watch <dir> [--out <dir>] watch directory, recompile on save
|
|
111
194
|
|
|
112
195
|
Examples:
|
|
113
|
-
engc
|
|
196
|
+
engc init my-app
|
|
114
197
|
engc screens/HomeScreen.eng --out rn/src/
|
|
115
198
|
engc compile screens/ --out rn/src/
|
|
116
199
|
engc watch screens/ --out rn/src/
|
|
117
200
|
`.trim());
|
|
118
201
|
process.exit(0);
|
|
119
202
|
}
|
|
120
|
-
//
|
|
203
|
+
// engc init <name>
|
|
204
|
+
if (args[0] === 'init') {
|
|
205
|
+
const name = args[1];
|
|
206
|
+
if (!name) {
|
|
207
|
+
console.error('[engc] Usage: engc init <project-name>');
|
|
208
|
+
process.exit(1);
|
|
209
|
+
}
|
|
210
|
+
initProject(name);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
// engc compile <dir> | engc watch <dir>
|
|
121
214
|
if (args[0] === 'compile' || args[0] === 'watch') {
|
|
122
215
|
const cmd = args[0];
|
|
123
216
|
const srcDir = args[1] ? path.resolve(args[1]) : process.cwd();
|
|
@@ -151,7 +244,6 @@ Examples:
|
|
|
151
244
|
}
|
|
152
245
|
const source = fs.readFileSync(inputPath, 'utf8');
|
|
153
246
|
const sourceFile = path.basename(inputPath);
|
|
154
|
-
// Debug modes — need raw Lexer/Parser
|
|
155
247
|
if (dumpTokens || dumpAST) {
|
|
156
248
|
const { Lexer } = require('../src/lexer/Lexer');
|
|
157
249
|
const { Parser } = require('../src/parser/Parser');
|