@extrahorizon/exh-cli 1.13.0-dev-171-045479f → 1.13.0-dev-173-4c24837

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,5 +1,14 @@
1
1
  import { Argv } from 'yargs';
2
2
  export declare const command = "sync";
3
3
  export declare const desc = "Synchronize Service Settings";
4
- export declare const builder: (yargs: Argv) => Argv<import("yargs").Omit<{}, never> & import("yargs").InferredOptionTypes<{}>>;
5
- export declare const handler: () => Promise<void>;
4
+ export declare const builder: (yargs: Argv) => Argv<import("yargs").Omit<{}, "file"> & import("yargs").InferredOptionTypes<{
5
+ file: {
6
+ demandOption: false;
7
+ describe: string;
8
+ type: "string";
9
+ default: string;
10
+ };
11
+ }>>;
12
+ export declare const handler: ({ file }: {
13
+ file: string;
14
+ }) => Promise<void>;
@@ -1,15 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
- const path = require("node:path");
5
4
  const util_1 = require("../../helpers/util");
6
5
  const serviceSettingService = require("../../services/settings");
7
6
  exports.command = 'sync';
8
7
  exports.desc = 'Synchronize Service Settings';
9
- const builder = (yargs) => (0, util_1.epilogue)(yargs).options({});
8
+ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
9
+ file: {
10
+ demandOption: false,
11
+ describe: 'Path to the file containing the Service Settings configuration',
12
+ type: 'string',
13
+ default: './service-settings.json',
14
+ },
15
+ });
10
16
  exports.builder = builder;
11
- const handler = async () => {
12
- const filePath = path.join(process.cwd(), 'service-settings.json');
13
- await serviceSettingService.sync(filePath);
17
+ const handler = async ({ file }) => {
18
+ await serviceSettingService.sync(file);
14
19
  };
15
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): Promise<any>;
2
+ export declare function getRepoConfig(targetPath: string): any;
@@ -1,57 +1,63 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getRepoConfig = exports.REPO_CONFIG_FILE = void 0;
4
- const fs = require("fs/promises");
4
+ const fs = require("fs");
5
5
  const ospath = require("path");
6
6
  const chalk = require("chalk");
7
7
  exports.REPO_CONFIG_FILE = 'repo-config.json';
8
- async function getDefaultConfig(targetPath) {
8
+ function getRepoConfig(targetPath) {
9
+ let cfg = getDefaultConfig(targetPath);
10
+ try {
11
+ const fileContent = fs.readFileSync(ospath.join(targetPath, exports.REPO_CONFIG_FILE), 'utf-8');
12
+ cfg = JSON.parse(fileContent);
13
+ }
14
+ catch (err) { }
15
+ return validateRepoConfig(targetPath, cfg);
16
+ }
17
+ exports.getRepoConfig = getRepoConfig;
18
+ function getDefaultConfig(targetPath) {
9
19
  const config = {};
10
20
  const sections = ['schemas', 'templates', 'tasks', 'localizations'];
11
21
  for (const s of sections) {
12
- try {
13
- await fs.access(ospath.join(targetPath, s));
22
+ if (pathExists(ospath.join(targetPath, s))) {
14
23
  config[s] = [s];
15
24
  }
16
- catch (err) {
17
- continue;
18
- }
19
25
  }
20
26
  return config;
21
27
  }
22
- async function validateRepoConfig(targetPath, config) {
23
- const checkDirAccess = async (basePath, paths) => {
24
- const result = [];
25
- if (!Array.isArray(paths)) {
26
- throw new Error('Not an array');
27
- }
28
- for (const p of paths) {
29
- try {
30
- await fs.access(ospath.join(basePath, p));
31
- }
32
- catch (err) {
33
- console.log(chalk.yellow(`Warning: '${p}' directory not found`));
34
- continue;
35
- }
36
- if (!(await fs.stat(ospath.join(basePath, p))).isDirectory()) {
37
- throw new Error(`${p} is not a directory`);
38
- }
39
- result.push(p);
40
- }
41
- return result;
42
- };
28
+ function validateRepoConfig(targetPath, config) {
43
29
  const newConfig = { ...config };
44
30
  for (const [key] of Object.entries(config)) {
45
- newConfig[key] = await checkDirAccess(targetPath, config[key]);
31
+ newConfig[key] = checkDirAccess(targetPath, config[key]);
46
32
  }
47
33
  return newConfig;
48
34
  }
49
- async function getRepoConfig(targetPath) {
50
- let cfg = await getDefaultConfig(targetPath);
35
+ function checkDirAccess(basePath, paths) {
36
+ const result = [];
37
+ if (!Array.isArray(paths)) {
38
+ throw new Error('Not an array');
39
+ }
40
+ for (const p of paths) {
41
+ if (!pathExists(ospath.join(basePath, p))) {
42
+ console.log(chalk.yellow(`Warning: '${p}' directory not found`));
43
+ continue;
44
+ }
45
+ if (!isDirectory(ospath.join(basePath, p))) {
46
+ throw new Error(`${p} is not a directory`);
47
+ }
48
+ result.push(p);
49
+ }
50
+ return result;
51
+ }
52
+ function pathExists(p) {
51
53
  try {
52
- cfg = JSON.parse((await fs.readFile(ospath.join(targetPath, exports.REPO_CONFIG_FILE))).toString());
54
+ fs.accessSync(p);
55
+ return true;
56
+ }
57
+ catch {
58
+ return false;
53
59
  }
54
- catch (err) { }
55
- return await validateRepoConfig(targetPath, cfg);
56
60
  }
57
- exports.getRepoConfig = getRepoConfig;
61
+ function isDirectory(path) {
62
+ return fs.statSync(path).isDirectory();
63
+ }
@@ -15,7 +15,7 @@ async function sync(path) {
15
15
  }
16
16
  exports.sync = sync;
17
17
  async function syncUserSettings(userServiceSettings) {
18
- if (!userServiceSettings) {
18
+ if (!userServiceSettings || Object.keys(userServiceSettings).length === 0) {
19
19
  return;
20
20
  }
21
21
  console.group((0, chalk_1.blue)('Syncing user service settings:'));
@@ -13,7 +13,7 @@ const taskService = require("../services/tasks");
13
13
  const templateService = require("../services/templates");
14
14
  async function sync({ path, schemas, tasks, templates, dispatchers, cleanDispatchers, localizations, settings, ignoreSchemaVerificationErrors, }) {
15
15
  const targetPath = path || '.';
16
- const cfg = await (0, repoConfig_1.getRepoConfig)(targetPath);
16
+ const cfg = (0, repoConfig_1.getRepoConfig)(targetPath);
17
17
  const syncAll = !(schemas || tasks || templates || dispatchers || localizations || settings);
18
18
  if ((syncAll || schemas) && cfg.schemas) {
19
19
  console.log(chalk.green('\n ⚙️ Syncing schemas ...'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extrahorizon/exh-cli",
3
- "version": "1.13.0-dev-171-045479f",
3
+ "version": "1.13.0-dev-173-4c24837",
4
4
  "main": "build/index.js",
5
5
  "exports": "./build/index.js",
6
6
  "license": "MIT",