poad 2.48.0 → 2.49.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.
@@ -0,0 +1,19 @@
1
+ // poad env create <nom> [--kind persistent|preview] [--project <id>] [--json]
2
+ // POST v1/projects/:id/branches { name, kind }
3
+ module.exports = (args, raw) =>
4
+ require('../../utils/cloud/cli').run(raw, { values: ['project', 'kind'] }, async ({ opts, positionals, out }) => {
5
+ const api = require('../../utils/cloud/api');
6
+ const cli = require('../../utils/cloud/cli');
7
+ const branches = require('../../utils/cloud/branches');
8
+ const { chalk } = out;
9
+ if (positionals.length !== 1) throw api.usageError('Usage: poad env create <name> [--kind persistent|preview]');
10
+ const name = cli.checkBranch(positionals[0]);
11
+ const kind = opts.kind || 'persistent';
12
+ if (!['persistent', 'preview'].includes(kind)) throw api.usageError('--kind is persistent or preview');
13
+ const { id } = cli.targetProject(opts);
14
+ const data = await api.call('POST', `v1/projects/${api.enc(id)}/branches`, { body: { name, kind }, what: `environment ${name}`, timeout: 60000 });
15
+ const b = branches.normalize(data.branch || data) || { name, kind };
16
+ out.log(`${chalk.greenBright('✔')} Environment ${chalk.bold(b.name)} created on ${id} ${chalk.grey(`(${b.kind || kind}${b.status ? `, ${b.status}` : ''})`)}.`);
17
+ out.log(chalk.grey(` "poad deploy --env ${b.name}" deploys to it (also by default from the git branch ${b.name}).`));
18
+ out.result(b);
19
+ });
@@ -0,0 +1,2 @@
1
+ // poad env : comme poad env ls
2
+ module.exports = require('./ls');
@@ -0,0 +1,24 @@
1
+ // poad env ls [--project <id>] [--json] : environnements (branches) du projet poad.io lié
2
+ module.exports = (args, raw) =>
3
+ require('../../utils/cloud/cli').run(raw, { values: ['project'] }, async ({ opts, out }) => {
4
+ const cli = require('../../utils/cloud/cli');
5
+ const branches = require('../../utils/cloud/branches');
6
+ const { chalk } = out;
7
+ const { id, root } = cli.targetProject(opts);
8
+ const list = await branches.list(id);
9
+ const git = root ? branches.gitBranch(require('path').dirname(require('path').dirname(root))) : null;
10
+ const current = (list.find((b) => b.name === git) || list.find(branches.isProduction) || {}).name || null;
11
+ if (out.json) return out.result(list.map((b) => ({ ...b, production: branches.isProduction(b), default: b.name === current })));
12
+ out.log(' ');
13
+ out.log(chalk.bold(` Environments of ${id}`) + chalk.grey(` (${list.length})`));
14
+ out.log(' ');
15
+ if (!list.length) return out.log(chalk.grey(' None yet: "poad deploy" deploys to main; "poad env create <name>" adds one.'));
16
+ for (const b of list) {
17
+ const mark = b.name === current ? chalk.cyan('→') : ' ';
18
+ const kind = branches.isProduction(b) ? chalk.magenta('production') : chalk.grey(b.kind || 'environment');
19
+ out.log(` ${mark} ${chalk.bold.white(b.name.padEnd(24))} ${kind}${b.status ? chalk.grey(` ${b.status}`) : ''}${b.url ? ` ${chalk.cyanBright(b.url)}` : ''}`);
20
+ }
21
+ out.log(' ');
22
+ out.log(chalk.grey(` → default of "poad deploy" here${git ? ` (git branch ${git}${current === git ? '' : ': not on poad.io, main used'})` : ''}; --env <name> to choose.`));
23
+ out.log(' ');
24
+ });
@@ -0,0 +1,21 @@
1
+ // poad env rm <nom> [--yes] [--project <id>] [--json]
2
+ // DELETE v1/projects/:id/branches/:branch, après confirmation. La production
3
+ // (main) ne se supprime pas ici.
4
+ module.exports = (args, raw) =>
5
+ require('../../utils/cloud/cli').run(raw, { values: ['project'] }, async ({ opts, positionals, out }) => {
6
+ const api = require('../../utils/cloud/api');
7
+ const cli = require('../../utils/cloud/cli');
8
+ const branches = require('../../utils/cloud/branches');
9
+ const { chalk } = out;
10
+ if (positionals.length !== 1) throw api.usageError('Usage: poad env rm <name> [--yes]');
11
+ const name = cli.checkBranch(positionals[0]);
12
+ const { id } = cli.targetProject(opts);
13
+ const list = await branches.list(id);
14
+ const b = list.find((x) => x.name === name);
15
+ if (!b) throw new api.CloudError(`Environment "${name}" does not exist on ${id} (known: ${list.map((x) => x.name).join(', ') || 'none'}).`, { status: 404, code: 'branch_not_found' });
16
+ if (branches.isProduction(b)) throw api.usageError(`"${name}" is the production environment: it is not removed by the CLI (delete the project on poad.io instead).`);
17
+ await cli.confirm(`Remove the environment ${name} of ${id}, its database and its files? This cannot be undone.`, { yes: opts.yes, json: out.json });
18
+ await api.call('DELETE', `v1/projects/${api.enc(id)}/branches/${api.enc(name)}`, { what: `environment ${name}`, timeout: 60000 });
19
+ out.log(`${chalk.greenBright('✔')} Environment ${chalk.bold(name)} removed from ${id}.`);
20
+ out.result({ removed: name, project: id });
21
+ });
@@ -0,0 +1,38 @@
1
+ // poad link [<id>] [--json]
2
+ // Lie le projet local à un projet poad.io : [cloud] project = "<id>" dans
3
+ // poad/config.toml (versionné, aucun secret). Sans <id> : choix dans la liste
4
+ // des projets du compte (terminal seulement).
5
+ module.exports = (args, raw) =>
6
+ require('../utils/cloud/cli').run(raw, {}, async ({ positionals, out }) => {
7
+ const api = require('../utils/cloud/api');
8
+ const cli = require('../utils/cloud/cli');
9
+ const { view } = require('../global/cloud/index');
10
+ const { chalk } = out;
11
+ const root = cli.projectRoot();
12
+ if (!root) throw api.usageError('Not in a poad project folder: cd into one (poad init creates one).');
13
+ if (positionals.length > 1) throw api.usageError('Usage: poad link [<id>]');
14
+
15
+ let id = positionals[0] ? cli.checkId(positionals[0]) : null;
16
+ let project;
17
+ if (id) {
18
+ project = view(await api.call('GET', `v1/projects/${api.enc(id)}`, { what: `project ${id}` }));
19
+ } else {
20
+ const data = await api.call('GET', 'v1/projects', { what: 'projects' });
21
+ const list = (Array.isArray(data) ? data : Array.isArray(data.projects) ? data.projects : []).map(view).filter((p) => p.id);
22
+ if (!list.length) throw api.usageError('No project on poad.io yet: "poad cloud create" creates one and links this folder.');
23
+ if (!cli.interactive() || out.json) throw api.usageError(`Which project? poad link <id> (yours: ${list.map((p) => p.id).join(', ')})`);
24
+ const { select } = require('@inquirer/prompts');
25
+ const current = cli.linkedId(root);
26
+ id = await select({
27
+ message: 'poad.io project to link to this folder',
28
+ choices: list.map((p) => ({ name: `${p.name || p.id} (${p.id}, ${p.status || '?'})${p.id === current ? ' current' : ''}`, value: p.id })),
29
+ default: current || undefined,
30
+ });
31
+ project = list.find((p) => p.id === id);
32
+ }
33
+ const before = cli.linkedId(root);
34
+ cli.writeLink(root, id);
35
+ out.log(`${chalk.greenBright('✔')} Linked to ${chalk.bold(project.name || id)} ${chalk.grey(`(${id})`)}${before && before !== id ? chalk.grey(`, was ${before}`) : ''}.`);
36
+ out.log(chalk.grey(` [cloud] project = "${id}" in ${cli.rel(root)}: no secret, commit it. Next: "poad deploy".`));
37
+ out.result({ linked: id, previous: before, project });
38
+ });
@@ -0,0 +1,12 @@
1
+ // poad unlink [--json] : retire [cloud] project de poad/config.toml (rien ne change sur poad.io)
2
+ module.exports = (args, raw) =>
3
+ require('../utils/cloud/cli').run(raw, {}, async ({ out }) => {
4
+ const api = require('../utils/cloud/api');
5
+ const cli = require('../utils/cloud/cli');
6
+ const { chalk } = out;
7
+ const root = cli.projectRoot();
8
+ if (!root) throw api.usageError('Not in a poad project folder.');
9
+ const before = cli.removeLink(root);
10
+ out.log(before ? `${chalk.greenBright('✔')} No longer linked to ${before} (the project on poad.io is untouched).` : chalk.grey(' This project was not linked to poad.io.'));
11
+ out.result({ unlinked: before });
12
+ });