@tenonhq/sincronia-core 0.0.39 → 0.0.40
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 +17 -4
- package/dist/allScopesCommands.js +7 -4
- package/dist/appUtils.js +74 -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
|
|
@@ -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
|
|
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,43 @@ 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 _generatedAt field
|
|
72
|
+
const metadataPromises = metadataFiles.map(async (file) => {
|
|
73
|
+
if (file.content) {
|
|
74
|
+
try {
|
|
75
|
+
const metadata = JSON.parse(file.content);
|
|
76
|
+
// Update _generatedAt with sys_updated_on value if it exists
|
|
77
|
+
if (metadata.sys_updated_on && metadata.sys_updated_on.value) {
|
|
78
|
+
metadata._generatedAt = metadata.sys_updated_on.value;
|
|
79
|
+
}
|
|
80
|
+
// Write the updated metadata
|
|
81
|
+
file.content = JSON.stringify(metadata, null, 2);
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
// If parsing fails, just write as-is
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return fileWrite(file, recPath);
|
|
88
|
+
});
|
|
89
|
+
// Write regular files
|
|
90
|
+
const regularPromises = regularFiles.map((file) => fileWrite(file, recPath));
|
|
91
|
+
await Promise.all([...metadataPromises, ...regularPromises]);
|
|
92
|
+
// Remove content from ALL files and exclude metadata from manifest
|
|
93
|
+
rec.files = regularFiles.map((file) => {
|
|
94
|
+
const fileCopy = { ...file };
|
|
95
|
+
delete fileCopy.content;
|
|
96
|
+
return fileCopy;
|
|
65
97
|
});
|
|
66
98
|
};
|
|
67
99
|
const processRecsInManTable = async (tablePath, table, forceWrite) => {
|
|
@@ -89,23 +121,50 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
89
121
|
};
|
|
90
122
|
const processManifest = async (manifest, forceWrite = false) => {
|
|
91
123
|
await processTablesInManifest(manifest.tables, forceWrite);
|
|
92
|
-
|
|
124
|
+
// Write to scope-specific manifest if scope is available
|
|
125
|
+
if (manifest.scope) {
|
|
126
|
+
await fUtils.writeScopeManifest(manifest.scope, manifest);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// Fall back to legacy single manifest
|
|
130
|
+
await fUtils.writeFileForce(ConfigManager.getManifestPath(), JSON.stringify(manifest, null, 2));
|
|
131
|
+
}
|
|
93
132
|
};
|
|
94
133
|
exports.processManifest = processManifest;
|
|
95
|
-
const syncManifest = async () => {
|
|
134
|
+
const syncManifest = async (scope) => {
|
|
96
135
|
try {
|
|
97
136
|
const curManifest = await ConfigManager.getManifest();
|
|
98
137
|
if (!curManifest)
|
|
99
138
|
throw new Error("No manifest file loaded!");
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
139
|
+
// If a specific scope is provided, sync only that scope
|
|
140
|
+
if (scope) {
|
|
141
|
+
Logger_1.logger.info(`Downloading fresh manifest for scope: ${scope}...`);
|
|
142
|
+
const client = (0, snClient_1.defaultClient)();
|
|
143
|
+
const config = ConfigManager.getConfig();
|
|
144
|
+
const newManifest = await (0, snClient_1.unwrapSNResponse)(client.getManifest(scope, config));
|
|
145
|
+
Logger_1.logger.info(`Writing manifest file for scope: ${scope}...`);
|
|
146
|
+
await fUtils.writeScopeManifest(scope, newManifest);
|
|
147
|
+
Logger_1.logger.info("Finding and creating missing files...");
|
|
148
|
+
await (0, exports.processMissingFiles)(newManifest);
|
|
149
|
+
// Update the in-memory manifest for this scope
|
|
150
|
+
if (typeof curManifest === 'object' && !curManifest.tables) {
|
|
151
|
+
curManifest[scope] = newManifest;
|
|
152
|
+
ConfigManager.updateManifest(curManifest);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
// Sync all scopes if manifest has multiple scopes
|
|
157
|
+
if (typeof curManifest === 'object' && !curManifest.tables) {
|
|
158
|
+
// Multiple scopes detected
|
|
159
|
+
for (const scopeName of Object.keys(curManifest)) {
|
|
160
|
+
await (0, exports.syncManifest)(scopeName);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else if (curManifest.scope) {
|
|
164
|
+
// Single scope manifest
|
|
165
|
+
await (0, exports.syncManifest)(curManifest.scope);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
109
168
|
}
|
|
110
169
|
catch (e) {
|
|
111
170
|
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) {
|