@extrahorizon/exh-cli 1.13.0-dev-170-ebde5f5 → 1.13.0-dev-172-a913253

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,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
+ }
@@ -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-170-ebde5f5",
3
+ "version": "1.13.0-dev-172-a913253",
4
4
  "main": "build/index.js",
5
5
  "exports": "./build/index.js",
6
6
  "license": "MIT",