poad 2.38.0 → 2.40.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/cli.js +2 -1
- package/global/create.js +513 -0
- package/global/init.js +17 -5
- package/global/run.js +17 -10
- package/package.json +4 -2
- package/poad.js +26 -1
- package/project/cli.js +3 -3
- package/project/client/index.js +2 -2
- package/project/client/init.js +43 -171
- package/project/info.js +22 -2
- package/templates/workspace/start.mjs +170 -0
- package/test/create.e2e.test.js +73 -0
- package/test/create.test.js +340 -0
- package/test/help-stub.js +29 -0
- package/test/help.test.js +124 -0
- package/test/helpers.js +53 -0
- package/test/offline-stub.js +5 -0
- package/test/registry.test.js +95 -0
- package/test/secrets.test.js +94 -0
- package/test/starter.test.js +122 -0
- package/test/tar.test.js +101 -0
- package/test/workspace.test.js +71 -0
- package/utils/engine.js +10 -5
- package/utils/git.js +1 -1
- package/utils/help.js +80 -0
- package/utils/registry.js +145 -0
- package/utils/report.js +23 -12
- package/utils/services.js +2 -2
- package/utils/starter.js +241 -0
- package/utils/tar.js +180 -0
- package/utils/workspace.js +207 -0
package/poad.js
CHANGED
|
@@ -365,7 +365,8 @@ const processCommands = (args) => {
|
|
|
365
365
|
if (POAD_GLOBAL_COMMANDS[command]) {
|
|
366
366
|
const px = parseCommandArgs(require(__dirname + '/global/cli'), args);
|
|
367
367
|
const unit = require(path.join(__dirname, 'global', px.dir));
|
|
368
|
-
|
|
368
|
+
// Second argument : les mots tels que tapés (poad create --template next)
|
|
369
|
+
unit(parseArgs(px.args), px.args);
|
|
369
370
|
} else {
|
|
370
371
|
if (POAD_COMMANDS[command]) {
|
|
371
372
|
console.log(' ');
|
|
@@ -476,8 +477,32 @@ const isNewerVersion = (a, b) => {
|
|
|
476
477
|
return false;
|
|
477
478
|
};
|
|
478
479
|
|
|
480
|
+
// Aide : `poad <commande…> --help` (ou -h, ou `poad help <commande…>`)
|
|
481
|
+
// affiche l'aide et s'arrête, avant la vérification de version et avant
|
|
482
|
+
// d'exécuter quoi que ce soit (poad stop --help n'arrête plus le projet).
|
|
483
|
+
const helpGuard = () => {
|
|
484
|
+
const help = require('./utils/help');
|
|
485
|
+
let argv = process.argv.slice(2);
|
|
486
|
+
const asked = argv[0] === 'help' || help.helpRequested(argv);
|
|
487
|
+
if (!asked) return false;
|
|
488
|
+
if (argv[0] === 'help') argv = argv.slice(1);
|
|
489
|
+
POAD_GLOBAL_COMMANDS = loadPoadCommands(__dirname + '/global/cli.js');
|
|
490
|
+
const words = argv.filter((a) => !help.HELP_FLAGS.includes(a));
|
|
491
|
+
if (!words.length) {
|
|
492
|
+
displayBanner();
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
495
|
+
if (!help.printHelp(argv)) {
|
|
496
|
+
process.exitCode = 1;
|
|
497
|
+
log.error('Unknown command : ' + words[0]);
|
|
498
|
+
displayBanner();
|
|
499
|
+
}
|
|
500
|
+
return true;
|
|
501
|
+
};
|
|
502
|
+
|
|
479
503
|
// Main function.
|
|
480
504
|
const main = async () => {
|
|
505
|
+
if (helpGuard()) return;
|
|
481
506
|
let version = await checkVersion();
|
|
482
507
|
const current_version = require(__dirname + '/package.json').version;
|
|
483
508
|
|
package/project/cli.js
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
module.exports = {
|
|
10
|
-
info:
|
|
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
|
|
13
|
-
init: '
|
|
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)',
|
package/project/client/index.js
CHANGED
|
@@ -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')}
|
|
7
|
-
console.log(` ${chalk.grey(' options: angular |
|
|
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
|
};
|
package/project/client/init.js
CHANGED
|
@@ -1,179 +1,51 @@
|
|
|
1
|
-
// poad client init [angular|
|
|
1
|
+
// poad client init [angular|next|nuxt|vanilla] [dir=<dossier>] [from=<dossier ou .tgz>] [--yes]
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
const FRAMEWORKS = [
|
|
12
|
-
{ value: 'angular', name: 'Angular (@cadriciel/ui)', package: '@poadio/starter-angular' },
|
|
13
|
-
{ value: 'vue', name: 'Vue.js (bientôt)', disabled: 'bientôt' },
|
|
14
|
-
{ value: 'react', name: 'React (bientôt)', disabled: 'bientôt' },
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
// Jamais copiés depuis un dossier modèle local
|
|
18
|
-
const SKIP = new Set(['node_modules', 'dist', '.angular', '.git', '.github', '.env.local', 'env.json', '.DS_Store', 'poad']);
|
|
19
|
-
|
|
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.
|
|
20
11
|
module.exports = async (args = {}) => {
|
|
21
12
|
const chalk = require('chalk-v2');
|
|
22
|
-
const fs = require('fs');
|
|
23
|
-
const os = require('os');
|
|
24
13
|
const path = require('path');
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const {
|
|
28
|
-
|
|
29
|
-
const root = findPoadDir(process.cwd());
|
|
30
|
-
if (!root) {
|
|
31
|
-
process.exitCode = 1;
|
|
32
|
-
return console.log(chalk.redBright('No poad project here: "poad init" first (the backend), then "poad client init".'));
|
|
33
|
-
}
|
|
34
|
-
const config = readConfig(root);
|
|
35
|
-
const projectDir = path.dirname(path.dirname(root)); // dossier qui contient poad/
|
|
36
|
-
const flag = (f) => Boolean(args[f] || args[`--${f}`]);
|
|
37
|
-
const tty = process.stdin.isTTY && process.stdout.isTTY && !flag('yes');
|
|
38
|
-
const prompts = tty ? require('@inquirer/prompts') : null;
|
|
39
|
-
|
|
40
|
-
// 1. Framework
|
|
41
|
-
let fw = FRAMEWORKS.find((f) => args[f.value]);
|
|
42
|
-
if (!fw && prompts) {
|
|
43
|
-
const v = await prompts.select({ message: 'Front-end framework', choices: FRAMEWORKS }).catch(() => null);
|
|
44
|
-
fw = FRAMEWORKS.find((f) => f.value === v);
|
|
45
|
-
}
|
|
46
|
-
if (!fw) fw = FRAMEWORKS[0];
|
|
47
|
-
if (fw.disabled) {
|
|
48
|
-
process.exitCode = 1;
|
|
49
|
-
return console.log(chalk.yellowBright(`${fw.value}: coming soon. Angular is available now.`));
|
|
50
|
-
}
|
|
14
|
+
const starter = require('../../utils/starter');
|
|
15
|
+
const ws = require('../../utils/workspace');
|
|
16
|
+
const { create } = require('../../global/create');
|
|
51
17
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (!dir) {
|
|
55
|
-
const rootTaken = fs.existsSync(path.join(projectDir, 'package.json'));
|
|
56
|
-
if (!rootTaken) dir = '.';
|
|
57
|
-
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);
|
|
58
|
-
else dir = 'web';
|
|
59
|
-
}
|
|
60
|
-
if (!dir) return;
|
|
61
|
-
const target = path.resolve(projectDir, dir);
|
|
62
|
-
if (fs.existsSync(path.join(target, 'package.json'))) {
|
|
18
|
+
const project = ws.findProject(process.cwd());
|
|
19
|
+
if (!project) {
|
|
63
20
|
process.exitCode = 1;
|
|
64
|
-
return console.log(chalk.redBright(
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
progress.fail(chalk.redBright(`Template unavailable: ${err.message}`));
|
|
90
|
-
process.exitCode = 1;
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// 4. Copie (sans écraser un fichier existant)
|
|
95
|
-
const copy = (from, to) => {
|
|
96
|
-
for (const name of fs.readdirSync(from)) {
|
|
97
|
-
if (SKIP.has(name)) continue;
|
|
98
|
-
const a = path.join(from, name);
|
|
99
|
-
const b = path.join(to, name);
|
|
100
|
-
if (fs.statSync(a).isDirectory()) {
|
|
101
|
-
fs.mkdirSync(b, { recursive: true });
|
|
102
|
-
copy(a, b);
|
|
103
|
-
} else if (!fs.existsSync(b)) fs.copyFileSync(a, b);
|
|
104
|
-
}
|
|
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>".'));
|
|
22
|
+
}
|
|
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;
|
|
32
|
+
}
|
|
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,
|
|
105
46
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const pkgFile = path.join(target, 'package.json');
|
|
111
|
-
const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf8'));
|
|
112
|
-
const tpl = (pkg.poad && pkg.poad.template) || {};
|
|
113
|
-
const name = String(config.project_id || path.basename(projectDir))
|
|
114
|
-
.toLowerCase()
|
|
115
|
-
.replace(/[^a-z0-9._-]+/g, '-')
|
|
116
|
-
.replace(/^[-._]+|[-._]+$/g, '') || 'app';
|
|
117
|
-
pkg.name = dir === '.' ? name : `${name}-${path.basename(target)}`;
|
|
118
|
-
pkg.title = config.project_id || pkg.title;
|
|
119
|
-
// La description du paquet npm parle du modèle : l'application reprend la sienne
|
|
120
|
-
if (tpl.description) pkg.description = tpl.description;
|
|
121
|
-
pkg.version = '0.1.0';
|
|
122
|
-
pkg.private = true;
|
|
123
|
-
for (const k of ['files', 'repository', 'publishConfig', 'license']) delete pkg[k];
|
|
124
|
-
const origin = require(path.join(source, 'package.json'));
|
|
125
|
-
pkg.poad = { ...(pkg.poad || {}), from: `${origin.name}@${origin.version}` };
|
|
126
|
-
delete pkg.poad.template;
|
|
127
|
-
fs.writeFileSync(pkgFile, JSON.stringify(pkg, null, 2) + '\n');
|
|
128
|
-
|
|
129
|
-
// 6. Port de développement libre (4200 est souvent pris)
|
|
130
|
-
const net = require('net');
|
|
131
|
-
const free = (port) =>
|
|
132
|
-
new Promise((ok) => {
|
|
133
|
-
const s = net.createServer().once('error', () => ok(false)).once('listening', () => s.close(() => ok(true)));
|
|
134
|
-
s.listen(port, '127.0.0.1');
|
|
135
|
-
});
|
|
136
|
-
let port = Number(tpl.port) || 4300;
|
|
137
|
-
while (!(await free(port)) && port < 4400) port++;
|
|
138
|
-
const ngFile = path.join(target, 'angular.json');
|
|
139
|
-
if (fw.value === 'angular' && fs.existsSync(ngFile)) {
|
|
140
|
-
const ng = JSON.parse(fs.readFileSync(ngFile, 'utf8'));
|
|
141
|
-
for (const p of Object.values(ng.projects || {})) {
|
|
142
|
-
const serve = p.architect && p.architect.serve;
|
|
143
|
-
if (serve) serve.options = { ...(serve.options || {}), port };
|
|
144
|
-
}
|
|
145
|
-
fs.writeFileSync(ngFile, JSON.stringify(ng, null, 2) + '\n');
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Titre de la page : le nom du projet
|
|
149
|
-
const html = path.join(target, 'src', 'index.html');
|
|
150
|
-
if (fs.existsSync(html)) fs.writeFileSync(html, fs.readFileSync(html, 'utf8').replace(/<title>[^<]*<\/title>/, `<title>${String(pkg.title).replace(/[<&]/g, '')}</title>`));
|
|
151
|
-
|
|
152
|
-
// 7. .gitignore : celui de poad init (racine), complété des fichiers du front
|
|
153
|
-
const git = require('../../utils/git');
|
|
154
|
-
git.ensureRootGitignore(projectDir);
|
|
155
|
-
if (Array.isArray(tpl.gitignore) && tpl.gitignore.length) {
|
|
156
|
-
const prefix = dir === '.' ? '' : `/${path.relative(projectDir, target).split(path.sep).join('/')}`;
|
|
157
|
-
const lines = tpl.gitignore.map((l) => (l.startsWith('/') ? `${prefix}${l}` : l));
|
|
158
|
-
git.ensureLines(projectDir, `Front-end (${fw.value})`, lines);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// 8. Dépendances
|
|
162
|
-
const hasBun = spawnSync('bun', ['--version'], { encoding: 'utf8' }).status === 0;
|
|
163
|
-
const pm = hasBun ? 'bun' : 'npm';
|
|
164
|
-
progress = ora(`Installing the dependencies (${pm} install)`).start();
|
|
165
|
-
const inst = spawnSync(pm, ['install'], { cwd: target, encoding: 'utf8', shell: process.platform === 'win32' });
|
|
166
|
-
if (inst.status !== 0) progress.fail(chalk.yellowBright(`${pm} install failed: run it in ${path.relative(process.cwd(), target) || '.'}`));
|
|
167
|
-
else progress.succeed('Dependencies installed');
|
|
168
|
-
fs.rmSync(work, { recursive: true, force: true });
|
|
169
|
-
|
|
170
|
-
const rel = path.relative(process.cwd(), target) || '.';
|
|
171
|
-
const run = hasBun ? 'bun start' : 'npm start';
|
|
172
|
-
console.log(' ');
|
|
173
|
-
console.log(`${chalk.greenBright('✔')} ${chalk.bold(`${fw.value} front-end created`)} in ${chalk.cyanBright(rel)}`);
|
|
174
|
-
console.log(chalk.grey(' Sign-in (e-mail, magic link, providers), account and app layout, wired to this poad project.'));
|
|
175
|
-
console.log(' ');
|
|
176
|
-
console.log(` ${chalk.bold('poad start')}${chalk.grey(' the backend (if not running)')}`);
|
|
177
|
-
console.log(` ${chalk.bold(`${rel === '.' ? '' : `cd ${rel} && `}${run}`)}${chalk.grey(` http://localhost:${port}`)}`);
|
|
178
|
-
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);
|
|
179
51
|
};
|
package/project/info.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
// poad info : le projet (URL, base, clés, migrations), puis un panneau à part
|
|
2
2
|
// pour les services qui tournent à côté de l'engine (Mailpit, Keycloak, Valkey).
|
|
3
3
|
// poad start affiche la même chose à la fin du démarrage.
|
|
4
|
-
|
|
4
|
+
// Les secrets (secret JWT, clé service_role, mot de passe admin de Keycloak…)
|
|
5
|
+
// sont masqués ; poad info --secrets les montre.
|
|
6
|
+
|
|
7
|
+
/** --secrets, secrets : montrer les secrets */
|
|
8
|
+
const wantsSecrets = (args = {}) => Boolean(args.secrets || args['--secrets']);
|
|
9
|
+
|
|
10
|
+
function help() {
|
|
11
|
+
const chalk = require('chalk-v2');
|
|
12
|
+
console.log(`${chalk.bold(' Usage :')} ${chalk.cyanBright('poad info')} ${chalk.cyan('[--secrets]')}`);
|
|
13
|
+
console.log(' ');
|
|
14
|
+
console.log(' State of the running project: URLs, database, keys, migrations, then the services next to the engine.');
|
|
15
|
+
console.log(' The JWT secret, the service_role key, the S3 secret key and the Keycloak admin password are hidden.');
|
|
16
|
+
console.log(' ');
|
|
17
|
+
console.log(` ${chalk.cyanBright('--secrets')} show them too (not in a shared screen, a recording or a ticket)`);
|
|
18
|
+
console.log(' ');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = async (args = {}) => {
|
|
5
22
|
const chalk = require('chalk-v2');
|
|
6
23
|
const { findPoadDir } = require('../utils/findpoad');
|
|
7
24
|
const { isDockerExist } = require('../utils/docker');
|
|
@@ -12,5 +29,8 @@ module.exports = async () => {
|
|
|
12
29
|
if (!(await isDockerExist(config.project_uuid))) {
|
|
13
30
|
return console.log(chalk.redBright('The project is not started: "poad start".'));
|
|
14
31
|
}
|
|
15
|
-
await require('../utils/report').printReport(root, config);
|
|
32
|
+
await require('../utils/report').printReport(root, config, { secrets: wantsSecrets(args) });
|
|
16
33
|
};
|
|
34
|
+
|
|
35
|
+
module.exports.help = help;
|
|
36
|
+
module.exports.wantsSecrets = wantsSecrets;
|
|
@@ -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'));
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Bout en bout, contre le vrai registre npm (sans Docker, sans poad start) :
|
|
2
|
+
// POAD_E2E=1 node --test test/create.e2e.test.js
|
|
3
|
+
const test = require('node:test');
|
|
4
|
+
const assert = require('node:assert');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { spawnSync } = require('child_process');
|
|
8
|
+
const { tmpdir } = require('./helpers');
|
|
9
|
+
|
|
10
|
+
const CLI = path.join(__dirname, '..', 'poad.js');
|
|
11
|
+
const e2e = process.env.POAD_E2E === '1';
|
|
12
|
+
|
|
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
|
+
const cwd = tmpdir(t, 'poad-create-');
|
|
15
|
+
const r = spawnSync(process.execPath, [CLI, 'create', 'my-app', '--flat', '--template', 'angular', '--no-install', '--yes'], {
|
|
16
|
+
cwd,
|
|
17
|
+
encoding: 'utf8',
|
|
18
|
+
input: '',
|
|
19
|
+
env: { ...process.env, GIT_AUTHOR_NAME: 'poad test', GIT_AUTHOR_EMAIL: 'test@example.invalid', GIT_COMMITTER_NAME: 'poad test', GIT_COMMITTER_EMAIL: 'test@example.invalid' },
|
|
20
|
+
});
|
|
21
|
+
const out = r.stdout + r.stderr;
|
|
22
|
+
assert.strictEqual(r.status, 0, out);
|
|
23
|
+
assert.match(out, /integrity verified/);
|
|
24
|
+
const app = path.join(cwd, 'my-app');
|
|
25
|
+
|
|
26
|
+
// package.json renommé, sans champs de publication
|
|
27
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(app, 'package.json'), 'utf8'));
|
|
28
|
+
assert.strictEqual(pkg.name, 'my-app');
|
|
29
|
+
assert.strictEqual(pkg.version, '0.1.0');
|
|
30
|
+
assert.strictEqual(pkg.private, true);
|
|
31
|
+
for (const k of ['files', 'repository', 'publishConfig']) assert.ok(!(k in pkg), `${k} dropped`);
|
|
32
|
+
assert.match(pkg.poad.from, /^@poadio\/starter-angular@\d+\.\d+\.\d+/);
|
|
33
|
+
assert.strictEqual(pkg.scripts.start, 'node scripts/dev.mjs');
|
|
34
|
+
|
|
35
|
+
// poad init : config.toml avec l'engine recommandé par permalink
|
|
36
|
+
const config = fs.readFileSync(path.join(app, 'poad', 'config.toml'), 'utf8');
|
|
37
|
+
assert.match(config, /^project_id = "my-app"$/m);
|
|
38
|
+
const engine = /^engine = "([^"]+)"$/m.exec(config);
|
|
39
|
+
assert.ok(engine, config);
|
|
40
|
+
const permalink = await fetch('https://raw.githubusercontent.com/poadio/permalink/main/poad.json', { signal: AbortSignal.timeout(5000) })
|
|
41
|
+
.then((res) => res.json())
|
|
42
|
+
.catch(() => null);
|
|
43
|
+
if (permalink && permalink.engine && permalink.engine.stable) assert.strictEqual(engine[1], permalink.engine.stable);
|
|
44
|
+
assert.ok(fs.existsSync(path.join(app, 'poad', 'secrets.toml')));
|
|
45
|
+
assert.ok(fs.existsSync(path.join(app, 'poad', 'migrations')));
|
|
46
|
+
|
|
47
|
+
// .gitignore : lignes du modèle et de poad init
|
|
48
|
+
const gitignore = fs.readFileSync(path.join(app, '.gitignore'), 'utf8');
|
|
49
|
+
for (const line of ['poad/secrets.toml', 'poad/data/', 'node_modules/', '/public/env.json']) assert.ok(gitignore.split('\n').includes(line), line);
|
|
50
|
+
|
|
51
|
+
// Premier commit, sans secret
|
|
52
|
+
const log = spawnSync('git', ['log', '--format=%s'], { cwd: app, encoding: 'utf8' });
|
|
53
|
+
assert.match(log.stdout.trim(), /^Initial commit from @poadio\/starter-angular@/);
|
|
54
|
+
const files = spawnSync('git', ['ls-files'], { cwd: app, encoding: 'utf8' }).stdout.split('\n');
|
|
55
|
+
assert.ok(files.includes('package.json') && files.includes('poad/config.toml'));
|
|
56
|
+
assert.ok(!files.some((f) => f.startsWith('poad/secrets') || f.startsWith('poad/data/') || f === '.npmignore'));
|
|
57
|
+
|
|
58
|
+
// Aucune clé dans la sortie
|
|
59
|
+
const secrets = fs.readFileSync(path.join(app, 'poad', 'secrets.toml'), 'utf8');
|
|
60
|
+
for (const [, value] of secrets.matchAll(/=\s*"([^"]{16,})"/g)) assert.ok(!out.includes(value), 'a secret was printed');
|
|
61
|
+
|
|
62
|
+
// Dossier non vide : refusé, rien n'est touché
|
|
63
|
+
const again = spawnSync(process.execPath, [CLI, 'create', 'my-app', '--flat', '--template', 'angular', '--yes'], { cwd, encoding: 'utf8', input: '' });
|
|
64
|
+
assert.match(again.stdout, /is not empty/);
|
|
65
|
+
assert.notStrictEqual(again.status, 0);
|
|
66
|
+
|
|
67
|
+
// Modèle pas encore publié : « coming soon »
|
|
68
|
+
const soon = spawnSync(process.execPath, [CLI, 'create', 'other', '--template', 'vanilla', '--yes'], { cwd, encoding: 'utf8', input: '' });
|
|
69
|
+
if (/coming soon/.test(soon.stdout)) {
|
|
70
|
+
assert.notStrictEqual(soon.status, 0);
|
|
71
|
+
assert.ok(!fs.existsSync(path.join(cwd, 'other')));
|
|
72
|
+
}
|
|
73
|
+
});
|