|
1 | 1 | #!/usr/bin/env node
|
2 |
| - |
| 2 | +const p = require('path') |
| 3 | +const os = require('os') |
| 4 | +const fs = require('fs').promises |
3 | 5 | const repl = require('repl')
|
4 | 6 | const { Server, Client } = require('./')
|
5 | 7 | const minimist = require('minimist')
|
6 | 8 | const { migrate: migrateFromDaemon, isMigrated } = require('@hyperspace/migration-tool')
|
7 | 9 |
|
| 10 | +// TODO: Default paths are duplicated here because we need to do the async migration check. |
| 11 | +const HYPERSPACE_STORAGE_DIR = p.join(os.homedir(), '.hyperspace', 'storage') |
| 12 | +const HYPERDRIVE_STORAGE_DIR = p.join(os.homedir(), '.hyperdrive', 'storage', 'cores') |
| 13 | + |
8 | 14 | const argv = minimist(process.argv.slice(2), {
|
9 | 15 | string: ['host', 'storage', 'bootstrap'],
|
10 | 16 | boolean: ['memory-only', 'announce', 'migrate', 'repl'],
|
@@ -49,17 +55,23 @@ async function main () {
|
49 | 55 | // Note: This will be removed in future releases of Hyperspace.
|
50 | 56 | // If the hyperdrive-daemon -> hyperspace migration has already completed, this is a no-op.
|
51 | 57 | if (argv.migrate) {
|
52 |
| - if (!(await isMigrated())) { |
| 58 | + if (!(await isMigrated({ noMove: true }))) { |
53 | 59 | console.log('Migrating from Hyperdrive daemon...')
|
54 |
| - await migrateFromDaemon() |
| 60 | + // TODO: For Beaker compat, do not move existing cores into ~/.hyperspace for now. |
| 61 | + await migrateFromDaemon({ noMove: true }) |
55 | 62 | console.log('Migration finished.')
|
56 | 63 | }
|
57 | 64 | }
|
58 | 65 |
|
| 66 | + // For now, the storage path is determined as follows: |
| 67 | + // If ~/.hyperdrive/storage/cores exists, use that (from an old hyperdrive daemon installation) |
| 68 | + // Else, use ~/.hyperspace/storage |
| 69 | + const storage = argv.storage ? argv.storage : await getStoragePath() |
| 70 | + |
59 | 71 | const s = new Server({
|
60 | 72 | host: argv.host,
|
61 | 73 | port: argv.port,
|
62 |
| - storage: argv.storage, |
| 74 | + storage, |
63 | 75 | network: argv.bootstrap ? { bootstrap: [].concat(argv.bootstrap) } : null,
|
64 | 76 | memoryOnly: argv['memory-only'],
|
65 | 77 | noAnnounce: !argv.announce,
|
@@ -121,6 +133,17 @@ async function main () {
|
121 | 133 | }
|
122 | 134 | }
|
123 | 135 |
|
| 136 | +async function getStoragePath () { |
| 137 | + try { |
| 138 | + // If this dir exists, use it. |
| 139 | + await fs.stat(HYPERDRIVE_STORAGE_DIR) |
| 140 | + return HYPERDRIVE_STORAGE_DIR |
| 141 | + } catch (err) { |
| 142 | + if (err.code !== 'ENOENT') throw err |
| 143 | + return HYPERSPACE_STORAGE_DIR |
| 144 | + } |
| 145 | +} |
| 146 | + |
124 | 147 | function onerror (err) {
|
125 | 148 | console.error(err.stack)
|
126 | 149 | process.exit(1)
|
|
0 commit comments