jsonata-w 1.0.1 → 1.0.2

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.
Files changed (2) hide show
  1. package/dist/cli.js +18 -17
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -104,7 +104,8 @@ function pickSubset(data, template) {
104
104
  })
105
105
  .command('transform <file>', 'Transform JSON using a single JSONata file with embedded @config', (yargs) => {
106
106
  return yargs
107
- .positional('file', { describe: 'JSONata file with embedded @config', type: 'string', demandOption: true });
107
+ .positional('file', { describe: 'JSONata file with embedded @config', type: 'string', demandOption: true })
108
+ .option('dry-run', { type: 'boolean', default: false, describe: 'Execute and validate without writing output to disk' });
108
109
  }, async (argv) => {
109
110
  try {
110
111
  const filePath = path_1.default.resolve(argv.file);
@@ -117,12 +118,14 @@ function pickSubset(data, template) {
117
118
  const resolvePath = (p) => path_1.default.resolve(fileDir, p);
118
119
  const inputPath = resolvePath(config.input);
119
120
  const outputPath = resolvePath(config.output);
120
- console.log(`Loading input from ${inputPath}...`);
121
+ if (!argv['dry-run'])
122
+ console.log(`Loading input from ${inputPath}...`);
121
123
  const json = loader.load(inputPath);
122
- console.log(`Executing transformation...`);
123
- // Use evaluate since we already have the content
124
+ if (!argv['dry-run'])
125
+ console.log(`Executing transformation...`);
124
126
  const result = await transformer.evaluate(json, fileContent);
125
- console.log(`Unflattening result...`);
127
+ if (!argv['dry-run'])
128
+ console.log(`Unflattening result...`);
126
129
  const finalResult = unflatten(result);
127
130
  if (config.schema) {
128
131
  const schemaPath = resolvePath(config.schema);
@@ -179,25 +182,17 @@ function pickSubset(data, template) {
179
182
  console.log('✅ Example validation passed.');
180
183
  }
181
184
  }
182
- const dir = path_1.default.dirname(outputPath);
183
- if (!fs_1.default.existsSync(dir))
184
- fs_1.default.mkdirSync(dir, { recursive: true });
185
185
  // Determine output format based on file extension
186
186
  const ext = path_1.default.extname(outputPath).toLowerCase();
187
187
  let outputContent;
188
188
  if (ext === '.yaml' || ext === '.yml') {
189
189
  outputContent = js_yaml_1.default.dump(finalResult, { indent: 2, lineWidth: -1 });
190
- console.log(`Writing YAML output to ${outputPath}...`);
191
190
  }
192
191
  else if (ext === '.json') {
193
192
  outputContent = JSON.stringify(finalResult, null, 2);
194
- console.log(`Writing JSON output to ${outputPath}...`);
195
193
  }
196
194
  else {
197
195
  // For other extensions (e.g., .css, .txt, .js), output as string
198
- // If the result is already a string, use it directly
199
- // If it's an array of strings, join them
200
- // Otherwise, convert to string representation
201
196
  if (typeof finalResult === 'string') {
202
197
  outputContent = finalResult;
203
198
  }
@@ -208,13 +203,19 @@ function pickSubset(data, template) {
208
203
  outputContent = String(finalResult);
209
204
  }
210
205
  else {
211
- // For complex objects, still use JSON
212
206
  outputContent = JSON.stringify(finalResult, null, 2);
213
207
  }
214
- console.log(`Writing string output to ${outputPath}...`);
215
208
  }
216
- fs_1.default.writeFileSync(outputPath, outputContent);
217
- console.log(`Transformed ${config.input} -> ${config.output}`);
209
+ if (argv['dry-run']) {
210
+ process.stdout.write(outputContent);
211
+ }
212
+ else {
213
+ const dir = path_1.default.dirname(outputPath);
214
+ if (!fs_1.default.existsSync(dir))
215
+ fs_1.default.mkdirSync(dir, { recursive: true });
216
+ fs_1.default.writeFileSync(outputPath, outputContent);
217
+ console.log(`Transformed ${config.input} -> ${config.output}`);
218
+ }
218
219
  }
219
220
  catch (e) {
220
221
  console.error(e.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsonata-w",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Tool to assist AI in transforming JSON files",
5
5
  "main": "dist/index.js",
6
6
  "bin": {