"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }

var _chunkSPS3KTJZcjs = require('./chunk-SPS3KTJZ.cjs');


var _chunkD6HDT2GUcjs = require('./chunk-D6HDT2GU.cjs');


var _chunkD3LYXCPGcjs = require('./chunk-D3LYXCPG.cjs');



var _chunkFYSASWVKcjs = require('./chunk-FYSASWVK.cjs');



var _chunkN3H4E6EHcjs = require('./chunk-N3H4E6EH.cjs');

// src/generate.ts
_chunkN3H4E6EHcjs.init_cjs_shims.call(void 0, );
var _glob = require('glob');
var _loader = require('untyped/loader');
var getGenerateAction = (config) => async (options) => {
  _chunkFYSASWVKcjs.writeTrace.call(void 0, 
    `Running Storm Untyped with options: ${JSON.stringify(options)}`,
    config
  );
  const files = await _glob.glob.call(void 0, options.entry || "**/{untyped.ts,*.untyped.ts}", {
    ignore: [
      "**/{*.stories.tsx,*.stories.ts,*.spec.tsx,*.spec.ts}",
      "**/dist/**",
      "**/tmp/**",
      "**/node_modules/**",
      "**/.git/**",
      "**/.cache/**",
      "**/.nx/**"
    ],
    withFileTypes: true,
    cwd: config.workspaceRoot
  });
  await Promise.all(
    files.map(async (file) => {
      _chunkFYSASWVKcjs.writeTrace.call(void 0, 
        `Generating files for schema file: ${_chunkN3H4E6EHcjs.joinPaths.call(void 0, file.parentPath, file.name)}`,
        config
      );
      let schema;
      try {
        schema = await _loader.loadSchema.call(void 0, _chunkN3H4E6EHcjs.joinPaths.call(void 0, file.parentPath, file.name), {
          jiti: {
            fsCache: config.skipCache ? false : _chunkN3H4E6EHcjs.joinPaths.call(void 0, 
              config.directories.cache || _chunkN3H4E6EHcjs.joinPaths.call(void 0, 
                config.workspaceRoot,
                "node_modules/.cache/storm"
              ),
              "jiti"
            ),
            interopDefault: true
          }
        });
      } catch (error) {
        _chunkFYSASWVKcjs.writeError.call(void 0, 
          `Error while parsing schema file: ${_chunkN3H4E6EHcjs.joinPaths.call(void 0, file.parentPath, file.name)}

Error:
${_optionalChain([error, 'optionalAccess', _ => _.message]) ? error.message : JSON.stringify(error)}${_optionalChain([error, 'optionalAccess', _2 => _2.stack]) ? `
Stack Trace: ${error.stack}` : ""}

Parsed schema:
${JSON.stringify(schema)}
`,
          config
        );
        throw error;
      }
      const promises = [];
      promises.push(_chunkSPS3KTJZcjs.generateDeclarationFile.call(void 0, schema, file, config));
      promises.push(_chunkD3LYXCPGcjs.generateMarkdownFile.call(void 0, schema, file, config));
      promises.push(_chunkD6HDT2GUcjs.generateJsonSchemaFile.call(void 0, schema, file, config));
      return Promise.all(promises);
    })
  );
};



exports.getGenerateAction = getGenerateAction;
