@tenonhq/sincronia-core 0.0.15 → 0.0.16

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.
@@ -56,13 +56,25 @@ var __importStar = (this && this.__importStar) || (function () {
56
56
  Logger_1.logger.info(`Processing scope: ${scopeName}`);
57
57
  // Get the client
58
58
  const client = (0, snClient_1.defaultClient)();
59
- // Set the scope
60
- Logger_1.logger.info(`Setting scope to ${scopeName}`);
61
- await AppUtils.swapScope(scopeName);
62
- // Sync and get manifest for this scope
63
- await AppUtils.syncManifest();
64
- // Get the updated manifest from ConfigManager
65
- const manifest = ConfigManager.getManifest();
59
+ // Get the config
60
+ const config = ConfigManager.getConfig();
61
+ // Get apps list for verification
62
+ Logger_1.logger.info(`Getting apps list from ServiceNow...`);
63
+ const apps = await (0, snClient_1.unwrapSNResponse)(client.getAppList());
64
+ // Check if the scope exists in the apps list
65
+ const scopeApp = apps.find((app) => app.scope === scopeName);
66
+ if (!scopeApp) {
67
+ Logger_1.logger.warn(`⚠️ Scope ${scopeName} not found in ServiceNow apps list`);
68
+ }
69
+ else {
70
+ Logger_1.logger.info(`Found app: ${scopeApp.displayName} (${scopeName})`);
71
+ }
72
+ // Get manifest with files for this scope
73
+ Logger_1.logger.info(`Downloading manifest for scope: ${scopeName}`);
74
+ const manifest = await (0, snClient_1.unwrapSNResponse)(client.getManifest(scopeName, config, true));
75
+ // Process the manifest to create local files
76
+ Logger_1.logger.info(`Processing manifest and creating local files for ${scopeName}...`);
77
+ await AppUtils.processManifest(manifest);
66
78
  // Create the scope-specific manifest structure
67
79
  const scopeManifest = {
68
80
  tables: (manifest && manifest.tables) || {},
@@ -88,7 +100,13 @@ var __importStar = (this && this.__importStar) || (function () {
88
100
  async function initScopesCommand(args) {
89
101
  (0, commands_1.setLogLevel)(args);
90
102
  try {
103
+ // First check if we have environment variables set
104
+ if (!process.env.SN_USER || !process.env.SN_PASSWORD || !process.env.SN_INSTANCE) {
105
+ Logger_1.logger.error("Missing ServiceNow credentials. Please ensure SN_USER, SN_PASSWORD, and SN_INSTANCE are set in your .env file");
106
+ throw new Error("ServiceNow credentials not configured");
107
+ }
91
108
  // Load config
109
+ await ConfigManager.loadConfigs();
92
110
  const config = ConfigManager.getConfig();
93
111
  if (!config.scopes) {
94
112
  Logger_1.logger.error("No scopes defined in sinc.config.js");
@@ -96,8 +114,32 @@ var __importStar = (this && this.__importStar) || (function () {
96
114
  }
97
115
  const scopes = Object.keys(config.scopes);
98
116
  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
+ }
99
140
  // Process all scopes in parallel
100
141
  Logger_1.logger.info("Starting parallel processing of all scopes...");
142
+ Logger_1.logger.info("This will download manifests and files for each scope from ServiceNow...\n");
101
143
  const scopePromises = scopes.map(scopeName => processScope(scopeName, config.scopes[scopeName]));
102
144
  const results = await Promise.allSettled(scopePromises);
103
145
  // Collect successful manifests
@@ -117,7 +159,7 @@ var __importStar = (this && this.__importStar) || (function () {
117
159
  Logger_1.logger.error(`Failed to process ${scopeName}: ${(error === null || error === void 0 ? void 0 : error.message) || "Unknown error"}`);
118
160
  }
119
161
  });
120
- // Write the combined manifest file
162
+ // Write the combined manifest file with the new structure
121
163
  const manifestPath = path.join(ConfigManager.getRootDir(), "sinc.manifest.json");
122
164
  await fsp.writeFile(manifestPath, JSON.stringify(manifests, null, 2));
123
165
  Logger_1.logger.info("=".repeat(50));
@@ -127,16 +169,8 @@ var __importStar = (this && this.__importStar) || (function () {
127
169
  Logger_1.logger.warn(`Failed to process: ${failCount} scopes`);
128
170
  }
129
171
  Logger_1.logger.info(`Manifest written to: ${manifestPath}`);
130
- // Create source directories for each scope if they don't exist
131
- for (const [scopeName, scopeConfig] of Object.entries(config.scopes)) {
132
- if (typeof scopeConfig === "object" && scopeConfig.sourceDirectory) {
133
- const srcDir = path.resolve(ConfigManager.getRootDir(), scopeConfig.sourceDirectory);
134
- if (!fs.existsSync(srcDir)) {
135
- await fsp.mkdir(srcDir, { recursive: true });
136
- Logger_1.logger.info(`Created source directory for ${scopeName}: ${srcDir}`);
137
- }
138
- }
139
- }
172
+ Logger_1.logger.info("\nAll scope files have been downloaded to their respective source directories.");
173
+ Logger_1.logger.success("\nYou can now use 'npx sinc dev' to start development mode!");
140
174
  }
141
175
  catch (e) {
142
176
  Logger_1.logger.error("Error initializing scopes: " + e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenonhq/sincronia-core",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "Next-gen file syncer",
5
5
  "license": "GPL-3.0",
6
6
  "main": "./dist/index.js",