feat: decouple l-s entrypoint
This commit is contained in:
parent
2a2c1fccc8
commit
f4d6b5e454
48 changed files with 411 additions and 232 deletions
|
|
@ -6,21 +6,21 @@ const fs = require('fs')
|
|||
const path = require('path')
|
||||
const os = require('os')
|
||||
const bip39 = require('bip39')
|
||||
const options = require('../lib/options-loader')()
|
||||
const setEnvVariable = require('../tools/set-env-var')
|
||||
|
||||
if (options.opts.mnemonicPath && !options.opts.seedPath) {
|
||||
const mnemonic = fs.readFileSync(options.opts.mnemonicPath, 'utf8')
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
|
||||
|
||||
if (process.env.MNEMONIC_PATH && !process.env.SEED_PATH) {
|
||||
const mnemonic = fs.readFileSync(process.env.MNEMONIC_PATH, 'utf8')
|
||||
const seed = bip39.mnemonicToEntropy(mnemonic.split('\n').join(' ').trim()).toString('hex')
|
||||
|
||||
options.opts.seedPath = path.resolve(os.homedir(), '.lamassu', 'seeds', 'seed.txt')
|
||||
setEnvVariable('SEED_PATH', path.resolve(os.homedir(), '.lamassu', 'seeds', 'seed.txt'))
|
||||
|
||||
if (!fs.existsSync(path.dirname(options.opts.seedPath))) {
|
||||
fs.mkdirSync(path.dirname(options.opts.seedPath))
|
||||
if (!fs.existsSync(path.dirname(process.env.SEED_PATH))) {
|
||||
fs.mkdirSync(path.dirname(process.env.SEED_PATH))
|
||||
}
|
||||
|
||||
if (!fs.existsSync(options.opts.seedPath)) {
|
||||
fs.writeFileSync(options.opts.seedPath, seed, 'utf8')
|
||||
if (!fs.existsSync(process.env.SEED_PATH)) {
|
||||
fs.writeFileSync(process.env.SEED_PATH, seed, 'utf8')
|
||||
}
|
||||
|
||||
fs.writeFileSync(options.path, JSON.stringify(options.opts, null, '\t'), 'utf8')
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue