@budibase/cli 2.3.19 → 2.3.21-alpha.0
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/dist/analytics/Client.js +32 -0
- package/dist/analytics/index.js +55 -0
- package/dist/backups/index.js +119 -0
- package/dist/backups/objectStore.js +82 -0
- package/dist/backups/utils.js +110 -0
- package/dist/constants.js +9 -0
- package/dist/core/db.js +55 -0
- package/dist/environment.js +4 -0
- package/dist/events.js +13 -0
- package/dist/exec.js +49 -0
- package/dist/hosting/genUser.js +32 -0
- package/dist/hosting/index.js +21 -0
- package/dist/hosting/init.js +117 -0
- package/dist/hosting/makeFiles.js +143 -0
- package/dist/hosting/start.js +63 -0
- package/dist/hosting/status.js +30 -0
- package/dist/hosting/stop.js +30 -0
- package/dist/hosting/types.js +2 -0
- package/dist/hosting/update.js +58 -0
- package/dist/hosting/utils.js +125 -0
- package/dist/hosting/watch.js +47 -0
- package/dist/index.js +36 -0
- package/dist/options.js +14 -0
- package/dist/plugins/index.js +199 -0
- package/dist/plugins/skeleton.js +75 -0
- package/dist/prebuilds.js +46 -0
- package/dist/questions.js +58 -0
- package/dist/structures/Command.js +75 -0
- package/dist/structures/ConfigManager.js +39 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/utils.js +126 -0
- package/package.json +20 -10
- package/src/analytics/Client.ts +33 -0
- package/src/analytics/{index.js → index.ts} +7 -10
- package/src/backups/{index.js → index.ts} +19 -19
- package/src/backups/{objectStore.js → objectStore.ts} +9 -9
- package/src/backups/{utils.js → utils.ts} +33 -28
- package/src/constants.ts +4 -0
- package/src/core/{db.js → db.ts} +8 -7
- package/src/{environment.js → environment.ts} +1 -0
- package/src/events.ts +11 -0
- package/src/{exec.js → exec.ts} +7 -7
- package/src/hosting/{genUser.js → genUser.ts} +4 -3
- package/src/hosting/{index.js → index.ts} +10 -12
- package/src/hosting/{init.js → init.ts} +20 -19
- package/src/hosting/{makeFiles.js → makeFiles.ts} +23 -21
- package/src/hosting/{start.js → start.ts} +6 -10
- package/src/hosting/{status.js → status.ts} +4 -8
- package/src/hosting/{stop.js → stop.ts} +4 -8
- package/src/hosting/types.ts +4 -0
- package/src/hosting/{update.js → update.ts} +10 -10
- package/src/hosting/{utils.js → utils.ts} +26 -23
- package/src/hosting/{watch.js → watch.ts} +7 -6
- package/src/{index.js → index.ts} +5 -5
- package/src/options.ts +8 -0
- package/src/plugins/{index.js → index.ts} +27 -25
- package/src/plugins/{skeleton.js → skeleton.ts} +14 -9
- package/src/{prebuilds.js → prebuilds.ts} +7 -6
- package/src/{questions.js → questions.ts} +6 -6
- package/src/structures/{Command.js → Command.ts} +29 -14
- package/src/structures/{ConfigManager.js → ConfigManager.ts} +7 -7
- package/src/utils.ts +112 -0
- package/start.sh +3 -0
- package/tsconfig.build.json +24 -0
- package/tsconfig.json +30 -0
- package/src/analytics/Client.js +0 -32
- package/src/constants.js +0 -25
- package/src/events.js +0 -11
- package/src/options.js +0 -8
- package/src/utils.js +0 -106
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Command } from "../structures/Command"
|
|
2
|
+
import { CommandWord } from "../constants"
|
|
3
|
+
import { success, error } from "../utils"
|
|
4
|
+
import { AnalyticsClient } from "./Client"
|
|
5
5
|
|
|
6
6
|
const client = new AnalyticsClient()
|
|
7
7
|
|
|
@@ -14,11 +14,10 @@ async function optOut() {
|
|
|
14
14
|
"Successfully opted out of Budibase analytics. You can opt in at any time by running 'budi analytics opt-in'"
|
|
15
15
|
)
|
|
16
16
|
)
|
|
17
|
-
} catch (err) {
|
|
17
|
+
} catch (err: any) {
|
|
18
18
|
console.log(
|
|
19
19
|
error(
|
|
20
|
-
|
|
21
|
-
err
|
|
20
|
+
`Error opting out of Budibase analytics. Please try again later - ${err}`
|
|
22
21
|
)
|
|
23
22
|
)
|
|
24
23
|
}
|
|
@@ -50,7 +49,7 @@ async function status() {
|
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
export default new Command(`${CommandWord.ANALYTICS}`)
|
|
54
53
|
.addHelp("Control the analytics you send to Budibase.")
|
|
55
54
|
.addSubOption("--optin", "Opt in to sending analytics to Budibase", optIn)
|
|
56
55
|
.addSubOption("--optout", "Opt out of sending analytics to Budibase.", optOut)
|
|
@@ -59,5 +58,3 @@ const command = new Command(`${CommandWords.ANALYTICS}`)
|
|
|
59
58
|
"Check whether you are currently opted in to Budibase analytics.",
|
|
60
59
|
status
|
|
61
60
|
)
|
|
62
|
-
|
|
63
|
-
exports.command = command
|
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const {
|
|
1
|
+
import { Command } from "../structures/Command"
|
|
2
|
+
import { CommandWord } from "../constants"
|
|
3
|
+
import fs from "fs"
|
|
4
|
+
import { join } from "path"
|
|
5
|
+
import { getAllDbs } from "../core/db"
|
|
6
|
+
import { progressBar, httpCall } from "../utils"
|
|
7
|
+
import {
|
|
9
8
|
TEMP_DIR,
|
|
10
9
|
COUCH_DIR,
|
|
11
10
|
MINIO_DIR,
|
|
12
11
|
getConfig,
|
|
13
12
|
replication,
|
|
14
13
|
getPouches,
|
|
15
|
-
}
|
|
16
|
-
|
|
14
|
+
} from "./utils"
|
|
15
|
+
import { exportObjects, importObjects } from "./objectStore"
|
|
16
|
+
const tar = require("tar")
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
type BackupOpts = { env?: string; import?: string; export?: string }
|
|
19
|
+
|
|
20
|
+
async function exportBackup(opts: BackupOpts) {
|
|
19
21
|
const envFile = opts.env || undefined
|
|
20
|
-
let filename = opts["export"] || opts
|
|
22
|
+
let filename = opts["export"] || (opts as string)
|
|
21
23
|
if (typeof filename !== "string") {
|
|
22
24
|
filename = `backup-${new Date().toISOString()}.tar.gz`
|
|
23
25
|
}
|
|
24
26
|
const config = await getConfig(envFile)
|
|
25
|
-
const dbList = await getAllDbs(config["COUCH_DB_URL"])
|
|
27
|
+
const dbList = (await getAllDbs(config["COUCH_DB_URL"])) as string[]
|
|
26
28
|
const { Remote, Local } = getPouches(config)
|
|
27
29
|
if (fs.existsSync(TEMP_DIR)) {
|
|
28
30
|
fs.rmSync(TEMP_DIR, { recursive: true })
|
|
@@ -55,9 +57,9 @@ async function exportBackup(opts) {
|
|
|
55
57
|
console.log(`Generated export file - ${filename}`)
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
async function importBackup(opts) {
|
|
60
|
+
async function importBackup(opts: BackupOpts) {
|
|
59
61
|
const envFile = opts.env || undefined
|
|
60
|
-
const filename = opts["import"] || opts
|
|
62
|
+
const filename = opts["import"] || (opts as string)
|
|
61
63
|
const config = await getConfig(envFile)
|
|
62
64
|
if (!filename || !fs.existsSync(filename)) {
|
|
63
65
|
console.error("Cannot import without specifying a valid file to import")
|
|
@@ -99,7 +101,7 @@ async function importBackup(opts) {
|
|
|
99
101
|
fs.rmSync(TEMP_DIR, { recursive: true })
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
async function pickOne(opts) {
|
|
104
|
+
async function pickOne(opts: BackupOpts) {
|
|
103
105
|
if (opts["import"]) {
|
|
104
106
|
return importBackup(opts)
|
|
105
107
|
} else if (opts["export"]) {
|
|
@@ -107,7 +109,7 @@ async function pickOne(opts) {
|
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
|
|
110
|
-
|
|
112
|
+
export default new Command(`${CommandWord.BACKUPS}`)
|
|
111
113
|
.addHelp(
|
|
112
114
|
"Allows building backups of Budibase, as well as importing a backup to a new instance."
|
|
113
115
|
)
|
|
@@ -126,5 +128,3 @@ const command = new Command(`${CommandWords.BACKUPS}`)
|
|
|
126
128
|
"Provide an environment variable file to configure the CLI.",
|
|
127
129
|
pickOne
|
|
128
130
|
)
|
|
129
|
-
|
|
130
|
-
exports.command = command
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { objectStore } from "@budibase/backend-core"
|
|
2
|
+
import fs from "fs"
|
|
3
|
+
import { join } from "path"
|
|
4
|
+
import { TEMP_DIR, MINIO_DIR } from "./utils"
|
|
5
|
+
import { progressBar } from "../utils"
|
|
6
6
|
const {
|
|
7
7
|
ObjectStoreBuckets,
|
|
8
8
|
ObjectStore,
|
|
@@ -13,10 +13,10 @@ const {
|
|
|
13
13
|
|
|
14
14
|
const bucketList = Object.values(ObjectStoreBuckets)
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
export async function exportObjects() {
|
|
17
17
|
const path = join(TEMP_DIR, MINIO_DIR)
|
|
18
18
|
fs.mkdirSync(path)
|
|
19
|
-
let fullList = []
|
|
19
|
+
let fullList: any[] = []
|
|
20
20
|
let errorCount = 0
|
|
21
21
|
for (let bucket of bucketList) {
|
|
22
22
|
const client = ObjectStore(bucket)
|
|
@@ -26,7 +26,7 @@ exports.exportObjects = async () => {
|
|
|
26
26
|
errorCount++
|
|
27
27
|
continue
|
|
28
28
|
}
|
|
29
|
-
const list = await client.listObjectsV2().promise()
|
|
29
|
+
const list = (await client.listObjectsV2().promise()) as { Contents: any[] }
|
|
30
30
|
fullList = fullList.concat(list.Contents.map(el => ({ ...el, bucket })))
|
|
31
31
|
}
|
|
32
32
|
if (errorCount === bucketList.length) {
|
|
@@ -48,7 +48,7 @@ exports.exportObjects = async () => {
|
|
|
48
48
|
bar.stop()
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
export async function importObjects() {
|
|
52
52
|
const path = join(TEMP_DIR, MINIO_DIR)
|
|
53
53
|
const buckets = fs.readdirSync(path)
|
|
54
54
|
let total = 0
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import dotenv from "dotenv"
|
|
2
|
+
import fs from "fs"
|
|
3
|
+
import { string } from "../questions"
|
|
4
|
+
import { getPouch } from "../core/db"
|
|
5
|
+
import { env as environment } from "@budibase/backend-core"
|
|
6
|
+
import PouchDB from "pouchdb"
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
export const TEMP_DIR = ".temp"
|
|
9
|
+
export const COUCH_DIR = "couchdb"
|
|
10
|
+
export const MINIO_DIR = "minio"
|
|
10
11
|
|
|
11
12
|
const REQUIRED = [
|
|
12
13
|
{ value: "MAIN_PORT", default: "10000" },
|
|
@@ -19,7 +20,7 @@ const REQUIRED = [
|
|
|
19
20
|
{ value: "MINIO_SECRET_KEY" },
|
|
20
21
|
]
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
export function checkURLs(config: Record<string, string>) {
|
|
23
24
|
const mainPort = config["MAIN_PORT"],
|
|
24
25
|
username = config["COUCH_DB_USER"],
|
|
25
26
|
password = config["COUCH_DB_PASSWORD"]
|
|
@@ -34,23 +35,23 @@ exports.checkURLs = config => {
|
|
|
34
35
|
return config
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
export async function askQuestions() {
|
|
38
39
|
console.log(
|
|
39
40
|
"*** NOTE: use a .env file to load these parameters repeatedly ***"
|
|
40
41
|
)
|
|
41
|
-
let config = {}
|
|
42
|
+
let config: Record<string, string> = {}
|
|
42
43
|
for (let property of REQUIRED) {
|
|
43
44
|
config[property.value] = await string(property.value, property.default)
|
|
44
45
|
}
|
|
45
46
|
return config
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
export function loadEnvironment(path: string) {
|
|
49
50
|
if (!fs.existsSync(path)) {
|
|
50
51
|
throw "Unable to file specified .env file"
|
|
51
52
|
}
|
|
52
53
|
const env = fs.readFileSync(path, "utf8")
|
|
53
|
-
const config =
|
|
54
|
+
const config = checkURLs(dotenv.parse(env))
|
|
54
55
|
for (let required of REQUIRED) {
|
|
55
56
|
if (!config[required.value]) {
|
|
56
57
|
throw `Cannot find "${required.value}" property in .env file`
|
|
@@ -60,12 +61,12 @@ exports.loadEnvironment = path => {
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
// true is the default value passed by commander
|
|
63
|
-
|
|
64
|
+
export async function getConfig(envFile: boolean | string = true) {
|
|
64
65
|
let config
|
|
65
66
|
if (envFile !== true) {
|
|
66
|
-
config =
|
|
67
|
+
config = loadEnvironment(envFile as string)
|
|
67
68
|
} else {
|
|
68
|
-
config = await
|
|
69
|
+
config = await askQuestions()
|
|
69
70
|
}
|
|
70
71
|
// fill out environment
|
|
71
72
|
for (let key of Object.keys(config)) {
|
|
@@ -74,20 +75,24 @@ exports.getConfig = async (envFile = true) => {
|
|
|
74
75
|
return config
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
78
|
+
export async function replication(
|
|
79
|
+
from: PouchDB.Database,
|
|
80
|
+
to: PouchDB.Database
|
|
81
|
+
) {
|
|
82
|
+
const pouch = getPouch()
|
|
83
|
+
try {
|
|
84
|
+
await pouch.replicate(from, to, {
|
|
85
|
+
batch_size: 1000,
|
|
86
|
+
batches_limit: 5,
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
style: "main_only",
|
|
89
|
+
})
|
|
90
|
+
} catch (err) {
|
|
91
|
+
throw new Error(`Replication failed - ${JSON.stringify(err)}`)
|
|
92
|
+
}
|
|
88
93
|
}
|
|
89
94
|
|
|
90
|
-
|
|
95
|
+
export function getPouches(config: Record<string, string>) {
|
|
91
96
|
const Remote = getPouch(config["COUCH_DB_URL"])
|
|
92
97
|
const Local = getPouch()
|
|
93
98
|
return { Remote, Local }
|
package/src/constants.ts
ADDED
package/src/core/{db.js → db.ts}
RENAMED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import PouchDB from "pouchdb"
|
|
2
|
+
import { checkSlashesInUrl } from "../utils"
|
|
3
|
+
import fetch from "node-fetch"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Fully qualified URL including username and password, or nothing for local
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
let POUCH_DB_DEFAULTS
|
|
8
|
+
export function getPouch(url?: string) {
|
|
9
|
+
let POUCH_DB_DEFAULTS
|
|
10
10
|
if (!url) {
|
|
11
11
|
POUCH_DB_DEFAULTS = {
|
|
12
12
|
prefix: undefined,
|
|
@@ -19,11 +19,12 @@ exports.getPouch = (url = undefined) => {
|
|
|
19
19
|
}
|
|
20
20
|
const replicationStream = require("pouchdb-replication-stream")
|
|
21
21
|
PouchDB.plugin(replicationStream.plugin)
|
|
22
|
+
// @ts-ignore
|
|
22
23
|
PouchDB.adapter("writableStream", replicationStream.adapters.writableStream)
|
|
23
|
-
return PouchDB.defaults(POUCH_DB_DEFAULTS)
|
|
24
|
+
return PouchDB.defaults(POUCH_DB_DEFAULTS) as PouchDB.Static
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
export async function getAllDbs(url: string) {
|
|
27
28
|
const response = await fetch(
|
|
28
29
|
checkSlashesInUrl(encodeURI(`${url}/_all_dbs`)),
|
|
29
30
|
{
|
package/src/events.ts
ADDED
package/src/{exec.js → exec.ts}
RENAMED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
import util from "util"
|
|
2
|
+
const runCommand = util.promisify(require("child_process").exec)
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
const { stdout } = await
|
|
4
|
+
export async function exec(command: string, dir = "./") {
|
|
5
|
+
const { stdout } = await runCommand(command, { cwd: dir })
|
|
6
6
|
return stdout
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
export async function utilityInstalled(utilName: string) {
|
|
10
10
|
try {
|
|
11
|
-
await
|
|
11
|
+
await exec(`${utilName} --version`)
|
|
12
12
|
return true
|
|
13
13
|
} catch (err) {
|
|
14
14
|
return false
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
export async function runPkgCommand(command: string, dir = "./") {
|
|
19
19
|
const yarn = await exports.utilityInstalled("yarn")
|
|
20
20
|
const npm = await exports.utilityInstalled("npm")
|
|
21
21
|
if (!yarn && !npm) {
|
|
@@ -2,15 +2,16 @@ const { success } = require("../utils")
|
|
|
2
2
|
const { updateDockerComposeService } = require("./utils")
|
|
3
3
|
const randomString = require("randomstring")
|
|
4
4
|
const { GENERATED_USER_EMAIL } = require("../constants")
|
|
5
|
+
import { DockerCompose } from "./types"
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
export async function generateUser(password: string | null, silent: boolean) {
|
|
7
8
|
const email = GENERATED_USER_EMAIL
|
|
8
9
|
if (!password) {
|
|
9
10
|
password = randomString.generate({ length: 6 })
|
|
10
11
|
}
|
|
11
|
-
updateDockerComposeService(service => {
|
|
12
|
+
updateDockerComposeService((service: DockerCompose) => {
|
|
12
13
|
service.environment["BB_ADMIN_USER_EMAIL"] = email
|
|
13
|
-
service.environment["BB_ADMIN_USER_PASSWORD"] = password
|
|
14
|
+
service.environment["BB_ADMIN_USER_PASSWORD"] = password as string
|
|
14
15
|
})
|
|
15
16
|
if (!silent) {
|
|
16
17
|
console.log(
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { Command } from "../structures/Command"
|
|
2
|
+
import { CommandWord } from "../constants"
|
|
3
|
+
import { init } from "./init"
|
|
4
|
+
import { start } from "./start"
|
|
5
|
+
import { stop } from "./stop"
|
|
6
|
+
import { status } from "./status"
|
|
7
|
+
import { update } from "./update"
|
|
8
|
+
import { generateUser } from "./genUser"
|
|
9
|
+
import { watchPlugins } from "./watch"
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
export default new Command(`${CommandWord.HOSTING}`)
|
|
12
12
|
.addHelp("Controls self hosting on the Budibase platform.")
|
|
13
13
|
.addSubOption(
|
|
14
14
|
"--init [type]",
|
|
@@ -46,5 +46,3 @@ const command = new Command(`${CommandWords.HOSTING}`)
|
|
|
46
46
|
generateUser
|
|
47
47
|
)
|
|
48
48
|
.addSubOption("--single", "Specify this with init to use the single image.")
|
|
49
|
-
|
|
50
|
-
exports.command = command
|
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { InitType, AnalyticsEvent } from "../constants"
|
|
2
|
+
import { confirmation } from "../questions"
|
|
3
|
+
import { captureEvent } from "../events"
|
|
4
|
+
import * as makeFiles from "./makeFiles"
|
|
5
|
+
import { parseEnv } from "../utils"
|
|
6
|
+
import { checkDockerConfigured, downloadDockerCompose } from "./utils"
|
|
7
|
+
import { watchPlugins } from "./watch"
|
|
8
|
+
import { generateUser } from "./genUser"
|
|
9
|
+
import fetch from "node-fetch"
|
|
10
10
|
|
|
11
11
|
const DO_USER_DATA_URL = "http://169.254.169.254/metadata/v1/user-data"
|
|
12
12
|
|
|
13
|
-
async function getInitConfig(type, isQuick, port) {
|
|
14
|
-
const config = isQuick ? makeFiles.QUICK_CONFIG : {}
|
|
15
|
-
if (type ===
|
|
13
|
+
async function getInitConfig(type: string, isQuick: boolean, port: number) {
|
|
14
|
+
const config: any = isQuick ? makeFiles.QUICK_CONFIG : {}
|
|
15
|
+
if (type === InitType.DIGITAL_OCEAN) {
|
|
16
16
|
try {
|
|
17
|
-
const output = await
|
|
18
|
-
const
|
|
17
|
+
const output = await fetch(DO_USER_DATA_URL)
|
|
18
|
+
const data = await output.text()
|
|
19
|
+
const response = parseEnv(data)
|
|
19
20
|
for (let [key, value] of Object.entries(makeFiles.ConfigMap)) {
|
|
20
21
|
if (response[key]) {
|
|
21
|
-
config[value] = response[key]
|
|
22
|
+
config[value as string] = response[key]
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
} catch (err) {
|
|
@@ -32,7 +33,7 @@ async function getInitConfig(type, isQuick, port) {
|
|
|
32
33
|
return config
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
export async function init(opts: any) {
|
|
36
37
|
let type, isSingle, watchDir, genUser, port, silent
|
|
37
38
|
if (typeof opts === "string") {
|
|
38
39
|
type = opts
|
|
@@ -44,7 +45,7 @@ exports.init = async opts => {
|
|
|
44
45
|
port = opts["port"]
|
|
45
46
|
silent = opts["silent"]
|
|
46
47
|
}
|
|
47
|
-
const isQuick = type ===
|
|
48
|
+
const isQuick = type === InitType.QUICK || type === InitType.DIGITAL_OCEAN
|
|
48
49
|
await checkDockerConfigured()
|
|
49
50
|
if (!isQuick) {
|
|
50
51
|
const shouldContinue = await confirmation(
|
|
@@ -55,12 +56,12 @@ exports.init = async opts => {
|
|
|
55
56
|
return
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
|
-
captureEvent(
|
|
59
|
+
captureEvent(AnalyticsEvent.SelfHostInit, {
|
|
59
60
|
type,
|
|
60
61
|
})
|
|
61
62
|
const config = await getInitConfig(type, isQuick, port)
|
|
62
63
|
if (!isSingle) {
|
|
63
|
-
await
|
|
64
|
+
await downloadDockerCompose()
|
|
64
65
|
await makeFiles.makeEnv(config, silent)
|
|
65
66
|
} else {
|
|
66
67
|
await makeFiles.makeSingleCompose(config, silent)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { number } from "../questions"
|
|
2
|
+
import { success, stringifyToDotEnv } from "../utils"
|
|
3
|
+
import fs from "fs"
|
|
4
|
+
import path from "path"
|
|
5
|
+
import yaml from "yaml"
|
|
6
|
+
import { getAppService } from "./utils"
|
|
5
7
|
const randomString = require("randomstring")
|
|
6
|
-
const yaml = require("yaml")
|
|
7
|
-
const { getAppService } = require("./utils")
|
|
8
8
|
|
|
9
9
|
const SINGLE_IMAGE = "budibase/budibase:latest"
|
|
10
10
|
const VOL_NAME = "budibase_data"
|
|
11
|
-
const COMPOSE_PATH = path.resolve("./docker-compose.yaml")
|
|
12
|
-
const ENV_PATH = path.resolve("./.env")
|
|
11
|
+
export const COMPOSE_PATH = path.resolve("./docker-compose.yaml")
|
|
12
|
+
export const ENV_PATH = path.resolve("./.env")
|
|
13
13
|
|
|
14
14
|
function getSecrets(opts = { single: false }) {
|
|
15
15
|
const secrets = [
|
|
@@ -19,7 +19,7 @@ function getSecrets(opts = { single: false }) {
|
|
|
19
19
|
"REDIS_PASSWORD",
|
|
20
20
|
"INTERNAL_API_KEY",
|
|
21
21
|
]
|
|
22
|
-
const obj = {}
|
|
22
|
+
const obj: Record<string, string> = {}
|
|
23
23
|
secrets.forEach(secret => (obj[secret] = randomString.generate()))
|
|
24
24
|
// setup couch creds separately
|
|
25
25
|
if (opts && opts.single) {
|
|
@@ -32,7 +32,7 @@ function getSecrets(opts = { single: false }) {
|
|
|
32
32
|
return obj
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function getSingleCompose(port) {
|
|
35
|
+
function getSingleCompose(port: number) {
|
|
36
36
|
const singleComposeObj = {
|
|
37
37
|
version: "3",
|
|
38
38
|
services: {
|
|
@@ -53,7 +53,7 @@ function getSingleCompose(port) {
|
|
|
53
53
|
return yaml.stringify(singleComposeObj)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
function getEnv(port) {
|
|
56
|
+
function getEnv(port: number) {
|
|
57
57
|
const partOne = stringifyToDotEnv({
|
|
58
58
|
MAIN_PORT: port,
|
|
59
59
|
})
|
|
@@ -77,19 +77,21 @@ function getEnv(port) {
|
|
|
77
77
|
].join("\n")
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
exports.COMPOSE_PATH = COMPOSE_PATH
|
|
82
|
-
|
|
83
|
-
module.exports.ConfigMap = {
|
|
80
|
+
export const ConfigMap = {
|
|
84
81
|
MAIN_PORT: "port",
|
|
85
82
|
}
|
|
86
83
|
|
|
87
|
-
|
|
84
|
+
export const QUICK_CONFIG = {
|
|
88
85
|
key: "budibase",
|
|
89
86
|
port: 10000,
|
|
90
87
|
}
|
|
91
88
|
|
|
92
|
-
async function make(
|
|
89
|
+
async function make(
|
|
90
|
+
path: string,
|
|
91
|
+
contentsFn: Function,
|
|
92
|
+
inputs: any = {},
|
|
93
|
+
silent: boolean
|
|
94
|
+
) {
|
|
93
95
|
const port =
|
|
94
96
|
inputs.port ||
|
|
95
97
|
(await number(
|
|
@@ -107,15 +109,15 @@ async function make(path, contentsFn, inputs = {}, silent) {
|
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
|
|
110
|
-
|
|
112
|
+
export async function makeEnv(inputs: any = {}, silent: boolean) {
|
|
111
113
|
return make(ENV_PATH, getEnv, inputs, silent)
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
|
|
116
|
+
export async function makeSingleCompose(inputs: any = {}, silent: boolean) {
|
|
115
117
|
return make(COMPOSE_PATH, getSingleCompose, inputs, silent)
|
|
116
118
|
}
|
|
117
119
|
|
|
118
|
-
|
|
120
|
+
export function getEnvProperty(property: string) {
|
|
119
121
|
const props = fs.readFileSync(ENV_PATH, "utf8").split(property)
|
|
120
122
|
if (props[0].charAt(0) === "=") {
|
|
121
123
|
property = props[0]
|
|
@@ -125,7 +127,7 @@ module.exports.getEnvProperty = property => {
|
|
|
125
127
|
return property.split("=")[1].split("\n")[0]
|
|
126
128
|
}
|
|
127
129
|
|
|
128
|
-
|
|
130
|
+
export function getComposeProperty(property: string) {
|
|
129
131
|
const { service } = getAppService(COMPOSE_PATH)
|
|
130
132
|
if (property === "port" && Array.isArray(service.ports)) {
|
|
131
133
|
const port = service.ports[0]
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { info, success } = require("../utils")
|
|
7
|
-
const makeFiles = require("./makeFiles")
|
|
8
|
-
const compose = require("docker-compose")
|
|
9
|
-
const fs = require("fs")
|
|
1
|
+
import { checkDockerConfigured, checkInitComplete, handleError } from "./utils"
|
|
2
|
+
import { info, success } from "../utils"
|
|
3
|
+
import * as makeFiles from "./makeFiles"
|
|
4
|
+
import compose from "docker-compose"
|
|
5
|
+
import fs from "fs"
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
export async function start() {
|
|
12
8
|
await checkDockerConfigured()
|
|
13
9
|
checkInitComplete()
|
|
14
10
|
console.log(
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
handleError,
|
|
5
|
-
} = require("./utils")
|
|
6
|
-
const { info } = require("../utils")
|
|
7
|
-
const compose = require("docker-compose")
|
|
1
|
+
import { checkDockerConfigured, checkInitComplete, handleError } from "./utils"
|
|
2
|
+
import { info } from "../utils"
|
|
3
|
+
import compose from "docker-compose"
|
|
8
4
|
|
|
9
|
-
|
|
5
|
+
export async function status() {
|
|
10
6
|
await checkDockerConfigured()
|
|
11
7
|
checkInitComplete()
|
|
12
8
|
console.log(info("Budibase status"))
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
handleError,
|
|
5
|
-
} = require("./utils")
|
|
6
|
-
const { info, success } = require("../utils")
|
|
7
|
-
const compose = require("docker-compose")
|
|
1
|
+
import { checkDockerConfigured, checkInitComplete, handleError } from "./utils"
|
|
2
|
+
import { info, success } from "../utils"
|
|
3
|
+
import compose from "docker-compose"
|
|
8
4
|
|
|
9
|
-
|
|
5
|
+
export async function stop() {
|
|
10
6
|
await checkDockerConfigured()
|
|
11
7
|
checkInitComplete()
|
|
12
8
|
console.log(info("Stopping services, this may take a moment."))
|