poad 2.61.0 → 2.61.1
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/create.js +40 -27
- package/package.json +1 -1
- package/poad.js +2 -0
- package/test/help.test.js +18 -0
- package/utils/banner.js +5 -4
- package/utils/help.js +60 -8
package/global/create.js
CHANGED
|
@@ -128,34 +128,47 @@ function modeOf(opts, project) {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
function usage(chalk) {
|
|
131
|
+
// Coupée à la largeur du terminal (utils/layout.js), comme les autres fiches : elle figure aussi dans poad --help
|
|
132
|
+
const { row, paragraph, terminalColumns } = require('../utils/layout');
|
|
133
|
+
const columns = terminalColumns();
|
|
131
134
|
const c = chalk.cyanBright;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
135
|
+
const out = [chalk.bold(' Usage :')];
|
|
136
|
+
const forms = [
|
|
137
|
+
['poad create <project> [--template t] [--app web]', 'a new project: poad/ (backend) and apps/<app> (first front-end)'],
|
|
138
|
+
['poad create <app> --template t [--dir <folder>]', 'inside a poad project: one more front-end, apps/<app>'],
|
|
139
|
+
['poad create <folder> --flat [--template t]', 'one front-end with poad/ inside it (the former layout)'],
|
|
140
|
+
];
|
|
141
|
+
for (const [form, text] of forms) {
|
|
142
|
+
out.push(` ${c(form)}`);
|
|
143
|
+
out.push(...paragraph([{ text, style: chalk.grey }], { columns, indent: 5 }));
|
|
144
|
+
}
|
|
145
|
+
out.push(' ');
|
|
146
|
+
out.push(' One poad backend, several front-ends:');
|
|
147
|
+
for (const l of [
|
|
148
|
+
' my-project/',
|
|
149
|
+
' poad/ backend (config, migrations, functions, flows)',
|
|
150
|
+
' apps/web/ Next.js poad create web --template next',
|
|
151
|
+
' apps/admin/ Angular poad create admin --template angular',
|
|
152
|
+
' package.json workspaces apps/*; bun start runs poad, then each front-end',
|
|
153
|
+
])
|
|
154
|
+
out.push(chalk.grey(` ${l}`));
|
|
155
|
+
out.push(' ');
|
|
156
|
+
const options = [
|
|
157
|
+
['--template', 'angular, next, nuxt or vanilla (asked when omitted in a terminal; angular otherwise)'],
|
|
158
|
+
['--app', 'name of the first front-end of a new project (default: web): its folder apps/<app>, and the application name of its public variables (PUBLIC_* with app=<name>, /env/v1?app=<name>)'],
|
|
159
|
+
['--dir', 'inside a project: folder of the new front-end (default: apps/<app>)'],
|
|
160
|
+
['--flat', 'the former layout: package.json and poad/ in the same folder'],
|
|
161
|
+
['--yes', 'no question'],
|
|
162
|
+
['--no-install', 'do not install the dependencies (bun start does it later)'],
|
|
163
|
+
['--no-git', 'no git repository, no commit (a front-end added to a project never commits)'],
|
|
164
|
+
['--pm', 'bun, npm or pnpm (default: bun if installed, else npm)'],
|
|
165
|
+
['--from', 'a local template (npm pack archive, or folder), to develop a template'],
|
|
166
|
+
];
|
|
167
|
+
for (const [k, v] of options) out.push(...row({ name: k, nameStyle: c, nameWidth: 14, columns, dots: false, segments: v }));
|
|
168
|
+
out.push(' ');
|
|
169
|
+
out.push(...paragraph([{ text: 'Each front-end gets a development port of its own: poad.port in its package.json (from the template, else its framework default), moved past the ports of the other front-ends and of the poad services. A front-end reads the public variables of its application name (package.json poad.app).' }], { columns }));
|
|
170
|
+
out.push(' ');
|
|
171
|
+
console.log(out.join('\n'));
|
|
159
172
|
}
|
|
160
173
|
|
|
161
174
|
/** Modèle choisi (question dans un terminal) : { template, metadata } ; null si abandon */
|
package/package.json
CHANGED
package/poad.js
CHANGED
|
@@ -120,6 +120,8 @@ const checkVersion = async () => {
|
|
|
120
120
|
// complète pour « poad --help », « poad -h » et « poad help ».
|
|
121
121
|
const displayBanner = ({ full = false } = {}) => {
|
|
122
122
|
const lines = require('./utils/banner').render({ full, inProject: Boolean(POAD_PATH), version: package.version });
|
|
123
|
+
// poad --help : la liste, puis la fiche de chaque commande (usage, options, notes)
|
|
124
|
+
if (full) lines.push(...require('./utils/help').allHelpLines());
|
|
123
125
|
console.log(lines.join('\n'));
|
|
124
126
|
};
|
|
125
127
|
|
package/test/help.test.js
CHANGED
|
@@ -136,3 +136,21 @@ test('--help : une description qui contient [section] plus loin n’est pas coup
|
|
|
136
136
|
assert.match(r.stdout, /start \.+\s+Start the project: engine, migrations/);
|
|
137
137
|
assert.match(r.stdout, /create \.+\s+Create a poad project/);
|
|
138
138
|
});
|
|
139
|
+
|
|
140
|
+
test('poad --help: every command, project ones too outside a project, then the sheet of each', (t) => {
|
|
141
|
+
const dir = tmpdir(t);
|
|
142
|
+
const run = (args) => spawnSync(process.execPath, [path.join(__dirname, '..', 'poad.js'), ...args], { cwd: dir, encoding: 'utf8', env: { ...process.env, NO_COLOR: '1', FORCE_COLOR: '0', COLUMNS: '100' } });
|
|
143
|
+
const full = run(['--help']).stdout;
|
|
144
|
+
const short = run([]).stdout;
|
|
145
|
+
assert.match(full, /Project commands \(in a project\)/);
|
|
146
|
+
assert.doesNotMatch(full, /You are not in a project directory/);
|
|
147
|
+
for (const name of [...Object.keys(require('../global/cli')), ...Object.keys(require('../project/cli'))]) {
|
|
148
|
+
assert.ok(full.includes(`── poad ${name} `), `fiche de poad ${name}`);
|
|
149
|
+
}
|
|
150
|
+
// Fiches des sous-commandes qui en ont une
|
|
151
|
+
assert.ok(full.includes('── poad storage ls '));
|
|
152
|
+
assert.ok(full.split('\n').length > 3 * short.split('\n').length, 'aide complète bien plus longue que la vue courte');
|
|
153
|
+
// poad seul : vue courte, inchangée
|
|
154
|
+
assert.match(short, /You are not in a project directory/);
|
|
155
|
+
assert.doesNotMatch(short, /── poad /);
|
|
156
|
+
});
|
package/utils/banner.js
CHANGED
|
@@ -83,7 +83,8 @@ function render({ full = false, inProject = true, columns = terminalColumns(), v
|
|
|
83
83
|
.filter(Boolean)
|
|
84
84
|
.map((e) => ({ ...e, short: SHORT[scope][e.name] }));
|
|
85
85
|
};
|
|
86
|
-
|
|
86
|
+
// Aide complète : les commandes de projet toujours listées, même hors d'un projet
|
|
87
|
+
const groups = { global: pick('global'), project: inProject || full ? pick('project') : [] };
|
|
87
88
|
const title = (e) => (full && e.subs && e.subs.length ? `${e.name} <subcommand>` : e.name);
|
|
88
89
|
const nameWidth = Math.max(...[...groups.global, ...groups.project].map((e) => title(e).length)) + 4;
|
|
89
90
|
|
|
@@ -113,12 +114,12 @@ function render({ full = false, inProject = true, columns = terminalColumns(), v
|
|
|
113
114
|
lines.push(chalk.bold(' Global commands :'));
|
|
114
115
|
table(groups.global);
|
|
115
116
|
lines.push('');
|
|
116
|
-
lines.push(chalk.bold(' Project commands :'));
|
|
117
|
-
if (!
|
|
117
|
+
lines.push(chalk.bold(full && !inProject ? ' Project commands (in a project) :' : ' Project commands :'));
|
|
118
|
+
if (!groups.project.length) lines.push(...paragraph([{ text: 'You are not in a project directory.' }], { columns }));
|
|
118
119
|
else table(groups.project);
|
|
119
120
|
lines.push('');
|
|
120
121
|
if (full) {
|
|
121
|
-
lines.push(...paragraph([{ text: '
|
|
122
|
+
lines.push(...paragraph([{ text: 'Details of every command below; one command only: ', style: chalk.grey }, { text: 'poad <command> --help', style: chalk.cyanBright }], { columns, indent: 1 }));
|
|
122
123
|
} else {
|
|
123
124
|
const more = [
|
|
124
125
|
['poad --help', 'every command and its options'],
|
package/utils/help.js
CHANGED
|
@@ -48,13 +48,13 @@ const describe = (entry) => {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
51
|
+
* Lignes de l'aide de la commande désignée par argv, ou null si aucune commande
|
|
52
|
+
* ne correspond. L'aide propre d'un module (help()) est captée telle qu'elle s'affiche.
|
|
53
53
|
*/
|
|
54
|
-
function
|
|
54
|
+
function helpLines(argv = [], { tables = loadTables(), base = path.join(__dirname, '..') } = {}) {
|
|
55
55
|
const chalk = require('chalk-v2');
|
|
56
56
|
const cmd = resolveCommand(argv, tables);
|
|
57
|
-
if (!cmd) return
|
|
57
|
+
if (!cmd) return null;
|
|
58
58
|
// Aide détaillée exportée par le module de la commande
|
|
59
59
|
let unit = null;
|
|
60
60
|
try {
|
|
@@ -63,8 +63,15 @@ function printHelp(argv = [], { tables = loadTables(), base = path.join(__dirnam
|
|
|
63
63
|
unit = null;
|
|
64
64
|
}
|
|
65
65
|
if (unit && typeof unit.help === 'function') {
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const captured = [];
|
|
67
|
+
const log = console.log;
|
|
68
|
+
console.log = (...args) => captured.push(args.join(' '));
|
|
69
|
+
try {
|
|
70
|
+
unit.help();
|
|
71
|
+
} finally {
|
|
72
|
+
console.log = log;
|
|
73
|
+
}
|
|
74
|
+
return captured.join('\n').split('\n');
|
|
68
75
|
}
|
|
69
76
|
const name = `poad ${cmd.dir.join(' ')}`;
|
|
70
77
|
const { row, paragraph, terminalColumns } = require('./layout');
|
|
@@ -99,8 +106,53 @@ function printHelp(argv = [], { tables = loadTables(), base = path.join(__dirnam
|
|
|
99
106
|
out.push(...paragraph(p, { columns }));
|
|
100
107
|
}
|
|
101
108
|
out.push(' ');
|
|
102
|
-
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Affiche l'aide de la commande désignée par argv. Renvoie false si aucune
|
|
114
|
+
* commande ne correspond (le répartiteur montre alors la liste générale).
|
|
115
|
+
*/
|
|
116
|
+
function printHelp(argv = [], opts = {}) {
|
|
117
|
+
const lines = helpLines(argv, opts);
|
|
118
|
+
if (!lines) return false;
|
|
119
|
+
console.log(lines.join('\n'));
|
|
103
120
|
return true;
|
|
104
121
|
}
|
|
105
122
|
|
|
106
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Aide complète (poad --help) : la fiche de chaque commande, globales puis projet, chacune sous
|
|
125
|
+
* son titre ; une sous-commande qui a sa propre fiche (help-details.js) suit celle de sa commande.
|
|
126
|
+
*/
|
|
127
|
+
function allHelpLines({ tables = loadTables(), base = path.join(__dirname, '..') } = {}) {
|
|
128
|
+
const chalk = require('chalk-v2');
|
|
129
|
+
const { wrap, visible, terminalColumns } = require('./layout');
|
|
130
|
+
const columns = terminalColumns();
|
|
131
|
+
// Une ligne écrite à largeur fixe par l'aide propre d'un module, ou un long usage : coupée à la largeur du
|
|
132
|
+
// terminal, retrait gardé (suite de ligne décalée de 2) ; ses couleurs tombent, ses mots restent
|
|
133
|
+
const fit = (line) => {
|
|
134
|
+
if (visible(line) <= columns) return [line];
|
|
135
|
+
const plain = String(line).replace(/\x1b\[[0-9;]*m/g, '');
|
|
136
|
+
const lead = plain.match(/^ */)[0];
|
|
137
|
+
const parts = wrap(plain.trim(), Math.max(20, columns - lead.length - 2));
|
|
138
|
+
return parts.map((p, i) => `${i ? `${lead} ` : lead}${p}`);
|
|
139
|
+
};
|
|
140
|
+
const out = [];
|
|
141
|
+
for (const scope of ['global', 'project']) {
|
|
142
|
+
for (const [name, entry] of Object.entries(tables[scope])) {
|
|
143
|
+
const words = [[name]];
|
|
144
|
+
if (entry && typeof entry === 'object') {
|
|
145
|
+
for (const sub of Object.keys(entry)) if (sub !== 'description' && sheets[`${name} ${sub}`]) words.push([name, sub]);
|
|
146
|
+
}
|
|
147
|
+
for (const w of words) {
|
|
148
|
+
const lines = helpLines(w, { tables, base });
|
|
149
|
+
if (!lines) continue;
|
|
150
|
+
const body = lines.filter((l, i, a) => !(i === a.length - 1 && !l.trim())).flatMap(fit);
|
|
151
|
+
out.push(chalk.bold.cyan(` ── poad ${w.join(' ')} ${'─'.repeat(Math.max(2, Math.min(70, columns) - 10 - w.join(' ').length))}`), '', ...body, '');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
module.exports = { HELP_FLAGS, helpRequested, resolveCommand, printHelp, helpLines, allHelpLines };
|