@saltcorn/cli 1.1.2-beta.9 → 1.1.3-beta.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.
@@ -1120,6 +1120,41 @@
1120
1120
  "plugins.js"
1121
1121
  ]
1122
1122
  },
1123
+ "prepare": {
1124
+ "aliases": [],
1125
+ "args": {},
1126
+ "description": "Prepare to serve. Optional, may accelerate subsequent 'saltcorn serve' startup",
1127
+ "flags": {
1128
+ "verbose": {
1129
+ "char": "v",
1130
+ "description": "Verbose",
1131
+ "name": "verbose",
1132
+ "allowNo": false,
1133
+ "type": "boolean"
1134
+ },
1135
+ "addschema": {
1136
+ "char": "a",
1137
+ "description": "Add schema if missing",
1138
+ "name": "addschema",
1139
+ "allowNo": false,
1140
+ "type": "boolean"
1141
+ }
1142
+ },
1143
+ "hasDynamicHelp": false,
1144
+ "hiddenAliases": [],
1145
+ "id": "prepare",
1146
+ "pluginAlias": "@saltcorn/cli",
1147
+ "pluginName": "@saltcorn/cli",
1148
+ "pluginType": "core",
1149
+ "strict": true,
1150
+ "enableJsonFlag": false,
1151
+ "isESM": false,
1152
+ "relativePath": [
1153
+ "src",
1154
+ "commands",
1155
+ "prepare.js"
1156
+ ]
1157
+ },
1123
1158
  "reset-schema": {
1124
1159
  "aliases": [],
1125
1160
  "args": {},
@@ -2139,7 +2174,43 @@
2139
2174
  "dev",
2140
2175
  "test-plugin.js"
2141
2176
  ]
2177
+ },
2178
+ "dev:translate": {
2179
+ "aliases": [],
2180
+ "args": {
2181
+ "locale": {
2182
+ "description": "locale to translate",
2183
+ "name": "locale",
2184
+ "required": true
2185
+ }
2186
+ },
2187
+ "description": "Produce translation files with LLM",
2188
+ "flags": {
2189
+ "module": {
2190
+ "char": "m",
2191
+ "description": "Module to translate (in development)",
2192
+ "name": "module",
2193
+ "hasDynamicHelp": false,
2194
+ "multiple": false,
2195
+ "type": "option"
2196
+ }
2197
+ },
2198
+ "hasDynamicHelp": false,
2199
+ "hiddenAliases": [],
2200
+ "id": "dev:translate",
2201
+ "pluginAlias": "@saltcorn/cli",
2202
+ "pluginName": "@saltcorn/cli",
2203
+ "pluginType": "core",
2204
+ "strict": true,
2205
+ "enableJsonFlag": false,
2206
+ "isESM": false,
2207
+ "relativePath": [
2208
+ "src",
2209
+ "commands",
2210
+ "dev",
2211
+ "translate.js"
2212
+ ]
2142
2213
  }
2143
2214
  },
2144
- "version": "1.1.2-beta.9"
2215
+ "version": "1.1.3-beta.0"
2145
2216
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@saltcorn/cli",
3
3
  "description": "Command-line interface for Saltcorn, open-source no-code platform",
4
4
  "homepage": "https://saltcorn.com",
5
- "version": "1.1.2-beta.9",
5
+ "version": "1.1.3-beta.0",
6
6
  "author": "Tom Nielsen @glutamate",
7
7
  "bin": {
8
8
  "saltcorn": "./bin/saltcorn"
@@ -11,13 +11,13 @@
11
11
  "dependencies": {
12
12
  "@oclif/core": "^4.2.4",
13
13
  "@oclif/plugin-plugins": "^5.4.26",
14
- "@saltcorn/admin-models": "1.1.2-beta.9",
15
- "@saltcorn/common-code": "1.1.2-beta.9",
16
- "@saltcorn/data": "1.1.2-beta.9",
17
- "@saltcorn/mobile-app": "1.1.2-beta.9",
18
- "@saltcorn/mobile-builder": "1.1.2-beta.9",
19
- "@saltcorn/plugins-loader": "1.1.2-beta.9",
20
- "@saltcorn/server": "1.1.2-beta.9",
14
+ "@saltcorn/admin-models": "1.1.3-beta.0",
15
+ "@saltcorn/common-code": "1.1.3-beta.0",
16
+ "@saltcorn/data": "1.1.3-beta.0",
17
+ "@saltcorn/mobile-app": "1.1.3-beta.0",
18
+ "@saltcorn/mobile-builder": "1.1.3-beta.0",
19
+ "@saltcorn/plugins-loader": "1.1.3-beta.0",
20
+ "@saltcorn/server": "1.1.3-beta.0",
21
21
  "contractis": "^0.1.0",
22
22
  "dateformat": "^4.6.3",
23
23
  "inquirer": "^12.3.3",
@@ -16,7 +16,7 @@ const runCmd = (cmd, args, options) => {
16
16
  throw new Error(
17
17
  `Non-zero exit status for command: "${cmd} ${args.join(" ")}" in ${
18
18
  options?.cwd || "."
19
- }`
19
+ }`,
20
20
  );
21
21
  };
22
22
 
@@ -55,6 +55,14 @@ class ReleaseCommand extends Command {
55
55
  stdio: "inherit",
56
56
  cwd: ".",
57
57
  });
58
+ runCmd("npm", ["run", "docs"], {
59
+ stdio: "inherit",
60
+ cwd: ".",
61
+ });
62
+ runCmd("cp", ["-r", "docs", "packages/server/"], {
63
+ stdio: "inherit",
64
+ cwd: ".",
65
+ });
58
66
  const pkgs = {
59
67
  "@saltcorn/db-common": { dir: "db-common", publish: true },
60
68
  "@saltcorn/common-code": { dir: "common-code", publish: true },
@@ -102,7 +110,7 @@ class ReleaseCommand extends Command {
102
110
  updateDependencies(json, "@saltcorn/cli", version);
103
111
  fs.writeFileSync(
104
112
  `packages/${dir}/package.json`,
105
- JSON.stringify(json, null, 2)
113
+ JSON.stringify(json, null, 2),
106
114
  );
107
115
  };
108
116
  const compileTsFiles = () => {
@@ -129,7 +137,7 @@ class ReleaseCommand extends Command {
129
137
  {
130
138
  stdio: "inherit",
131
139
  cwd: `packages/${dir}/`,
132
- }
140
+ },
133
141
  );
134
142
  tags.shift();
135
143
  for (const tag of tags) {
@@ -175,7 +183,7 @@ class ReleaseCommand extends Command {
175
183
  updatePkgJson("saltcorn-cli");
176
184
  fs.writeFileSync(
177
185
  `package.json`,
178
- JSON.stringify({ ...rootPackageJson, workspaces: undefined }, null, 2)
186
+ JSON.stringify({ ...rootPackageJson, workspaces: undefined }, null, 2),
179
187
  );
180
188
 
181
189
  runCmd("npm", ["install", "--legacy-peer-deps"], {
@@ -215,15 +223,18 @@ class ReleaseCommand extends Command {
215
223
  const dockerfile = fs.readFileSync(`Dockerfile.release`, "utf8");
216
224
  fs.writeFileSync(
217
225
  `Dockerfile.release`,
218
- dockerfile.replace(/cli@.* --omit=dev/, `cli@${version} --omit=dev`)
226
+ dockerfile.replace(/cli@.* --omit=dev/, `cli@${version} --omit=dev`),
219
227
  );
220
228
  const dockerfileWithMobile = fs.readFileSync(
221
229
  `Dockerfile.mobile.release`,
222
- "utf8"
230
+ "utf8",
223
231
  );
224
232
  fs.writeFileSync(
225
233
  `Dockerfile.mobile.release`,
226
- dockerfileWithMobile.replace(/cli@.* --omit=dev/, `cli@${version} --omit=dev`)
234
+ dockerfileWithMobile.replace(
235
+ /cli@.* --omit=dev/,
236
+ `cli@${version} --omit=dev`,
237
+ ),
227
238
  );
228
239
  //git commit tag and push
229
240
  runCmd("git", ["commit", "-am", "v" + version], {
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @category saltcorn-cli
3
+ * @module commands/translate
4
+ */
5
+ const { Command, Flags, Args } = require("@oclif/core");
6
+ const { maybe_as_tenant, init_some_tenants } = require("../../common");
7
+ const { getState, features } = require("@saltcorn/data/db/state");
8
+ const path = require("path");
9
+ const fs = require("fs");
10
+
11
+ /**
12
+ * TranslateCommand Class
13
+ * @extends oclif.Command
14
+ * @category saltcorn-cli
15
+ */
16
+ class TranslateCommand extends Command {
17
+ /**
18
+ * @returns {Promise<void>}
19
+ */
20
+ async run() {
21
+ const db = require("@saltcorn/data/db");
22
+ const Plugin = require("@saltcorn/data/models/plugin");
23
+ const { args, flags } = await this.parse(TranslateCommand);
24
+ await init_some_tenants();
25
+ await maybe_as_tenant(null, async () => {
26
+ console.log(getState().functions);
27
+ const dir = path.join(
28
+ __dirname,
29
+ "..",
30
+ "..",
31
+ "..",
32
+ "..",
33
+ "server",
34
+ "locales",
35
+ );
36
+ const english = JSON.parse(fs.readFileSync(path.join(dir, "en.json")));
37
+ const locale = JSON.parse(
38
+ fs.readFileSync(path.join(dir, args.locale + ".json")),
39
+ );
40
+
41
+ let count = 0;
42
+ for (const key of Object.keys(english)) {
43
+ if (skipKeys.includes(key) || (locale[key] && locale[key] !== key)) {
44
+ //console.log("Skipping", locale[key]);
45
+ continue;
46
+ }
47
+ process.stdout.write(`Translating ${key} to: `);
48
+ const answer = await getState().functions.llm_generate.run(
49
+ key,
50
+ { systemPrompt: systemPrompt(args.locale), temperature: 0 },
51
+ );
52
+ console.log(answer);
53
+ locale[key] = answer;
54
+ count += 1;
55
+ fs.writeFileSync(
56
+ path.join(dir, args.locale + ".json"),
57
+ JSON.stringify(locale, null, 2),
58
+ );
59
+ //if (count > 10) break;
60
+ }
61
+ });
62
+ this.exit(0);
63
+ }
64
+ }
65
+
66
+ // prompt explain: tables, users, tenants
67
+ const languageNames = new Intl.DisplayNames(["en"], {
68
+ type: "language",
69
+ });
70
+ const skipKeys = ["HTTP", "Plugins"];
71
+
72
+ const systemPrompt = (
73
+ locale,
74
+ ) => `You are purely a translation assistant. Translate
75
+ the entered text into ${languageNames.of(locale)} without any additional information.
76
+ the translation is in the domain of database user interface/ application development software. the term Table referes to
77
+ the database table, the row is a row in the database table, media is the type of media file,
78
+ the user is the user account in the system, with each user having a role that defines permissions, and as the system is
79
+ multi-tenant the term tenant refers an instance of the application for a particular purpose.
80
+ 2FA is two factor authentication, building refers to building software applications. A view is a
81
+ representation of the database content on the screen for the user, and actions are user-defined ways of
82
+ manipulating data or files. The system is modular, and an extension is known as a Module. Use technical language.
83
+ Translate anything the user enters to ${languageNames.of(locale)}.`;
84
+
85
+ TranslateCommand.args = {
86
+ locale: Args.string({
87
+ required: true,
88
+ description: "locale to translate",
89
+ }),
90
+ };
91
+
92
+ /**
93
+ * @type {string}
94
+ */
95
+ TranslateCommand.description = `Produce translation files with LLM`;
96
+
97
+ /**
98
+ * @type {object}
99
+ */
100
+ TranslateCommand.flags = {
101
+ module: Flags.string({
102
+ char: "m",
103
+ description: "Module to translate (in development)",
104
+ }),
105
+ };
106
+
107
+ module.exports = TranslateCommand;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @category saltcorn-cli
3
+ * @module commands/prepare
4
+ */
5
+ const { Command, Flags } = require("@oclif/core");
6
+
7
+ /**
8
+ * PrepareCommand Class
9
+ * @extends oclif.Command
10
+ * @category saltcorn-cli
11
+ */
12
+ class PrepareCommand extends Command {
13
+ /**
14
+ * @returns {Promise<void>}
15
+ */
16
+ async run() {
17
+ const { flags } = await this.parse(PrepareCommand);
18
+ const serveArgs = {
19
+ defaultNCPUs: 1,
20
+ };
21
+ if (flags.addschema) {
22
+ try {
23
+ const { getConfig } = require("@saltcorn/data/models/config");
24
+ await getConfig("log_sql");
25
+ } catch (e) {
26
+ const msg = e.message;
27
+ if (msg && msg.includes("_sc_config")) {
28
+ console.log("Adding Saltcorn schema to database...");
29
+ const reset = require("@saltcorn/data/db/reset_schema");
30
+ await reset(true);
31
+ } else {
32
+ console.error("Database is not reachable. The error was: ", msg);
33
+ process.exit(1);
34
+ }
35
+ }
36
+ }
37
+
38
+ if (flags.verbose) {
39
+ const db = require("@saltcorn/data/db");
40
+ db.set_sql_logging();
41
+ }
42
+
43
+ const getApp = require("@saltcorn/server/app");
44
+ await getApp(serveArgs);
45
+ process.exit(0);
46
+
47
+ }
48
+ }
49
+
50
+ /**
51
+ * @type {string}
52
+ */
53
+ PrepareCommand.description = `Prepare to serve. Optional, may accelerate subsequent 'saltcorn serve' startup`;
54
+
55
+ /**
56
+ * @type {object}
57
+ */
58
+ PrepareCommand.flags = {
59
+ verbose: Flags.boolean({ char: "v", description: "Verbose" }),
60
+ addschema: Flags.boolean({ char: "a", description: "Add schema if missing" }),
61
+ };
62
+
63
+ module.exports = PrepareCommand;