poad 2.47.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.
- package/global/cli.js +14 -0
- package/global/cloud/action.js +37 -0
- package/global/cloud/create.js +42 -0
- package/global/cloud/index.js +19 -0
- package/global/cloud/info.js +37 -0
- package/global/cloud/pause.js +2 -0
- package/global/cloud/projects.js +32 -0
- package/global/cloud/resume.js +2 -0
- package/global/cloud/upgrade.js +2 -0
- package/global/create.js +4 -4
- package/global/init.js +2 -0
- package/global/login.js +32 -0
- package/global/logout.js +14 -0
- package/global/ls.js +2 -0
- package/global/projects.js +124 -0
- package/global/start.js +2 -0
- package/global/whoami.js +13 -0
- package/package.json +1 -1
- package/poad.js +5 -2
- package/project/cli.js +11 -0
- package/project/db/index.js +2 -0
- package/project/db/pull.js +92 -0
- package/project/db/url.js +33 -0
- package/project/deploy.js +136 -0
- package/project/env/create.js +19 -0
- package/project/env/index.js +2 -0
- package/project/env/ls.js +24 -0
- package/project/env/rm.js +21 -0
- package/project/link.js +38 -0
- package/project/unlink.js +12 -0
- package/project/upgrade.js +1 -0
- package/test/cloud.test.js +589 -0
- package/test/projects.test.js +167 -0
- package/utils/banner.js +3 -0
- package/utils/cloud/api.js +120 -0
- package/utils/cloud/branches.js +63 -0
- package/utils/cloud/bundle.js +226 -0
- package/utils/cloud/cli.js +166 -0
- package/utils/cloud/credentials.js +92 -0
- package/utils/cloud/db.js +34 -0
- package/utils/cloud/device.js +66 -0
- package/utils/cloud/system.js +45 -0
- package/utils/engine.js +1 -0
- package/utils/help-details.js +135 -0
- package/utils/projects.js +338 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// poad db url [--env <branche>] [--mode session|transaction] [--show-password] [--copy] [--json]
|
|
2
|
+
// Chaîne de connexion à la base du projet poad.io lié. Le mot de passe n'est
|
|
3
|
+
// jamais affiché sans --show-password : dans un terminal, la chaîne complète
|
|
4
|
+
// part dans le presse-papiers ; à l'écran, elle est masquée.
|
|
5
|
+
module.exports = (args, raw) =>
|
|
6
|
+
require('../../utils/cloud/cli').run(raw, { values: ['env', 'mode', 'project'], flags: ['show-password', 'copy', 'no-copy'] }, async ({ opts, out }) => {
|
|
7
|
+
const api = require('../../utils/cloud/api');
|
|
8
|
+
const cli = require('../../utils/cloud/cli');
|
|
9
|
+
const branches = require('../../utils/cloud/branches');
|
|
10
|
+
const db = require('../../utils/cloud/db');
|
|
11
|
+
const { chalk } = out;
|
|
12
|
+
const mode = opts.mode || 'session';
|
|
13
|
+
if (!['session', 'transaction'].includes(mode)) throw api.usageError('--mode is session (port 5432) or transaction (port 6543)');
|
|
14
|
+
const { id, root } = cli.targetProject(opts);
|
|
15
|
+
const env = await branches.resolve(id, { wanted: opts.env, root });
|
|
16
|
+
const show = Boolean(opts['show-password']);
|
|
17
|
+
// Presse-papiers : dans un terminal par défaut, ou demandé par --copy
|
|
18
|
+
const wantCopy = !opts['no-copy'] && (opts.copy || (process.stdout.isTTY && !out.json));
|
|
19
|
+
const c = await db.credentials(id, { env, purpose: show ? 'reveal' : 'copy' });
|
|
20
|
+
const full = db.url(c, mode, { show: true });
|
|
21
|
+
const masked = db.url(c, mode);
|
|
22
|
+
const copied = wantCopy ? require('../../utils/cloud/system').copy(full) : null;
|
|
23
|
+
|
|
24
|
+
if (out.json) return out.result({ project: id, env: env.branch, mode, url: show ? full : masked, password_shown: show, copied: Boolean(copied) });
|
|
25
|
+
if (show) {
|
|
26
|
+
console.log(full);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
out.log(masked);
|
|
30
|
+
if (copied) out.log(chalk.grey(` Full connection string copied to the clipboard (${copied}); the password is masked here.`));
|
|
31
|
+
else out.log(chalk.grey(` Password masked${wantCopy ? ' (no clipboard tool found: pbcopy, wl-copy, xclip or xsel)' : ''}: "poad db url --show-password" prints it (it then stays in your terminal history).`));
|
|
32
|
+
out.log(chalk.grey(` Mode ${mode}: ${mode === 'session' ? 'port 5432, long connections (psql, pg_dump, migrations)' : 'port 6543, pooled short connections (serverless)'}.`));
|
|
33
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// poad deploy [--env <branche>] [--dry-run] [--yes] [--json]
|
|
2
|
+
//
|
|
3
|
+
// Envoie le dossier poad/ (liste blanche, sans aucun secret : utils/cloud/bundle.js)
|
|
4
|
+
// à l'environnement du projet poad.io lié :
|
|
5
|
+
// POST v1/projects/:id/branches/:branch/deploy (application/gzip)
|
|
6
|
+
// x-poad-sha commit git courant, si poad/ n'a aucun changement non commité
|
|
7
|
+
// x-poad-dry-run 1 avec --dry-run : le serveur dit ce qu'il ferait, rien ne change
|
|
8
|
+
// réponse : { deploy_id?, status?, migrations: { applied, pending, errors } }
|
|
9
|
+
// asynchrone (deploy_id et état non terminé) : GET …/deploys/:deploy_id jusqu'à la fin
|
|
10
|
+
//
|
|
11
|
+
// Production (main) : résumé puis confirmation, sauf --yes (obligatoire hors
|
|
12
|
+
// terminal). Codes de sortie : 0 déployé, 5 déploiement en échec (erreurs de
|
|
13
|
+
// migration), 4 confirmation manquante, 3 session, 2 usage, 1 autre erreur.
|
|
14
|
+
const DONE = ['succeeded', 'success', 'done', 'deployed', 'completed', 'ok', 'failed', 'error', 'cancelled', 'canceled'];
|
|
15
|
+
const FAILED = ['failed', 'error', 'cancelled', 'canceled'];
|
|
16
|
+
|
|
17
|
+
const names = (list) => (Array.isArray(list) ? list : []).map((m) => (typeof m === 'string' ? m : m && (m.name || m.version || m.file || m.migration)) || '?');
|
|
18
|
+
const errorsOf = (list) =>
|
|
19
|
+
(Array.isArray(list) ? list : []).map((e) => (typeof e === 'string' ? { migration: null, message: e } : { migration: (e && (e.migration || e.name || e.version || e.file)) || null, message: String((e && (e.message || e.error)) || 'error') }));
|
|
20
|
+
|
|
21
|
+
/** Résultat d'un déploiement, ramené aux champs connus */
|
|
22
|
+
function summarize(d = {}) {
|
|
23
|
+
const m = d.migrations || {};
|
|
24
|
+
const errors = errorsOf(m.errors || d.errors);
|
|
25
|
+
const status = typeof d.status === 'string' ? d.status.toLowerCase() : null;
|
|
26
|
+
return {
|
|
27
|
+
deploy_id: typeof d.deploy_id === 'string' || typeof d.deploy_id === 'number' ? String(d.deploy_id) : typeof d.id === 'string' ? d.id : null,
|
|
28
|
+
status,
|
|
29
|
+
dry_run: Boolean(d.dry_run),
|
|
30
|
+
migrations: { applied: names(m.applied), pending: names(m.pending), errors },
|
|
31
|
+
message: typeof d.message === 'string' ? d.message : null,
|
|
32
|
+
failed: errors.length > 0 || FAILED.includes(status),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function gitState(dir) {
|
|
37
|
+
const { spawnSync } = require('child_process');
|
|
38
|
+
const git = (a) => spawnSync('git', a, { cwd: dir, encoding: 'utf8', timeout: 10000 });
|
|
39
|
+
const head = git(['rev-parse', 'HEAD']);
|
|
40
|
+
if (head.status !== 0) return { repo: false, sha: null, dirty: false };
|
|
41
|
+
const st = git(['status', '--porcelain', '--', '.']);
|
|
42
|
+
const dirty = st.status === 0 ? st.stdout.split('\n').filter(Boolean) : [];
|
|
43
|
+
return { repo: true, sha: head.stdout.trim(), dirty: dirty.length > 0, changes: dirty.length };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = (args, raw) =>
|
|
47
|
+
require('../utils/cloud/cli').run(raw, { values: ['env', 'project'], flags: ['dry-run'] }, async ({ opts, out }) => {
|
|
48
|
+
const path = require('path');
|
|
49
|
+
const api = require('../utils/cloud/api');
|
|
50
|
+
const cli = require('../utils/cloud/cli');
|
|
51
|
+
const branches = require('../utils/cloud/branches');
|
|
52
|
+
const bundle = require('../utils/cloud/bundle');
|
|
53
|
+
const { chalk } = out;
|
|
54
|
+
|
|
55
|
+
const root = cli.projectRoot();
|
|
56
|
+
if (!root) throw api.usageError('Not in a poad project folder: cd into one.');
|
|
57
|
+
const { id } = cli.targetProject(opts);
|
|
58
|
+
const poadDir = path.dirname(root);
|
|
59
|
+
const dryRun = Boolean(opts['dry-run']);
|
|
60
|
+
|
|
61
|
+
const env = await branches.resolve(id, { wanted: opts.env, root });
|
|
62
|
+
let b;
|
|
63
|
+
try {
|
|
64
|
+
b = bundle.build(poadDir);
|
|
65
|
+
} catch (err) {
|
|
66
|
+
if (err instanceof bundle.BundleError) throw new api.CloudError(`Nothing sent: ${err.message}`, { code: 'bundle' });
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
const git = gitState(poadDir);
|
|
70
|
+
const sha = git.repo && !git.dirty ? git.sha : null;
|
|
71
|
+
const kb = (n) => (n < 1024 ? `${n} B` : `${(n / 1024).toFixed(1)} KB`);
|
|
72
|
+
|
|
73
|
+
const migrations = b.files.filter((f) => f.path.startsWith('migrations/') && f.path.endsWith('.sql')).length;
|
|
74
|
+
const functions = new Set(b.files.filter((f) => f.path.startsWith('functions/')).map((f) => f.path.split('/')[1])).size;
|
|
75
|
+
const flows = b.files.filter((f) => f.path.startsWith('flows/') && f.path.endsWith('.json')).length;
|
|
76
|
+
|
|
77
|
+
out.log(' ');
|
|
78
|
+
out.log(` ${chalk.bold(dryRun ? 'Deploy (dry run)' : 'Deploy')} ${chalk.white(id)} → ${env.production ? chalk.magenta.bold(env.branch + ' (production)') : chalk.cyan.bold(env.branch)}${chalk.grey(env.source === 'git' ? ' (git branch)' : env.source === 'default' ? (env.git ? ` (git branch ${env.git} not on poad.io)` : '') : '')}`);
|
|
79
|
+
out.log(chalk.grey(` ${b.files.length} files, ${kb(b.tgz.length)} compressed: ${migrations} migration(s), ${functions} function(s), ${flows} flow(s)`));
|
|
80
|
+
if (git.repo && git.dirty) out.log(chalk.yellowBright(` ⚠ poad/ has ${git.changes} uncommitted change(s): the files of the disk are sent, without a commit id.`));
|
|
81
|
+
else if (sha) out.log(chalk.grey(` commit ${sha.slice(0, 12)}`));
|
|
82
|
+
else out.log(chalk.grey(' not in a git repository: no commit id'));
|
|
83
|
+
for (const s of b.skipped) out.log(chalk.grey(` skipped ${s.path}: ${s.reason}`));
|
|
84
|
+
|
|
85
|
+
if (env.production && !dryRun) {
|
|
86
|
+
await cli.confirm(`Deploy to production (${env.branch}) of ${id}? Pending migrations are applied to its database.`, { yes: opts.yes, json: out.json });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const route = `v1/projects/${api.enc(id)}/branches/${api.enc(env.branch)}`;
|
|
90
|
+
const headers = {};
|
|
91
|
+
if (sha) headers['x-poad-sha'] = sha;
|
|
92
|
+
if (dryRun) headers['x-poad-dry-run'] = '1';
|
|
93
|
+
let result = summarize(await api.call('POST', `${route}/deploy`, { body: b.tgz, contentType: 'application/gzip', headers, what: 'deploy', timeout: 300000 }));
|
|
94
|
+
|
|
95
|
+
// Déploiement asynchrone : suivi jusqu'à son terme
|
|
96
|
+
if (result.deploy_id && result.status && !DONE.includes(result.status)) {
|
|
97
|
+
const started = Date.now();
|
|
98
|
+
let last = result.status;
|
|
99
|
+
out.log(chalk.grey(` deploy ${result.deploy_id}: ${last}…`));
|
|
100
|
+
while (!DONE.includes(result.status)) {
|
|
101
|
+
if (Date.now() - started > 15 * 60 * 1000) throw new api.CloudError(`Deploy ${result.deploy_id} still ${result.status} after 15 min: follow it on poad.io.`, { code: 'timeout' });
|
|
102
|
+
await new Promise((r) => setTimeout(r, Number(process.env.POAD_DEPLOY_POLL_MS) || 2000));
|
|
103
|
+
const next = summarize(await api.call('GET', `${route}/deploys/${api.enc(result.deploy_id)}`, { what: 'deploy status' }));
|
|
104
|
+
result = { ...next, deploy_id: next.deploy_id || result.deploy_id };
|
|
105
|
+
if (result.status !== last) out.log(chalk.grey(` deploy ${result.deploy_id}: ${(last = result.status)}`));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const m = result.migrations;
|
|
110
|
+
out.log(' ');
|
|
111
|
+
for (const n of m.applied) out.log(` ${chalk.greenBright('✔')} ${n}`);
|
|
112
|
+
for (const n of m.pending) out.log(` ${chalk.yellow('○')} ${n} ${chalk.grey(dryRun ? '(would be applied)' : '(pending)')}`);
|
|
113
|
+
for (const e of m.errors) out.log(` ${chalk.redBright('✕')} ${e.migration ? chalk.bold(e.migration) + ': ' : ''}${e.message}`);
|
|
114
|
+
if (!m.applied.length && !m.pending.length && !m.errors.length) out.log(chalk.grey(' No migration to apply.'));
|
|
115
|
+
out.log(' ');
|
|
116
|
+
if (result.failed) out.log(chalk.redBright(` Deploy failed${result.message ? `: ${result.message}` : ''}.`));
|
|
117
|
+
else if (dryRun) out.log(`${chalk.greenBright('✔')} Dry run: nothing changed on ${env.branch}.`);
|
|
118
|
+
else out.log(`${chalk.greenBright('✔')} Deployed to ${env.branch}${result.deploy_id ? chalk.grey(` (${result.deploy_id})`) : ''}.`);
|
|
119
|
+
out.log(' ');
|
|
120
|
+
|
|
121
|
+
out.result({
|
|
122
|
+
project: id,
|
|
123
|
+
env: env.branch,
|
|
124
|
+
production: env.production,
|
|
125
|
+
sha,
|
|
126
|
+
dirty: git.dirty,
|
|
127
|
+
files: b.files.length,
|
|
128
|
+
bytes: b.tgz.length,
|
|
129
|
+
skipped: b.skipped,
|
|
130
|
+
...result,
|
|
131
|
+
dry_run: dryRun,
|
|
132
|
+
});
|
|
133
|
+
return result.failed ? api.EXIT.failed : 0;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
module.exports.summarize = summarize;
|
|
@@ -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,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
|
+
});
|
package/project/link.js
ADDED
|
@@ -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
|
+
});
|
package/project/upgrade.js
CHANGED
|
@@ -91,6 +91,7 @@ module.exports = async (args = {}) => {
|
|
|
91
91
|
progress = ora('Restoring the backup').start();
|
|
92
92
|
await backup.restore(docker, root, image, chosen);
|
|
93
93
|
progress.succeed(chalk.bold(`Restored ${chosen.file} (engine ${chosen.engine}).`));
|
|
94
|
+
require('../utils/projects').record(root);
|
|
94
95
|
} catch (err) {
|
|
95
96
|
const msg = chalk.redBright(`Restore failed: ${err.message}. Nothing restarted.`);
|
|
96
97
|
if (progress) progress.fail(msg);
|