english-lang 0.2.0 → 0.2.2
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/dist/cli/engc.js +71 -20
- package/package.json +1 -1
package/dist/cli/engc.js
CHANGED
|
@@ -77,6 +77,42 @@ screen HomeScreen:
|
|
|
77
77
|
button "Say Hello"
|
|
78
78
|
button "Reset"
|
|
79
79
|
`;
|
|
80
|
+
// ── Dev ───────────────────────────────────────────────────────
|
|
81
|
+
function devProject(projectDir = process.cwd()) {
|
|
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
|
+
}
|
|
80
116
|
// ── Init ──────────────────────────────────────────────────────
|
|
81
117
|
function initProject(name) {
|
|
82
118
|
const projectDir = path.resolve(name);
|
|
@@ -84,12 +120,11 @@ function initProject(name) {
|
|
|
84
120
|
console.error(`[engc] Directory already exists: ${projectDir}`);
|
|
85
121
|
process.exit(1);
|
|
86
122
|
}
|
|
87
|
-
console.log(`[engc] Creating project ${name}
|
|
88
|
-
// Create folder
|
|
123
|
+
console.log(`[engc] Creating project ${name} ...\n`);
|
|
124
|
+
// Create screens folder
|
|
89
125
|
const screensDir = path.join(projectDir, 'screens');
|
|
90
126
|
const rnSrcDir = path.join(projectDir, 'rn', 'src');
|
|
91
127
|
fs.mkdirSync(screensDir, { recursive: true });
|
|
92
|
-
fs.mkdirSync(rnSrcDir, { recursive: true });
|
|
93
128
|
// Write starter .eng file
|
|
94
129
|
fs.writeFileSync(path.join(screensDir, 'HomeScreen.eng'), STARTER_ENG, 'utf8');
|
|
95
130
|
console.log('[engc] Created screens/HomeScreen.eng');
|
|
@@ -99,6 +134,7 @@ function initProject(name) {
|
|
|
99
134
|
version: '0.0.1',
|
|
100
135
|
private: true,
|
|
101
136
|
scripts: {
|
|
137
|
+
'dev': 'engc dev',
|
|
102
138
|
'compile': 'engc compile screens/ --out rn/src/',
|
|
103
139
|
'watch': 'engc watch screens/ --out rn/src/',
|
|
104
140
|
},
|
|
@@ -107,29 +143,37 @@ function initProject(name) {
|
|
|
107
143
|
},
|
|
108
144
|
};
|
|
109
145
|
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
|
|
112
|
-
console.log('[engc] Scaffolding React Native app in rn/
|
|
146
|
+
console.log('[engc] Created package.json\n');
|
|
147
|
+
// Scaffold latest React Native app
|
|
148
|
+
console.log('[engc] Scaffolding latest React Native app in rn/ ...');
|
|
113
149
|
try {
|
|
114
|
-
childProcess.execSync('npx @react-native-community/cli init rn
|
|
150
|
+
childProcess.execSync('npx @react-native-community/cli@latest init rn', { cwd: projectDir, stdio: 'inherit' });
|
|
115
151
|
}
|
|
116
152
|
catch {
|
|
117
|
-
console.error('[engc] Failed to scaffold React Native app.
|
|
153
|
+
console.error('[engc] Failed to scaffold React Native app.');
|
|
118
154
|
process.exit(1);
|
|
119
155
|
}
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
156
|
+
// Pod install for iOS
|
|
157
|
+
const iosDir = path.join(projectDir, 'rn', 'ios');
|
|
158
|
+
if (fs.existsSync(iosDir)) {
|
|
159
|
+
console.log('\n[engc] Installing iOS CocoaPods ...');
|
|
160
|
+
try {
|
|
161
|
+
childProcess.execSync('bundle install && bundle exec pod install', {
|
|
162
|
+
cwd: iosDir,
|
|
163
|
+
stdio: 'inherit',
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
console.warn('[engc] Pod install failed — run it manually: cd rn/ios && pod install');
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Compile starter screens into rn/src/
|
|
171
|
+
fs.mkdirSync(rnSrcDir, { recursive: true });
|
|
172
|
+
console.log('\n[engc] Compiling starter screens ...');
|
|
125
173
|
compileDir(screensDir, rnSrcDir);
|
|
126
|
-
console.log(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
cd ${name}
|
|
130
|
-
npm run watch ← recompiles .eng files on save
|
|
131
|
-
cd rn && npx react-native run-ios
|
|
132
|
-
`);
|
|
174
|
+
console.log('\n[engc] All done! Starting Metro + eng watcher ...\n');
|
|
175
|
+
// Auto-start dev mode immediately
|
|
176
|
+
devProject(projectDir);
|
|
133
177
|
}
|
|
134
178
|
// ── Compile helpers ───────────────────────────────────────────
|
|
135
179
|
function compileFile(inputPath, outDir) {
|
|
@@ -183,6 +227,7 @@ English Compiler (engc)
|
|
|
183
227
|
|
|
184
228
|
Usage:
|
|
185
229
|
engc init <name> scaffold a new project
|
|
230
|
+
engc dev start Metro + watch .eng files
|
|
186
231
|
engc <file.eng> compile → .tsx alongside source
|
|
187
232
|
engc <file.eng> --out <dir> compile → specific output directory
|
|
188
233
|
engc <file.eng> -o <output.tsx> compile → specific output file
|
|
@@ -194,12 +239,18 @@ Usage:
|
|
|
194
239
|
|
|
195
240
|
Examples:
|
|
196
241
|
engc init my-app
|
|
242
|
+
engc dev
|
|
197
243
|
engc screens/HomeScreen.eng --out rn/src/
|
|
198
244
|
engc compile screens/ --out rn/src/
|
|
199
245
|
engc watch screens/ --out rn/src/
|
|
200
246
|
`.trim());
|
|
201
247
|
process.exit(0);
|
|
202
248
|
}
|
|
249
|
+
// engc dev
|
|
250
|
+
if (args[0] === 'dev') {
|
|
251
|
+
devProject(process.cwd());
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
203
254
|
// engc init <name>
|
|
204
255
|
if (args[0] === 'init') {
|
|
205
256
|
const name = args[1];
|