@saltcorn/cli 0.6.0 → 0.6.1
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/README.md +35 -30
- package/npm-shrinkwrap.json +324 -496
- package/oclif.manifest.json +1 -1
- package/package.json +7 -7
- package/src/commands/add-schema.js +15 -0
- package/src/commands/backup.js +18 -0
- package/src/commands/create-tenant.js +21 -0
- package/src/commands/create-user.js +18 -0
- package/src/commands/fixtures.js +18 -0
- package/src/commands/info.js +37 -2
- package/src/commands/install-pack.js +18 -0
- package/src/commands/install-plugin.js +18 -0
- package/src/commands/list-tenants.js +19 -0
- package/src/commands/localize-plugin.js +38 -12
- package/src/commands/make-migration.js +21 -0
- package/src/commands/migrate.js +22 -1
- package/src/commands/plugins.js +22 -0
- package/src/commands/release.js +24 -1
- package/src/commands/reset-schema.js +18 -0
- package/src/commands/restore.js +34 -0
- package/src/commands/rm-tenant.js +21 -0
- package/src/commands/run-benchmark.js +36 -0
- package/src/commands/run-tests.js +88 -16
- package/src/commands/scheduler.js +19 -0
- package/src/commands/serve.js +18 -0
- package/src/commands/set-cfg.js +23 -0
- package/src/commands/setup-benchmark.js +23 -0
- package/src/commands/setup.js +82 -0
- package/src/commands/test-plugin.js +23 -0
- package/src/commands/transform-field.js +21 -0
- package/src/common.js +18 -0
- package/src/index.js +5 -0
package/src/commands/setup.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category saltcorn-cli
|
|
3
|
+
* @module commands/setup
|
|
4
|
+
*/
|
|
1
5
|
const { Command, flags } = require("@oclif/command");
|
|
2
6
|
const {
|
|
3
7
|
getConnectObject,
|
|
@@ -14,12 +18,20 @@ var tcpPortUsed = require("tcp-port-used");
|
|
|
14
18
|
const { spawnSync } = require("child_process");
|
|
15
19
|
var sudo = require("sudo");
|
|
16
20
|
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @returns {string}
|
|
24
|
+
*/
|
|
17
25
|
const gen_password = () => {
|
|
18
26
|
const s = is.str.generate().replace(" ", "");
|
|
19
27
|
if (s.length > 7) return s;
|
|
20
28
|
else return gen_password();
|
|
21
29
|
};
|
|
22
30
|
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @returns {Promise<object>}
|
|
34
|
+
*/
|
|
23
35
|
const askDevServer = async () => {
|
|
24
36
|
if (process.platform !== "linux") {
|
|
25
37
|
console.log("Non-linux platform, continuing development-mode install");
|
|
@@ -45,11 +57,18 @@ const askDevServer = async () => {
|
|
|
45
57
|
return responses.mode;
|
|
46
58
|
};
|
|
47
59
|
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
* @param {*} mod
|
|
63
|
+
*/
|
|
48
64
|
const unloadModule = (mod) => {
|
|
49
65
|
var name = require.resolve(mod);
|
|
50
66
|
delete require.cache[name];
|
|
51
67
|
};
|
|
52
68
|
|
|
69
|
+
/**
|
|
70
|
+
* @returns {Promise<void>}
|
|
71
|
+
*/
|
|
53
72
|
const setupDevMode = async () => {
|
|
54
73
|
const dbPath = path.join(defaultDataPath, "scdb.sqlite");
|
|
55
74
|
fs.promises.mkdir(defaultDataPath, { recursive: true });
|
|
@@ -65,6 +84,9 @@ const setupDevMode = async () => {
|
|
|
65
84
|
}
|
|
66
85
|
};
|
|
67
86
|
|
|
87
|
+
/**
|
|
88
|
+
* @returns {Promise<void>}
|
|
89
|
+
*/
|
|
68
90
|
const check_db = async () => {
|
|
69
91
|
const inUse = await tcpPortUsed.check(5432, "127.0.0.1");
|
|
70
92
|
if (!inUse) {
|
|
@@ -92,6 +114,11 @@ const check_db = async () => {
|
|
|
92
114
|
}
|
|
93
115
|
};
|
|
94
116
|
|
|
117
|
+
/**
|
|
118
|
+
*
|
|
119
|
+
* @param {*} args
|
|
120
|
+
* @returns {Promise<void>}
|
|
121
|
+
*/
|
|
95
122
|
const asyncSudo = (args) => {
|
|
96
123
|
return new Promise(function (resolve, reject) {
|
|
97
124
|
var child = sudo(args, { cachePassword: true });
|
|
@@ -108,10 +135,20 @@ const asyncSudo = (args) => {
|
|
|
108
135
|
});
|
|
109
136
|
};
|
|
110
137
|
|
|
138
|
+
/**
|
|
139
|
+
*
|
|
140
|
+
* @param {*} args
|
|
141
|
+
* @returns {Promise<void>}
|
|
142
|
+
*/
|
|
111
143
|
const asyncSudoPostgres = (args) => {
|
|
112
144
|
return asyncSudo(["sudo", "-u", "postgres", ...args]);
|
|
113
145
|
};
|
|
114
146
|
|
|
147
|
+
/**
|
|
148
|
+
*
|
|
149
|
+
* @param {string} for_who
|
|
150
|
+
* @returns {Promise<string>}
|
|
151
|
+
*/
|
|
115
152
|
const get_password = async (for_who) => {
|
|
116
153
|
var password = await cli.prompt(`Set ${for_who} to [auto-generate]`, {
|
|
117
154
|
type: "hide",
|
|
@@ -125,6 +162,9 @@ const get_password = async (for_who) => {
|
|
|
125
162
|
return password;
|
|
126
163
|
};
|
|
127
164
|
|
|
165
|
+
/**
|
|
166
|
+
* @returns {Promise<void>}
|
|
167
|
+
*/
|
|
128
168
|
const install_db = async () => {
|
|
129
169
|
await asyncSudo(["apt", "install", "-y", "postgresql", "postgresql-client"]);
|
|
130
170
|
await asyncSudo(["service", "postgresql", "start"]);
|
|
@@ -175,6 +215,10 @@ const install_db = async () => {
|
|
|
175
215
|
});
|
|
176
216
|
};
|
|
177
217
|
|
|
218
|
+
/**
|
|
219
|
+
*
|
|
220
|
+
* @returns {Promise<object>}
|
|
221
|
+
*/
|
|
178
222
|
const prompt_connection = async () => {
|
|
179
223
|
console.log("Enter database connection parameters");
|
|
180
224
|
const host = await cli.prompt("Database host [localhost]", {
|
|
@@ -203,16 +247,27 @@ const prompt_connection = async () => {
|
|
|
203
247
|
};
|
|
204
248
|
};
|
|
205
249
|
|
|
250
|
+
/**
|
|
251
|
+
* @returns {Promise<void>}
|
|
252
|
+
*/
|
|
206
253
|
const setup_connection_config = async () => {
|
|
207
254
|
const connobj = await prompt_connection();
|
|
208
255
|
await write_connection_config(connobj);
|
|
209
256
|
};
|
|
210
257
|
|
|
258
|
+
/**
|
|
259
|
+
*
|
|
260
|
+
* @param {object} connobj
|
|
261
|
+
* @returns {Promise<void>}
|
|
262
|
+
*/
|
|
211
263
|
const write_connection_config = async (connobj) => {
|
|
212
264
|
fs.promises.mkdir(configFileDir, { recursive: true });
|
|
213
265
|
fs.writeFileSync(configFilePath, JSON.stringify(connobj), { mode: 0o600 });
|
|
214
266
|
};
|
|
215
267
|
|
|
268
|
+
/**
|
|
269
|
+
* @returns {Promise<void>}
|
|
270
|
+
*/
|
|
216
271
|
const setup_connection = async () => {
|
|
217
272
|
const connobj = getConnectObject();
|
|
218
273
|
if (connobj) {
|
|
@@ -234,6 +289,12 @@ const setup_connection = async () => {
|
|
|
234
289
|
}
|
|
235
290
|
};
|
|
236
291
|
|
|
292
|
+
/**
|
|
293
|
+
*
|
|
294
|
+
* @param {object} db
|
|
295
|
+
* @param {string} tblname
|
|
296
|
+
* @returns {Promise<boolean>}
|
|
297
|
+
*/
|
|
237
298
|
const table_exists = async (db, tblname) => {
|
|
238
299
|
const { rows } = await db.query(`SELECT EXISTS
|
|
239
300
|
(
|
|
@@ -245,6 +306,9 @@ const table_exists = async (db, tblname) => {
|
|
|
245
306
|
return rows[0].exists;
|
|
246
307
|
};
|
|
247
308
|
|
|
309
|
+
/**
|
|
310
|
+
* @returns {Promise<void>}
|
|
311
|
+
*/
|
|
248
312
|
const setup_schema = async () => {
|
|
249
313
|
const db = require("@saltcorn/data/db");
|
|
250
314
|
const ex_tables = await table_exists(db, "_sc_tables");
|
|
@@ -256,6 +320,9 @@ const setup_schema = async () => {
|
|
|
256
320
|
} else console.log("Schema already present");
|
|
257
321
|
};
|
|
258
322
|
|
|
323
|
+
/**
|
|
324
|
+
* @returns {Promise<void>}
|
|
325
|
+
*/
|
|
259
326
|
const setup_users = async () => {
|
|
260
327
|
const User = require("@saltcorn/data/models/user");
|
|
261
328
|
const hasUsers = await User.nonEmpty();
|
|
@@ -269,8 +336,17 @@ const setup_users = async () => {
|
|
|
269
336
|
}
|
|
270
337
|
};
|
|
271
338
|
|
|
339
|
+
/**
|
|
340
|
+
* SetupCommand Class
|
|
341
|
+
* @extends oclif.Command
|
|
342
|
+
* @category saltcorn-cli
|
|
343
|
+
*/
|
|
272
344
|
class SetupCommand extends Command {
|
|
345
|
+
/**
|
|
346
|
+
* @returns {Promise<void>}
|
|
347
|
+
*/
|
|
273
348
|
async run() {
|
|
349
|
+
console.log("Run setip");
|
|
274
350
|
const mode = await askDevServer();
|
|
275
351
|
if (mode == "server") {
|
|
276
352
|
// check if i already know how to connect
|
|
@@ -286,12 +362,18 @@ class SetupCommand extends Command {
|
|
|
286
362
|
}
|
|
287
363
|
}
|
|
288
364
|
|
|
365
|
+
/**
|
|
366
|
+
* @type {string}
|
|
367
|
+
*/
|
|
289
368
|
SetupCommand.description = `Set up a new system
|
|
290
369
|
...
|
|
291
370
|
This will attempt to install or connect a database, and set up a
|
|
292
371
|
configuration file
|
|
293
372
|
`;
|
|
294
373
|
|
|
374
|
+
/**
|
|
375
|
+
* @type {object}
|
|
376
|
+
*/
|
|
295
377
|
SetupCommand.flags = {
|
|
296
378
|
coverage: flags.boolean({ char: "c", description: "Coverage" }),
|
|
297
379
|
};
|
|
@@ -1,9 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category saltcorn-cli
|
|
3
|
+
* @module commands/test-plugin
|
|
4
|
+
*/
|
|
1
5
|
const { Command, flags } = require("@oclif/command");
|
|
2
6
|
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {object[]} ps
|
|
10
|
+
* @returns {object}
|
|
11
|
+
*/
|
|
3
12
|
const lastPath = (ps) =>
|
|
4
13
|
ps[ps.length - 1] === "" ? ps[ps.length - 2] : ps[ps.length - 1];
|
|
5
14
|
|
|
15
|
+
/**
|
|
16
|
+
* TestPluginCommand Class
|
|
17
|
+
* @extends oclif.Command
|
|
18
|
+
* @category saltcorn-cli
|
|
19
|
+
*/
|
|
6
20
|
class TestPluginCommand extends Command {
|
|
21
|
+
/**
|
|
22
|
+
* @returns {Promise<void>}
|
|
23
|
+
*/
|
|
7
24
|
async run() {
|
|
8
25
|
const fixtures = require("@saltcorn/data/db/fixtures");
|
|
9
26
|
const reset = require("@saltcorn/data/db/reset_schema");
|
|
@@ -32,10 +49,16 @@ class TestPluginCommand extends Command {
|
|
|
32
49
|
}
|
|
33
50
|
}
|
|
34
51
|
|
|
52
|
+
/**
|
|
53
|
+
* @type {object}
|
|
54
|
+
*/
|
|
35
55
|
TestPluginCommand.args = [
|
|
36
56
|
{ name: "path", description: "path to plugin package", required: true },
|
|
37
57
|
];
|
|
38
58
|
|
|
59
|
+
/**
|
|
60
|
+
* @type {string}
|
|
61
|
+
*/
|
|
39
62
|
TestPluginCommand.description = `Test a plugin
|
|
40
63
|
...
|
|
41
64
|
Extra documentation goes here
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category saltcorn-cli
|
|
3
|
+
* @module commands/transform-field
|
|
4
|
+
*/
|
|
1
5
|
const { Command, flags } = require("@oclif/command");
|
|
2
6
|
|
|
7
|
+
/**
|
|
8
|
+
* TransformFieldCommand Class
|
|
9
|
+
* @extends oclif.Command
|
|
10
|
+
* @category saltcorn-cli
|
|
11
|
+
*/
|
|
3
12
|
class TransformFieldCommand extends Command {
|
|
13
|
+
/**
|
|
14
|
+
* @returns {Promise<void>}
|
|
15
|
+
*/
|
|
4
16
|
async run() {
|
|
5
17
|
const db = require("@saltcorn/data/db");
|
|
6
18
|
const Table = require("@saltcorn/data/models/table");
|
|
@@ -36,6 +48,9 @@ class TransformFieldCommand extends Command {
|
|
|
36
48
|
}
|
|
37
49
|
}
|
|
38
50
|
|
|
51
|
+
/**
|
|
52
|
+
* @type {object}
|
|
53
|
+
*/
|
|
39
54
|
TransformFieldCommand.args = [
|
|
40
55
|
{
|
|
41
56
|
name: "expression",
|
|
@@ -47,8 +62,14 @@ TransformFieldCommand.args = [
|
|
|
47
62
|
{ name: "tenant", required: false, description: "tenant name" },
|
|
48
63
|
];
|
|
49
64
|
|
|
65
|
+
/**
|
|
66
|
+
* @type {string}
|
|
67
|
+
*/
|
|
50
68
|
TransformFieldCommand.description = `transform an existing field by applying a calculated expression`;
|
|
51
69
|
|
|
70
|
+
/**
|
|
71
|
+
* @type {object}
|
|
72
|
+
*/
|
|
52
73
|
TransformFieldCommand.flags = {};
|
|
53
74
|
|
|
54
75
|
module.exports = TransformFieldCommand;
|
package/src/common.js
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category saltcorn-cli
|
|
3
|
+
* @module common
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {object} ten
|
|
8
|
+
* @param {function} f
|
|
9
|
+
* @returns {Promise<void>}
|
|
10
|
+
*/
|
|
1
11
|
const maybe_as_tenant = async (ten, f) => {
|
|
2
12
|
if (!ten) return await f();
|
|
3
13
|
const db = require("@saltcorn/data/db");
|
|
4
14
|
return await db.runWithTenant(ten, f);
|
|
5
15
|
};
|
|
6
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} s
|
|
19
|
+
* @returns {object}
|
|
20
|
+
*/
|
|
7
21
|
const parseJSONorString = (s) => {
|
|
8
22
|
try {
|
|
9
23
|
return JSON.parse(s);
|
|
@@ -12,6 +26,10 @@ const parseJSONorString = (s) => {
|
|
|
12
26
|
}
|
|
13
27
|
};
|
|
14
28
|
|
|
29
|
+
/**
|
|
30
|
+
* @param {numer} ms
|
|
31
|
+
* @returns {Promise<void>}
|
|
32
|
+
*/
|
|
15
33
|
function sleep(ms) {
|
|
16
34
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
17
35
|
}
|