@tenonhq/sincronia-core 0.0.16 → 0.0.18

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.
@@ -37,7 +37,7 @@ var __importStar = (this && this.__importStar) || (function () {
37
37
  if (v !== undefined) module.exports = v;
38
38
  }
39
39
  else if (typeof define === "function" && define.amd) {
40
- define(["require", "exports", "./Logger", "./config", "./appUtils", "./snClient", "./commands", "path", "fs"], factory);
40
+ define(["require", "exports", "./Logger", "./config", "./FileUtils", "./snClient", "./commands", "path", "fs"], factory);
41
41
  }
42
42
  })(function (require, exports) {
43
43
  "use strict";
@@ -45,12 +45,34 @@ var __importStar = (this && this.__importStar) || (function () {
45
45
  exports.initScopesCommand = initScopesCommand;
46
46
  const Logger_1 = require("./Logger");
47
47
  const ConfigManager = __importStar(require("./config"));
48
- const AppUtils = __importStar(require("./appUtils"));
48
+ const fUtils = __importStar(require("./FileUtils"));
49
49
  const snClient_1 = require("./snClient");
50
50
  const commands_1 = require("./commands");
51
51
  const path = __importStar(require("path"));
52
52
  const fs = __importStar(require("fs"));
53
53
  const fsp = fs.promises;
54
+ // Custom function to process manifest with specific source directory
55
+ async function processManifestForScope(manifest, sourceDirectory, forceWrite = false) {
56
+ // Process each table in the manifest
57
+ const tables = manifest.tables || {};
58
+ const tableNames = Object.keys(tables);
59
+ for (const tableName of tableNames) {
60
+ const tableRecords = tables[tableName];
61
+ const tablePath = path.join(sourceDirectory, tableName);
62
+ // Process each record in the table
63
+ const recordNames = Object.keys(tableRecords.records || {});
64
+ for (const recordName of recordNames) {
65
+ const record = tableRecords.records[recordName];
66
+ // Process each file in the record
67
+ for (const file of record.files || []) {
68
+ const filePath = path.join(tablePath, recordName, `${file.name}.${file.type}`);
69
+ const fileContent = file.content || "";
70
+ // Create the file
71
+ await fUtils.writeFileForce(filePath, fileContent);
72
+ }
73
+ }
74
+ }
75
+ }
54
76
  async function processScope(scopeName, scopeConfig) {
55
77
  try {
56
78
  Logger_1.logger.info(`Processing scope: ${scopeName}`);
@@ -58,6 +80,16 @@ var __importStar = (this && this.__importStar) || (function () {
58
80
  const client = (0, snClient_1.defaultClient)();
59
81
  // Get the config
60
82
  const config = ConfigManager.getConfig();
83
+ // Determine the source directory for this scope
84
+ let sourceDirectory;
85
+ if (typeof scopeConfig === "object" && scopeConfig.sourceDirectory) {
86
+ sourceDirectory = path.resolve(ConfigManager.getRootDir(), scopeConfig.sourceDirectory);
87
+ }
88
+ else {
89
+ // Default to src/{scope} if no sourceDirectory specified
90
+ sourceDirectory = path.resolve(ConfigManager.getRootDir(), "src", scopeName);
91
+ }
92
+ Logger_1.logger.info(`Source directory for ${scopeName}: ${sourceDirectory}`);
61
93
  // Get apps list for verification
62
94
  Logger_1.logger.info(`Getting apps list from ServiceNow...`);
63
95
  const apps = await (0, snClient_1.unwrapSNResponse)(client.getAppList());
@@ -72,15 +104,16 @@ var __importStar = (this && this.__importStar) || (function () {
72
104
  // Get manifest with files for this scope
73
105
  Logger_1.logger.info(`Downloading manifest for scope: ${scopeName}`);
74
106
  const manifest = await (0, snClient_1.unwrapSNResponse)(client.getManifest(scopeName, config, true));
75
- // Process the manifest to create local files
107
+ // Process the manifest to create local files in the correct directory
76
108
  Logger_1.logger.info(`Processing manifest and creating local files for ${scopeName}...`);
77
- await AppUtils.processManifest(manifest);
109
+ await processManifestForScope(manifest, sourceDirectory, true);
78
110
  // Create the scope-specific manifest structure
79
111
  const scopeManifest = {
80
112
  tables: (manifest && manifest.tables) || {},
81
113
  scope: scopeName
82
114
  };
83
115
  Logger_1.logger.success(`✅ Successfully processed scope: ${scopeName}`);
116
+ Logger_1.logger.info(`Files saved to: ${sourceDirectory}`);
84
117
  return {
85
118
  scope: scopeName,
86
119
  success: true,
@@ -114,29 +147,6 @@ var __importStar = (this && this.__importStar) || (function () {
114
147
  }
115
148
  const scopes = Object.keys(config.scopes);
116
149
  Logger_1.logger.info(`Found ${scopes.length} scopes to process: ${scopes.join(", ")}`);
117
- // Create source directories for each scope first
118
- Logger_1.logger.info("Setting up directory structure for scopes...");
119
- for (const [scopeName, scopeConfig] of Object.entries(config.scopes)) {
120
- if (typeof scopeConfig === "object" && scopeConfig.sourceDirectory) {
121
- const srcDir = path.resolve(ConfigManager.getRootDir(), scopeConfig.sourceDirectory);
122
- if (!fs.existsSync(srcDir)) {
123
- await fsp.mkdir(srcDir, { recursive: true });
124
- Logger_1.logger.info(`Created source directory for ${scopeName}: ${srcDir}`);
125
- }
126
- // Temporarily set the source path for this scope
127
- // This ensures processManifest puts files in the right location
128
- process.env[`SCOPE_${scopeName}_SOURCE`] = srcDir;
129
- }
130
- else {
131
- // Use default src/{scope} structure
132
- const srcDir = path.resolve(ConfigManager.getRootDir(), "src", scopeName);
133
- if (!fs.existsSync(srcDir)) {
134
- await fsp.mkdir(srcDir, { recursive: true });
135
- Logger_1.logger.info(`Created default source directory for ${scopeName}: ${srcDir}`);
136
- }
137
- process.env[`SCOPE_${scopeName}_SOURCE`] = srcDir;
138
- }
139
- }
140
150
  // Process all scopes in parallel
141
151
  Logger_1.logger.info("Starting parallel processing of all scopes...");
142
152
  Logger_1.logger.info("This will download manifests and files for each scope from ServiceNow...\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenonhq/sincronia-core",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "Next-gen file syncer",
5
5
  "license": "GPL-3.0",
6
6
  "main": "./dist/index.js",
@@ -8,7 +8,11 @@
8
8
  "private": false,
9
9
  "scripts": {
10
10
  "prepack": "tsc",
11
- "test": "jest --ci --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura --coverageReporters=html"
11
+ "test": "jest --ci --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura --coverageReporters=html",
12
+ "version:bump": "node bump-version.js",
13
+ "version:bump:commit": "./bump-version.sh --commit",
14
+ "version:bump:release": "./bump-version.sh --commit --tag --push",
15
+ "postpublish": "version:bump"
12
16
  },
13
17
  "repository": {
14
18
  "type": "git",