@extrahorizon/exh-cli 1.5.1 → 1.6.0-dev-39-14d33ad
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/CHANGELOG.md +7 -0
- package/README.md +1 -1
- package/build/commands/localizations/sync.d.ts +16 -0
- package/build/commands/localizations/sync.js +20 -0
- package/build/commands/localizations.d.ts +5 -0
- package/build/commands/localizations.js +10 -0
- package/build/commands/sync.d.ts +19 -11
- package/build/commands/sync.js +19 -6
- package/build/commands/whoami.d.ts +8 -0
- package/build/commands/whoami.js +20 -0
- package/build/helpers/repoConfig.d.ts +1 -1
- package/build/helpers/repoConfig.js +3 -6
- package/build/index.js +0 -7
- package/build/repositories/auth.d.ts +3 -0
- package/build/repositories/auth.js +11 -0
- package/build/repositories/localizations.d.ts +4 -0
- package/build/repositories/localizations.js +11 -0
- package/build/services/localizations/assertValidFileContent.d.ts +1 -0
- package/build/services/localizations/assertValidFileContent.js +14 -0
- package/build/services/localizations/assertValidLanguageCode.d.ts +2 -0
- package/build/services/localizations/assertValidLanguageCode.js +21 -0
- package/build/services/localizations/index.d.ts +2 -0
- package/build/services/localizations/index.js +25 -0
- package/build/services/localizations/readFiles.d.ts +2 -0
- package/build/services/localizations/readFiles.js +44 -0
- package/build/services/localizations/syncLocalizations.d.ts +3 -0
- package/build/services/localizations/syncLocalizations.js +23 -0
- package/package.json +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Extra Horizon CLI changelog
|
|
2
2
|
|
|
3
|
+
### v1.6.0
|
|
4
|
+
* Removed the update notifier. The version of the package we used had security vulnerabilities and we're unable to migrate to the latest version right now. We'll look into this again in the future.
|
|
5
|
+
* Added the `exh whoami` command, showing the currently logged in user
|
|
6
|
+
* Added the `exh localizations sync` command, allowing you to sync localizations from a folder containing your translations
|
|
7
|
+
* Added localization syncing support to the `exh sync` command
|
|
8
|
+
* The `exh sync` command now also supports absolute paths for the `--path` argument
|
|
9
|
+
|
|
3
10
|
### v1.5.1
|
|
4
11
|
* Now also publishing to the NPM registry, no longer needing to authenticate with GitHub Packages to install the CLI
|
|
5
12
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Extra Horizon CLI
|
|
2
2
|
|
|
3
|
-
This is the command-line interface to the Extra Horizon platform. It allows you to manage
|
|
3
|
+
This is the command-line interface to the Extra Horizon platform. It allows you to manage just some parts of your Extra Horizon configuration for now, but
|
|
4
4
|
will be extended with additional functionality.
|
|
5
5
|
|
|
6
6
|
See [changelog](CHANGELOG.md) for the latest changes.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="yargs" />
|
|
2
|
+
import { OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
3
|
+
export declare const command = "sync";
|
|
4
|
+
export declare const desc = "Sync all localizations in a directory with the ExH cloud";
|
|
5
|
+
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "path"> & import("yargs").InferredOptionTypes<{
|
|
6
|
+
path: {
|
|
7
|
+
demandOption: false;
|
|
8
|
+
describe: string;
|
|
9
|
+
type: "string";
|
|
10
|
+
default: string;
|
|
11
|
+
};
|
|
12
|
+
}>>;
|
|
13
|
+
export declare const handler: ({ sdk, path }: {
|
|
14
|
+
sdk: OAuth1Client;
|
|
15
|
+
path?: string;
|
|
16
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
+
const util_1 = require("../../helpers/util");
|
|
5
|
+
const localizationsService = require("../../services/localizations");
|
|
6
|
+
exports.command = 'sync';
|
|
7
|
+
exports.desc = 'Sync all localizations in a directory with the ExH cloud';
|
|
8
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
9
|
+
path: {
|
|
10
|
+
demandOption: false,
|
|
11
|
+
describe: 'Directory containing the localizations which need to be synced in a JSON format. By Default: ./localizations',
|
|
12
|
+
type: 'string',
|
|
13
|
+
default: './localizations',
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
exports.builder = builder;
|
|
17
|
+
const handler = async ({ sdk, path }) => {
|
|
18
|
+
await localizationsService.sync(sdk, path);
|
|
19
|
+
};
|
|
20
|
+
exports.handler = handler;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
+
const util_1 = require("../helpers/util");
|
|
5
|
+
exports.command = 'localizations <command>';
|
|
6
|
+
exports.desc = 'Manage localizations';
|
|
7
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs).commandDir('localizations');
|
|
8
|
+
exports.builder = builder;
|
|
9
|
+
const handler = () => { };
|
|
10
|
+
exports.handler = handler;
|
package/build/commands/sync.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="yargs" />
|
|
2
|
+
import { OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
2
3
|
export declare const command = "sync";
|
|
3
|
-
export declare const desc = "
|
|
4
|
-
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "path" | "schemas" | "tasks" | "dispatchers" | "templates" | "cleanDispatchers" | "ignoreSchemaVerificationErrors"> & import("yargs").InferredOptionTypes<{
|
|
4
|
+
export declare const desc = "Sync your ExH configuration to the cloud environment";
|
|
5
|
+
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "path" | "schemas" | "tasks" | "dispatchers" | "localizations" | "templates" | "cleanDispatchers" | "ignoreSchemaVerificationErrors"> & import("yargs").InferredOptionTypes<{
|
|
5
6
|
path: {
|
|
6
7
|
demandOption: false;
|
|
7
8
|
describe: string;
|
|
@@ -36,6 +37,12 @@ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs
|
|
|
36
37
|
describe: string;
|
|
37
38
|
type: "boolean";
|
|
38
39
|
};
|
|
40
|
+
localizations: {
|
|
41
|
+
demandOption: false;
|
|
42
|
+
describe: string;
|
|
43
|
+
type: "boolean";
|
|
44
|
+
default: boolean;
|
|
45
|
+
};
|
|
39
46
|
ignoreSchemaVerificationErrors: {
|
|
40
47
|
demandOption: false;
|
|
41
48
|
describe: string;
|
|
@@ -43,13 +50,14 @@ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs
|
|
|
43
50
|
default: boolean;
|
|
44
51
|
};
|
|
45
52
|
}>>;
|
|
46
|
-
export declare const handler: ({ sdk, path, schemas, tasks, templates, dispatchers, cleanDispatchers, ignoreSchemaVerificationErrors }: {
|
|
47
|
-
sdk:
|
|
48
|
-
path
|
|
49
|
-
schemas
|
|
50
|
-
tasks
|
|
51
|
-
templates
|
|
52
|
-
dispatchers
|
|
53
|
-
cleanDispatchers
|
|
54
|
-
|
|
53
|
+
export declare const handler: ({ sdk, path, schemas, tasks, templates, dispatchers, cleanDispatchers, localizations, ignoreSchemaVerificationErrors, }: {
|
|
54
|
+
sdk: OAuth1Client;
|
|
55
|
+
path?: string;
|
|
56
|
+
schemas?: boolean;
|
|
57
|
+
tasks?: boolean;
|
|
58
|
+
templates?: boolean;
|
|
59
|
+
dispatchers?: boolean;
|
|
60
|
+
cleanDispatchers?: boolean;
|
|
61
|
+
localizations?: boolean;
|
|
62
|
+
ignoreSchemaVerificationErrors?: boolean;
|
|
55
63
|
}) => Promise<void>;
|
package/build/commands/sync.js
CHANGED
|
@@ -8,17 +8,18 @@ const chalk = require("chalk");
|
|
|
8
8
|
const repoConfig_1 = require("../helpers/repoConfig");
|
|
9
9
|
const util_1 = require("../helpers/util");
|
|
10
10
|
const dispatchers_1 = require("../services/dispatchers");
|
|
11
|
+
const localizations_1 = require("../services/localizations");
|
|
11
12
|
const sync_1 = require("./data/schemas/sync");
|
|
12
13
|
const sync_2 = require("./tasks/sync");
|
|
13
14
|
const sync_3 = require("./templates/sync");
|
|
14
15
|
exports.command = 'sync';
|
|
15
|
-
exports.desc = '
|
|
16
|
+
exports.desc = 'Sync your ExH configuration to the cloud environment';
|
|
16
17
|
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
17
18
|
.options({
|
|
18
19
|
path: {
|
|
19
20
|
demandOption: false,
|
|
20
21
|
describe: `Path to folder which needs to be synchronized. The target folder should contain a ${repoConfig_1.REPO_CONFIG_FILE} file.
|
|
21
|
-
If not, the local directory is assumed with a default configuration which assumes tasks are in a 'tasks' folder, schemas in a 'schemas' folder
|
|
22
|
+
If not, the local directory is assumed with a default configuration which assumes tasks are in a 'tasks' folder, schemas in a 'schemas' folder, etc...`,
|
|
22
23
|
type: 'string',
|
|
23
24
|
},
|
|
24
25
|
schemas: {
|
|
@@ -50,6 +51,12 @@ If not, the local directory is assumed with a default configuration which assume
|
|
|
50
51
|
describe: 'Delete Dispatchers created using the CLI, that are no longer present in the local Dispatcher file',
|
|
51
52
|
type: 'boolean',
|
|
52
53
|
},
|
|
54
|
+
localizations: {
|
|
55
|
+
demandOption: false,
|
|
56
|
+
describe: 'Sync localizations only',
|
|
57
|
+
type: 'boolean',
|
|
58
|
+
default: false,
|
|
59
|
+
},
|
|
53
60
|
ignoreSchemaVerificationErrors: {
|
|
54
61
|
demandOption: false,
|
|
55
62
|
describe: 'Allow schema synchronization to proceed with validation errors.',
|
|
@@ -71,10 +78,10 @@ If not, the local directory is assumed with a default configuration which assume
|
|
|
71
78
|
return true;
|
|
72
79
|
});
|
|
73
80
|
exports.builder = builder;
|
|
74
|
-
const handler = async ({ sdk, path, schemas, tasks, templates, dispatchers, cleanDispatchers, ignoreSchemaVerificationErrors }) => {
|
|
75
|
-
const targetPath =
|
|
76
|
-
const cfg = await (0, repoConfig_1.getRepoConfig)(targetPath
|
|
77
|
-
const syncAll = !(schemas || tasks || templates || dispatchers);
|
|
81
|
+
const handler = async ({ sdk, path, schemas, tasks, templates, dispatchers, cleanDispatchers, localizations, ignoreSchemaVerificationErrors, }) => {
|
|
82
|
+
const targetPath = path || '.';
|
|
83
|
+
const cfg = await (0, repoConfig_1.getRepoConfig)(targetPath);
|
|
84
|
+
const syncAll = !(schemas || tasks || templates || dispatchers || localizations);
|
|
78
85
|
if ((syncAll || schemas) && cfg.schemas) {
|
|
79
86
|
console.log(chalk.green('\n ⚙️ Syncing schemas ...'));
|
|
80
87
|
for (const schema of cfg.schemas) {
|
|
@@ -93,6 +100,12 @@ const handler = async ({ sdk, path, schemas, tasks, templates, dispatchers, clea
|
|
|
93
100
|
await (0, sync_2.handler)({ sdk, path: ospath.join(targetPath, task) });
|
|
94
101
|
}
|
|
95
102
|
}
|
|
103
|
+
if ((syncAll || localizations) && cfg.localizations) {
|
|
104
|
+
console.log(chalk.green('\n ⚙️ Syncing localizations...'));
|
|
105
|
+
for (const localization of cfg.localizations) {
|
|
106
|
+
await (0, localizations_1.sync)(sdk, ospath.join(targetPath, localization));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
96
109
|
if ((syncAll || dispatchers)) {
|
|
97
110
|
const dispatchersPath = ospath.join(targetPath, 'dispatchers.json');
|
|
98
111
|
const isValidPath = (0, fs_1.existsSync)(dispatchersPath);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="yargs" />
|
|
2
|
+
import type { OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
3
|
+
export declare const command = "whoami";
|
|
4
|
+
export declare const desc = "Shows the currently logged in user";
|
|
5
|
+
export declare const builder: (yargs: any) => import("yargs").Argv<{}>;
|
|
6
|
+
export declare const handler: ({ sdk }: {
|
|
7
|
+
sdk: OAuth1Client;
|
|
8
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
+
const util_1 = require("../helpers/util");
|
|
5
|
+
const authRepository = require("../repositories/auth");
|
|
6
|
+
exports.command = 'whoami';
|
|
7
|
+
exports.desc = 'Shows the currently logged in user';
|
|
8
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs);
|
|
9
|
+
exports.builder = builder;
|
|
10
|
+
const handler = async function list({ sdk }) {
|
|
11
|
+
const host = authRepository.getHost(sdk);
|
|
12
|
+
if (!host) {
|
|
13
|
+
console.log('No ExH cluster host was found in the configuration.');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
console.log('You are targeting:', host);
|
|
17
|
+
const currentUser = await authRepository.fetchMe(sdk);
|
|
18
|
+
console.log('You are logged in as:', currentUser.email);
|
|
19
|
+
};
|
|
20
|
+
exports.handler = handler;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const REPO_CONFIG_FILE = "repo-config.json";
|
|
2
|
-
export declare function getRepoConfig(targetPath: string
|
|
2
|
+
export declare function getRepoConfig(targetPath: string): Promise<any>;
|
|
@@ -7,7 +7,7 @@ const chalk = require("chalk");
|
|
|
7
7
|
exports.REPO_CONFIG_FILE = 'repo-config.json';
|
|
8
8
|
async function getDefaultConfig(targetPath) {
|
|
9
9
|
const config = {};
|
|
10
|
-
const sections = ['schemas', 'templates', 'tasks'];
|
|
10
|
+
const sections = ['schemas', 'templates', 'tasks', 'localizations'];
|
|
11
11
|
for (const s of sections) {
|
|
12
12
|
try {
|
|
13
13
|
await fs.access(ospath.join(targetPath, s));
|
|
@@ -46,15 +46,12 @@ async function validateRepoConfig(targetPath, config) {
|
|
|
46
46
|
}
|
|
47
47
|
return newConfig;
|
|
48
48
|
}
|
|
49
|
-
async function getRepoConfig(targetPath
|
|
49
|
+
async function getRepoConfig(targetPath) {
|
|
50
50
|
let cfg = await getDefaultConfig(targetPath);
|
|
51
51
|
try {
|
|
52
52
|
cfg = JSON.parse((await fs.readFile(ospath.join(targetPath, exports.REPO_CONFIG_FILE))).toString());
|
|
53
53
|
}
|
|
54
54
|
catch (err) { }
|
|
55
|
-
|
|
56
|
-
return await validateRepoConfig(targetPath, cfg);
|
|
57
|
-
}
|
|
58
|
-
return cfg;
|
|
55
|
+
return await validateRepoConfig(targetPath, cfg);
|
|
59
56
|
}
|
|
60
57
|
exports.getRepoConfig = getRepoConfig;
|
package/build/index.js
CHANGED
|
@@ -6,13 +6,6 @@ const lodash_1 = require("lodash");
|
|
|
6
6
|
const yargs = require("yargs");
|
|
7
7
|
const helpers_1 = require("yargs/helpers");
|
|
8
8
|
const exh_1 = require("./exh");
|
|
9
|
-
function checkVersion() {
|
|
10
|
-
const pkg = require('../package.json');
|
|
11
|
-
const updateNotifier = require('update-notifier');
|
|
12
|
-
const notifier = updateNotifier({ pkg, updateCheckInterval: 0 });
|
|
13
|
-
notifier.notify();
|
|
14
|
-
}
|
|
15
|
-
checkVersion();
|
|
16
9
|
yargs((0, helpers_1.hideBin)(process.argv))
|
|
17
10
|
.middleware(async (argv) => {
|
|
18
11
|
const isTTY = tty.isatty(process.stdout.fd);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchMe = exports.getHost = void 0;
|
|
4
|
+
function getHost(sdk) {
|
|
5
|
+
return sdk?.raw?.defaults?.baseURL;
|
|
6
|
+
}
|
|
7
|
+
exports.getHost = getHost;
|
|
8
|
+
async function fetchMe(sdk) {
|
|
9
|
+
return await sdk?.users.me();
|
|
10
|
+
}
|
|
11
|
+
exports.fetchMe = fetchMe;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Localization, OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
2
|
+
export declare function create(sdk: OAuth1Client, localizations: PartialLocalization[]): Promise<import("@extrahorizon/javascript-sdk").BulkCreationResponse>;
|
|
3
|
+
export declare function update(sdk: OAuth1Client, localizations: PartialLocalization[]): Promise<import("@extrahorizon/javascript-sdk").BulkUpdateResponse>;
|
|
4
|
+
export declare type PartialLocalization = Pick<Localization, 'key' | 'text'>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.update = exports.create = void 0;
|
|
4
|
+
async function create(sdk, localizations) {
|
|
5
|
+
return await sdk.localizations.create({ localizations });
|
|
6
|
+
}
|
|
7
|
+
exports.create = create;
|
|
8
|
+
async function update(sdk, localizations) {
|
|
9
|
+
return await sdk.localizations.update({ localizations });
|
|
10
|
+
}
|
|
11
|
+
exports.update = update;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function assertValidFileContent(fileName: string, content: unknown): asserts content is Record<string, string>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertValidFileContent = void 0;
|
|
4
|
+
const Joi = require("joi");
|
|
5
|
+
const keyPattern = /^[a-z0-9_.-]{1,200}$/i;
|
|
6
|
+
const localizationFileSchema = Joi.object()
|
|
7
|
+
.pattern(keyPattern, Joi.string());
|
|
8
|
+
function assertValidFileContent(fileName, content) {
|
|
9
|
+
const result = localizationFileSchema.validate(content);
|
|
10
|
+
if (result.error != null) {
|
|
11
|
+
throw new Error(`The content of localization file '${fileName}' is not valid: ${result.error.message}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.assertValidFileContent = assertValidFileContent;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertValidLanguageCode = exports.availableLanguagesCodes = void 0;
|
|
4
|
+
exports.availableLanguagesCodes = [
|
|
5
|
+
'EN', 'AA', 'AB', 'AE', 'AF', 'AK', 'AM', 'AN', 'AR', 'AS', 'AV', 'AY', 'AZ', 'BA', 'BE', 'BG', 'BH', 'BI', 'BM', 'BN', 'BO',
|
|
6
|
+
'BR', 'BS', 'CA', 'CE', 'CH', 'CO', 'CR', 'CS', 'CU', 'CV', 'CY', 'DA', 'DE', 'DV', 'DZ', 'EE', 'EL', 'EO', 'ES', 'ET', 'EU',
|
|
7
|
+
'FA', 'FF', 'FI', 'FJ', 'FO', 'FR', 'FY', 'GA', 'GD', 'GL', 'GN', 'GU', 'GV', 'HA', 'HE', 'HI', 'HO', 'HR', 'HT', 'HU', 'HY',
|
|
8
|
+
'HZ', 'IA', 'ID', 'IE', 'IG', 'II', 'IK', 'IN', 'IO', 'IS', 'IT', 'IW', 'IU', 'JA', 'JI', 'JW', 'JV', 'KA', 'KG', 'KI', 'KJ',
|
|
9
|
+
'KK', 'KL', 'KM', 'KN', 'KO', 'KR', 'KS', 'KU', 'KV', 'KW', 'KY', 'LA', 'LB', 'LG', 'LI', 'LN', 'LO', 'LT', 'LU', 'LV', 'MG',
|
|
10
|
+
'MH', 'MI', 'MK', 'ML', 'MN', 'MO', 'MR', 'MS', 'MT', 'MY', 'NA', 'NB', 'ND', 'NE', 'NG', 'NL', 'NN', 'NO', 'NR', 'NV', 'NY',
|
|
11
|
+
'OC', 'OJ', 'OM', 'OR', 'OS', 'PA', 'PI', 'PL', 'PS', 'PT', 'QU', 'RM', 'RN', 'RO', 'RU', 'RW', 'SA', 'SC', 'SD', 'SE', 'SG',
|
|
12
|
+
'SH', 'SI', 'SK', 'SL', 'SM', 'SN', 'SO', 'SQ', 'SR', 'SS', 'ST', 'SU', 'SV', 'SW', 'TA', 'TE', 'TG', 'TH', 'TI', 'TK', 'TL',
|
|
13
|
+
'TN', 'TO', 'TR', 'TS', 'TT', 'TW', 'TY', 'UG', 'UK', 'UR', 'UZ', 'VE', 'VI', 'VO', 'WA', 'WO', 'XH', 'YI', 'YO', 'ZA', 'ZH',
|
|
14
|
+
'ZU',
|
|
15
|
+
];
|
|
16
|
+
function assertValidLanguageCode(languageCode) {
|
|
17
|
+
if (!exports.availableLanguagesCodes.includes(languageCode)) {
|
|
18
|
+
throw new Error(`The language code ${languageCode} is not available! The available language codes are: ${exports.availableLanguagesCodes.join(', ')}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.assertValidLanguageCode = assertValidLanguageCode;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sync = void 0;
|
|
4
|
+
const chalk_1 = require("chalk");
|
|
5
|
+
const readFiles_1 = require("./readFiles");
|
|
6
|
+
const syncLocalizations_1 = require("./syncLocalizations");
|
|
7
|
+
async function sync(sdk, path) {
|
|
8
|
+
console.log((0, chalk_1.yellow)(`Synchronizing localizations from ${path}`));
|
|
9
|
+
const localizations = (0, readFiles_1.readFiles)(path);
|
|
10
|
+
if (localizations.length < 1) {
|
|
11
|
+
console.log((0, chalk_1.yellow)('No localizations found'));
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
assertDefaultLanguageSetForAll(localizations);
|
|
15
|
+
await (0, syncLocalizations_1.syncLocalizations)(sdk, localizations);
|
|
16
|
+
}
|
|
17
|
+
exports.sync = sync;
|
|
18
|
+
function assertDefaultLanguageSetForAll(localizations) {
|
|
19
|
+
const defaultLanguage = 'EN';
|
|
20
|
+
const faultyLocalizations = localizations.filter(localization => localization.text[defaultLanguage] === undefined);
|
|
21
|
+
const faultyKeys = faultyLocalizations.map(localization => localization.key);
|
|
22
|
+
if (faultyKeys.length > 0) {
|
|
23
|
+
throw new Error(`The following localizations do not have a value for the default language (${defaultLanguage}): ${faultyKeys.join(', ')}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readFiles = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const osPath = require("path");
|
|
6
|
+
const assertValidFileContent_1 = require("./assertValidFileContent");
|
|
7
|
+
const assertValidLanguageCode_1 = require("./assertValidLanguageCode");
|
|
8
|
+
function readFiles(path) {
|
|
9
|
+
let fileNames;
|
|
10
|
+
try {
|
|
11
|
+
fileNames = (0, fs_1.readdirSync)(path);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
throw new Error(`Was not able to list localization files in directory '${path}': ${error}`);
|
|
15
|
+
}
|
|
16
|
+
const localizationMap = {};
|
|
17
|
+
for (const fileName of fileNames) {
|
|
18
|
+
const parsedFileName = osPath.parse(fileName);
|
|
19
|
+
if (parsedFileName.ext !== '.json') {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const languageCode = parsedFileName.name.toUpperCase();
|
|
23
|
+
(0, assertValidLanguageCode_1.assertValidLanguageCode)(languageCode);
|
|
24
|
+
const localizationJson = readLocalizationFileSync(path, fileName);
|
|
25
|
+
(0, assertValidFileContent_1.assertValidFileContent)(fileName, localizationJson);
|
|
26
|
+
for (const [key, text] of Object.entries(localizationJson)) {
|
|
27
|
+
if (!(key in localizationMap)) {
|
|
28
|
+
localizationMap[key] = { key, text: {} };
|
|
29
|
+
}
|
|
30
|
+
localizationMap[key].text[languageCode] = text;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return Object.values(localizationMap);
|
|
34
|
+
}
|
|
35
|
+
exports.readFiles = readFiles;
|
|
36
|
+
function readLocalizationFileSync(path, fileName) {
|
|
37
|
+
const fileContent = (0, fs_1.readFileSync)(osPath.join(path, fileName), { encoding: 'utf-8' });
|
|
38
|
+
try {
|
|
39
|
+
return JSON.parse(fileContent);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
throw Error(`Was not able to parse '${fileName}', not a valid JSON file`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.syncLocalizations = void 0;
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const localizationRepository = require("../../repositories/localizations");
|
|
7
|
+
const chunkSize = 30;
|
|
8
|
+
const syncLocalizations = async (sdk, localizations) => {
|
|
9
|
+
console.log(`${localizations.length} localization(s) to synchronize.`);
|
|
10
|
+
const localizationChunks = (0, lodash_1.chunk)(localizations, chunkSize);
|
|
11
|
+
for (const localizationChunk of localizationChunks) {
|
|
12
|
+
const creationResult = await localizationRepository.create(sdk, localizationChunk);
|
|
13
|
+
console.log(`Created ${creationResult.created} localization(s).`);
|
|
14
|
+
if (creationResult.existingIds && creationResult.existingIds.length > 0) {
|
|
15
|
+
const existingKeys = creationResult.existingIds;
|
|
16
|
+
const existingLocalizations = localizationChunk.filter(localization => existingKeys.includes(localization.key));
|
|
17
|
+
const updateResult = await localizationRepository.update(sdk, existingLocalizations);
|
|
18
|
+
console.log(`Updated ${updateResult.updated} localization(s).`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
console.log(chalk.green('Successful!'));
|
|
22
|
+
};
|
|
23
|
+
exports.syncLocalizations = syncLocalizations;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@extrahorizon/exh-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0-dev-39-14d33ad",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"exports": "./build/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://github.com/ExtraHorizon/exh-cli.git"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"start": "yarn
|
|
14
|
+
"start": "yarn build && node ./build/index.js",
|
|
15
15
|
"clean": "rimraf build",
|
|
16
16
|
"build": "yarn clean && tsc",
|
|
17
17
|
"test": "jest",
|
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
"chalk": "^4.0.0",
|
|
47
47
|
"joi": "^17.6.0",
|
|
48
48
|
"lodash": "^4.17.21",
|
|
49
|
-
"update-notifier": "^5.1.0",
|
|
50
49
|
"uuid": "^8.3.2",
|
|
51
50
|
"yargs": "^17.5.1"
|
|
52
51
|
}
|