cli init now working...
This commit is contained in:
parent
b2b94c8ccc
commit
2ab564d224
|
@ -9,7 +9,7 @@
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "init",
|
"name": "init",
|
||||||
"program": "${workspaceFolder}\\bin\\budi",
|
"program": "${workspaceFolder}\\bin\\budi",
|
||||||
"args": ["init", "-b", "pouch"],
|
"args": ["init", "-b", "remote"],
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"cwd": "${workspaceFolder}/sandbox"
|
"cwd": "${workspaceFolder}/sandbox"
|
||||||
},
|
},
|
||||||
|
|
|
@ -31,10 +31,11 @@ const ensureAppDir = async opts => {
|
||||||
}
|
}
|
||||||
await ensureDir(opts.dir)
|
await ensureDir(opts.dir)
|
||||||
|
|
||||||
if (opts.database === "pouch") {
|
if (opts.database === "local") {
|
||||||
const dataDir = join(opts.dir, ".data")
|
const dataDir = join(opts.dir, ".data")
|
||||||
await ensureDir(dataDir)
|
await ensureDir(dataDir)
|
||||||
process.env.COUCH_DB_URL = dataDir
|
process.env.COUCH_DB_URL =
|
||||||
|
dataDir + (dataDir.endsWith("/") || dataDir.endsWith("\\") ? "" : "/")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,12 +52,14 @@ const prompts = async opts => {
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
if (opts.database === "couch" && !opts.couchDbUrl) {
|
if (opts.database === "remote" && !opts.couchDbUrl) {
|
||||||
const answers = await inquirer.prompt(questions)
|
const answers = await inquirer.prompt(questions)
|
||||||
opts.couchDbUrl = answers.couchDbUrl
|
opts.couchDbUrl = answers.couchDbUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//https://admin:password@localhost:5984
|
||||||
|
|
||||||
const createClientDatabse = async opts => {
|
const createClientDatabse = async opts => {
|
||||||
const couch = CouchDb()
|
const couch = CouchDb()
|
||||||
if (opts.clientId === "new") {
|
if (opts.clientId === "new") {
|
||||||
|
@ -72,6 +75,7 @@ const createClientDatabse = async opts => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const db = new couch(`client-${opts.clientId}`)
|
const db = new couch(`client-${opts.clientId}`)
|
||||||
|
console.log(await db.info())
|
||||||
await initialiseClientDb(db)
|
await initialiseClientDb(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
const PouchDB = require("pouchdb")
|
const PouchDB = require("pouchdb")
|
||||||
require("pouchdb-all-dbs")(PouchDB)
|
const allDbs = require("pouchdb-all-dbs")
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
const COUCH_DB_URL =
|
const COUCH_DB_URL =
|
||||||
process.env.COUCH_DB_URL || "http://admin:password@localhost:5984"
|
process.env.COUCH_DB_URL || "http://admin:password@localhost:5984"
|
||||||
const DATABASE_TYPE = process.env.DATABASE_TYPE || "couch"
|
const DATABASE_TYPE = process.env.DATABASE_TYPE || "couch"
|
||||||
|
|
||||||
PouchDB.defaults({
|
const pouch = PouchDB.defaults({
|
||||||
prefix: COUCH_DB_URL,
|
prefix: COUCH_DB_URL,
|
||||||
})
|
})
|
||||||
|
allDbs(pouch)
|
||||||
return PouchDB
|
return pouch
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue