@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.
@@ -1,9 +1,18 @@
1
+ /**
2
+ * @category saltcorn-cli
3
+ * @module commands/plugins
4
+ */
1
5
  const { Command, flags } = require("@oclif/command");
2
6
 
3
7
  /**
4
8
  * Plugins list and update command
9
+ * @extends oclif.Command
10
+ * @category saltcorn-cli
5
11
  */
6
12
  class PluginsCommand extends Command {
13
+ /**
14
+ * @returns {Promise<void>}
15
+ */
7
16
  async run() {
8
17
  const db = require("@saltcorn/data/db");
9
18
  const { requirePlugin } = require("@saltcorn/server/load_plugins");
@@ -77,6 +86,9 @@ class PluginsCommand extends Command {
77
86
  }
78
87
  }
79
88
 
89
+ /**
90
+ * @type {object}
91
+ */
80
92
  PluginsCommand.flags = {
81
93
  //list: flags.boolean({ char: "l", description: "List" }),
82
94
  upgrade: flags.boolean({ char: "u", description: "Upgrade" }),
@@ -91,17 +103,27 @@ PluginsCommand.flags = {
91
103
  };
92
104
 
93
105
  // TODO Extra documentation goes here
106
+ /**
107
+ * @type {string}
108
+ */
94
109
  PluginsCommand.description = `List and upgrade plugins for tenants
95
110
  ...
96
111
  Extra documentation goes here
97
112
  `;
98
113
 
114
+ /**
115
+ * @type {string}
116
+ */
99
117
  PluginsCommand.examples = [ //"plugins -l - outputs detailed information about plugins",
100
118
  "plugins -v - verbose output of commands",
101
119
  "plugins -u -d - dry-run for plugin update",
102
120
  "plugins -u -f - force plugin update"
103
121
  ];
122
+
104
123
  // TODO Extra help here
124
+ /**
125
+ * @type {string}
126
+ */
105
127
  PluginsCommand.help= "Extra help here"
106
128
 
107
129
  // PluginsCommand.usage
@@ -1,8 +1,20 @@
1
+ /**
2
+ * @category saltcorn-cli
3
+ * @module commands/release
4
+ */
1
5
  const { Command, flags } = require("@oclif/command");
2
6
  const fs = require("fs");
3
7
  const { spawnSync } = require("child_process");
4
8
 
9
+ /**
10
+ * ReleaseCommand Class
11
+ * @extends oclif.Command
12
+ * @category saltcorn-cli
13
+ */
5
14
  class ReleaseCommand extends Command {
15
+ /**
16
+ * @returns {Promise<void>}
17
+ */
6
18
  async run() {
7
19
  const {
8
20
  args: { version },
@@ -10,6 +22,9 @@ class ReleaseCommand extends Command {
10
22
 
11
23
  const pkgs = {
12
24
  "@saltcorn/e2e": { dir: "e2e" },
25
+ "@saltcorn/db-common": { dir: "db-common", publish: true },
26
+ "@saltcorn/sqlite": { dir: "sqlite", publish: true },
27
+ "@saltcorn/postgres": { dir: "postgres", publish: true },
13
28
  "@saltcorn/builder": { dir: "saltcorn-builder", publish: true },
14
29
  "@saltcorn/data": { dir: "saltcorn-data", publish: true },
15
30
  "@saltcorn/random-tests": { dir: "saltcorn-random-tests" },
@@ -29,6 +44,8 @@ class ReleaseCommand extends Command {
29
44
  json.dependencies[dpkgnm] = version;
30
45
  if (json.devDependencies && json.devDependencies[dpkgnm])
31
46
  json.devDependencies[dpkgnm] = version;
47
+ if (json.optionalDependencies && json.optionalDependencies[dpkgnm])
48
+ json.optionalDependencies[dpkgnm] = version;
32
49
  });
33
50
  fs.writeFileSync(
34
51
  `packages/${dir}/package.json`,
@@ -71,7 +88,7 @@ class ReleaseCommand extends Command {
71
88
  publish("saltcorn-cli");
72
89
 
73
90
  // update Dockerfile
74
- const dockerfile = fs.readFileSync(`Dockerfile.release`, 'utf8');
91
+ const dockerfile = fs.readFileSync(`Dockerfile.release`, "utf8");
75
92
  fs.writeFileSync(
76
93
  `Dockerfile.release`,
77
94
  dockerfile.replace(/cli\@.* --unsafe/, `cli@${version} --unsafe`)
@@ -95,8 +112,14 @@ class ReleaseCommand extends Command {
95
112
  }
96
113
  }
97
114
 
115
+ /**
116
+ * @type {string}
117
+ */
98
118
  ReleaseCommand.description = `Release a new saltcorn version`;
99
119
 
120
+ /**
121
+ * @type {object}
122
+ */
100
123
  ReleaseCommand.args = [
101
124
  { name: "version", required: true, description: "New version number" },
102
125
  ];
@@ -1,8 +1,20 @@
1
+ /**
2
+ * @category saltcorn-cli
3
+ * @module commands/reset-schema
4
+ */
1
5
  const { Command, flags } = require("@oclif/command");
2
6
  const { cli } = require("cli-ux");
3
7
  const { maybe_as_tenant } = require("../common");
4
8
 
9
+ /**
10
+ * ResetCommand Class
11
+ * @extends oclif.Command
12
+ * @category saltcorn-cli
13
+ */
5
14
  class ResetCommand extends Command {
15
+ /**
16
+ * @returns {Promise<void>}
17
+ */
6
18
  async run() {
7
19
  const reset = require("@saltcorn/data/db/reset_schema");
8
20
  const db = require("@saltcorn/data/db/");
@@ -24,11 +36,17 @@ class ResetCommand extends Command {
24
36
  }
25
37
  }
26
38
 
39
+ /**
40
+ * @type {string}
41
+ */
27
42
  ResetCommand.description = `Reset the database
28
43
  ...
29
44
  This will delete all existing information
30
45
  `;
31
46
 
47
+ /**
48
+ * @type {object}
49
+ */
32
50
  ResetCommand.flags = {
33
51
  force: flags.boolean({ char: "f", description: "force" }),
34
52
  tenant: flags.string({
@@ -1,9 +1,23 @@
1
+ /**
2
+ * @category saltcorn-cli
3
+ * @module commands/restore
4
+ */
1
5
  const { Command, flags } = require("@oclif/command");
2
6
  const { spawnSync } = require("child_process");
3
7
  const path = require("path");
4
8
  const { maybe_as_tenant } = require("../common");
5
9
 
10
+ /**
11
+ * RestoreCommand Class
12
+ * @extends oclif.Command
13
+ * @category saltcorn-cli
14
+ */
6
15
  class RestoreCommand extends Command {
16
+ /**
17
+ *
18
+ * @param {string} fnm
19
+ * @returns {Promise<void>}
20
+ */
7
21
  async pg_restore(fnm) {
8
22
  const { getConnectObject } = require("@saltcorn/data/db/connect");
9
23
  const connobj = getConnectObject();
@@ -19,6 +33,13 @@ class RestoreCommand extends Command {
19
33
  );
20
34
  this.exit(res.status);
21
35
  }
36
+
37
+ /**
38
+ *
39
+ * @param {string} fnm
40
+ * @param {object} tenant
41
+ * @returns {Promise<void>}
42
+ */
22
43
  async zip_restore(fnm, tenant) {
23
44
  const { restore } = require("@saltcorn/data/models/backup");
24
45
  const User = require("@saltcorn/data/models/user");
@@ -34,6 +55,10 @@ class RestoreCommand extends Command {
34
55
  }
35
56
  });
36
57
  }
58
+
59
+ /**
60
+ * @returns {Promise<void>}
61
+ */
37
62
  async run() {
38
63
  const { args, flags } = this.parse(RestoreCommand);
39
64
  switch (path.extname(args.file)) {
@@ -54,12 +79,21 @@ class RestoreCommand extends Command {
54
79
  }
55
80
  }
56
81
 
82
+ /**
83
+ * @type {object}
84
+ */
57
85
  RestoreCommand.args = [
58
86
  { name: "file", required: true, description: "backup file to restore" },
59
87
  ];
60
88
 
89
+ /**
90
+ * @type {string}
91
+ */
61
92
  RestoreCommand.description = `Restore a previously backed up database (zip or sqlc format)`;
62
93
 
94
+ /**
95
+ * @type {object}
96
+ */
63
97
  RestoreCommand.flags = {
64
98
  tenant: flags.string({
65
99
  char: "t",
@@ -1,6 +1,18 @@
1
+ /**
2
+ * @category saltcorn-cli
3
+ * @module commands/rm-tenant
4
+ */
1
5
  const { Command, flags } = require("@oclif/command");
2
6
 
7
+ /**
8
+ * RmTenantCommand Class
9
+ * @extends oclif.Command
10
+ * @category saltcorn-cli
11
+ */
3
12
  class RmTenantCommand extends Command {
13
+ /**
14
+ * @returns {Promise<void>}
15
+ */
4
16
  async run() {
5
17
  const { args } = this.parse(RmTenantCommand);
6
18
  const { deleteTenant } = require("@saltcorn/data/models/tenant");
@@ -9,12 +21,21 @@ class RmTenantCommand extends Command {
9
21
  }
10
22
  }
11
23
 
24
+ /**
25
+ * @type {object}
26
+ */
12
27
  RmTenantCommand.args = [
13
28
  { name: "tenant", required: true, description: "Tenant to remove" },
14
29
  ];
15
30
 
31
+ /**
32
+ * @type {string}
33
+ */
16
34
  RmTenantCommand.description = `Remove a tenant`;
17
35
 
36
+ /**
37
+ * @type {object}
38
+ */
18
39
  RmTenantCommand.flags = {};
19
40
 
20
41
  module.exports = RmTenantCommand;
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @category saltcorn-cli
3
+ * @module commands/run-nenchmark
4
+ */
1
5
  const { Command, flags } = require("@oclif/command");
2
6
  const si = require("systeminformation");
3
7
  const fetch = require("node-fetch");
@@ -6,9 +10,19 @@ const wrkCB = require("wrk");
6
10
  const { sleep } = require("../common");
7
11
  const packagejson = require("../../package.json");
8
12
 
13
+ /**
14
+ *
15
+ * @param {string} s
16
+ * @returns {number}
17
+ */
9
18
  const parseMillisecs = (s) =>
10
19
  s.endsWith("ms") ? parseFloat(s) : parseFloat(s) * 1000;
11
20
 
21
+ /**
22
+ *
23
+ * @param {*} args
24
+ * @returns {Promise<object>}
25
+ */
12
26
  const wrk = (args) =>
13
27
  new Promise(function (resolve, reject) {
14
28
  wrkCB(args, function (err, out) {
@@ -22,9 +36,22 @@ const wrk = (args) =>
22
36
  });
23
37
  });
24
38
 
39
+ /**
40
+ *
41
+ * @param {string} s
42
+ * @returns {string}
43
+ */
25
44
  const ensure_no_final_slash = (s) => (s.endsWith("/") ? s.slice(0, -1) : s);
26
45
 
46
+ /**
47
+ * RunBenchmarkCommand Class
48
+ * @extends oclif.Command
49
+ * @category saltcorn-cli
50
+ */
27
51
  class RunBenchmarkCommand extends Command {
52
+ /**
53
+ * @returns {Promise<void>}
54
+ */
28
55
  async run() {
29
56
  const {
30
57
  args: { baseurl },
@@ -108,12 +135,21 @@ class RunBenchmarkCommand extends Command {
108
135
  }
109
136
  }
110
137
 
138
+ /**
139
+ * @type {object}
140
+ */
111
141
  RunBenchmarkCommand.args = [
112
142
  { name: "baseurl", required: false, description: "Base URL" },
113
143
  ];
114
144
 
145
+ /**
146
+ * @type {string}
147
+ */
115
148
  RunBenchmarkCommand.description = `Run benchmark`;
116
149
 
150
+ /**
151
+ * @type {object}
152
+ */
117
153
  RunBenchmarkCommand.flags = {
118
154
  token: flags.string({
119
155
  char: "t",
@@ -1,20 +1,42 @@
1
+ /**
2
+ * @category saltcorn-cli
3
+ * @module commands/run-tests
4
+ */
1
5
  const { Command, flags } = require("@oclif/command");
2
6
 
3
7
  const { spawnSync, spawn } = require("child_process");
4
8
  const { sleep } = require("../common");
5
9
 
10
+ /**
11
+ * RunTestsCommand Class
12
+ * @extends oclif.Command
13
+ * @category saltcorn-cli
14
+ */
6
15
  class RunTestsCommand extends Command {
7
- async do_test(cmd, args, env, forever, cwd, keepalive) {
16
+ /**
17
+ *
18
+ * @param {string} cmd
19
+ * @param {string[]} args
20
+ * @param {*} env
21
+ * @param {*} cwd
22
+ * @param {boolean} keepalive
23
+ * @returns {object}
24
+ */
25
+ async do_test(cmd, args, env, cwd, keepalive) {
8
26
  const res = spawnSync(cmd, args, {
9
27
  stdio: "inherit",
10
28
  env,
11
29
  cwd,
12
30
  });
13
- if (forever && res.status === 0)
14
- await this.do_test(cmd, args, env, forever, cwd);
15
- else if (res.status !== 0 && !keepalive) this.exit(res.status);
31
+ if (res.status !== 0 && !keepalive) this.exit(res.status);
16
32
  return res;
17
33
  }
34
+
35
+ /**
36
+ *
37
+ * @param {*} env
38
+ * @returns {Promise<void>}
39
+ */
18
40
  async e2etest(env) {
19
41
  spawnSync("packages/saltcorn-cli/bin/saltcorn", ["fixtures", "-r"], {
20
42
  stdio: "inherit",
@@ -34,15 +56,39 @@ class RunTestsCommand extends Command {
34
56
  "npm",
35
57
  ["run", "gotest"],
36
58
  env,
37
- false,
38
59
  "packages/e2e",
39
60
  true
40
61
  );
41
62
  server.kill();
42
63
  if (res.status !== 0) this.exit(res.status);
43
64
  }
65
+
66
+ /**
67
+ *
68
+ * @param {object} args
69
+ * @param {object} flags
70
+ * @throws {Error}
71
+ * @returns {void}
72
+ */
73
+ validateCall(args, flags) {
74
+ if (!args.package && flags.testFilter) {
75
+ throw new Error(
76
+ "No package name given. To use -t please specify a package or use core."
77
+ );
78
+ }
79
+ if (flags.watch && flags.watchAll) {
80
+ throw new Error(
81
+ "Ether use 'watch' or 'watchAll' but not both at the same time."
82
+ );
83
+ }
84
+ }
85
+
86
+ /**
87
+ * @returns {Promise<void>}
88
+ */
44
89
  async run() {
45
90
  const { args, flags } = this.parse(RunTestsCommand);
91
+ this.validateCall(args, flags);
46
92
  var env;
47
93
  const db = require("@saltcorn/data/db");
48
94
 
@@ -59,13 +105,24 @@ class RunTestsCommand extends Command {
59
105
  await reset();
60
106
  await fixtures();
61
107
  await db.close();
62
- const covargs = flags.coverage ? ["--", "--coverage"] : [];
108
+ let jestParams = ["--"];
109
+ if (flags.coverage) {
110
+ jestParams.push("--coverage");
111
+ }
112
+ if (flags.testFilter) {
113
+ jestParams.push("-t", flags.testFilter);
114
+ }
115
+ if (flags.watch) {
116
+ jestParams.push("--watch");
117
+ }
118
+ if (flags.watchAll) {
119
+ jestParams.push("--watchAll");
120
+ }
63
121
  if (args.package === "core") {
64
122
  await this.do_test(
65
123
  "npm",
66
- ["run", "test", ...covargs],
124
+ ["run", "test", ...jestParams],
67
125
  env,
68
- flags.forever
69
126
  );
70
127
  } else if (args.package === "e2e") {
71
128
  await this.e2etest(env);
@@ -73,18 +130,16 @@ class RunTestsCommand extends Command {
73
130
  const cwd = "packages/" + args.package;
74
131
  await this.do_test(
75
132
  "npm",
76
- ["run", "test", ...covargs],
133
+ ["run", "test", ...jestParams],
77
134
  env,
78
- flags.forever,
79
- cwd
135
+ cwd,
80
136
  );
81
137
  } else {
82
138
  const lerna = process.platform === "win32" ? "lerna.cmd" : "lerna";
83
139
  await this.do_test(
84
140
  lerna,
85
- ["run", "test", ...covargs],
141
+ ["run", "test", ...jestParams],
86
142
  env,
87
- flags.forever
88
143
  );
89
144
  await this.e2etest(env);
90
145
  }
@@ -92,18 +147,35 @@ class RunTestsCommand extends Command {
92
147
  }
93
148
  }
94
149
 
150
+ /**
151
+ * @type {object}
152
+ */
95
153
  RunTestsCommand.args = [
96
154
  { name: "package", description: "which package to run tests for" },
97
155
  ];
98
156
 
157
+ /**
158
+ * @type {string}
159
+ */
99
160
  RunTestsCommand.description = `Run test suites`;
100
161
 
162
+ /**
163
+ * @type {object}
164
+ */
101
165
  RunTestsCommand.flags = {
102
166
  coverage: flags.boolean({ char: "c", description: "Coverage" }),
103
- forever: flags.boolean({
104
- char: "f",
105
- description: "Run forever till failure",
167
+ testFilter: flags.string({
168
+ char: "t",
169
+ description: "Filter tests by suite or test name",
170
+ }),
171
+ watch: flags.boolean({
172
+ string: "watch",
173
+ description: "Watch files for changes and rerun tests related to changed files."
106
174
  }),
175
+ watchAll: flags.boolean({
176
+ string: "watchAll",
177
+ description: "Watch files for changes and rerun all tests."
178
+ })
107
179
  };
108
180
 
109
181
  module.exports = RunTestsCommand;
@@ -1,5 +1,18 @@
1
+ /**
2
+ * @category saltcorn-cli
3
+ * @module commands/scheduler
4
+ */
1
5
  const { Command, flags } = require("@oclif/command");
6
+
7
+ /**
8
+ * ScheduleCommand Class
9
+ * @extends oclif.Command
10
+ * @category saltcorn-cli
11
+ */
2
12
  class ScheduleCommand extends Command {
13
+ /**
14
+ * @returns {Promise<void>}
15
+ */
3
16
  async run() {
4
17
  const { flags } = this.parse(ScheduleCommand);
5
18
  if (flags.verbose) {
@@ -11,8 +24,14 @@ class ScheduleCommand extends Command {
11
24
  }
12
25
  }
13
26
 
27
+ /**
28
+ * @type {string}
29
+ */
14
30
  ScheduleCommand.description = `Run the Saltcorn scheduler`;
15
31
 
32
+ /**
33
+ * @type {object}
34
+ */
16
35
  ScheduleCommand.flags = {
17
36
  verbose: flags.boolean({ char: "v", description: "Verbose" }),
18
37
  };
@@ -1,7 +1,19 @@
1
+ /**
2
+ * @category saltcorn-cli
3
+ * @module commands/serve
4
+ */
1
5
  const { Command, flags } = require("@oclif/command");
2
6
  const si = require("systeminformation");
3
7
 
8
+ /**
9
+ * ServeCommand Class
10
+ * @extends oclif.Command
11
+ * @category saltcorn-cli
12
+ */
4
13
  class ServeCommand extends Command {
14
+ /**
15
+ * @returns {Promise<void>}
16
+ */
5
17
  async run() {
6
18
  const { flags } = this.parse(ServeCommand);
7
19
  const cpu = await si.cpu();
@@ -37,8 +49,14 @@ class ServeCommand extends Command {
37
49
  }
38
50
  }
39
51
 
52
+ /**
53
+ * @type {string}
54
+ */
40
55
  ServeCommand.description = `Start the Saltcorn server`;
41
56
 
57
+ /**
58
+ * @type {object}
59
+ */
42
60
  ServeCommand.flags = {
43
61
  port: flags.integer({ char: "p", description: "port", default: 3000 }),
44
62
  port: flags.integer({ char: "p", description: "port", default: 3000 }),
@@ -1,8 +1,20 @@
1
+ /**
2
+ * @category saltcorn-cli
3
+ * @module commands/set-cfg
4
+ */
1
5
  const { Command, flags } = require("@oclif/command");
2
6
  const { cli } = require("cli-ux");
3
7
  const { maybe_as_tenant, parseJSONorString } = require("../common");
4
8
 
9
+ /**
10
+ * SetCfgCommand Class
11
+ * @extends oclif.Command
12
+ * @category saltcorn-cli
13
+ */
5
14
  class SetCfgCommand extends Command {
15
+ /**
16
+ * @returns {Promise<void>}
17
+ */
6
18
  async run() {
7
19
  const { args, flags } = this.parse(SetCfgCommand);
8
20
  await maybe_as_tenant(flags.tenant, async () => {
@@ -20,7 +32,14 @@ class SetCfgCommand extends Command {
20
32
  }
21
33
  }
22
34
 
35
+ /**
36
+ * @type {string}
37
+ */
23
38
  SetCfgCommand.description = `Set a configuration value`;
39
+
40
+ /**
41
+ * @type {object[]}
42
+ */
24
43
  SetCfgCommand.args = [
25
44
  { name: "key", required: true, description: "Configuration key" },
26
45
  {
@@ -29,6 +48,10 @@ SetCfgCommand.args = [
29
48
  description: "Configuration value (JSON or string)",
30
49
  },
31
50
  ];
51
+
52
+ /**
53
+ * @type {object}
54
+ */
32
55
  SetCfgCommand.flags = {
33
56
  tenant: flags.string({
34
57
  char: "t",
@@ -1,7 +1,19 @@
1
+ /**
2
+ * @category saltcorn-cli
3
+ * @module commands/setup-benchmark
4
+ */
1
5
  const { Command, flags } = require("@oclif/command");
2
6
  const { maybe_as_tenant } = require("../common");
3
7
 
8
+ /**
9
+ * SetupBenchmarkCommand Class
10
+ * @extends oclif.Command
11
+ * @category saltcorn-cli
12
+ */
4
13
  class SetupBenchmarkCommand extends Command {
14
+ /**
15
+ * @returns {Promise<void>}
16
+ */
5
17
  async install_forum_pack() {
6
18
  const {
7
19
  fetch_pack_by_name,
@@ -17,6 +29,10 @@ class SetupBenchmarkCommand extends Command {
17
29
  load_plugins.loadAndSaveNewPlugin(p)
18
30
  );
19
31
  }
32
+
33
+ /**
34
+ * @returns {Promise<void>}
35
+ */
20
36
  async run() {
21
37
  const { args, flags } = this.parse(SetupBenchmarkCommand);
22
38
  await maybe_as_tenant(flags.tenant, async () => {
@@ -62,10 +78,17 @@ class SetupBenchmarkCommand extends Command {
62
78
  }
63
79
  }
64
80
 
81
+ /** @type {object[]} */
65
82
  SetupBenchmarkCommand.args = [];
66
83
 
84
+ /**
85
+ * @type {string}
86
+ */
67
87
  SetupBenchmarkCommand.description = `Setup an instance for benchmarking`;
68
88
 
89
+ /**
90
+ * @type {object}
91
+ */
69
92
  SetupBenchmarkCommand.flags = {
70
93
  tenant: flags.string({
71
94
  char: "t",