@budibase/cli 2.3.18-alpha.3 → 2.3.18-alpha.30

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 (70) hide show
  1. package/dist/analytics/Client.js +32 -0
  2. package/dist/analytics/index.js +55 -0
  3. package/dist/backups/index.js +119 -0
  4. package/dist/backups/objectStore.js +82 -0
  5. package/dist/backups/utils.js +110 -0
  6. package/dist/constants.js +9 -0
  7. package/dist/core/db.js +55 -0
  8. package/dist/environment.js +4 -0
  9. package/dist/events.js +13 -0
  10. package/dist/exec.js +49 -0
  11. package/dist/hosting/genUser.js +32 -0
  12. package/dist/hosting/index.js +21 -0
  13. package/dist/hosting/init.js +117 -0
  14. package/dist/hosting/makeFiles.js +143 -0
  15. package/dist/hosting/start.js +63 -0
  16. package/dist/hosting/status.js +30 -0
  17. package/dist/hosting/stop.js +30 -0
  18. package/dist/hosting/types.js +2 -0
  19. package/dist/hosting/update.js +58 -0
  20. package/dist/hosting/utils.js +125 -0
  21. package/dist/hosting/watch.js +47 -0
  22. package/dist/index.js +36 -0
  23. package/dist/options.js +14 -0
  24. package/dist/plugins/index.js +199 -0
  25. package/dist/plugins/skeleton.js +75 -0
  26. package/dist/prebuilds.js +46 -0
  27. package/dist/questions.js +58 -0
  28. package/dist/structures/Command.js +75 -0
  29. package/dist/structures/ConfigManager.js +39 -0
  30. package/dist/tsconfig.build.tsbuildinfo +1 -0
  31. package/dist/utils.js +126 -0
  32. package/package.json +20 -11
  33. package/src/analytics/Client.ts +33 -0
  34. package/src/analytics/{index.js → index.ts} +7 -10
  35. package/src/backups/{index.js → index.ts} +19 -19
  36. package/src/backups/{objectStore.js → objectStore.ts} +9 -9
  37. package/src/backups/{utils.js → utils.ts} +24 -19
  38. package/src/constants.ts +4 -0
  39. package/src/core/{db.js → db.ts} +8 -7
  40. package/src/{environment.js → environment.ts} +1 -0
  41. package/src/events.ts +11 -0
  42. package/src/{exec.js → exec.ts} +7 -7
  43. package/src/hosting/{genUser.js → genUser.ts} +4 -3
  44. package/src/hosting/{index.js → index.ts} +10 -12
  45. package/src/hosting/{init.js → init.ts} +20 -19
  46. package/src/hosting/{makeFiles.js → makeFiles.ts} +23 -21
  47. package/src/hosting/{start.js → start.ts} +6 -10
  48. package/src/hosting/{status.js → status.ts} +4 -8
  49. package/src/hosting/{stop.js → stop.ts} +4 -8
  50. package/src/hosting/types.ts +4 -0
  51. package/src/hosting/{update.js → update.ts} +10 -10
  52. package/src/hosting/{utils.js → utils.ts} +26 -23
  53. package/src/hosting/{watch.js → watch.ts} +7 -6
  54. package/src/{index.js → index.ts} +5 -5
  55. package/src/options.ts +8 -0
  56. package/src/plugins/{index.js → index.ts} +27 -25
  57. package/src/plugins/{skeleton.js → skeleton.ts} +14 -9
  58. package/src/{prebuilds.js → prebuilds.ts} +7 -6
  59. package/src/{questions.js → questions.ts} +6 -6
  60. package/src/structures/{Command.js → Command.ts} +29 -14
  61. package/src/structures/{ConfigManager.js → ConfigManager.ts} +7 -7
  62. package/src/utils.ts +112 -0
  63. package/start.sh +3 -0
  64. package/tsconfig.build.json +24 -0
  65. package/tsconfig.json +30 -0
  66. package/src/analytics/Client.js +0 -32
  67. package/src/constants.js +0 -25
  68. package/src/events.js +0 -11
  69. package/src/options.js +0 -8
  70. package/src/utils.js +0 -106
@@ -1,7 +1,7 @@
1
- const Command = require("../structures/Command")
2
- const { CommandWords } = require("../constants")
3
- const { success, error } = require("../utils")
4
- const AnalyticsClient = require("./Client")
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
- "Error opting out of Budibase analytics. Please try again later.",
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
- const command = new Command(`${CommandWords.ANALYTICS}`)
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
- const Command = require("../structures/Command")
2
- const { CommandWords } = require("../constants")
3
- const fs = require("fs")
4
- const { join } = require("path")
5
- const { getAllDbs } = require("../core/db")
6
- const tar = require("tar")
7
- const { progressBar, httpCall } = require("../utils")
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
- } = require("./utils")
16
- const { exportObjects, importObjects } = require("./objectStore")
14
+ } from "./utils"
15
+ import { exportObjects, importObjects } from "./objectStore"
16
+ const tar = require("tar")
17
17
 
18
- async function exportBackup(opts) {
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
- const command = new Command(`${CommandWords.BACKUPS}`)
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
- const { objectStore } = require("@budibase/backend-core")
2
- const fs = require("fs")
3
- const { join } = require("path")
4
- const { TEMP_DIR, MINIO_DIR } = require("./utils")
5
- const { progressBar } = require("../utils")
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
- exports.exportObjects = async () => {
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
- exports.importObjects = async () => {
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
- const dotenv = require("dotenv")
2
- const fs = require("fs")
3
- const { string } = require("../questions")
4
- const { getPouch } = require("../core/db")
5
- const { env: environment } = require("@budibase/backend-core")
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
- exports.TEMP_DIR = ".temp"
8
- exports.COUCH_DIR = "couchdb"
9
- exports.MINIO_DIR = "minio"
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
- exports.checkURLs = config => {
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
- exports.askQuestions = async () => {
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
- exports.loadEnvironment = path => {
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 = exports.checkURLs(dotenv.parse(env))
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
- exports.getConfig = async (envFile = true) => {
64
+ export async function getConfig(envFile: boolean | string = true) {
64
65
  let config
65
66
  if (envFile !== true) {
66
- config = exports.loadEnvironment(envFile)
67
+ config = loadEnvironment(envFile as string)
67
68
  } else {
68
- config = await exports.askQuestions()
69
+ config = await askQuestions()
69
70
  }
70
71
  // fill out environment
71
72
  for (let key of Object.keys(config)) {
@@ -74,12 +75,16 @@ exports.getConfig = async (envFile = true) => {
74
75
  return config
75
76
  }
76
77
 
77
- exports.replication = async (from, to) => {
78
+ export async function replication(
79
+ from: PouchDB.Database,
80
+ to: PouchDB.Database
81
+ ) {
78
82
  const pouch = getPouch()
79
83
  try {
80
84
  await pouch.replicate(from, to, {
81
85
  batch_size: 1000,
82
- batch_limit: 5,
86
+ batches_limit: 5,
87
+ // @ts-ignore
83
88
  style: "main_only",
84
89
  })
85
90
  } catch (err) {
@@ -87,7 +92,7 @@ exports.replication = async (from, to) => {
87
92
  }
88
93
  }
89
94
 
90
- exports.getPouches = config => {
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 }
@@ -0,0 +1,4 @@
1
+ export { CommandWord, InitType, AnalyticsEvent } from "@budibase/types"
2
+
3
+ export const POSTHOG_TOKEN = "phc_yGOn4i7jWKaCTapdGR6lfA4AvmuEQ2ijn5zAVSFYPlS"
4
+ export const GENERATED_USER_EMAIL = "admin@admin.com"
@@ -1,12 +1,12 @@
1
- const PouchDB = require("pouchdb")
2
- const { checkSlashesInUrl } = require("../utils")
3
- const fetch = require("node-fetch")
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
- exports.getPouch = (url = undefined) => {
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
- exports.getAllDbs = async url => {
27
+ export async function getAllDbs(url: string) {
27
28
  const response = await fetch(
28
29
  checkSlashesInUrl(encodeURI(`${url}/_all_dbs`)),
29
30
  {
@@ -1,2 +1,3 @@
1
1
  process.env.NO_JS = "1"
2
2
  process.env.JS_BCRYPT = "1"
3
+ process.env.DISABLE_JWT_WARNING = "1"
package/src/events.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { AnalyticsClient } from "./analytics/Client"
2
+
3
+ const client = new AnalyticsClient()
4
+
5
+ export function captureEvent(event: string, properties: any) {
6
+ client.capture({
7
+ distinctId: "cli",
8
+ event,
9
+ properties,
10
+ })
11
+ }
@@ -1,21 +1,21 @@
1
- const util = require("util")
2
- const exec = util.promisify(require("child_process").exec)
1
+ import util from "util"
2
+ const runCommand = util.promisify(require("child_process").exec)
3
3
 
4
- exports.exec = async (command, dir = "./") => {
5
- const { stdout } = await exec(command, { cwd: dir })
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
- exports.utilityInstalled = async utilName => {
9
+ export async function utilityInstalled(utilName: string) {
10
10
  try {
11
- await exports.exec(`${utilName} --version`)
11
+ await exec(`${utilName} --version`)
12
12
  return true
13
13
  } catch (err) {
14
14
  return false
15
15
  }
16
16
  }
17
17
 
18
- exports.runPkgCommand = async (command, dir = "./") => {
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
- exports.generateUser = async (password, silent) => {
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
- const Command = require("../structures/Command")
2
- const { CommandWords } = require("../constants")
3
- const { init } = require("./init")
4
- const { start } = require("./start")
5
- const { stop } = require("./stop")
6
- const { status } = require("./status")
7
- const { update } = require("./update")
8
- const { generateUser } = require("./genUser")
9
- const { watchPlugins } = require("./watch")
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
- const command = new Command(`${CommandWords.HOSTING}`)
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
- const { InitTypes, AnalyticsEvents } = require("../constants")
2
- const { confirmation } = require("../questions")
3
- const { captureEvent } = require("../events")
4
- const makeFiles = require("./makeFiles")
5
- const axios = require("axios")
6
- const { parseEnv } = require("../utils")
7
- const { checkDockerConfigured, downloadFiles } = require("./utils")
8
- const { watchPlugins } = require("./watch")
9
- const { generateUser } = require("./genUser")
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 === InitTypes.DIGITAL_OCEAN) {
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 axios.get(DO_USER_DATA_URL)
18
- const response = parseEnv(output.data)
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
- exports.init = async opts => {
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 === InitTypes.QUICK || type === InitTypes.DIGITAL_OCEAN
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(AnalyticsEvents.SelfHostInit, {
59
+ captureEvent(AnalyticsEvent.SelfHostInit, {
59
60
  type,
60
61
  })
61
62
  const config = await getInitConfig(type, isQuick, port)
62
63
  if (!isSingle) {
63
- await downloadFiles()
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
- const { number } = require("../questions")
2
- const { success, stringifyToDotEnv } = require("../utils")
3
- const fs = require("fs")
4
- const path = require("path")
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
- exports.ENV_PATH = ENV_PATH
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
- module.exports.QUICK_CONFIG = {
84
+ export const QUICK_CONFIG = {
88
85
  key: "budibase",
89
86
  port: 10000,
90
87
  }
91
88
 
92
- async function make(path, contentsFn, inputs = {}, silent) {
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
- module.exports.makeEnv = async (inputs = {}, silent) => {
112
+ export async function makeEnv(inputs: any = {}, silent: boolean) {
111
113
  return make(ENV_PATH, getEnv, inputs, silent)
112
114
  }
113
115
 
114
- module.exports.makeSingleCompose = async (inputs = {}, silent) => {
116
+ export async function makeSingleCompose(inputs: any = {}, silent: boolean) {
115
117
  return make(COMPOSE_PATH, getSingleCompose, inputs, silent)
116
118
  }
117
119
 
118
- module.exports.getEnvProperty = property => {
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
- module.exports.getComposeProperty = property => {
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
- const {
2
- checkDockerConfigured,
3
- checkInitComplete,
4
- handleError,
5
- } = require("./utils")
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
- exports.start = async () => {
7
+ export async function start() {
12
8
  await checkDockerConfigured()
13
9
  checkInitComplete()
14
10
  console.log(
@@ -1,12 +1,8 @@
1
- const {
2
- checkDockerConfigured,
3
- checkInitComplete,
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
- exports.status = async () => {
5
+ export async function status() {
10
6
  await checkDockerConfigured()
11
7
  checkInitComplete()
12
8
  console.log(info("Budibase status"))
@@ -1,12 +1,8 @@
1
- const {
2
- checkDockerConfigured,
3
- checkInitComplete,
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
- exports.stop = async () => {
5
+ export async function stop() {
10
6
  await checkDockerConfigured()
11
7
  checkInitComplete()
12
8
  console.log(info("Stopping services, this may take a moment."))
@@ -0,0 +1,4 @@
1
+ export interface DockerCompose {
2
+ environment: Record<string, string>
3
+ volumes: string[]
4
+ }