"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 _chunkSWEAUQFPcjs = require('./chunk-SWEAUQFP.cjs');


var _chunkD7AD543Ccjs = require('./chunk-D7AD543C.cjs');


var _chunk4J7EWWDEcjs = require('./chunk-4J7EWWDE.cjs');



var _chunk43FWSHY7cjs = require('./chunk-43FWSHY7.cjs');



var _chunkLHEMJ6IScjs = require('./chunk-LHEMJ6IS.cjs');

// src/generate.ts
_chunkLHEMJ6IScjs.init_cjs_shims.call(void 0, );
var _glob = require('glob');
var _loader = require('untyped/loader');
var getGenerateAction = (config) => async (options) => {
  _chunk43FWSHY7cjs.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) => {
      _chunk43FWSHY7cjs.writeTrace.call(void 0, 
        `Generating files for schema file: ${_chunkLHEMJ6IScjs.joinPaths.call(void 0, file.parentPath, file.name)}`,
        config
      );
      let schema;
      try {
        schema = await _loader.loadSchema.call(void 0, _chunkLHEMJ6IScjs.joinPaths.call(void 0, file.parentPath, file.name), {
          jiti: {
            fsCache: config.skipCache ? false : _chunkLHEMJ6IScjs.joinPaths.call(void 0, 
              config.directories.cache || _chunkLHEMJ6IScjs.joinPaths.call(void 0, 
                config.workspaceRoot,
                "node_modules/.cache/storm"
              ),
              "jiti"
            ),
            interopDefault: true
          }
        });
      } catch (error) {
        _chunk43FWSHY7cjs.writeError.call(void 0, 
          `Error while parsing schema file: ${_chunkLHEMJ6IScjs.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(_chunkSWEAUQFPcjs.generateDeclarationFile.call(void 0, schema, file, config));
      promises.push(_chunk4J7EWWDEcjs.generateMarkdownFile.call(void 0, schema, file, config));
      promises.push(_chunkD7AD543Ccjs.generateJsonSchemaFile.call(void 0, schema, file, config));
      return Promise.all(promises);
    })
  );
};



exports.getGenerateAction = getGenerateAction;
