poad 2.39.0 → 2.41.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/global/start.js CHANGED
@@ -25,6 +25,7 @@ module.exports = async (args = {}) => {
25
25
  const mail = require('../utils/mail');
26
26
  const valkey = require('../utils/valkey');
27
27
  const runner = require('../utils/runner');
28
+ const gateway = require('../utils/gateway');
28
29
  const root = findPoadDir(process.cwd());
29
30
  if (!root) return console.log(chalk.redBright('You are not in a poad project directory.'));
30
31
  const config = require('../utils/config').readConfig(root);
@@ -50,6 +51,8 @@ module.exports = async (args = {}) => {
50
51
  return finish();
51
52
  }
52
53
  config.engine = await offerEngineUpgrade(root, config, args);
54
+ const gatewayWarning = gateway.maxBody(config).warning;
55
+ if (gatewayWarning) console.log(chalk.yellowBright(gatewayWarning));
53
56
  const image = 'poadio/engine:' + config.engine;
54
57
  // L'image de la version du projet n'est pas forcément là (poad install tire
55
58
  // celle du CLI, et config.toml peut en demander une autre) : on la tire.
@@ -120,6 +123,8 @@ module.exports = async (args = {}) => {
120
123
  ...valkey.engineEnv(config),
121
124
  // FLOWS_* : engine 0.18.0+ et Valkey configuré ; sinon le service flows reste arrêté
122
125
  ...runner.engineEnv(config),
126
+ // Taille maximale d'un corps de requête : [gateway] max_body (engine 0.28.2+)
127
+ ...gateway.engineEnv(config),
123
128
  ],
124
129
  ExposedPorts: { '5432/tcp': {}, '8000/tcp': {}, ...gelf.exposed },
125
130
  HostConfig: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poad",
3
- "version": "2.39.0",
3
+ "version": "2.41.0",
4
4
  "engine": "0.28.0",
5
5
  "runner": "0.2.0",
6
6
  "main": "index.js",
package/project/cli.js CHANGED
@@ -9,8 +9,8 @@
9
9
  module.exports = {
10
10
  info: 'Information about your project: URLs, keys, migrations, services (secrets hidden; info --secrets shows the JWT secret, the service_role key and the admin passwords)',
11
11
  client: {
12
- description: 'Front-end of the project: client init creates it from a template (Angular; Next.js, Nuxt and vanilla soon), wired to poad with sign-in. For a new folder: poad create',
13
- init: 'Create the front-end (angular | next | nuxt | vanilla, dir=<folder>, from=<local template>, --yes)',
12
+ description: 'Front-end of the project: client init is now poad create <app> --template t (adds apps/<app>, kept as an alias)',
13
+ init: 'Alias of poad create <app>: adds a front-end (angular | next | nuxt | vanilla, dir=<folder>, from=<local template>, --yes)',
14
14
  },
15
15
  console: 'Open the administration console of the running project in the browser (engine 0.11.0+, no password, this machine only)',
16
16
  kc: 'Keycloak test set of the project (poad/keycloak.json; kc export saves the running realm)',
@@ -3,7 +3,7 @@ module.exports = async () => {
3
3
  const chalk = require('chalk-v2');
4
4
  console.log(`${chalk.bold(' Usage :')}`);
5
5
  console.log(' ');
6
- console.log(` ${chalk.cyanBright('poad client init')} Create the front-end of the project (Angular; Next.js, Nuxt and vanilla soon), wired to poad with sign-in`);
7
- console.log(` ${chalk.grey(' options: angular | next | nuxt | vanilla, dir=<folder>, from=<local template>, --yes')}`);
6
+ console.log(` ${chalk.cyanBright('poad client init')} Now "poad create <app> --template t" (same thing): adds a front-end to the project, apps/<app>`);
7
+ console.log(` ${chalk.grey(' options: angular | next | nuxt | vanilla, dir=<folder> (--dir), from=<local template> (--from), --yes')}`);
8
8
  console.log(' ');
9
9
  };
@@ -1,163 +1,51 @@
1
- // poad client init [angular|next|nuxt|vanilla] [dir=web] [from=<dossier ou .tgz>] [--yes]
1
+ // poad client init [angular|next|nuxt|vanilla] [dir=<dossier>] [from=<dossier ou .tgz>] [--yes]
2
2
  //
3
- // Crée le front du projet à partir d'un modèle (@poadio/starter-<framework>
4
- // sur npm) : connexion, compte, cadre d'application, branché sur le projet
5
- // poad (URL et clé lues dans poad/config.toml au démarrage, rien à écrire).
6
- // - à la racine du projet, ou dans dir= (proposé si la racine a déjà un
7
- // package.json) ;
8
- // - port de développement du modèle (poad.port ; Angular : libre à partir de 4300) ;
9
- // - .gitignore complété, dépendances installées (bun, sinon npm).
10
- // from= : un modèle local (dossier ou archive), pour le développer.
11
- // Archive npm : intégrité vérifiée et extraction sûre (utils/registry, utils/tar),
12
- // comme poad create.
13
-
14
- // Jamais copiés depuis un dossier modèle local
15
- const SKIP = new Set(['node_modules', 'dist', '.angular', '.git', '.github', '.env.local', 'env.json', '.DS_Store', 'poad']);
16
-
3
+ // Remplacée par « poad create <app> --template <t> » lancée dans le projet :
4
+ // c'est le même chemin (global/create.js, mode « front ajouté »), gardé ici
5
+ // sous son ancien nom pour les scripts et les habitudes. Correspondance :
6
+ // angular|next|… -> --template
7
+ // dir=<dossier> -> --dir <dossier> ; nom d'application : celui du dossier
8
+ // (dir=. : le front à la racine du projet, ancienne disposition)
9
+ // from=<…> -> --from
10
+ // Sans dir= : apps/web (apps/<nom> si web est pris), comme poad create.
17
11
  module.exports = async (args = {}) => {
18
12
  const chalk = require('chalk-v2');
19
- const fs = require('fs');
20
- const os = require('os');
21
13
  const path = require('path');
22
- const { spawnSync } = require('child_process');
23
- const { findPoadDir } = require('../../utils/findpoad');
24
- const { readConfig } = require('../../utils/config');
25
-
26
- const root = findPoadDir(process.cwd());
27
- if (!root) {
28
- process.exitCode = 1;
29
- return console.log(chalk.redBright('No poad project here: "poad init" first (the backend), then "poad client init".'));
30
- }
31
- const config = readConfig(root);
32
- const projectDir = path.dirname(path.dirname(root)); // dossier qui contient poad/
33
- const flag = (f) => Boolean(args[f] || args[`--${f}`]);
34
- const tty = process.stdin.isTTY && process.stdout.isTTY && !flag('yes');
35
- const prompts = tty ? require('@inquirer/prompts') : null;
36
14
  const starter = require('../../utils/starter');
37
- const registry = require('../../utils/registry');
38
- const local = typeof args.from === 'string';
15
+ const ws = require('../../utils/workspace');
16
+ const { create } = require('../../global/create');
39
17
 
40
- // 1. Framework : seuls les modèles publiés sur npm peuvent être choisis
41
- let fw = starter.TEMPLATES.find((f) => args[f.value]);
42
- let metadata = null;
43
- if (!fw && prompts && !local) {
44
- const states = await Promise.all(starter.TEMPLATES.map(async (t) => ({ ...t, metadata: await registry.packageMetadata(t.package) })));
45
- const choices = states.map((t) => ({ value: t.value, name: t.label, disabled: t.metadata.status === 'missing' ? 'coming soon' : t.metadata.status === 'offline' && !registry.cachedVersion(t.package) ? 'offline' : false }));
46
- const v = await prompts.select({ message: 'Front-end framework', choices }).catch(() => null);
47
- if (!v) return;
48
- fw = starter.templateByValue(v);
49
- metadata = states.find((t) => t.value === v).metadata;
50
- }
51
- if (!fw) fw = starter.TEMPLATES[0];
52
- if (!local) {
53
- metadata = metadata || (await registry.packageMetadata(fw.package, { timeout: 5000 }));
54
- if (metadata.status === 'missing') {
55
- process.exitCode = 1;
56
- return console.log(chalk.yellowBright(`${fw.value}: coming soon (${fw.package} is not published yet).`));
57
- }
58
- }
59
-
60
- // 2. Dossier : la racine si elle est libre, sinon un sous-dossier
61
- let dir = typeof args.dir === 'string' ? args.dir : null;
62
- if (!dir) {
63
- const rootTaken = fs.existsSync(path.join(projectDir, 'package.json'));
64
- if (!rootTaken) dir = '.';
65
- else if (prompts) dir = await prompts.input({ message: 'The project root already has a package.json. Folder for the front-end', default: 'web' }).catch(() => null);
66
- else dir = 'web';
67
- }
68
- if (!dir) return;
69
- const target = path.resolve(projectDir, dir);
70
- if (fs.existsSync(path.join(target, 'package.json'))) {
18
+ const project = ws.findProject(process.cwd());
19
+ if (!project) {
71
20
  process.exitCode = 1;
72
- return console.log(chalk.redBright(`${path.relative(process.cwd(), path.join(target, 'package.json')) || 'package.json'} already exists: choose another folder (dir=<folder>).`));
21
+ return console.log(chalk.redBright('No poad project here: "poad create <project>" makes one (backend and first front-end), or "poad init" then "poad create <app>".'));
73
22
  }
74
-
75
- // 3. Modèle : dossier local, archive, ou npm
76
- const work = fs.mkdtempSync(path.join(os.tmpdir(), 'poad-client-'));
77
- const ora = require('ora');
78
- let progress = ora(`Fetching the ${fw.value} template`).start();
79
- let source;
80
- try {
81
- const from = typeof args.from === 'string' ? path.resolve(process.cwd(), args.from.replace(/^~(?=\/)/, os.homedir())) : null;
82
- let tgz = null;
83
- if (from && fs.statSync(from).isDirectory()) source = from;
84
- else if (from) tgz = from;
85
- let buf = null;
86
- if (!from) buf = (await registry.fetchLatestTarball(fw.package, { metadata, timeout: 5000 })).buf;
87
- else if (tgz) buf = fs.readFileSync(tgz);
88
- if (buf) {
89
- source = path.join(work, 'package');
90
- require('../../utils/tar').extractTgz(buf, source);
91
- }
92
- progress.succeed(`Template: ${chalk.bold(require(path.join(source, 'package.json')).name)} ${chalk.grey(require(path.join(source, 'package.json')).version)}`);
93
- } catch (err) {
94
- progress.fail(chalk.redBright(`Template unavailable: ${err.message}`));
95
- process.exitCode = 1;
96
- return;
23
+ const fw = starter.TEMPLATES.find((f) => args[f.value]);
24
+ const dir = typeof args.dir === 'string' ? args.dir : args.dir === undefined ? null : String(args.dir);
25
+ let app = null;
26
+ if (dir) {
27
+ const abs = path.resolve(project.root, dir);
28
+ app = ws.appNameOf({ name: path.basename(abs) }) || null;
29
+ } else {
30
+ const taken = new Set(ws.listApps(project.root).map((a) => a.name));
31
+ app = ['web', 'admin', 'site'].find((n) => !taken.has(n)) || null;
97
32
  }
98
-
99
- // 4. Copie (sans écraser un fichier existant)
100
- const copy = (from, to) => {
101
- for (const name of fs.readdirSync(from)) {
102
- if (SKIP.has(name)) continue;
103
- const a = path.join(from, name);
104
- const b = path.join(to, name);
105
- if (fs.statSync(a).isDirectory()) {
106
- fs.mkdirSync(b, { recursive: true });
107
- copy(a, b);
108
- } else if (!fs.existsSync(b)) fs.copyFileSync(a, b);
109
- }
33
+ const opts = {
34
+ name: app,
35
+ template: fw ? fw.value : null,
36
+ pm: null,
37
+ from: typeof args.from === 'string' ? args.from : null,
38
+ app: null,
39
+ // dir= était relatif à la racine du projet
40
+ dir: dir ? path.resolve(project.root, dir) : null,
41
+ yes: Boolean(args.yes || args['--yes'] || args.y || args['-y']),
42
+ noInstall: Boolean(args['--no-install']),
43
+ noGit: true,
44
+ flat: false,
45
+ help: false,
110
46
  };
111
- fs.mkdirSync(target, { recursive: true });
112
- copy(source, target);
113
-
114
- // 5. package.json de l'application : nom du projet, rien de la publication
115
- const pkgFile = path.join(target, 'package.json');
116
- const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf8'));
117
- const tpl = (pkg.poad && pkg.poad.template) || {};
118
- const name = starter.packageName(config.project_id || path.basename(projectDir));
119
- const origin = require(path.join(source, 'package.json'));
120
- const app = starter.rewritePackageJson(pkg, {
121
- name: dir === '.' ? name : `${name}-${path.basename(target)}`,
122
- title: config.project_id || pkg.title,
123
- from: `${origin.name}@${origin.version}`,
124
- });
125
- fs.writeFileSync(pkgFile, JSON.stringify(app, null, 2) + '\n');
126
-
127
- // 6. Port de développement selon le framework (poad.port / poad.template.port
128
- // du modèle ; Angular : premier libre, écrit dans angular.json)
129
- const dev = await starter.devServer(target, pkg);
130
- const label = dev.label || (local ? 'Front-end' : fw.label.split(' (')[0]);
131
-
132
- // Titre de la page : le nom du projet
133
- const html = path.join(target, 'src', 'index.html');
134
- if (fs.existsSync(html)) fs.writeFileSync(html, fs.readFileSync(html, 'utf8').replace(/<title>[^<]*<\/title>/, `<title>${String(app.title).replace(/[<&]/g, '')}</title>`));
135
-
136
- // 7. .gitignore : celui de poad init (racine), complété des fichiers du front
137
- const git = require('../../utils/git');
138
- git.ensureRootGitignore(projectDir);
139
- if (Array.isArray(tpl.gitignore) && tpl.gitignore.length) {
140
- const prefix = dir === '.' ? '' : `/${path.relative(projectDir, target).split(path.sep).join('/')}`;
141
- const lines = tpl.gitignore.map((l) => (l.startsWith('/') ? `${prefix}${l}` : l));
142
- git.ensureLines(projectDir, `Front-end (${fw.value})`, lines);
143
- }
144
-
145
- // 8. Dépendances
146
- const hasBun = spawnSync('bun', ['--version'], { encoding: 'utf8' }).status === 0;
147
- const pm = hasBun ? 'bun' : 'npm';
148
- progress = ora(`Installing the dependencies (${pm} install)`).start();
149
- const inst = spawnSync(pm, ['install'], { cwd: target, encoding: 'utf8', shell: process.platform === 'win32' });
150
- if (inst.status !== 0) progress.fail(chalk.yellowBright(`${pm} install failed: run it in ${path.relative(process.cwd(), target) || '.'}`));
151
- else progress.succeed('Dependencies installed');
152
- fs.rmSync(work, { recursive: true, force: true });
153
-
154
- const rel = path.relative(process.cwd(), target) || '.';
155
- const run = hasBun ? 'bun start' : 'npm start';
156
- console.log(' ');
157
- console.log(`${chalk.greenBright('✔')} ${chalk.bold(label === 'Front-end' ? 'Front-end created' : `${label} front-end created`)} in ${chalk.cyanBright(rel)}`);
158
- console.log(chalk.grey(' Sign-in (e-mail, magic link, providers), account and app layout, wired to this poad project.'));
159
- console.log(' ');
160
- console.log(` ${chalk.bold('poad start')}${chalk.grey(' the backend (if not running)')}`);
161
- console.log(` ${chalk.bold(`${rel === '.' ? '' : `cd ${rel} && `}${run}`)}${dev.url ? chalk.grey(` ${dev.url}`) : ''}`);
162
- console.log(' ');
47
+ const t = opts.template ? ` --template ${opts.template}` : '';
48
+ const d = dir ? ` --dir ${dir}` : '';
49
+ console.log(chalk.grey(` poad client init is now "poad create ${app || '<app>'}${t}${d}" (same result): run that next time.`));
50
+ return create(opts);
163
51
  };
@@ -0,0 +1,170 @@
1
+ // bun start (à la racine du projet) : le backend poad une fois, puis le serveur
2
+ // de développement de chaque front, en parallèle, chacun sur son port.
3
+ //
4
+ // bun start poad, puis tous les fronts (workspaces du package.json, apps/*)
5
+ // bun start web admin poad, puis ces fronts-là seulement (bun run start:web : un seul)
6
+ //
7
+ // Chaque ligne est préfixée du nom du front ([web], [admin]). Ctrl+C arrête
8
+ // tous les fronts ; le backend continue (poad stop pour l'arrêter).
9
+ //
10
+ // Écrit par poad create ; sans dépendance (modules de Node seulement), à
11
+ // modifier librement.
12
+ import { spawn, spawnSync } from 'node:child_process';
13
+ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
14
+ import { connect, createServer } from 'node:net';
15
+ import { basename, dirname, join, relative, resolve } from 'node:path';
16
+ import { fileURLToPath } from 'node:url';
17
+
18
+ const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
19
+ const windows = process.platform === 'win32';
20
+ const readJson = (file) => {
21
+ try {
22
+ return JSON.parse(readFileSync(file, 'utf8'));
23
+ } catch {
24
+ return null;
25
+ }
26
+ };
27
+
28
+ const APP_RE = /^[a-z][a-z0-9-]{0,62}$/;
29
+ const rootPkg = readJson(join(root, 'package.json')) || {};
30
+
31
+ /** Fronts du projet : dossiers des workspaces (« apps/* » ou chemin exact), sinon apps/* */
32
+ function apps() {
33
+ const patterns = Array.isArray(rootPkg.workspaces) ? rootPkg.workspaces : rootPkg.workspaces?.packages || ['apps/*'];
34
+ const dirs = [];
35
+ for (const raw of patterns) {
36
+ const p = String(raw).replace(/\/+$/, '');
37
+ if (p.startsWith('!')) continue;
38
+ if (p.endsWith('/*')) {
39
+ const base = join(root, p.slice(0, -2));
40
+ if (!existsSync(base)) continue;
41
+ for (const n of readdirSync(base).sort()) if (statSync(join(base, n)).isDirectory()) dirs.push(join(base, n));
42
+ } else if (!p.includes('*')) dirs.push(join(root, p));
43
+ }
44
+ return [...new Set(dirs)]
45
+ .map((dir) => ({ dir, pkg: readJson(join(dir, 'package.json')) }))
46
+ .filter((a) => a.pkg?.scripts?.start)
47
+ .map(({ dir, pkg }) => ({ dir, pkg, name: APP_RE.test(pkg.poad?.app ?? '') ? pkg.poad.app : basename(dir), port: portOf(dir, pkg) }));
48
+ }
49
+
50
+ /** Port de développement : poad.port, sinon celui d'angular.json */
51
+ function portOf(dir, pkg) {
52
+ if (Number(pkg.poad?.port)) return Number(pkg.poad.port);
53
+ const ng = readJson(join(dir, 'angular.json'));
54
+ for (const p of Object.values(ng?.projects || {})) if (Number(p?.architect?.serve?.options?.port)) return Number(p.architect.serve.options.port);
55
+ return null;
56
+ }
57
+
58
+ // Port libre : rien n'y répond (IPv4 ni IPv6 : un serveur sur [::1] seul
59
+ // n'empêche pas d'écouter sur 127.0.0.1, mais localhost peut y mener) et on
60
+ // peut y écouter
61
+ const answers = (port, host) =>
62
+ new Promise((ok) => {
63
+ const c = connect({ port, host });
64
+ c.setTimeout(500, () => c.destroy() && ok(false));
65
+ c.once('connect', () => c.destroy() && ok(true));
66
+ c.once('error', () => ok(false));
67
+ });
68
+ const bindable = (port) =>
69
+ new Promise((ok) => {
70
+ const s = createServer().once('error', () => ok(false)).once('listening', () => s.close(() => ok(true)));
71
+ s.listen(port, '127.0.0.1');
72
+ });
73
+ const free = async (port) => !(await answers(port, '127.0.0.1')) && !(await answers(port, '::1')) && (await bindable(port));
74
+
75
+ /** Gestionnaire de paquets du projet : packageManager, sinon le fichier de verrouillage, sinon bun s'il est là */
76
+ function packageManager() {
77
+ const declared = /^(bun|npm|pnpm|yarn)@/.exec(rootPkg.packageManager || '');
78
+ if (declared) return declared[1];
79
+ if (existsSync(join(root, 'bun.lock')) || existsSync(join(root, 'bun.lockb'))) return 'bun';
80
+ if (existsSync(join(root, 'pnpm-lock.yaml'))) return 'pnpm';
81
+ if (existsSync(join(root, 'yarn.lock'))) return 'yarn';
82
+ if (existsSync(join(root, 'package-lock.json'))) return 'npm';
83
+ const bun = spawnSync('bun', ['--version'], { shell: windows });
84
+ return !bun.error && bun.status === 0 ? 'bun' : 'npm';
85
+ }
86
+
87
+ const all = apps();
88
+ const wanted = process.argv.slice(2).filter((a) => !a.startsWith('-'));
89
+ const unknown = wanted.filter((w) => !all.some((a) => a.name === w || relative(root, a.dir) === w));
90
+ if (unknown.length) {
91
+ console.error(`Unknown front-end: ${unknown.join(', ')}. Known: ${all.map((a) => a.name).join(', ') || 'none'}.`);
92
+ process.exit(1);
93
+ }
94
+ const chosen = wanted.length ? all.filter((a) => wanted.includes(a.name) || wanted.includes(relative(root, a.dir))) : all;
95
+ if (!chosen.length) {
96
+ console.error('No front-end here: poad create <name> --template next|angular adds one (apps/<name>).');
97
+ process.exit(1);
98
+ }
99
+
100
+ // 1. Le backend, une seule fois (sans effet s'il tourne déjà)
101
+ if (!process.env.POAD_URL && existsSync(join(root, 'poad', 'config.toml'))) {
102
+ const r = spawnSync('poad', ['start', '--quiet'], { cwd: root, stdio: 'inherit', shell: windows });
103
+ if (r.error && r.error.code === 'ENOENT') console.warn('The poad CLI is not installed: the local backend was not started (npm install -g poad, then "poad start").');
104
+ else if (r.error || r.status) console.warn('The local poad project did not start: the front-ends will not reach their backend ("poad start" to see why).');
105
+ }
106
+
107
+ // 2. Un port libre et distinct par front, à partir du sien
108
+ const taken = new Set();
109
+ for (const app of chosen) {
110
+ if (!app.port) continue;
111
+ let port = app.port;
112
+ while (taken.has(port) || !(await free(port))) port++;
113
+ taken.add(port);
114
+ app.port = port;
115
+ }
116
+
117
+ // 3. Les fronts, en parallèle, sortie préfixée
118
+ const pm = packageManager();
119
+ const colors = [36, 35, 33, 32, 34, 31];
120
+ const width = Math.max(...chosen.map((a) => a.name.length));
121
+ const tty = process.stdout.isTTY;
122
+ const children = [];
123
+
124
+ for (const [i, app] of chosen.entries()) {
125
+ const label = `[${app.name}]`.padEnd(width + 2);
126
+ const prefix = tty ? `\x1b[${colors[i % colors.length]}m${label}\x1b[0m ` : `${label} `;
127
+ const extra = app.port ? ['--port', String(app.port)] : [];
128
+ const args = pm === 'npm' || pm === 'bun' ? ['run', 'start', ...(extra.length ? ['--', ...extra] : [])] : ['run', 'start', ...extra];
129
+ console.log(`${prefix}${pm} ${args.join(' ')}${app.port ? ` http://localhost:${app.port}` : ''}`);
130
+ const child = spawn(pm, args, {
131
+ cwd: app.dir,
132
+ // Groupe de processus à lui : Ctrl+C arrête le front et ce qu'il a lancé
133
+ detached: !windows,
134
+ shell: windows,
135
+ stdio: ['ignore', 'pipe', 'pipe'],
136
+ env: { ...process.env, POAD_APP: app.name, POAD_SKIP_START: '1', ...(tty ? { FORCE_COLOR: '1' } : {}) },
137
+ });
138
+ for (const stream of [child.stdout, child.stderr]) {
139
+ let rest = '';
140
+ stream.on('data', (chunk) => {
141
+ const lines = (rest + chunk).split(/\r?\n/);
142
+ rest = lines.pop();
143
+ for (const line of lines) (stream === child.stderr ? process.stderr : process.stdout).write(`${prefix}${line}\n`);
144
+ });
145
+ stream.on('end', () => rest && process.stdout.write(`${prefix}${rest}\n`));
146
+ }
147
+ child.on('exit', (code, signal) => {
148
+ console.log(`${prefix}stopped${signal ? ` (${signal})` : code ? ` (exit ${code})` : ''}`);
149
+ children.splice(children.indexOf(child), 1);
150
+ if (!children.length) process.exit(stopping ? 0 : code ?? 0);
151
+ });
152
+ children.push(child);
153
+ }
154
+
155
+ let stopping = false;
156
+ const stop = (signal) => {
157
+ const hard = stopping;
158
+ stopping = true;
159
+ for (const child of children) {
160
+ try {
161
+ if (windows) child.kill();
162
+ else process.kill(-child.pid, hard ? 'SIGKILL' : signal);
163
+ } catch {
164
+ /* déjà arrêté */
165
+ }
166
+ }
167
+ if (!hard) console.log('Stopping the front-ends (again to force). The poad backend keeps running: poad stop.');
168
+ };
169
+ process.on('SIGINT', () => stop('SIGINT'));
170
+ process.on('SIGTERM', () => stop('SIGTERM'));
@@ -10,9 +10,9 @@ const { tmpdir } = require('./helpers');
10
10
  const CLI = path.join(__dirname, '..', 'poad.js');
11
11
  const e2e = process.env.POAD_E2E === '1';
12
12
 
13
- test('poad create my-app --template angular --no-install --yes', { skip: !e2e && 'POAD_E2E=1 to run it (network)', timeout: 120000 }, async (t) => {
13
+ test('poad create my-app --flat --template angular --no-install --yes', { skip: !e2e && 'POAD_E2E=1 to run it (network)', timeout: 120000 }, async (t) => {
14
14
  const cwd = tmpdir(t, 'poad-create-');
15
- const r = spawnSync(process.execPath, [CLI, 'create', 'my-app', '--template', 'angular', '--no-install', '--yes'], {
15
+ const r = spawnSync(process.execPath, [CLI, 'create', 'my-app', '--flat', '--template', 'angular', '--no-install', '--yes'], {
16
16
  cwd,
17
17
  encoding: 'utf8',
18
18
  input: '',
@@ -60,7 +60,7 @@ test('poad create my-app --template angular --no-install --yes', { skip: !e2e &&
60
60
  for (const [, value] of secrets.matchAll(/=\s*"([^"]{16,})"/g)) assert.ok(!out.includes(value), 'a secret was printed');
61
61
 
62
62
  // Dossier non vide : refusé, rien n'est touché
63
- const again = spawnSync(process.execPath, [CLI, 'create', 'my-app', '--template', 'angular', '--yes'], { cwd, encoding: 'utf8', input: '' });
63
+ const again = spawnSync(process.execPath, [CLI, 'create', 'my-app', '--flat', '--template', 'angular', '--yes'], { cwd, encoding: 'utf8', input: '' });
64
64
  assert.match(again.stdout, /is not empty/);
65
65
  assert.notStrictEqual(again.status, 0);
66
66