@tenonhq/sincronia-core 0.0.39 → 0.0.41

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.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.writeScopeManifest = 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,10 +61,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
61
61
  }
62
62
  };
63
63
  exports.SNFileExists = SNFileExists;
64
- const writeManifestFile = async (man) => {
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
65
70
  return fs_1.promises.writeFile(ConfigManager.getManifestPath(), JSON.stringify(man, null, 2));
66
71
  };
67
72
  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;
68
77
  const writeSNFileCurry = (checkExists) => async (file, parentPath) => {
69
78
  let { name, type, content = "" } = file;
70
79
  // content can sometimes be null
@@ -170,9 +170,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
170
170
  // The sourceDirectory is like /path/to/ServiceNow/src/x_cadso_core
171
171
  // We need to go up two levels to get to the ServiceNow directory where manifests are stored
172
172
  const projectRoot = path.dirname(path.dirname(sourceDirectory)); // Go up from src/scope to project root
173
- // Try to load the manifest (could be single-scope or multi-scope)
174
- const manifestPath = path.join(projectRoot, "sinc.manifest.json");
175
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");
176
189
  if (fs.existsSync(manifestPath)) {
177
190
  const manifestContent = await fs.promises.readFile(manifestPath, "utf-8");
178
191
  const fullManifest = JSON.parse(manifestContent);
@@ -183,7 +196,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
183
196
  // Add the scope field for compatibility
184
197
  scopeManifest.scope = scopeName;
185
198
  ConfigManager.updateManifest(scopeManifest);
186
- Logger_1.logger.debug(`Loaded manifest for scope: ${scopeName} from multi-scope manifest`);
199
+ Logger_1.logger.debug(`Loaded manifest for scope: ${scopeName} from legacy multi-scope manifest`);
187
200
  }
188
201
  else if (fullManifest.scope === scopeName) {
189
202
  // Single-scope manifest for the correct scope
@@ -201,7 +214,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
201
214
  }
202
215
  }
203
216
  else {
204
- Logger_1.logger.warn(`[${scopeName}] No manifest found at ${manifestPath}`);
217
+ Logger_1.logger.warn(`[${scopeName}] No manifest found at ${scopeManifestPath} or ${manifestPath}`);
205
218
  }
206
219
  }
207
220
  catch (error) {
@@ -253,16 +253,19 @@ 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 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));
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
+ }
259
262
  Logger_1.logger.info("=".repeat(50));
260
263
  Logger_1.logger.success(`✅ Scope initialization complete!`);
261
264
  Logger_1.logger.info(`Successfully processed: ${successCount} scopes`);
262
265
  if (failCount > 0) {
263
266
  Logger_1.logger.warn(`Failed to process: ${failCount} scopes`);
264
267
  }
265
- Logger_1.logger.info(`Manifest written to: ${manifestPath}`);
268
+ Logger_1.logger.info(`Manifests written as per-scope files (sinc.manifest.<scope>.json)`);
266
269
  Logger_1.logger.info("\nAll scope files have been downloaded to their respective source directories.");
267
270
  Logger_1.logger.success("\nYou can now use 'npx sinc watchAllScopes' to start development mode!");
268
271
  }
package/dist/appUtils.js CHANGED
@@ -57,11 +57,25 @@ 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
- 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
60
+ // Process metadata files separately
61
+ const metadataFiles = [];
62
+ const regularFiles = [];
63
63
  rec.files.forEach((file) => {
64
- delete file.content;
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;
65
79
  });
66
80
  };
67
81
  const processRecsInManTable = async (tablePath, table, forceWrite) => {
@@ -89,23 +103,50 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
89
103
  };
90
104
  const processManifest = async (manifest, forceWrite = false) => {
91
105
  await processTablesInManifest(manifest.tables, forceWrite);
92
- await fUtils.writeFileForce(ConfigManager.getManifestPath(), JSON.stringify(manifest, null, 2));
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
+ }
93
114
  };
94
115
  exports.processManifest = processManifest;
95
- const syncManifest = async () => {
116
+ const syncManifest = async (scope) => {
96
117
  try {
97
118
  const curManifest = await ConfigManager.getManifest();
98
119
  if (!curManifest)
99
120
  throw new Error("No manifest file loaded!");
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);
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
+ }
109
150
  }
110
151
  catch (e) {
111
152
  let message;
package/dist/config.js CHANGED
@@ -53,6 +53,7 @@ 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;
56
57
  exports.getSourcePath = getSourcePath;
57
58
  exports.getBuildPath = getBuildPath;
58
59
  exports.getEnvPath = getEnvPath;
@@ -60,6 +61,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
60
61
  exports.getDiffFile = getDiffFile;
61
62
  exports.getRefresh = getRefresh;
62
63
  exports.getDefaultConfigFile = getDefaultConfigFile;
64
+ exports.loadScopeManifest = loadScopeManifest;
63
65
  exports.updateManifest = updateManifest;
64
66
  const path_1 = __importDefault(require("path"));
65
67
  const fs_1 = require("fs");
@@ -138,11 +140,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
138
140
  if (!setup)
139
141
  throw new Error("Error getting manifest");
140
142
  }
141
- function getManifestPath() {
143
+ function getManifestPath(scope) {
144
+ if (scope) {
145
+ const rootDir = getRootDir();
146
+ return path_1.default.join(rootDir, `sinc.manifest.${scope}.json`);
147
+ }
142
148
  if (manifest_path)
143
149
  return manifest_path;
144
150
  throw new Error("Error getting manifest path");
145
151
  }
152
+ function getScopeManifestPath(scope) {
153
+ const rootDir = getRootDir();
154
+ return path_1.default.join(rootDir, `sinc.manifest.${scope}.json`);
155
+ }
146
156
  function getSourcePath() {
147
157
  if (source_path)
148
158
  return source_path;
@@ -221,11 +231,58 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
221
231
  }
222
232
  async function loadManifest() {
223
233
  try {
234
+ // Try to load legacy single manifest first
224
235
  let manifestString = await fs_1.promises.readFile(getManifestPath(), "utf-8");
225
236
  manifest = JSON.parse(manifestString);
226
237
  }
227
238
  catch (e) {
228
- manifest = undefined;
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;
229
286
  }
230
287
  }
231
288
  function updateManifest(man) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenonhq/sincronia-core",
3
- "version": "0.0.39",
3
+ "version": "0.0.41",
4
4
  "description": "Next-gen file syncer",
5
5
  "license": "GPL-3.0",
6
6
  "main": "./dist/index.js",