selfnify-host 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/host.js +33 -11
  2. 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.0';
12
+ const VERSION = '1.0.1';
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 total = dry ? 2 : 5 + (flags.env ? 1 : 0) + (flags['no-install'] ? 0 : 1);
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,6 +689,10 @@ 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
698
  if (bot.status === 'running') {
@@ -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 (flags.env) {
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
- const pairs = parseEnvFile(flags.env);
701
- if (!Object.keys(pairs).length) throw new CliError('no variables found in ' + flags.env);
702
- const r = await request('POST', bp(name, '/env'), { body: pairs });
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
  }
@@ -723,10 +748,6 @@ async function deploy(opts, flags) {
723
748
  return finalLine;
724
749
  });
725
750
 
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
751
  out();
731
752
  out(' ' + c.green('Done') + c.dim(' in ' + Math.round((Date.now() - t0) / 1000) + 's'));
732
753
  out(c.dim(' logs: host logs ' + name + ' -f stop: host stop ' + name + ' redeploy: host deploy ' + name));
@@ -770,7 +791,8 @@ function printHelp() {
770
791
  out(' host login host logout host pin host help host version');
771
792
  out();
772
793
  h(' Flags');
773
- out(' --mem MB --autostart --no-install --env <file> --dry-run');
794
+ out(' --mem MB --autostart --no-install --env <file> --no-env --dry-run');
795
+ out(c.dim(' (a .env in your bot folder is never uploaded with the code, it asks before sending it as env vars)'));
774
796
  out(' -f/--follow -n <lines> --install --server <url> -v/--verbose --no-color');
775
797
  out();
776
798
  out(c.dim(' Also works as: selfnify <same commands>'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "selfnify-host",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Deploy and manage bots (Python, Node.js, Rust) on the Selfnify host with one command.",
5
5
  "bin": {
6
6
  "host": "host.js",