create-astratra-app 0.1.3 → 0.1.4

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
@@ -61,8 +61,8 @@ bonne URL. Pour forcer un port precis, utilise par exemple
61
61
  `PORT=4000 npm run dev:api`.
62
62
 
63
63
  En developpement, l'API accepte automatiquement les origins
64
- `localhost`/`127.0.0.1`, meme si Vite choisit un port comme `5174` ou `5175`.
65
- En production, definis explicitement `CORS_ORIGIN`.
64
+ `localhost`/`127.0.0.1`, quel que soit le port choisi par Vite. En production,
65
+ definis explicitement `CORS_ORIGIN`.
66
66
 
67
67
  Avant la production, il faut remplacer `JWT_SECRET`, brancher de vrais stores
68
68
  et utiliser une vraie verification de mot de passe.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-astratra-app",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "CLI generator for new Astratra SaaS applications.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -164,8 +164,7 @@ export default defineConfig({
164
164
  root: 'web',
165
165
  plugins: [react()],
166
166
  server: {
167
- host: '127.0.0.1',
168
- port: 5173
167
+ host: '127.0.0.1'
169
168
  }
170
169
  });
171
170
  `;
@@ -173,6 +172,7 @@ export default defineConfig({
173
172
 
174
173
  function devScript() {
175
174
  return `import fs from 'node:fs';
175
+ import net from 'node:net';
176
176
  import { spawn } from 'node:child_process';
177
177
 
178
178
  const isWindows = process.platform === 'win32';
@@ -199,6 +199,19 @@ function run(label, args) {
199
199
  return child;
200
200
  }
201
201
 
202
+ function findFreePort(host = '127.0.0.1') {
203
+ return new Promise((resolve, reject) => {
204
+ const server = net.createServer();
205
+ server.unref();
206
+ server.on('error', reject);
207
+ server.listen(0, host, () => {
208
+ const address = server.address();
209
+ const port = typeof address === 'object' && address ? address.port : 0;
210
+ server.close(() => resolve(port));
211
+ });
212
+ });
213
+ }
214
+
202
215
  function shutdown(code = 0) {
203
216
  shuttingDown = true;
204
217
  for (const child of children) {
@@ -207,9 +220,10 @@ function shutdown(code = 0) {
207
220
  process.exit(code);
208
221
  }
209
222
 
210
- function waitForApiConfig() {
223
+ async function waitForApiConfig() {
211
224
  if (fs.existsSync(apiConfigPath)) {
212
- run('web', ['run', 'dev:web']);
225
+ const webPort = await findFreePort();
226
+ run('web', ['run', 'dev:web', '--', '--port', String(webPort)]);
213
227
  return;
214
228
  }
215
229
 
@@ -219,7 +233,12 @@ function waitForApiConfig() {
219
233
  return;
220
234
  }
221
235
 
222
- setTimeout(waitForApiConfig, pollMs);
236
+ setTimeout(() => {
237
+ waitForApiConfig().catch((error) => {
238
+ console.error(error.message);
239
+ shutdown(1);
240
+ });
241
+ }, pollMs);
223
242
  }
224
243
 
225
244
  process.on('SIGINT', () => shutdown(0));
@@ -227,7 +246,10 @@ process.on('SIGTERM', () => shutdown(0));
227
246
 
228
247
  fs.rmSync(apiConfigPath, { force: true });
229
248
  run('api', ['run', 'dev:api']);
230
- waitForApiConfig();
249
+ waitForApiConfig().catch((error) => {
250
+ console.error(error.message);
251
+ shutdown(1);
252
+ });
231
253
  `;
232
254
  }
233
255