orval 6.22.1 → 6.24.0

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/index.js CHANGED
@@ -32,7 +32,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
32
32
 
33
33
  // ../../node_modules/lodash.omit/index.js
34
34
  var require_lodash = __commonJS({
35
- "../../node_modules/lodash.omit/index.js"(exports, module2) {
35
+ "../../node_modules/lodash.omit/index.js"(exports2, module2) {
36
36
  "use strict";
37
37
  var LARGE_ARRAY_SIZE = 200;
38
38
  var HASH_UNDEFINED = "__lodash_hash_undefined__";
@@ -374,14 +374,14 @@ var require_lodash = __commonJS({
374
374
  return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
375
375
  }
376
376
  function baseIsNative(value) {
377
- if (!isObject6(value) || isMasked(value)) {
377
+ if (!isObject7(value) || isMasked(value)) {
378
378
  return false;
379
379
  }
380
380
  var pattern = isFunction5(value) || isHostObject(value) ? reIsNative : reIsHostCtor;
381
381
  return pattern.test(toSource(value));
382
382
  }
383
383
  function baseKeysIn(object) {
384
- if (!isObject6(object)) {
384
+ if (!isObject7(object)) {
385
385
  return nativeKeysIn(object);
386
386
  }
387
387
  var isProto = isPrototype(object), result = [];
@@ -505,13 +505,13 @@ var require_lodash = __commonJS({
505
505
  return isObjectLike(value) && isArrayLike(value);
506
506
  }
507
507
  function isFunction5(value) {
508
- var tag = isObject6(value) ? objectToString.call(value) : "";
508
+ var tag = isObject7(value) ? objectToString.call(value) : "";
509
509
  return tag == funcTag || tag == genTag;
510
510
  }
511
511
  function isLength(value) {
512
512
  return typeof value == "number" && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
513
513
  }
514
- function isObject6(value) {
514
+ function isObject7(value) {
515
515
  var type2 = typeof value;
516
516
  return !!value && (type2 == "object" || type2 == "function");
517
517
  }
@@ -548,11 +548,9 @@ __export(src_exports, {
548
548
  });
549
549
  module.exports = __toCommonJS(src_exports);
550
550
  var import_core12 = require("@orval/core");
551
- var import_chalk7 = __toESM(require("chalk"));
552
551
 
553
552
  // src/generate.ts
554
553
  var import_core11 = require("@orval/core");
555
- var import_chalk6 = __toESM(require("chalk"));
556
554
 
557
555
  // src/import-specs.ts
558
556
  var import_swagger_parser = __toESM(require("@apidevtools/swagger-parser"));
@@ -3356,7 +3354,8 @@ var generateClientFooter = ({
3356
3354
  if (!footer) {
3357
3355
  return {
3358
3356
  implementation: "",
3359
- implementationMock: `]
3357
+ implementationMock: `
3358
+ ]
3360
3359
  `
3361
3360
  };
3362
3361
  }
@@ -3585,10 +3584,7 @@ var importOpenApi = async ({
3585
3584
  target,
3586
3585
  workspace,
3587
3586
  specs,
3588
- override: output.override,
3589
- tslint: output.tslint,
3590
- tsconfig: output.tsconfig,
3591
- packageJson: output.packageJson
3587
+ output
3592
3588
  }
3593
3589
  });
3594
3590
  return {
@@ -3632,50 +3628,50 @@ var getApiSchemas = ({
3632
3628
  workspace,
3633
3629
  specs
3634
3630
  }) => {
3635
- return Object.entries(specs).reduce((acc, [specKey, spec]) => {
3636
- var _a, _b, _c, _d;
3637
- const context = {
3638
- specKey,
3639
- target,
3640
- workspace,
3641
- specs,
3642
- override: output.override,
3643
- tslint: output.tslint,
3644
- tsconfig: output.tsconfig,
3645
- packageJson: output.packageJson
3646
- };
3647
- const schemaDefinition = (0, import_core3.generateSchemasDefinition)(
3648
- !spec.openapi ? getAllSchemas(spec, specKey) : (_a = spec.components) == null ? void 0 : _a.schemas,
3649
- context,
3650
- output.override.components.schemas.suffix
3651
- );
3652
- const responseDefinition = (0, import_core3.generateComponentDefinition)(
3653
- (_b = spec.components) == null ? void 0 : _b.responses,
3654
- context,
3655
- output.override.components.responses.suffix
3656
- );
3657
- const bodyDefinition = (0, import_core3.generateComponentDefinition)(
3658
- (_c = spec.components) == null ? void 0 : _c.requestBodies,
3659
- context,
3660
- output.override.components.requestBodies.suffix
3661
- );
3662
- const parameters = (0, import_core3.generateParameterDefinition)(
3663
- (_d = spec.components) == null ? void 0 : _d.parameters,
3664
- context,
3665
- output.override.components.parameters.suffix
3666
- );
3667
- const schemas = [
3668
- ...schemaDefinition,
3669
- ...responseDefinition,
3670
- ...bodyDefinition,
3671
- ...parameters
3672
- ];
3673
- if (!schemas.length) {
3631
+ return Object.entries(specs).reduce(
3632
+ (acc, [specKey, spec]) => {
3633
+ var _a, _b, _c, _d;
3634
+ const context = {
3635
+ specKey,
3636
+ target,
3637
+ workspace,
3638
+ specs,
3639
+ output
3640
+ };
3641
+ const schemaDefinition = (0, import_core3.generateSchemasDefinition)(
3642
+ !spec.openapi ? getAllSchemas(spec, specKey) : (_a = spec.components) == null ? void 0 : _a.schemas,
3643
+ context,
3644
+ output.override.components.schemas.suffix
3645
+ );
3646
+ const responseDefinition = (0, import_core3.generateComponentDefinition)(
3647
+ (_b = spec.components) == null ? void 0 : _b.responses,
3648
+ context,
3649
+ output.override.components.responses.suffix
3650
+ );
3651
+ const bodyDefinition = (0, import_core3.generateComponentDefinition)(
3652
+ (_c = spec.components) == null ? void 0 : _c.requestBodies,
3653
+ context,
3654
+ output.override.components.requestBodies.suffix
3655
+ );
3656
+ const parameters = (0, import_core3.generateParameterDefinition)(
3657
+ (_d = spec.components) == null ? void 0 : _d.parameters,
3658
+ context,
3659
+ output.override.components.parameters.suffix
3660
+ );
3661
+ const schemas = [
3662
+ ...schemaDefinition,
3663
+ ...responseDefinition,
3664
+ ...bodyDefinition,
3665
+ ...parameters
3666
+ ];
3667
+ if (!schemas.length) {
3668
+ return acc;
3669
+ }
3670
+ acc[specKey] = schemas;
3674
3671
  return acc;
3675
- }
3676
- acc[specKey] = schemas;
3677
- return acc;
3678
- }, {});
3672
+ },
3673
+ {}
3674
+ );
3679
3675
  };
3680
3676
  var getAllSchemas = (spec, specKey) => {
3681
3677
  var _a;
@@ -3744,7 +3740,7 @@ var resolveSpecs = async (path, { validate, ...options }, isUrl3, isOnlySchema)
3744
3740
  return data;
3745
3741
  }
3746
3742
  return Object.fromEntries(
3747
- Object.entries(data).map(([key, value]) => [import_core4.upath.resolve(key), value])
3743
+ Object.entries(data).sort().map(([key, value]) => [import_core4.upath.resolve(key), value])
3748
3744
  );
3749
3745
  } catch {
3750
3746
  const file = await import_fs_extra.default.readFile(path, "utf8");
@@ -3793,7 +3789,7 @@ var import_chalk2 = __toESM(require("chalk"));
3793
3789
  var package_default = {
3794
3790
  name: "orval",
3795
3791
  description: "A swagger client generator for typescript",
3796
- version: "6.22.1",
3792
+ version: "6.24.0",
3797
3793
  license: "MIT",
3798
3794
  files: [
3799
3795
  "dist"
@@ -3833,8 +3829,8 @@ var package_default = {
3833
3829
  url: "https://github.com/anymaniax/orval"
3834
3830
  },
3835
3831
  scripts: {
3836
- build: "tsup ./src/bin/orval.ts ./src/index.ts --target node12 --clean --dts",
3837
- dev: "tsup ./src/bin/orval.ts ./src/index.ts --target node12 --clean --watch ./src --onSuccess 'yarn generate-api'",
3832
+ build: "tsup ./src/bin/orval.ts ./src/index.ts --target node12 --clean --sourcemap --dts",
3833
+ dev: "tsup ./src/bin/orval.ts ./src/index.ts --target node12 --clean --sourcemap --watch ./src --onSuccess 'yarn generate-api'",
3838
3834
  lint: "eslint src/**/*.ts",
3839
3835
  "generate-api": "node ./dist/bin/orval.js --config ../../samples/react-query/basic/orval.config.ts",
3840
3836
  test: "tsc --noEmit && vitest --passWithNoTests"
@@ -3846,13 +3842,13 @@ var package_default = {
3846
3842
  },
3847
3843
  dependencies: {
3848
3844
  "@apidevtools/swagger-parser": "^10.1.0",
3849
- "@orval/angular": "6.22.1",
3850
- "@orval/axios": "6.22.1",
3851
- "@orval/core": "6.22.1",
3852
- "@orval/mock": "6.22.1",
3853
- "@orval/query": "6.22.1",
3854
- "@orval/swr": "6.22.1",
3855
- "@orval/zod": "6.22.1",
3845
+ "@orval/angular": "6.24.0",
3846
+ "@orval/axios": "6.24.0",
3847
+ "@orval/core": "6.24.0",
3848
+ "@orval/mock": "6.24.0",
3849
+ "@orval/query": "6.24.0",
3850
+ "@orval/swr": "6.24.0",
3851
+ "@orval/zod": "6.24.0",
3856
3852
  ajv: "^8.12.0",
3857
3853
  cac: "^6.7.14",
3858
3854
  chalk: "^4.1.2",
@@ -3862,8 +3858,7 @@ var package_default = {
3862
3858
  "find-up": "5.0.0",
3863
3859
  "fs-extra": "^11.2.0",
3864
3860
  "lodash.uniq": "^4.5.0",
3865
- "openapi-types": "^12.1.3",
3866
- "openapi3-ts": "^3.2.0",
3861
+ "openapi3-ts": "4.2.1",
3867
3862
  "string-argv": "^0.3.2",
3868
3863
  tsconfck: "^2.0.1"
3869
3864
  }
@@ -4081,7 +4076,7 @@ function defineConfig(options) {
4081
4076
  return options;
4082
4077
  }
4083
4078
  var normalizeOptions = async (optionsExport, workspace = process.cwd(), globalOptions = {}) => {
4084
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma;
4079
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra;
4085
4080
  const options = await ((0, import_core7.isFunction)(optionsExport) ? optionsExport() : optionsExport);
4086
4081
  if (!options.input) {
4087
4082
  (0, import_core7.createLogger)().error(import_chalk2.default.red(`Config require an input`));
@@ -4149,75 +4144,78 @@ var normalizeOptions = async (optionsExport, workspace = process.cwd(), globalOp
4149
4144
  headers: (_n = outputOptions.headers) != null ? _n : false,
4150
4145
  indexFiles: (_o = outputOptions.indexFiles) != null ? _o : true,
4151
4146
  baseUrl: outputOptions.baseUrl,
4147
+ unionAddMissingProperties: (_p = outputOptions.unionAddMissingProperties) != null ? _p : false,
4152
4148
  override: {
4153
4149
  ...outputOptions.override,
4154
4150
  mock: {
4155
- arrayMin: (_r = (_q = (_p = outputOptions.override) == null ? void 0 : _p.mock) == null ? void 0 : _q.arrayMin) != null ? _r : 1,
4156
- arrayMax: (_u = (_t = (_s = outputOptions.override) == null ? void 0 : _s.mock) == null ? void 0 : _t.arrayMax) != null ? _u : 10,
4157
- ...(_w = (_v = outputOptions.override) == null ? void 0 : _v.mock) != null ? _w : {}
4151
+ arrayMin: (_s = (_r = (_q = outputOptions.override) == null ? void 0 : _q.mock) == null ? void 0 : _r.arrayMin) != null ? _s : 1,
4152
+ arrayMax: (_v = (_u = (_t = outputOptions.override) == null ? void 0 : _t.mock) == null ? void 0 : _u.arrayMax) != null ? _v : 10,
4153
+ ...(_x = (_w = outputOptions.override) == null ? void 0 : _w.mock) != null ? _x : {}
4158
4154
  },
4159
4155
  operations: normalizeOperationsAndTags(
4160
- (_y = (_x = outputOptions.override) == null ? void 0 : _x.operations) != null ? _y : {},
4156
+ (_z = (_y = outputOptions.override) == null ? void 0 : _y.operations) != null ? _z : {},
4161
4157
  outputWorkspace
4162
4158
  ),
4163
4159
  tags: normalizeOperationsAndTags(
4164
- (_A = (_z = outputOptions.override) == null ? void 0 : _z.tags) != null ? _A : {},
4160
+ (_B = (_A = outputOptions.override) == null ? void 0 : _A.tags) != null ? _B : {},
4165
4161
  outputWorkspace
4166
4162
  ),
4167
4163
  mutator: normalizeMutator(
4168
4164
  outputWorkspace,
4169
- (_B = outputOptions.override) == null ? void 0 : _B.mutator
4165
+ (_C = outputOptions.override) == null ? void 0 : _C.mutator
4170
4166
  ),
4171
- formData: (_F = !(0, import_core7.isBoolean)((_C = outputOptions.override) == null ? void 0 : _C.formData) ? normalizeMutator(
4167
+ formData: (_G = !(0, import_core7.isBoolean)((_D = outputOptions.override) == null ? void 0 : _D.formData) ? normalizeMutator(
4172
4168
  outputWorkspace,
4173
- (_D = outputOptions.override) == null ? void 0 : _D.formData
4174
- ) : (_E = outputOptions.override) == null ? void 0 : _E.formData) != null ? _F : true,
4175
- formUrlEncoded: (_J = !(0, import_core7.isBoolean)((_G = outputOptions.override) == null ? void 0 : _G.formUrlEncoded) ? normalizeMutator(
4169
+ (_E = outputOptions.override) == null ? void 0 : _E.formData
4170
+ ) : (_F = outputOptions.override) == null ? void 0 : _F.formData) != null ? _G : true,
4171
+ formUrlEncoded: (_K = !(0, import_core7.isBoolean)((_H = outputOptions.override) == null ? void 0 : _H.formUrlEncoded) ? normalizeMutator(
4176
4172
  outputWorkspace,
4177
- (_H = outputOptions.override) == null ? void 0 : _H.formUrlEncoded
4178
- ) : (_I = outputOptions.override) == null ? void 0 : _I.formUrlEncoded) != null ? _J : true,
4173
+ (_I = outputOptions.override) == null ? void 0 : _I.formUrlEncoded
4174
+ ) : (_J = outputOptions.override) == null ? void 0 : _J.formUrlEncoded) != null ? _K : true,
4179
4175
  paramsSerializer: normalizeMutator(
4180
4176
  outputWorkspace,
4181
- (_K = outputOptions.override) == null ? void 0 : _K.paramsSerializer
4177
+ (_L = outputOptions.override) == null ? void 0 : _L.paramsSerializer
4182
4178
  ),
4183
- header: ((_L = outputOptions.override) == null ? void 0 : _L.header) === false ? false : (0, import_core7.isFunction)((_M = outputOptions.override) == null ? void 0 : _M.header) ? (_N = outputOptions.override) == null ? void 0 : _N.header : getDefaultFilesHeader,
4184
- requestOptions: (_P = (_O = outputOptions.override) == null ? void 0 : _O.requestOptions) != null ? _P : true,
4179
+ header: ((_M = outputOptions.override) == null ? void 0 : _M.header) === false ? false : (0, import_core7.isFunction)((_N = outputOptions.override) == null ? void 0 : _N.header) ? (_O = outputOptions.override) == null ? void 0 : _O.header : getDefaultFilesHeader,
4180
+ requestOptions: (_Q = (_P = outputOptions.override) == null ? void 0 : _P.requestOptions) != null ? _Q : true,
4185
4181
  components: {
4186
4182
  schemas: {
4187
4183
  suffix: import_core7.RefComponentSuffix.schemas,
4188
- ...(_S = (_R = (_Q = outputOptions.override) == null ? void 0 : _Q.components) == null ? void 0 : _R.schemas) != null ? _S : {}
4184
+ itemSuffix: (_U = (_T = (_S = (_R = outputOptions.override) == null ? void 0 : _R.components) == null ? void 0 : _S.schemas) == null ? void 0 : _T.itemSuffix) != null ? _U : "Item",
4185
+ ...(_X = (_W = (_V = outputOptions.override) == null ? void 0 : _V.components) == null ? void 0 : _W.schemas) != null ? _X : {}
4189
4186
  },
4190
4187
  responses: {
4191
4188
  suffix: import_core7.RefComponentSuffix.responses,
4192
- ...(_V = (_U = (_T = outputOptions.override) == null ? void 0 : _T.components) == null ? void 0 : _U.responses) != null ? _V : {}
4189
+ ...(__ = (_Z = (_Y = outputOptions.override) == null ? void 0 : _Y.components) == null ? void 0 : _Z.responses) != null ? __ : {}
4193
4190
  },
4194
4191
  parameters: {
4195
4192
  suffix: import_core7.RefComponentSuffix.parameters,
4196
- ...(_Y = (_X = (_W = outputOptions.override) == null ? void 0 : _W.components) == null ? void 0 : _X.parameters) != null ? _Y : {}
4193
+ ...(_ba = (_aa = (_$ = outputOptions.override) == null ? void 0 : _$.components) == null ? void 0 : _aa.parameters) != null ? _ba : {}
4197
4194
  },
4198
4195
  requestBodies: {
4199
4196
  suffix: import_core7.RefComponentSuffix.requestBodies,
4200
- ...(_$ = (__ = (_Z = outputOptions.override) == null ? void 0 : _Z.components) == null ? void 0 : __.requestBodies) != null ? _$ : {}
4197
+ ...(_ea = (_da = (_ca = outputOptions.override) == null ? void 0 : _ca.components) == null ? void 0 : _da.requestBodies) != null ? _ea : {}
4201
4198
  }
4202
4199
  },
4203
4200
  query: {
4204
4201
  useQuery: true,
4205
4202
  useMutation: true,
4206
4203
  signal: true,
4207
- ...normalizeQueryOptions((_aa = outputOptions.override) == null ? void 0 : _aa.query, workspace)
4204
+ shouldExportMutatorHooks: true,
4205
+ ...normalizeQueryOptions((_fa = outputOptions.override) == null ? void 0 : _fa.query, workspace)
4208
4206
  },
4209
4207
  swr: {
4210
- ...(_ca = (_ba = outputOptions.override) == null ? void 0 : _ba.swr) != null ? _ca : {}
4208
+ ...(_ha = (_ga = outputOptions.override) == null ? void 0 : _ga.swr) != null ? _ha : {}
4211
4209
  },
4212
4210
  angular: {
4213
- provideIn: (_fa = (_ea = (_da = outputOptions.override) == null ? void 0 : _da.angular) == null ? void 0 : _ea.provideIn) != null ? _fa : "root"
4211
+ provideIn: (_ka = (_ja = (_ia = outputOptions.override) == null ? void 0 : _ia.angular) == null ? void 0 : _ja.provideIn) != null ? _ka : "root"
4214
4212
  },
4215
- useDates: ((_ga = outputOptions.override) == null ? void 0 : _ga.useDates) || false,
4216
- useDeprecatedOperations: (_ia = (_ha = outputOptions.override) == null ? void 0 : _ha.useDeprecatedOperations) != null ? _ia : true,
4217
- useNativeEnums: (_ka = (_ja = outputOptions.override) == null ? void 0 : _ja.useNativeEnums) != null ? _ka : false
4213
+ useDates: ((_la = outputOptions.override) == null ? void 0 : _la.useDates) || false,
4214
+ useDeprecatedOperations: (_na = (_ma = outputOptions.override) == null ? void 0 : _ma.useDeprecatedOperations) != null ? _na : true,
4215
+ useNativeEnums: (_pa = (_oa = outputOptions.override) == null ? void 0 : _oa.useNativeEnums) != null ? _pa : false
4218
4216
  },
4219
- allParamsOptional: (_la = outputOptions.allParamsOptional) != null ? _la : false,
4220
- urlEncodeParameters: (_ma = outputOptions.urlEncodeParameters) != null ? _ma : false
4217
+ allParamsOptional: (_qa = outputOptions.allParamsOptional) != null ? _qa : false,
4218
+ urlEncodeParameters: (_ra = outputOptions.urlEncodeParameters) != null ? _ra : false
4221
4219
  },
4222
4220
  hooks: options.hooks ? normalizeHooks(options.hooks) : {}
4223
4221
  };
@@ -4340,6 +4338,11 @@ var normalizeHooks = (hooks) => {
4340
4338
  ...acc,
4341
4339
  [key]: [hooks[key]]
4342
4340
  };
4341
+ } else if ((0, import_core7.isObject)(hooks[key])) {
4342
+ return {
4343
+ ...acc,
4344
+ [key]: [hooks[key]]
4345
+ };
4343
4346
  }
4344
4347
  return acc;
4345
4348
  }, {});
@@ -4374,6 +4377,7 @@ var normalizeQueryOptions = (queryOptions = {}, outputWorkspace) => {
4374
4377
  queryOptions == null ? void 0 : queryOptions.mutationOptions
4375
4378
  )
4376
4379
  } : {},
4380
+ ...!(0, import_core7.isUndefined)(queryOptions.shouldExportMutatorHooks) ? { shouldExportMutatorHooks: queryOptions.shouldExportMutatorHooks } : {},
4377
4381
  ...!(0, import_core7.isUndefined)(queryOptions.signal) ? { signal: queryOptions.signal } : {},
4378
4382
  ...!(0, import_core7.isUndefined)(queryOptions.version) ? { version: queryOptions.version } : {}
4379
4383
  };
@@ -4392,13 +4396,14 @@ var getDefaultFilesHeader = ({
4392
4396
 
4393
4397
  // src/utils/watcher.ts
4394
4398
  var import_core8 = require("@orval/core");
4395
- var import_chalk3 = __toESM(require("chalk"));
4396
4399
  var startWatcher = async (watchOptions, watchFn, defaultTarget = ".") => {
4397
4400
  if (!watchOptions)
4398
4401
  return;
4399
4402
  const { watch } = await Promise.resolve().then(() => __toESM(require("chokidar")));
4400
4403
  const ignored = ["**/{.git,node_modules}/**"];
4401
- const watchPaths = typeof watchOptions === "boolean" ? defaultTarget : Array.isArray(watchOptions) ? watchOptions.filter((path) => typeof path === "string") : watchOptions;
4404
+ const watchPaths = typeof watchOptions === "boolean" ? defaultTarget : Array.isArray(watchOptions) ? watchOptions.filter(
4405
+ (path) => typeof path === "string"
4406
+ ) : watchOptions;
4402
4407
  (0, import_core8.log)(
4403
4408
  `Watching for changes in ${Array.isArray(watchPaths) ? watchPaths.map((v) => '"' + v + '"').join(" | ") : '"' + watchPaths + '"'}`
4404
4409
  );
@@ -4411,38 +4416,53 @@ var startWatcher = async (watchOptions, watchFn, defaultTarget = ".") => {
4411
4416
  try {
4412
4417
  await watchFn();
4413
4418
  } catch (e) {
4414
- (0, import_core8.log)(import_chalk3.default.red(e));
4419
+ (0, import_core8.logError)(e);
4415
4420
  }
4416
4421
  });
4417
4422
  };
4418
4423
 
4419
4424
  // src/write-specs.ts
4420
4425
  var import_core10 = require("@orval/core");
4421
- var import_chalk5 = __toESM(require("chalk"));
4426
+ var import_chalk4 = __toESM(require("chalk"));
4422
4427
  var import_execa2 = __toESM(require("execa"));
4423
4428
  var import_fs_extra5 = __toESM(require("fs-extra"));
4424
4429
  var import_lodash2 = __toESM(require("lodash.uniq"));
4425
4430
 
4426
4431
  // src/utils/executeHook.ts
4427
4432
  var import_core9 = require("@orval/core");
4428
- var import_chalk4 = __toESM(require("chalk"));
4433
+ var import_chalk3 = __toESM(require("chalk"));
4429
4434
  var import_execa = __toESM(require("execa"));
4430
4435
  var import_string_argv = require("string-argv");
4431
4436
  var executeHook = async (name, commands = [], args = []) => {
4432
- (0, import_core9.log)(import_chalk4.default.white(`Running ${name} hook...`));
4437
+ (0, import_core9.log)(import_chalk3.default.white(`Running ${name} hook...`));
4433
4438
  for (const command of commands) {
4434
- if ((0, import_core9.isString)(command)) {
4435
- const [cmd, ..._args] = [...(0, import_string_argv.parseArgsStringToArgv)(command), ...args];
4436
- try {
4437
- await (0, import_execa.default)(cmd, _args);
4438
- } catch (e) {
4439
- (0, import_core9.log)(import_chalk4.default.red(`\u{1F6D1} Failed to run ${name} hook: ${e}`));
4439
+ try {
4440
+ if ((0, import_core9.isString)(command)) {
4441
+ await executeCommand(command, args);
4442
+ } else if ((0, import_core9.isFunction)(command)) {
4443
+ await command(args);
4444
+ } else if ((0, import_core9.isObject)(command)) {
4445
+ await executeObjectCommand(command, args);
4440
4446
  }
4441
- } else if ((0, import_core9.isFunction)(command)) {
4442
- await command(args);
4447
+ } catch (e) {
4448
+ (0, import_core9.logError)(e, `Failed to run ${name} hook`);
4443
4449
  }
4444
4450
  }
4445
4451
  };
4452
+ async function executeCommand(command, args) {
4453
+ const [cmd, ..._args] = [...(0, import_string_argv.parseArgsStringToArgv)(command), ...args];
4454
+ await (0, import_execa.default)(cmd, _args);
4455
+ }
4456
+ async function executeObjectCommand(command, args) {
4457
+ if (command.injectGeneratedDirsAndFiles === false) {
4458
+ args = [];
4459
+ }
4460
+ if ((0, import_core9.isString)(command.command)) {
4461
+ await executeCommand(command.command, args);
4462
+ } else if ((0, import_core9.isFunction)(command.command)) {
4463
+ await command.command();
4464
+ }
4465
+ }
4446
4466
 
4447
4467
  // src/write-specs.ts
4448
4468
  var getHeader = (option, info) => {
@@ -4456,12 +4476,15 @@ var writeSpecs = async (builder, workspace, options, projectName) => {
4456
4476
  const { info = { title: "", version: 0 }, schemas, target } = builder;
4457
4477
  const { output } = options;
4458
4478
  const projectTitle = projectName || info.title;
4459
- const specsName = Object.keys(schemas).reduce((acc, specKey) => {
4460
- const basePath = import_core10.upath.getSpecName(specKey, target);
4461
- const name = basePath.slice(1).split("/").join("-");
4462
- acc[specKey] = name;
4463
- return acc;
4464
- }, {});
4479
+ const specsName = Object.keys(schemas).reduce(
4480
+ (acc, specKey) => {
4481
+ const basePath = import_core10.upath.getSpecName(specKey, target);
4482
+ const name = basePath.slice(1).split("/").join("-");
4483
+ acc[specKey] = name;
4484
+ return acc;
4485
+ },
4486
+ {}
4487
+ );
4465
4488
  const header = getHeader(output.override.header, info);
4466
4489
  if (output.schemas) {
4467
4490
  const rootSchemaPath = output.schemas;
@@ -4542,7 +4565,7 @@ var writeSpecs = async (builder, workspace, options, projectName) => {
4542
4565
  await (0, import_execa2.default)("prettier", ["--write", ...paths]);
4543
4566
  } catch (e) {
4544
4567
  (0, import_core10.log)(
4545
- import_chalk5.default.yellow(
4568
+ import_chalk4.default.yellow(
4546
4569
  `\u26A0\uFE0F ${projectTitle ? `${projectTitle} - ` : ""}Prettier not found`
4547
4570
  )
4548
4571
  );
@@ -4592,11 +4615,11 @@ var generateSpecs = async (config, workspace, projectName) => {
4592
4615
  try {
4593
4616
  await generateSpec(workspace, options, projectName);
4594
4617
  } catch (e) {
4595
- (0, import_core11.log)(import_chalk6.default.red(`\u{1F6D1} ${projectName ? `${projectName} - ` : ""}${e}`));
4618
+ (0, import_core11.logError)(e, projectName);
4596
4619
  process.exit(1);
4597
4620
  }
4598
4621
  } else {
4599
- (0, import_core11.errorMessage)("Project not found");
4622
+ (0, import_core11.logError)("Project not found");
4600
4623
  process.exit(1);
4601
4624
  }
4602
4625
  return;
@@ -4609,7 +4632,7 @@ var generateSpecs = async (config, workspace, projectName) => {
4609
4632
  acc.push(await generateSpec(workspace, options, projectName2));
4610
4633
  } catch (e) {
4611
4634
  hasErrors = true;
4612
- (0, import_core11.log)(import_chalk6.default.red(`\u{1F6D1} ${projectName2 ? `${projectName2} - ` : ""}${e}`));
4635
+ (0, import_core11.logError)(e, projectName2);
4613
4636
  }
4614
4637
  return acc;
4615
4638
  },
@@ -4671,11 +4694,7 @@ var generate = async (optionsExport, workspace = process.cwd(), options) => {
4671
4694
  try {
4672
4695
  await generateSpec(workspace, normalizedOptions);
4673
4696
  } catch (e) {
4674
- (0, import_core12.log)(
4675
- import_chalk7.default.red(
4676
- `\u{1F6D1} ${(options == null ? void 0 : options.projectName) ? `${options == null ? void 0 : options.projectName} - ` : ""}${e}`
4677
- )
4678
- );
4697
+ (0, import_core12.logError)(e, options == null ? void 0 : options.projectName);
4679
4698
  }
4680
4699
  },
4681
4700
  normalizedOptions.input.target
@@ -4684,11 +4703,7 @@ var generate = async (optionsExport, workspace = process.cwd(), options) => {
4684
4703
  try {
4685
4704
  return await generateSpec(workspace, normalizedOptions);
4686
4705
  } catch (e) {
4687
- (0, import_core12.log)(
4688
- import_chalk7.default.red(
4689
- `\u{1F6D1} ${(options == null ? void 0 : options.projectName) ? `${options == null ? void 0 : options.projectName} - ` : ""}${e}`
4690
- )
4691
- );
4706
+ (0, import_core12.logError)(e, options == null ? void 0 : options.projectName);
4692
4707
  }
4693
4708
  }
4694
4709
  };
@@ -4704,3 +4719,4 @@ var src_default = generate;
4704
4719
  js-yaml/dist/js-yaml.mjs:
4705
4720
  (*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT *)
4706
4721
  */
4722
+ //# sourceMappingURL=index.js.map