@tenonhq/sincronia-core 0.0.43 → 0.0.44

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/dist/FileUtils.js CHANGED
@@ -45,7 +45,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
45
45
  })(function (require, exports) {
46
46
  "use strict";
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.writeFileForce = exports.writeSNFileForce = exports.writeSNFileIfNotExists = exports.writeBuildFile = exports.summarizeFile = exports.encodedPathsToFilePaths = exports.isValidPath = exports.splitEncodedPaths = exports.getPathsInPath = exports.isDirectory = exports.toAbsolutePath = exports.getFileContextFromPath = exports.getBuildExt = exports.isUnderPath = exports.appendToPath = exports.pathExists = exports.createDirRecursively = exports.writeSNFileCurry = exports.writeScopeManifest = exports.writeManifestFile = exports.SNFileExists = void 0;
48
+ exports.writeFileForce = exports.writeSNFileForce = exports.writeSNFileIfNotExists = exports.writeBuildFile = exports.summarizeFile = exports.encodedPathsToFilePaths = exports.isValidPath = exports.splitEncodedPaths = exports.getPathsInPath = exports.isDirectory = exports.toAbsolutePath = exports.getFileContextFromPath = exports.getBuildExt = exports.isUnderPath = exports.appendToPath = exports.pathExists = exports.createDirRecursively = exports.writeSNFileCurry = exports.writeManifestFile = exports.SNFileExists = void 0;
49
49
  const constants_1 = require("./constants");
50
50
  const fs_1 = __importStar(require("fs"));
51
51
  const path_1 = __importDefault(require("path"));
@@ -61,19 +61,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
61
61
  }
62
62
  };
63
63
  exports.SNFileExists = SNFileExists;
64
- const writeManifestFile = async (man, scope) => {
65
- if (scope) {
66
- // Write scope-specific manifest
67
- return fs_1.promises.writeFile(ConfigManager.getScopeManifestPath(scope), JSON.stringify(man, null, 2));
68
- }
69
- // Write legacy single manifest
64
+ const writeManifestFile = async (man) => {
70
65
  return fs_1.promises.writeFile(ConfigManager.getManifestPath(), JSON.stringify(man, null, 2));
71
66
  };
72
67
  exports.writeManifestFile = writeManifestFile;
73
- const writeScopeManifest = async (scope, man) => {
74
- return fs_1.promises.writeFile(ConfigManager.getScopeManifestPath(scope), JSON.stringify(man, null, 2));
75
- };
76
- exports.writeScopeManifest = writeScopeManifest;
77
68
  const writeSNFileCurry = (checkExists) => async (file, parentPath) => {
78
69
  let { name, type, content = "" } = file;
79
70
  // content can sometimes be null
@@ -142,8 +142,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
142
142
  try {
143
143
  // First, switch to the correct scope
144
144
  await this.switchToScope(scopeWatcher.scope);
145
- // Load the manifest for this specific scope
146
- await this.loadScopeManifest(scopeWatcher.scope, scopeWatcher.sourceDirectory);
147
145
  // Process the files
148
146
  const fileContexts = toProcess
149
147
  .map(FileUtils_1.getFileContextFromPath)
@@ -165,65 +163,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
165
163
  Logger_1.logger.error(`[${scopeWatcher.scope}] Error processing queue: ${error}`);
166
164
  }
167
165
  }
168
- async loadScopeManifest(scopeName, sourceDirectory) {
169
- try {
170
- // The sourceDirectory is like /path/to/ServiceNow/src/x_cadso_core
171
- // We need to go up two levels to get to the ServiceNow directory where manifests are stored
172
- const projectRoot = path.dirname(path.dirname(sourceDirectory)); // Go up from src/scope to project root
173
- const fs = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("fs"))) : new Promise((resolve_1, reject_1) => { require(["fs"], resolve_1, reject_1); }).then(__importStar));
174
- // First try to load scope-specific manifest file
175
- const scopeManifestPath = path.join(projectRoot, `sinc.manifest.${scopeName}.json`);
176
- if (fs.existsSync(scopeManifestPath)) {
177
- const manifestContent = await fs.promises.readFile(scopeManifestPath, "utf-8");
178
- const scopeManifest = JSON.parse(manifestContent);
179
- // Ensure scope field is set
180
- if (!scopeManifest.scope) {
181
- scopeManifest.scope = scopeName;
182
- }
183
- ConfigManager.updateManifest(scopeManifest);
184
- Logger_1.logger.debug(`Loaded scope-specific manifest for: ${scopeName}`);
185
- return;
186
- }
187
- // Fall back to checking legacy single manifest file
188
- const manifestPath = path.join(projectRoot, "sinc.manifest.json");
189
- if (fs.existsSync(manifestPath)) {
190
- const manifestContent = await fs.promises.readFile(manifestPath, "utf-8");
191
- const fullManifest = JSON.parse(manifestContent);
192
- // Check if this is a multi-scope manifest (has scopes as top-level keys)
193
- if (fullManifest[scopeName]) {
194
- // Multi-scope manifest - extract the specific scope's data
195
- const scopeManifest = fullManifest[scopeName];
196
- // Add the scope field for compatibility
197
- scopeManifest.scope = scopeName;
198
- ConfigManager.updateManifest(scopeManifest);
199
- Logger_1.logger.debug(`Loaded manifest for scope: ${scopeName} from legacy multi-scope manifest`);
200
- }
201
- else if (fullManifest.scope === scopeName) {
202
- // Single-scope manifest for the correct scope
203
- ConfigManager.updateManifest(fullManifest);
204
- Logger_1.logger.debug(`Loaded single-scope manifest for scope: ${scopeName}`);
205
- }
206
- else if (fullManifest.tables) {
207
- // Old-style single-scope manifest without scope field - assume it's for this scope
208
- fullManifest.scope = scopeName;
209
- ConfigManager.updateManifest(fullManifest);
210
- Logger_1.logger.debug(`Loaded manifest for scope: ${scopeName} (legacy format)`);
211
- }
212
- else {
213
- Logger_1.logger.warn(`[${scopeName}] Scope not found in manifest`);
214
- }
215
- }
216
- else {
217
- Logger_1.logger.warn(`[${scopeName}] No manifest found at ${scopeManifestPath} or ${manifestPath}`);
218
- }
219
- }
220
- catch (error) {
221
- Logger_1.logger.error(`Failed to load manifest for scope ${scopeName}: ${error}`);
222
- }
223
- }
224
166
  async switchToScope(scopeName) {
225
167
  try {
226
- const { defaultClient, unwrapSNResponse } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./snClient"))) : new Promise((resolve_2, reject_2) => { require(["./snClient"], resolve_2, reject_2); }).then(__importStar));
168
+ const { defaultClient, unwrapSNResponse } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./snClient"))) : new Promise((resolve_1, reject_1) => { require(["./snClient"], resolve_1, reject_1); }).then(__importStar));
227
169
  const client = defaultClient();
228
170
  // Get the scope ID
229
171
  const scopeResponse = await unwrapSNResponse(client.getScopeId(scopeName));
@@ -262,7 +204,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
262
204
  }
263
205
  async checkAllUpdateSets() {
264
206
  try {
265
- const { defaultClient, unwrapSNResponse } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./snClient"))) : new Promise((resolve_3, reject_3) => { require(["./snClient"], resolve_3, reject_3); }).then(__importStar));
207
+ const { defaultClient, unwrapSNResponse } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./snClient"))) : new Promise((resolve_2, reject_2) => { require(["./snClient"], resolve_2, reject_2); }).then(__importStar));
266
208
  const client = defaultClient();
267
209
  const config = ConfigManager.getConfig();
268
210
  if (!config.scopes)
@@ -317,10 +259,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
317
259
  }
318
260
  async getUpdateSetDetails(updateSetId) {
319
261
  try {
320
- const { defaultClient } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./snClient"))) : new Promise((resolve_4, reject_4) => { require(["./snClient"], resolve_4, reject_4); }).then(__importStar));
262
+ const { defaultClient } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./snClient"))) : new Promise((resolve_3, reject_3) => { require(["./snClient"], resolve_3, reject_3); }).then(__importStar));
321
263
  const client = defaultClient();
322
264
  // Create axios client directly to get update set details
323
- const axios = (await (__syncRequire ? Promise.resolve().then(() => __importStar(require("axios"))) : new Promise((resolve_5, reject_5) => { require(["axios"], resolve_5, reject_5); }).then(__importStar))).default;
265
+ const axios = (await (__syncRequire ? Promise.resolve().then(() => __importStar(require("axios"))) : new Promise((resolve_4, reject_4) => { require(["axios"], resolve_4, reject_4); }).then(__importStar))).default;
324
266
  const { SN_USER = "", SN_PASSWORD = "", SN_INSTANCE = "" } = process.env;
325
267
  const axiosClient = axios.create({
326
268
  auth: {
@@ -253,19 +253,16 @@ var __importStar = (this && this.__importStar) || (function () {
253
253
  Logger_1.logger.error(`Failed to process ${scopeName}: ${(error === null || error === void 0 ? void 0 : error.message) || "Unknown error"}`);
254
254
  }
255
255
  });
256
- // Write per-scope manifest files instead of a single combined one
257
- for (const [scopeName, scopeData] of Object.entries(manifests)) {
258
- const scopeManifestPath = ConfigManager.getScopeManifestPath(scopeName);
259
- await fsp.writeFile(scopeManifestPath, JSON.stringify(scopeData, null, 2));
260
- Logger_1.logger.info(`Wrote manifest for ${scopeName} to: ${scopeManifestPath}`);
261
- }
256
+ // Write the combined manifest file with the new structure
257
+ const manifestPath = path.join(ConfigManager.getRootDir(), "sinc.manifest.json");
258
+ await fsp.writeFile(manifestPath, JSON.stringify(manifests, null, 2));
262
259
  Logger_1.logger.info("=".repeat(50));
263
260
  Logger_1.logger.success(`✅ Scope initialization complete!`);
264
261
  Logger_1.logger.info(`Successfully processed: ${successCount} scopes`);
265
262
  if (failCount > 0) {
266
263
  Logger_1.logger.warn(`Failed to process: ${failCount} scopes`);
267
264
  }
268
- Logger_1.logger.info(`Manifests written as per-scope files (sinc.manifest.<scope>.json)`);
265
+ Logger_1.logger.info(`Manifest written to: ${manifestPath}`);
269
266
  Logger_1.logger.info("\nAll scope files have been downloaded to their respective source directories.");
270
267
  Logger_1.logger.success("\nYou can now use 'npx sinc watchAllScopes' to start development mode!");
271
268
  }
package/dist/appUtils.js CHANGED
@@ -57,25 +57,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
57
57
  const genericUtils_1 = require("./genericUtils");
58
58
  const processFilesInManRec = async (recPath, rec, forceWrite) => {
59
59
  const fileWrite = fUtils.writeSNFileCurry(forceWrite);
60
- // Process metadata files separately
61
- const metadataFiles = [];
62
- const regularFiles = [];
60
+ const filePromises = rec.files.map((file) => fileWrite(file, recPath));
61
+ await Promise.all(filePromises);
62
+ // Side effect, remove content from files so it doesn't get written to manifest
63
63
  rec.files.forEach((file) => {
64
- if (file.name === "metaData" && file.type === "json") {
65
- metadataFiles.push(file);
66
- }
67
- else {
68
- regularFiles.push(file);
69
- }
70
- });
71
- // Write regular files
72
- const regularPromises = regularFiles.map((file) => fileWrite(file, recPath));
73
- await Promise.all([...regularPromises]);
74
- // Remove content from ALL files and exclude metadata from manifest
75
- rec.files = regularFiles.map((file) => {
76
- const fileCopy = { ...file };
77
- delete fileCopy.content;
78
- return fileCopy;
64
+ delete file.content;
79
65
  });
80
66
  };
81
67
  const processRecsInManTable = async (tablePath, table, forceWrite) => {
@@ -103,50 +89,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
103
89
  };
104
90
  const processManifest = async (manifest, forceWrite = false) => {
105
91
  await processTablesInManifest(manifest.tables, forceWrite);
106
- // Write to scope-specific manifest if scope is available
107
- if (manifest.scope) {
108
- await fUtils.writeScopeManifest(manifest.scope, manifest);
109
- }
110
- else {
111
- // Fall back to legacy single manifest
112
- await fUtils.writeFileForce(ConfigManager.getManifestPath(), JSON.stringify(manifest, null, 2));
113
- }
92
+ await fUtils.writeFileForce(ConfigManager.getManifestPath(), JSON.stringify(manifest, null, 2));
114
93
  };
115
94
  exports.processManifest = processManifest;
116
- const syncManifest = async (scope) => {
95
+ const syncManifest = async () => {
117
96
  try {
118
97
  const curManifest = await ConfigManager.getManifest();
119
98
  if (!curManifest)
120
99
  throw new Error("No manifest file loaded!");
121
- // If a specific scope is provided, sync only that scope
122
- if (scope) {
123
- Logger_1.logger.info(`Downloading fresh manifest for scope: ${scope}...`);
124
- const client = (0, snClient_1.defaultClient)();
125
- const config = ConfigManager.getConfig();
126
- const newManifest = await (0, snClient_1.unwrapSNResponse)(client.getManifest(scope, config));
127
- Logger_1.logger.info(`Writing manifest file for scope: ${scope}...`);
128
- await fUtils.writeScopeManifest(scope, newManifest);
129
- Logger_1.logger.info("Finding and creating missing files...");
130
- await (0, exports.processMissingFiles)(newManifest);
131
- // Update the in-memory manifest for this scope
132
- if (typeof curManifest === "object" && !curManifest.tables) {
133
- curManifest[scope] = newManifest;
134
- ConfigManager.updateManifest(curManifest);
135
- }
136
- }
137
- else {
138
- // Sync all scopes if manifest has multiple scopes
139
- if (typeof curManifest === "object" && !curManifest.tables) {
140
- // Multiple scopes detected
141
- for (const scopeName of Object.keys(curManifest)) {
142
- await (0, exports.syncManifest)(scopeName);
143
- }
144
- }
145
- else if (curManifest.scope) {
146
- // Single scope manifest
147
- await (0, exports.syncManifest)(curManifest.scope);
148
- }
149
- }
100
+ Logger_1.logger.info("Downloading fresh manifest...");
101
+ const client = (0, snClient_1.defaultClient)();
102
+ const config = ConfigManager.getConfig();
103
+ const newManifest = await (0, snClient_1.unwrapSNResponse)(client.getManifest(curManifest.scope, config));
104
+ Logger_1.logger.info("Writing new manifest file...");
105
+ fUtils.writeManifestFile(newManifest);
106
+ Logger_1.logger.info("Finding and creating missing files...");
107
+ await (0, exports.processMissingFiles)(newManifest);
108
+ ConfigManager.updateManifest(newManifest);
150
109
  }
151
110
  catch (e) {
152
111
  let message;
package/dist/config.js CHANGED
@@ -53,7 +53,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
53
53
  exports.getRootDir = getRootDir;
54
54
  exports.getManifest = getManifest;
55
55
  exports.getManifestPath = getManifestPath;
56
- exports.getScopeManifestPath = getScopeManifestPath;
57
56
  exports.getSourcePath = getSourcePath;
58
57
  exports.getBuildPath = getBuildPath;
59
58
  exports.getEnvPath = getEnvPath;
@@ -61,7 +60,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
61
60
  exports.getDiffFile = getDiffFile;
62
61
  exports.getRefresh = getRefresh;
63
62
  exports.getDefaultConfigFile = getDefaultConfigFile;
64
- exports.loadScopeManifest = loadScopeManifest;
65
63
  exports.updateManifest = updateManifest;
66
64
  const path_1 = __importDefault(require("path"));
67
65
  const fs_1 = require("fs");
@@ -140,19 +138,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
140
138
  if (!setup)
141
139
  throw new Error("Error getting manifest");
142
140
  }
143
- function getManifestPath(scope) {
144
- if (scope) {
145
- const rootDir = getRootDir();
146
- return path_1.default.join(rootDir, `sinc.manifest.${scope}.json`);
147
- }
141
+ function getManifestPath() {
148
142
  if (manifest_path)
149
143
  return manifest_path;
150
144
  throw new Error("Error getting manifest path");
151
145
  }
152
- function getScopeManifestPath(scope) {
153
- const rootDir = getRootDir();
154
- return path_1.default.join(rootDir, `sinc.manifest.${scope}.json`);
155
- }
156
146
  function getSourcePath() {
157
147
  if (source_path)
158
148
  return source_path;
@@ -231,58 +221,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
231
221
  }
232
222
  async function loadManifest() {
233
223
  try {
234
- // Try to load legacy single manifest first
235
224
  let manifestString = await fs_1.promises.readFile(getManifestPath(), "utf-8");
236
225
  manifest = JSON.parse(manifestString);
237
226
  }
238
227
  catch (e) {
239
- // If no single manifest, try to load all scope-specific manifests
240
- manifest = await loadAllScopeManifests();
241
- }
242
- }
243
- async function loadAllScopeManifests() {
244
- try {
245
- const rootDir = getRootDir();
246
- const files = await fs_1.promises.readdir(rootDir);
247
- const manifestFiles = files.filter(f => f.startsWith('sinc.manifest.') && f.endsWith('.json') && f !== 'sinc.manifest.json');
248
- if (manifestFiles.length === 0) {
249
- return undefined;
250
- }
251
- // Combine all scope manifests into a single structure for backward compatibility
252
- const combinedManifest = {};
253
- for (const file of manifestFiles) {
254
- const scope = file.replace('sinc.manifest.', '').replace('.json', '');
255
- const manifestPath = path_1.default.join(rootDir, file);
256
- try {
257
- const content = await fs_1.promises.readFile(manifestPath, "utf-8");
258
- const scopeManifest = JSON.parse(content);
259
- // If the manifest already has the scope at root level, use it directly
260
- if (scopeManifest.scope && scopeManifest.tables) {
261
- combinedManifest[scope] = scopeManifest;
262
- }
263
- else {
264
- // Otherwise wrap it
265
- combinedManifest[scope] = scopeManifest;
266
- }
267
- }
268
- catch (e) {
269
- Logger_1.logger.warn(`Failed to load manifest for scope ${scope}: ${e}`);
270
- }
271
- }
272
- return Object.keys(combinedManifest).length > 0 ? combinedManifest : undefined;
273
- }
274
- catch (e) {
275
- return undefined;
276
- }
277
- }
278
- async function loadScopeManifest(scope) {
279
- try {
280
- const manifestPath = getScopeManifestPath(scope);
281
- const content = await fs_1.promises.readFile(manifestPath, "utf-8");
282
- return JSON.parse(content);
283
- }
284
- catch (e) {
285
- return undefined;
228
+ manifest = undefined;
286
229
  }
287
230
  }
288
231
  function updateManifest(man) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenonhq/sincronia-core",
3
- "version": "0.0.43",
3
+ "version": "0.0.44",
4
4
  "description": "Next-gen file syncer",
5
5
  "license": "GPL-3.0",
6
6
  "main": "./dist/index.js",