selfnify-host 1.0.0 → 1.0.2
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/host.js +36 -13
- package/package.json +1 -1
package/host.js
CHANGED
|
@@ -9,7 +9,7 @@ const https = require('https');
|
|
|
9
9
|
const crypto = require('crypto');
|
|
10
10
|
const readline = require('readline');
|
|
11
11
|
|
|
12
|
-
const VERSION = '1.0.
|
|
12
|
+
const VERSION = '1.0.2';
|
|
13
13
|
const DEFAULT_URL = 'https://host.lume.dpdns.org';
|
|
14
14
|
const CONFIG_DIR = path.join(os.homedir(), '.selfnify');
|
|
15
15
|
const CONFIG_FILE = path.join(CONFIG_DIR, 'host.json');
|
|
@@ -27,6 +27,7 @@ const BOOL_FLAGS = {
|
|
|
27
27
|
'--autostart': 'autostart',
|
|
28
28
|
'--no-autostart': 'no-autostart',
|
|
29
29
|
'--no-install': 'no-install',
|
|
30
|
+
'--no-env': 'no-env',
|
|
30
31
|
'--dry-run': 'dry-run',
|
|
31
32
|
'-v': 'verbose',
|
|
32
33
|
'--verbose': 'verbose',
|
|
@@ -627,7 +628,11 @@ async function deploy(opts, flags) {
|
|
|
627
628
|
}
|
|
628
629
|
|
|
629
630
|
const dry = Boolean(flags['dry-run']);
|
|
630
|
-
const
|
|
631
|
+
const localEnv = path.join(dir, '.env');
|
|
632
|
+
let envMode = null; // 'explicit' = --env given (no question), 'ask' = .env found, ask first
|
|
633
|
+
if (flags.env) envMode = 'explicit';
|
|
634
|
+
else if (!flags['no-env'] && fs.existsSync(localEnv)) envMode = 'ask';
|
|
635
|
+
const total = dry ? 2 : 5 + (envMode ? 1 : 0) + (flags['no-install'] ? 0 : 1);
|
|
631
636
|
let n = 0;
|
|
632
637
|
const next = (label, fn) => step(++n, total, label, fn);
|
|
633
638
|
|
|
@@ -684,9 +689,13 @@ async function deploy(opts, flags) {
|
|
|
684
689
|
return 'found, updating';
|
|
685
690
|
});
|
|
686
691
|
|
|
692
|
+
const saved = loadConfig();
|
|
693
|
+
saved.bots = Object.assign({}, saved.bots, { [name]: { path: dir, start: startStr, main: opts.main || null } });
|
|
694
|
+
saveConfig(saved);
|
|
695
|
+
|
|
687
696
|
await next('Uploading', async ({ progress }) => {
|
|
688
697
|
if (bot.status === 'installing') throw new CliError('an install is already running for this bot, try again in a minute');
|
|
689
|
-
if (bot.status === 'running') {
|
|
698
|
+
if (bot.status === 'running' && lang !== 'rust') {
|
|
690
699
|
progress('stopping old version');
|
|
691
700
|
await request('POST', bp(name, '/stop'));
|
|
692
701
|
}
|
|
@@ -695,11 +704,27 @@ async function deploy(opts, flags) {
|
|
|
695
704
|
return r.extracted_mb + ' MB on the server';
|
|
696
705
|
});
|
|
697
706
|
|
|
698
|
-
if (
|
|
707
|
+
if (envMode) {
|
|
708
|
+
const envPath = envMode === 'explicit' ? flags.env : localEnv;
|
|
709
|
+
let send = envMode === 'explicit';
|
|
710
|
+
let pairs = null;
|
|
711
|
+
if (envMode === 'ask') {
|
|
712
|
+
pairs = parseEnvFile(envPath);
|
|
713
|
+
const keys = Object.keys(pairs);
|
|
714
|
+
if (keys.length && process.stdin.isTTY) {
|
|
715
|
+
const onServer = new Set(bot.env_keys || []);
|
|
716
|
+
const already = keys.filter((k) => onServer.has(k)).length;
|
|
717
|
+
out(' ' + c.yellow('Found .env') + ' with ' + keys.length + ' variables (' + already + ' already on the server)');
|
|
718
|
+
out(c.dim(' ' + keys.join(', ')));
|
|
719
|
+
const answer = (await ask(' Send it to the server as environment variables? [y/N] ')).toLowerCase();
|
|
720
|
+
send = answer === 'y' || answer === 'yes';
|
|
721
|
+
}
|
|
722
|
+
}
|
|
699
723
|
await next('Sending env vars', async () => {
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
724
|
+
if (!send) return 'skipped (send later: host env ' + name + ' push)';
|
|
725
|
+
const toSend = pairs || parseEnvFile(envPath);
|
|
726
|
+
if (!Object.keys(toSend).length) throw new CliError('no variables found in ' + envPath);
|
|
727
|
+
const r = await request('POST', bp(name, '/env'), { body: toSend });
|
|
703
728
|
return r.env_keys.length + ' on the server';
|
|
704
729
|
});
|
|
705
730
|
}
|
|
@@ -710,7 +735,8 @@ async function deploy(opts, flags) {
|
|
|
710
735
|
|
|
711
736
|
let finalLine = '';
|
|
712
737
|
await next('Starting', async () => {
|
|
713
|
-
|
|
738
|
+
const swap = bot.status === 'running' && lang === 'rust';
|
|
739
|
+
await request('POST', bp(name, swap ? '/restart' : '/start'));
|
|
714
740
|
await sleep(4000);
|
|
715
741
|
const now = await request('GET', bp(name));
|
|
716
742
|
if (now.status !== 'running') {
|
|
@@ -723,10 +749,6 @@ async function deploy(opts, flags) {
|
|
|
723
749
|
return finalLine;
|
|
724
750
|
});
|
|
725
751
|
|
|
726
|
-
const fresh = loadConfig();
|
|
727
|
-
fresh.bots = Object.assign({}, fresh.bots, { [name]: { path: dir, start: startStr, main: opts.main || null } });
|
|
728
|
-
saveConfig(fresh);
|
|
729
|
-
|
|
730
752
|
out();
|
|
731
753
|
out(' ' + c.green('Done') + c.dim(' in ' + Math.round((Date.now() - t0) / 1000) + 's'));
|
|
732
754
|
out(c.dim(' logs: host logs ' + name + ' -f stop: host stop ' + name + ' redeploy: host deploy ' + name));
|
|
@@ -770,7 +792,8 @@ function printHelp() {
|
|
|
770
792
|
out(' host login host logout host pin host help host version');
|
|
771
793
|
out();
|
|
772
794
|
h(' Flags');
|
|
773
|
-
out(' --mem MB --autostart --no-install --env <file> --dry-run');
|
|
795
|
+
out(' --mem MB --autostart --no-install --env <file> --no-env --dry-run');
|
|
796
|
+
out(c.dim(' (a .env in your bot folder is never uploaded with the code, it asks before sending it as env vars)'));
|
|
774
797
|
out(' -f/--follow -n <lines> --install --server <url> -v/--verbose --no-color');
|
|
775
798
|
out();
|
|
776
799
|
out(c.dim(' Also works as: selfnify <same commands>'));
|