@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.
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 -10
  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} +33 -28
  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
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const Command_1 = require("../structures/Command");
39
+ const constants_1 = require("../constants");
40
+ const skeleton_1 = require("./skeleton");
41
+ const questions = __importStar(require("../questions"));
42
+ const fs_1 = __importDefault(require("fs"));
43
+ const types_1 = require("@budibase/types");
44
+ const backend_core_1 = require("@budibase/backend-core");
45
+ const exec_1 = require("../exec");
46
+ const path_1 = require("path");
47
+ const utils_1 = require("../utils");
48
+ const events_1 = require("../events");
49
+ const constants_2 = require("../constants");
50
+ const init_1 = require("../hosting/init");
51
+ const start_1 = require("../hosting/start");
52
+ const fp = require("find-free-port");
53
+ function checkInPlugin() {
54
+ if (!fs_1.default.existsSync("package.json")) {
55
+ throw new Error("Please run in a plugin directory - must contain package.json");
56
+ }
57
+ if (!fs_1.default.existsSync("schema.json")) {
58
+ throw new Error("Please run in a plugin directory - must contain schema.json");
59
+ }
60
+ }
61
+ function askAboutTopLevel(name) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ const files = fs_1.default.readdirSync(process.cwd());
64
+ // we are in an empty git repo, don't ask
65
+ if (files.find(file => file === ".git")) {
66
+ return false;
67
+ }
68
+ else {
69
+ console.log((0, utils_1.info)(`By default the plugin will be created in the directory "${name}"`));
70
+ console.log((0, utils_1.info)("if you are already in an empty directory, such as a new Git repo, you can disable this functionality."));
71
+ return questions.confirmation("Create top level directory?");
72
+ }
73
+ });
74
+ }
75
+ function init(opts) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ const type = opts["init"] || opts;
78
+ if (!type || !types_1.PLUGIN_TYPE_ARR.includes(type)) {
79
+ console.log((0, utils_1.error)("Please provide a type to init, either 'component' or 'datasource'."));
80
+ return;
81
+ }
82
+ console.log((0, utils_1.info)("Lets get some details about your new plugin:"));
83
+ const name = yield questions.string("Name", `budibase-${type}`);
84
+ if (fs_1.default.existsSync(name)) {
85
+ console.log((0, utils_1.error)("Directory by plugin name already exists, pick a new name."));
86
+ return;
87
+ }
88
+ const description = yield questions.string("Description", `An amazing Budibase ${type}!`);
89
+ const version = yield questions.string("Version", "1.0.0");
90
+ const topLevel = yield askAboutTopLevel(name);
91
+ // get the skeleton
92
+ console.log((0, utils_1.info)("Retrieving project..."));
93
+ yield (0, skeleton_1.getSkeleton)(type, name);
94
+ yield (0, skeleton_1.fleshOutSkeleton)(type, name, description, version);
95
+ console.log((0, utils_1.info)("Installing dependencies..."));
96
+ yield (0, exec_1.runPkgCommand)("install", (0, path_1.join)(process.cwd(), name));
97
+ // if no parent directory desired move to cwd
98
+ if (!topLevel) {
99
+ (0, utils_1.moveDirectory)(name, process.cwd());
100
+ console.log((0, utils_1.info)(`Plugin created in current directory.`));
101
+ }
102
+ else {
103
+ console.log((0, utils_1.info)(`Plugin created in directory "${name}"`));
104
+ }
105
+ (0, events_1.captureEvent)(constants_1.AnalyticsEvent.PluginInit, {
106
+ type,
107
+ name,
108
+ description,
109
+ version,
110
+ });
111
+ });
112
+ }
113
+ function verify() {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ // will throw errors if not acceptable
116
+ checkInPlugin();
117
+ console.log((0, utils_1.info)("Verifying plugin..."));
118
+ const schema = fs_1.default.readFileSync("schema.json", "utf8");
119
+ const pkg = fs_1.default.readFileSync("package.json", "utf8");
120
+ let name, version;
121
+ try {
122
+ const schemaJson = JSON.parse(schema);
123
+ const pkgJson = JSON.parse(pkg);
124
+ if (!pkgJson.name || !pkgJson.version || !pkgJson.description) {
125
+ throw new Error("package.json is missing one of 'name', 'version' or 'description'.");
126
+ }
127
+ name = pkgJson.name;
128
+ version = pkgJson.version;
129
+ backend_core_1.plugins.validate(schemaJson);
130
+ return { name, version };
131
+ }
132
+ catch (err) {
133
+ if (err && err.message && err.message.includes("not valid JSON")) {
134
+ console.log((0, utils_1.error)(`schema.json is not valid JSON: ${err.message}`));
135
+ }
136
+ else {
137
+ console.log((0, utils_1.error)(`Invalid schema/package.json: ${err.message}`));
138
+ }
139
+ }
140
+ });
141
+ }
142
+ function build() {
143
+ return __awaiter(this, void 0, void 0, function* () {
144
+ const verified = yield verify();
145
+ if (!(verified === null || verified === void 0 ? void 0 : verified.name)) {
146
+ return;
147
+ }
148
+ console.log((0, utils_1.success)("Verified!"));
149
+ console.log((0, utils_1.info)("Building plugin..."));
150
+ yield (0, exec_1.runPkgCommand)("build");
151
+ const output = (0, path_1.join)("dist", `${verified.name}-${verified.version}.tar.gz`);
152
+ console.log((0, utils_1.success)(`Build complete - output in: ${output}`));
153
+ });
154
+ }
155
+ function watch() {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ const verified = yield verify();
158
+ if (!(verified === null || verified === void 0 ? void 0 : verified.name)) {
159
+ return;
160
+ }
161
+ const output = (0, path_1.join)("dist", `${verified.name}-${verified.version}.tar.gz`);
162
+ console.log((0, utils_1.info)(`Watching - build in: ${output}`));
163
+ try {
164
+ yield (0, exec_1.runPkgCommand)("watch");
165
+ }
166
+ catch (err) {
167
+ // always errors when user escapes
168
+ console.log((0, utils_1.success)("Watch exited."));
169
+ }
170
+ });
171
+ }
172
+ function dev() {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ const pluginDir = yield questions.string("Directory to watch", "./");
175
+ const [port] = yield fp(10000);
176
+ const password = "admin";
177
+ yield (0, init_1.init)({
178
+ init: constants_1.InitType.QUICK,
179
+ single: true,
180
+ watchPluginDir: pluginDir,
181
+ genUser: password,
182
+ port,
183
+ silent: true,
184
+ });
185
+ yield (0, start_1.start)();
186
+ console.log((0, utils_1.success)(`Configuration has been written to docker-compose.yaml`));
187
+ console.log((0, utils_1.success)("Development environment started successfully - connect at: ") +
188
+ (0, utils_1.info)(`http://localhost:${port}`));
189
+ console.log((0, utils_1.success)("Use the following credentials to login:"));
190
+ console.log((0, utils_1.success)("Email: ") + (0, utils_1.info)(constants_2.GENERATED_USER_EMAIL));
191
+ console.log((0, utils_1.success)("Password: ") + (0, utils_1.info)(password));
192
+ });
193
+ }
194
+ exports.default = new Command_1.Command(`${constants_1.CommandWord.PLUGIN}`)
195
+ .addHelp("Custom plugins for Budibase, init, build and verify your components and datasources with this tool.")
196
+ .addSubOption("--init [type]", "Init a new plugin project, with a type of either component or datasource.", init)
197
+ .addSubOption("--build", "Build your plugin, this will verify and produce a final tarball for your project.", build)
198
+ .addSubOption("--watch", "Automatically build any changes to your plugin.", watch)
199
+ .addSubOption("--dev", "Run a development environment which automatically watches the current directory.", dev);
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.fleshOutSkeleton = exports.getSkeleton = void 0;
16
+ const node_fetch_1 = __importDefault(require("node-fetch"));
17
+ const fs_1 = __importDefault(require("fs"));
18
+ const os_1 = __importDefault(require("os"));
19
+ const path_1 = require("path");
20
+ const string_templates_1 = require("@budibase/string-templates");
21
+ const download = require("download");
22
+ const tar = require("tar");
23
+ const HBS_FILES = ["package.json.hbs", "schema.json.hbs", "README.md.hbs"];
24
+ function getSkeletonUrl(type) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const resp = yield (0, node_fetch_1.default)("https://api.github.com/repos/budibase/budibase-skeleton/releases/latest");
27
+ if (resp.status >= 300) {
28
+ throw new Error("Failed to retrieve skeleton metadata");
29
+ }
30
+ const json = (yield resp.json());
31
+ for (let asset of json["assets"]) {
32
+ if (asset.name && asset.name.includes(type)) {
33
+ return asset["browser_download_url"];
34
+ }
35
+ }
36
+ throw new Error("No skeleton found in latest release.");
37
+ });
38
+ }
39
+ function getSkeleton(type, name) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const url = yield getSkeletonUrl(type);
42
+ const tarballFile = (0, path_1.join)(os_1.default.tmpdir(), "skeleton.tar.gz");
43
+ // download the full skeleton tarball
44
+ fs_1.default.writeFileSync(tarballFile, yield download(url));
45
+ fs_1.default.mkdirSync(name);
46
+ // extract it and get what we need
47
+ yield tar.extract({
48
+ file: tarballFile,
49
+ C: name,
50
+ });
51
+ // clear up
52
+ fs_1.default.rmSync(tarballFile);
53
+ });
54
+ }
55
+ exports.getSkeleton = getSkeleton;
56
+ function fleshOutSkeleton(type, name, description, version) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ for (let file of HBS_FILES) {
59
+ const oldFile = (0, path_1.join)(name, file), newFile = (0, path_1.join)(name, file.substring(0, file.length - 4));
60
+ const hbsContents = fs_1.default.readFileSync(oldFile, "utf8");
61
+ if (!hbsContents) {
62
+ continue;
63
+ }
64
+ const output = (0, string_templates_1.processStringSync)(hbsContents, {
65
+ name,
66
+ description,
67
+ version,
68
+ });
69
+ // write the updated file and remove the HBS file
70
+ fs_1.default.writeFileSync(newFile, output);
71
+ fs_1.default.rmSync(oldFile);
72
+ }
73
+ });
74
+ }
75
+ exports.fleshOutSkeleton = fleshOutSkeleton;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const os_1 = __importDefault(require("os"));
7
+ const path_1 = require("path");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const utils_1 = require("./utils");
10
+ const PREBUILDS = "prebuilds";
11
+ const ARCH = `${os_1.default.platform()}-${os_1.default.arch()}`;
12
+ const PREBUILD_DIR = (0, path_1.join)(process.execPath, "..", PREBUILDS, ARCH);
13
+ // running as built CLI pkg bundle
14
+ if (!process.argv[0].includes("node")) {
15
+ checkForBinaries();
16
+ }
17
+ function checkForBinaries() {
18
+ const readDir = (0, path_1.join)(__filename, "..", "..", PREBUILDS, ARCH);
19
+ if (fs_1.default.existsSync(PREBUILD_DIR) || !fs_1.default.existsSync(readDir)) {
20
+ return;
21
+ }
22
+ const natives = fs_1.default.readdirSync(readDir);
23
+ if (fs_1.default.existsSync(readDir)) {
24
+ fs_1.default.mkdirSync(PREBUILD_DIR, { recursive: true });
25
+ for (let native of natives) {
26
+ const filename = `${native.split(".fake")[0]}.node`;
27
+ fs_1.default.cpSync((0, path_1.join)(readDir, native), (0, path_1.join)(PREBUILD_DIR, filename));
28
+ }
29
+ }
30
+ }
31
+ function cleanup(evt) {
32
+ if (evt && !isNaN(evt)) {
33
+ return;
34
+ }
35
+ if (evt) {
36
+ console.error((0, utils_1.error)("Failed to run CLI command - please report with the following message:"));
37
+ console.error((0, utils_1.error)(evt));
38
+ }
39
+ if (fs_1.default.existsSync(PREBUILD_DIR)) {
40
+ fs_1.default.rmSync(PREBUILD_DIR, { recursive: true });
41
+ }
42
+ }
43
+ const events = ["exit", "SIGINT", "SIGUSR1", "SIGUSR2", "uncaughtException"];
44
+ events.forEach(event => {
45
+ process.on(event, cleanup);
46
+ });
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.number = exports.string = exports.confirmation = void 0;
13
+ const inquirer = require("inquirer");
14
+ function confirmation(question) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const config = {
17
+ type: "confirm",
18
+ message: question,
19
+ default: true,
20
+ name: "confirmation",
21
+ };
22
+ return (yield inquirer.prompt(config)).confirmation;
23
+ });
24
+ }
25
+ exports.confirmation = confirmation;
26
+ function string(question, defaultString) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const config = {
29
+ type: "input",
30
+ name: "string",
31
+ message: question,
32
+ };
33
+ if (defaultString) {
34
+ config.default = defaultString;
35
+ }
36
+ return (yield inquirer.prompt(config)).string;
37
+ });
38
+ }
39
+ exports.string = string;
40
+ function number(question, defaultNumber) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const config = {
43
+ type: "input",
44
+ name: "number",
45
+ message: question,
46
+ validate: (value) => {
47
+ let valid = !isNaN(parseFloat(value));
48
+ return valid || "Please enter a number";
49
+ },
50
+ filter: Number,
51
+ };
52
+ if (defaultNumber) {
53
+ config.default = defaultNumber;
54
+ }
55
+ return (yield inquirer.prompt(config)).number;
56
+ });
57
+ }
58
+ exports.number = number;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Command = void 0;
13
+ const utils_1 = require("../utils");
14
+ class Command {
15
+ constructor(command, func) {
16
+ // if there are options, need to just get the command name
17
+ this.command = command;
18
+ this.opts = [];
19
+ this.func = func;
20
+ }
21
+ convertToCommander(lookup) {
22
+ const parts = lookup.toLowerCase().split("-");
23
+ // camel case, separate out first
24
+ const first = parts.shift();
25
+ return [first]
26
+ .concat(parts.map(part => (0, utils_1.capitaliseFirstLetter)(part)))
27
+ .join("");
28
+ }
29
+ addHelp(help) {
30
+ this.help = help;
31
+ return this;
32
+ }
33
+ addSubOption(command, help, func, extras = []) {
34
+ this.opts.push({ command, help, func, extras });
35
+ return this;
36
+ }
37
+ configure(program) {
38
+ const thisCmd = this;
39
+ let command = program.command(thisCmd.command);
40
+ if (this.help) {
41
+ command = command.description((0, utils_1.getHelpDescription)(thisCmd.help));
42
+ }
43
+ for (let opt of thisCmd.opts) {
44
+ command = command.option(opt.command, (0, utils_1.getSubHelpDescription)(opt.help));
45
+ }
46
+ command.helpOption("--help", (0, utils_1.getSubHelpDescription)(`Get help with ${this.command} options`));
47
+ command.action((options) => __awaiter(this, void 0, void 0, function* () {
48
+ try {
49
+ let executed = false, found = false;
50
+ for (let opt of thisCmd.opts) {
51
+ let lookup = opt.command.split(" ")[0].replace("--", "");
52
+ // need to handle how commander converts watch-plugin-dir to watchPluginDir
53
+ lookup = this.convertToCommander(lookup);
54
+ found = !executed && !!options[lookup];
55
+ if (found && opt.func) {
56
+ const input = Object.keys(options).length > 1 ? options : options[lookup];
57
+ yield opt.func(input);
58
+ executed = true;
59
+ }
60
+ }
61
+ if (found && !executed) {
62
+ console.log((0, utils_1.error)(`${Object.keys(options)[0]} is an option, not an operation.`));
63
+ }
64
+ else if (!executed) {
65
+ console.log((0, utils_1.error)(`Unknown ${this.command} option.`));
66
+ command.help();
67
+ }
68
+ }
69
+ catch (err) {
70
+ console.log((0, utils_1.error)(err));
71
+ }
72
+ }));
73
+ }
74
+ }
75
+ exports.Command = Command;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigManager = void 0;
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const os = require("os");
7
+ const { error } = require("../utils");
8
+ class ConfigManager {
9
+ constructor() {
10
+ this.path = path.join(os.homedir(), ".budibase.json");
11
+ if (!fs.existsSync(this.path)) {
12
+ fs.writeFileSync(this.path, "{}");
13
+ }
14
+ }
15
+ get config() {
16
+ try {
17
+ return JSON.parse(fs.readFileSync(this.path, "utf8"));
18
+ }
19
+ catch (err) {
20
+ console.log(error("Error parsing configuration file. Please check your .budibase.json is valid."));
21
+ return {};
22
+ }
23
+ }
24
+ set config(json) {
25
+ fs.writeFileSync(this.path, JSON.stringify(json));
26
+ }
27
+ getValue(key) {
28
+ return this.config[key];
29
+ }
30
+ setValue(key, value) {
31
+ this.config = Object.assign(Object.assign({}, this.config), { [key]: value });
32
+ }
33
+ removeKey(key) {
34
+ const updated = Object.assign({}, this.config);
35
+ delete updated[key];
36
+ this.config = updated;
37
+ }
38
+ }
39
+ exports.ConfigManager = ConfigManager;