@tenonhq/sincronia-core 0.0.44 → 0.0.45
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 +11 -2
- package/dist/MultiScopeWatcher.js +62 -4
- package/dist/allScopesCommands.js +7 -4
- package/dist/appUtils.js +60 -15
- package/dist/config.js +59 -2
- package/package.json +1 -1
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
|
|
@@ -142,6 +142,8 @@ 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);
|
|
145
147
|
// Process the files
|
|
146
148
|
const fileContexts = toProcess
|
|
147
149
|
.map(FileUtils_1.getFileContextFromPath)
|
|
@@ -163,9 +165,65 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
163
165
|
Logger_1.logger.error(`[${scopeWatcher.scope}] Error processing queue: ${error}`);
|
|
164
166
|
}
|
|
165
167
|
}
|
|
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
|
+
}
|
|
166
224
|
async switchToScope(scopeName) {
|
|
167
225
|
try {
|
|
168
|
-
const { defaultClient, unwrapSNResponse } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./snClient"))) : new Promise((
|
|
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));
|
|
169
227
|
const client = defaultClient();
|
|
170
228
|
// Get the scope ID
|
|
171
229
|
const scopeResponse = await unwrapSNResponse(client.getScopeId(scopeName));
|
|
@@ -204,7 +262,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
204
262
|
}
|
|
205
263
|
async checkAllUpdateSets() {
|
|
206
264
|
try {
|
|
207
|
-
const { defaultClient, unwrapSNResponse } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./snClient"))) : new Promise((
|
|
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));
|
|
208
266
|
const client = defaultClient();
|
|
209
267
|
const config = ConfigManager.getConfig();
|
|
210
268
|
if (!config.scopes)
|
|
@@ -259,10 +317,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
259
317
|
}
|
|
260
318
|
async getUpdateSetDetails(updateSetId) {
|
|
261
319
|
try {
|
|
262
|
-
const { defaultClient } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./snClient"))) : new Promise((
|
|
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));
|
|
263
321
|
const client = defaultClient();
|
|
264
322
|
// Create axios client directly to get update set details
|
|
265
|
-
const axios = (await (__syncRequire ? Promise.resolve().then(() => __importStar(require("axios"))) : new Promise((
|
|
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;
|
|
266
324
|
const { SN_USER = "", SN_PASSWORD = "", SN_INSTANCE = "" } = process.env;
|
|
267
325
|
const axiosClient = axios.create({
|
|
268
326
|
auth: {
|
|
@@ -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
|
|
257
|
-
const
|
|
258
|
-
|
|
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(`
|
|
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,29 @@ 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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
// Process metadata files separately
|
|
61
|
+
const metadataFiles = [];
|
|
62
|
+
const regularFiles = [];
|
|
63
63
|
rec.files.forEach((file) => {
|
|
64
|
-
|
|
64
|
+
if (file.name === "metaData" && file.type === "json") {
|
|
65
|
+
metadataFiles.push(file);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
regularFiles.push(file);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
// Write metadata files with updated _lastUpdatedOn field
|
|
72
|
+
const metadataPromises = metadataFiles.map(async (file) => {
|
|
73
|
+
return fileWrite(file, recPath);
|
|
74
|
+
});
|
|
75
|
+
// Write regular files
|
|
76
|
+
const regularPromises = regularFiles.map((file) => fileWrite(file, recPath));
|
|
77
|
+
await Promise.all([...metadataPromises, ...regularPromises]);
|
|
78
|
+
// Remove content from ALL files and exclude metadata from manifest
|
|
79
|
+
rec.files = regularFiles.map((file) => {
|
|
80
|
+
const fileCopy = { ...file };
|
|
81
|
+
delete fileCopy.content;
|
|
82
|
+
return fileCopy;
|
|
65
83
|
});
|
|
66
84
|
};
|
|
67
85
|
const processRecsInManTable = async (tablePath, table, forceWrite) => {
|
|
@@ -89,23 +107,50 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
89
107
|
};
|
|
90
108
|
const processManifest = async (manifest, forceWrite = false) => {
|
|
91
109
|
await processTablesInManifest(manifest.tables, forceWrite);
|
|
92
|
-
|
|
110
|
+
// Write to scope-specific manifest if scope is available
|
|
111
|
+
if (manifest.scope) {
|
|
112
|
+
await fUtils.writeScopeManifest(manifest.scope, manifest);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// Fall back to legacy single manifest
|
|
116
|
+
await fUtils.writeFileForce(ConfigManager.getManifestPath(), JSON.stringify(manifest, null, 2));
|
|
117
|
+
}
|
|
93
118
|
};
|
|
94
119
|
exports.processManifest = processManifest;
|
|
95
|
-
const syncManifest = async () => {
|
|
120
|
+
const syncManifest = async (scope) => {
|
|
96
121
|
try {
|
|
97
122
|
const curManifest = await ConfigManager.getManifest();
|
|
98
123
|
if (!curManifest)
|
|
99
124
|
throw new Error("No manifest file loaded!");
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
125
|
+
// If a specific scope is provided, sync only that scope
|
|
126
|
+
if (scope) {
|
|
127
|
+
Logger_1.logger.info(`Downloading fresh manifest for scope: ${scope}...`);
|
|
128
|
+
const client = (0, snClient_1.defaultClient)();
|
|
129
|
+
const config = ConfigManager.getConfig();
|
|
130
|
+
const newManifest = await (0, snClient_1.unwrapSNResponse)(client.getManifest(scope, config));
|
|
131
|
+
Logger_1.logger.info(`Writing manifest file for scope: ${scope}...`);
|
|
132
|
+
await fUtils.writeScopeManifest(scope, newManifest);
|
|
133
|
+
Logger_1.logger.info("Finding and creating missing files...");
|
|
134
|
+
await (0, exports.processMissingFiles)(newManifest);
|
|
135
|
+
// Update the in-memory manifest for this scope
|
|
136
|
+
if (typeof curManifest === "object" && !curManifest.tables) {
|
|
137
|
+
curManifest[scope] = newManifest;
|
|
138
|
+
ConfigManager.updateManifest(curManifest);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
// Sync all scopes if manifest has multiple scopes
|
|
143
|
+
if (typeof curManifest === "object" && !curManifest.tables) {
|
|
144
|
+
// Multiple scopes detected
|
|
145
|
+
for (const scopeName of Object.keys(curManifest)) {
|
|
146
|
+
await (0, exports.syncManifest)(scopeName);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else if (curManifest.scope) {
|
|
150
|
+
// Single scope manifest
|
|
151
|
+
await (0, exports.syncManifest)(curManifest.scope);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
109
154
|
}
|
|
110
155
|
catch (e) {
|
|
111
156
|
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
|
|
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) {
|