orval 6.23.0 → 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/bin/orval.js CHANGED
@@ -370,14 +370,14 @@ var require_lodash = __commonJS({
370
370
  return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
371
371
  }
372
372
  function baseIsNative(value) {
373
- if (!isObject6(value) || isMasked(value)) {
373
+ if (!isObject7(value) || isMasked(value)) {
374
374
  return false;
375
375
  }
376
376
  var pattern = isFunction5(value) || isHostObject(value) ? reIsNative : reIsHostCtor;
377
377
  return pattern.test(toSource(value));
378
378
  }
379
379
  function baseKeysIn(object) {
380
- if (!isObject6(object)) {
380
+ if (!isObject7(object)) {
381
381
  return nativeKeysIn(object);
382
382
  }
383
383
  var isProto = isPrototype(object), result = [];
@@ -501,13 +501,13 @@ var require_lodash = __commonJS({
501
501
  return isObjectLike(value) && isArrayLike(value);
502
502
  }
503
503
  function isFunction5(value) {
504
- var tag = isObject6(value) ? objectToString.call(value) : "";
504
+ var tag = isObject7(value) ? objectToString.call(value) : "";
505
505
  return tag == funcTag || tag == genTag;
506
506
  }
507
507
  function isLength(value) {
508
508
  return typeof value == "number" && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
509
509
  }
510
- function isObject6(value) {
510
+ function isObject7(value) {
511
511
  var type2 = typeof value;
512
512
  return !!value && (type2 == "object" || type2 == "function");
513
513
  }
@@ -537,11 +537,9 @@ var require_lodash = __commonJS({
537
537
  // src/bin/orval.ts
538
538
  var import_core12 = require("@orval/core");
539
539
  var import_cac = require("cac");
540
- var import_chalk7 = __toESM(require("chalk"));
541
540
 
542
541
  // src/generate.ts
543
542
  var import_core11 = require("@orval/core");
544
- var import_chalk6 = __toESM(require("chalk"));
545
543
 
546
544
  // src/import-specs.ts
547
545
  var import_swagger_parser = __toESM(require("@apidevtools/swagger-parser"));
@@ -3345,7 +3343,8 @@ var generateClientFooter = ({
3345
3343
  if (!footer) {
3346
3344
  return {
3347
3345
  implementation: "",
3348
- implementationMock: `]
3346
+ implementationMock: `
3347
+ ]
3349
3348
  `
3350
3349
  };
3351
3350
  }
@@ -3574,10 +3573,7 @@ var importOpenApi = async ({
3574
3573
  target,
3575
3574
  workspace,
3576
3575
  specs,
3577
- override: output.override,
3578
- tslint: output.tslint,
3579
- tsconfig: output.tsconfig,
3580
- packageJson: output.packageJson
3576
+ output
3581
3577
  }
3582
3578
  });
3583
3579
  return {
@@ -3621,50 +3617,50 @@ var getApiSchemas = ({
3621
3617
  workspace,
3622
3618
  specs
3623
3619
  }) => {
3624
- return Object.entries(specs).reduce((acc, [specKey, spec]) => {
3625
- var _a, _b, _c, _d;
3626
- const context = {
3627
- specKey,
3628
- target,
3629
- workspace,
3630
- specs,
3631
- override: output.override,
3632
- tslint: output.tslint,
3633
- tsconfig: output.tsconfig,
3634
- packageJson: output.packageJson
3635
- };
3636
- const schemaDefinition = (0, import_core3.generateSchemasDefinition)(
3637
- !spec.openapi ? getAllSchemas(spec, specKey) : (_a = spec.components) == null ? void 0 : _a.schemas,
3638
- context,
3639
- output.override.components.schemas.suffix
3640
- );
3641
- const responseDefinition = (0, import_core3.generateComponentDefinition)(
3642
- (_b = spec.components) == null ? void 0 : _b.responses,
3643
- context,
3644
- output.override.components.responses.suffix
3645
- );
3646
- const bodyDefinition = (0, import_core3.generateComponentDefinition)(
3647
- (_c = spec.components) == null ? void 0 : _c.requestBodies,
3648
- context,
3649
- output.override.components.requestBodies.suffix
3650
- );
3651
- const parameters = (0, import_core3.generateParameterDefinition)(
3652
- (_d = spec.components) == null ? void 0 : _d.parameters,
3653
- context,
3654
- output.override.components.parameters.suffix
3655
- );
3656
- const schemas = [
3657
- ...schemaDefinition,
3658
- ...responseDefinition,
3659
- ...bodyDefinition,
3660
- ...parameters
3661
- ];
3662
- if (!schemas.length) {
3620
+ return Object.entries(specs).reduce(
3621
+ (acc, [specKey, spec]) => {
3622
+ var _a, _b, _c, _d;
3623
+ const context = {
3624
+ specKey,
3625
+ target,
3626
+ workspace,
3627
+ specs,
3628
+ output
3629
+ };
3630
+ const schemaDefinition = (0, import_core3.generateSchemasDefinition)(
3631
+ !spec.openapi ? getAllSchemas(spec, specKey) : (_a = spec.components) == null ? void 0 : _a.schemas,
3632
+ context,
3633
+ output.override.components.schemas.suffix
3634
+ );
3635
+ const responseDefinition = (0, import_core3.generateComponentDefinition)(
3636
+ (_b = spec.components) == null ? void 0 : _b.responses,
3637
+ context,
3638
+ output.override.components.responses.suffix
3639
+ );
3640
+ const bodyDefinition = (0, import_core3.generateComponentDefinition)(
3641
+ (_c = spec.components) == null ? void 0 : _c.requestBodies,
3642
+ context,
3643
+ output.override.components.requestBodies.suffix
3644
+ );
3645
+ const parameters = (0, import_core3.generateParameterDefinition)(
3646
+ (_d = spec.components) == null ? void 0 : _d.parameters,
3647
+ context,
3648
+ output.override.components.parameters.suffix
3649
+ );
3650
+ const schemas = [
3651
+ ...schemaDefinition,
3652
+ ...responseDefinition,
3653
+ ...bodyDefinition,
3654
+ ...parameters
3655
+ ];
3656
+ if (!schemas.length) {
3657
+ return acc;
3658
+ }
3659
+ acc[specKey] = schemas;
3663
3660
  return acc;
3664
- }
3665
- acc[specKey] = schemas;
3666
- return acc;
3667
- }, {});
3661
+ },
3662
+ {}
3663
+ );
3668
3664
  };
3669
3665
  var getAllSchemas = (spec, specKey) => {
3670
3666
  var _a;
@@ -3733,7 +3729,7 @@ var resolveSpecs = async (path, { validate, ...options }, isUrl3, isOnlySchema)
3733
3729
  return data;
3734
3730
  }
3735
3731
  return Object.fromEntries(
3736
- Object.entries(data).map(([key, value]) => [import_core4.upath.resolve(key), value])
3732
+ Object.entries(data).sort().map(([key, value]) => [import_core4.upath.resolve(key), value])
3737
3733
  );
3738
3734
  } catch {
3739
3735
  const file = await import_fs_extra.default.readFile(path, "utf8");
@@ -3782,7 +3778,7 @@ var import_chalk2 = __toESM(require("chalk"));
3782
3778
  var package_default = {
3783
3779
  name: "orval",
3784
3780
  description: "A swagger client generator for typescript",
3785
- version: "6.23.0",
3781
+ version: "6.24.0",
3786
3782
  license: "MIT",
3787
3783
  files: [
3788
3784
  "dist"
@@ -3822,8 +3818,8 @@ var package_default = {
3822
3818
  url: "https://github.com/anymaniax/orval"
3823
3819
  },
3824
3820
  scripts: {
3825
- build: "tsup ./src/bin/orval.ts ./src/index.ts --target node12 --clean --dts",
3826
- dev: "tsup ./src/bin/orval.ts ./src/index.ts --target node12 --clean --watch ./src --onSuccess 'yarn generate-api'",
3821
+ build: "tsup ./src/bin/orval.ts ./src/index.ts --target node12 --clean --sourcemap --dts",
3822
+ dev: "tsup ./src/bin/orval.ts ./src/index.ts --target node12 --clean --sourcemap --watch ./src --onSuccess 'yarn generate-api'",
3827
3823
  lint: "eslint src/**/*.ts",
3828
3824
  "generate-api": "node ./dist/bin/orval.js --config ../../samples/react-query/basic/orval.config.ts",
3829
3825
  test: "tsc --noEmit && vitest --passWithNoTests"
@@ -3835,13 +3831,13 @@ var package_default = {
3835
3831
  },
3836
3832
  dependencies: {
3837
3833
  "@apidevtools/swagger-parser": "^10.1.0",
3838
- "@orval/angular": "6.23.0",
3839
- "@orval/axios": "6.23.0",
3840
- "@orval/core": "6.23.0",
3841
- "@orval/mock": "6.23.0",
3842
- "@orval/query": "6.23.0",
3843
- "@orval/swr": "6.23.0",
3844
- "@orval/zod": "6.23.0",
3834
+ "@orval/angular": "6.24.0",
3835
+ "@orval/axios": "6.24.0",
3836
+ "@orval/core": "6.24.0",
3837
+ "@orval/mock": "6.24.0",
3838
+ "@orval/query": "6.24.0",
3839
+ "@orval/swr": "6.24.0",
3840
+ "@orval/zod": "6.24.0",
3845
3841
  ajv: "^8.12.0",
3846
3842
  cac: "^6.7.14",
3847
3843
  chalk: "^4.1.2",
@@ -3851,8 +3847,7 @@ var package_default = {
3851
3847
  "find-up": "5.0.0",
3852
3848
  "fs-extra": "^11.2.0",
3853
3849
  "lodash.uniq": "^4.5.0",
3854
- "openapi-types": "^12.1.3",
3855
- "openapi3-ts": "^3.2.0",
3850
+ "openapi3-ts": "4.2.1",
3856
3851
  "string-argv": "^0.3.2",
3857
3852
  tsconfck: "^2.0.1"
3858
3853
  }
@@ -4067,7 +4062,7 @@ var loadTsconfig = async (tsconfig, workspace = process.cwd()) => {
4067
4062
 
4068
4063
  // src/utils/options.ts
4069
4064
  var normalizeOptions = async (optionsExport, workspace = process.cwd(), globalOptions = {}) => {
4070
- 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;
4065
+ 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;
4071
4066
  const options = await ((0, import_core7.isFunction)(optionsExport) ? optionsExport() : optionsExport);
4072
4067
  if (!options.input) {
4073
4068
  (0, import_core7.createLogger)().error(import_chalk2.default.red(`Config require an input`));
@@ -4135,76 +4130,78 @@ var normalizeOptions = async (optionsExport, workspace = process.cwd(), globalOp
4135
4130
  headers: (_n = outputOptions.headers) != null ? _n : false,
4136
4131
  indexFiles: (_o = outputOptions.indexFiles) != null ? _o : true,
4137
4132
  baseUrl: outputOptions.baseUrl,
4133
+ unionAddMissingProperties: (_p = outputOptions.unionAddMissingProperties) != null ? _p : false,
4138
4134
  override: {
4139
4135
  ...outputOptions.override,
4140
4136
  mock: {
4141
- arrayMin: (_r = (_q = (_p = outputOptions.override) == null ? void 0 : _p.mock) == null ? void 0 : _q.arrayMin) != null ? _r : 1,
4142
- arrayMax: (_u = (_t = (_s = outputOptions.override) == null ? void 0 : _s.mock) == null ? void 0 : _t.arrayMax) != null ? _u : 10,
4143
- ...(_w = (_v = outputOptions.override) == null ? void 0 : _v.mock) != null ? _w : {}
4137
+ arrayMin: (_s = (_r = (_q = outputOptions.override) == null ? void 0 : _q.mock) == null ? void 0 : _r.arrayMin) != null ? _s : 1,
4138
+ arrayMax: (_v = (_u = (_t = outputOptions.override) == null ? void 0 : _t.mock) == null ? void 0 : _u.arrayMax) != null ? _v : 10,
4139
+ ...(_x = (_w = outputOptions.override) == null ? void 0 : _w.mock) != null ? _x : {}
4144
4140
  },
4145
4141
  operations: normalizeOperationsAndTags(
4146
- (_y = (_x = outputOptions.override) == null ? void 0 : _x.operations) != null ? _y : {},
4142
+ (_z = (_y = outputOptions.override) == null ? void 0 : _y.operations) != null ? _z : {},
4147
4143
  outputWorkspace
4148
4144
  ),
4149
4145
  tags: normalizeOperationsAndTags(
4150
- (_A = (_z = outputOptions.override) == null ? void 0 : _z.tags) != null ? _A : {},
4146
+ (_B = (_A = outputOptions.override) == null ? void 0 : _A.tags) != null ? _B : {},
4151
4147
  outputWorkspace
4152
4148
  ),
4153
4149
  mutator: normalizeMutator(
4154
4150
  outputWorkspace,
4155
- (_B = outputOptions.override) == null ? void 0 : _B.mutator
4151
+ (_C = outputOptions.override) == null ? void 0 : _C.mutator
4156
4152
  ),
4157
- formData: (_F = !(0, import_core7.isBoolean)((_C = outputOptions.override) == null ? void 0 : _C.formData) ? normalizeMutator(
4153
+ formData: (_G = !(0, import_core7.isBoolean)((_D = outputOptions.override) == null ? void 0 : _D.formData) ? normalizeMutator(
4158
4154
  outputWorkspace,
4159
- (_D = outputOptions.override) == null ? void 0 : _D.formData
4160
- ) : (_E = outputOptions.override) == null ? void 0 : _E.formData) != null ? _F : true,
4161
- formUrlEncoded: (_J = !(0, import_core7.isBoolean)((_G = outputOptions.override) == null ? void 0 : _G.formUrlEncoded) ? normalizeMutator(
4155
+ (_E = outputOptions.override) == null ? void 0 : _E.formData
4156
+ ) : (_F = outputOptions.override) == null ? void 0 : _F.formData) != null ? _G : true,
4157
+ formUrlEncoded: (_K = !(0, import_core7.isBoolean)((_H = outputOptions.override) == null ? void 0 : _H.formUrlEncoded) ? normalizeMutator(
4162
4158
  outputWorkspace,
4163
- (_H = outputOptions.override) == null ? void 0 : _H.formUrlEncoded
4164
- ) : (_I = outputOptions.override) == null ? void 0 : _I.formUrlEncoded) != null ? _J : true,
4159
+ (_I = outputOptions.override) == null ? void 0 : _I.formUrlEncoded
4160
+ ) : (_J = outputOptions.override) == null ? void 0 : _J.formUrlEncoded) != null ? _K : true,
4165
4161
  paramsSerializer: normalizeMutator(
4166
4162
  outputWorkspace,
4167
- (_K = outputOptions.override) == null ? void 0 : _K.paramsSerializer
4163
+ (_L = outputOptions.override) == null ? void 0 : _L.paramsSerializer
4168
4164
  ),
4169
- 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,
4170
- requestOptions: (_P = (_O = outputOptions.override) == null ? void 0 : _O.requestOptions) != null ? _P : true,
4165
+ 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,
4166
+ requestOptions: (_Q = (_P = outputOptions.override) == null ? void 0 : _P.requestOptions) != null ? _Q : true,
4171
4167
  components: {
4172
4168
  schemas: {
4173
4169
  suffix: import_core7.RefComponentSuffix.schemas,
4174
- itemSuffix: (_T = (_S = (_R = (_Q = outputOptions.override) == null ? void 0 : _Q.components) == null ? void 0 : _R.schemas) == null ? void 0 : _S.itemSuffix) != null ? _T : "Item",
4175
- ...(_W = (_V = (_U = outputOptions.override) == null ? void 0 : _U.components) == null ? void 0 : _V.schemas) != null ? _W : {}
4170
+ 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",
4171
+ ...(_X = (_W = (_V = outputOptions.override) == null ? void 0 : _V.components) == null ? void 0 : _W.schemas) != null ? _X : {}
4176
4172
  },
4177
4173
  responses: {
4178
4174
  suffix: import_core7.RefComponentSuffix.responses,
4179
- ...(_Z = (_Y = (_X = outputOptions.override) == null ? void 0 : _X.components) == null ? void 0 : _Y.responses) != null ? _Z : {}
4175
+ ...(__ = (_Z = (_Y = outputOptions.override) == null ? void 0 : _Y.components) == null ? void 0 : _Z.responses) != null ? __ : {}
4180
4176
  },
4181
4177
  parameters: {
4182
4178
  suffix: import_core7.RefComponentSuffix.parameters,
4183
- ...(_aa = (_$ = (__ = outputOptions.override) == null ? void 0 : __.components) == null ? void 0 : _$.parameters) != null ? _aa : {}
4179
+ ...(_ba = (_aa = (_$ = outputOptions.override) == null ? void 0 : _$.components) == null ? void 0 : _aa.parameters) != null ? _ba : {}
4184
4180
  },
4185
4181
  requestBodies: {
4186
4182
  suffix: import_core7.RefComponentSuffix.requestBodies,
4187
- ...(_da = (_ca = (_ba = outputOptions.override) == null ? void 0 : _ba.components) == null ? void 0 : _ca.requestBodies) != null ? _da : {}
4183
+ ...(_ea = (_da = (_ca = outputOptions.override) == null ? void 0 : _ca.components) == null ? void 0 : _da.requestBodies) != null ? _ea : {}
4188
4184
  }
4189
4185
  },
4190
4186
  query: {
4191
4187
  useQuery: true,
4192
4188
  useMutation: true,
4193
4189
  signal: true,
4194
- ...normalizeQueryOptions((_ea = outputOptions.override) == null ? void 0 : _ea.query, workspace)
4190
+ shouldExportMutatorHooks: true,
4191
+ ...normalizeQueryOptions((_fa = outputOptions.override) == null ? void 0 : _fa.query, workspace)
4195
4192
  },
4196
4193
  swr: {
4197
- ...(_ga = (_fa = outputOptions.override) == null ? void 0 : _fa.swr) != null ? _ga : {}
4194
+ ...(_ha = (_ga = outputOptions.override) == null ? void 0 : _ga.swr) != null ? _ha : {}
4198
4195
  },
4199
4196
  angular: {
4200
- provideIn: (_ja = (_ia = (_ha = outputOptions.override) == null ? void 0 : _ha.angular) == null ? void 0 : _ia.provideIn) != null ? _ja : "root"
4197
+ provideIn: (_ka = (_ja = (_ia = outputOptions.override) == null ? void 0 : _ia.angular) == null ? void 0 : _ja.provideIn) != null ? _ka : "root"
4201
4198
  },
4202
- useDates: ((_ka = outputOptions.override) == null ? void 0 : _ka.useDates) || false,
4203
- useDeprecatedOperations: (_ma = (_la = outputOptions.override) == null ? void 0 : _la.useDeprecatedOperations) != null ? _ma : true,
4204
- useNativeEnums: (_oa = (_na = outputOptions.override) == null ? void 0 : _na.useNativeEnums) != null ? _oa : false
4199
+ useDates: ((_la = outputOptions.override) == null ? void 0 : _la.useDates) || false,
4200
+ useDeprecatedOperations: (_na = (_ma = outputOptions.override) == null ? void 0 : _ma.useDeprecatedOperations) != null ? _na : true,
4201
+ useNativeEnums: (_pa = (_oa = outputOptions.override) == null ? void 0 : _oa.useNativeEnums) != null ? _pa : false
4205
4202
  },
4206
- allParamsOptional: (_pa = outputOptions.allParamsOptional) != null ? _pa : false,
4207
- urlEncodeParameters: (_qa = outputOptions.urlEncodeParameters) != null ? _qa : false
4203
+ allParamsOptional: (_qa = outputOptions.allParamsOptional) != null ? _qa : false,
4204
+ urlEncodeParameters: (_ra = outputOptions.urlEncodeParameters) != null ? _ra : false
4208
4205
  },
4209
4206
  hooks: options.hooks ? normalizeHooks(options.hooks) : {}
4210
4207
  };
@@ -4327,6 +4324,11 @@ var normalizeHooks = (hooks) => {
4327
4324
  ...acc,
4328
4325
  [key]: [hooks[key]]
4329
4326
  };
4327
+ } else if ((0, import_core7.isObject)(hooks[key])) {
4328
+ return {
4329
+ ...acc,
4330
+ [key]: [hooks[key]]
4331
+ };
4330
4332
  }
4331
4333
  return acc;
4332
4334
  }, {});
@@ -4361,6 +4363,7 @@ var normalizeQueryOptions = (queryOptions = {}, outputWorkspace) => {
4361
4363
  queryOptions == null ? void 0 : queryOptions.mutationOptions
4362
4364
  )
4363
4365
  } : {},
4366
+ ...!(0, import_core7.isUndefined)(queryOptions.shouldExportMutatorHooks) ? { shouldExportMutatorHooks: queryOptions.shouldExportMutatorHooks } : {},
4364
4367
  ...!(0, import_core7.isUndefined)(queryOptions.signal) ? { signal: queryOptions.signal } : {},
4365
4368
  ...!(0, import_core7.isUndefined)(queryOptions.version) ? { version: queryOptions.version } : {}
4366
4369
  };
@@ -4379,13 +4382,14 @@ var getDefaultFilesHeader = ({
4379
4382
 
4380
4383
  // src/utils/watcher.ts
4381
4384
  var import_core8 = require("@orval/core");
4382
- var import_chalk3 = __toESM(require("chalk"));
4383
4385
  var startWatcher = async (watchOptions, watchFn, defaultTarget = ".") => {
4384
4386
  if (!watchOptions)
4385
4387
  return;
4386
4388
  const { watch } = await Promise.resolve().then(() => __toESM(require("chokidar")));
4387
4389
  const ignored = ["**/{.git,node_modules}/**"];
4388
- const watchPaths = typeof watchOptions === "boolean" ? defaultTarget : Array.isArray(watchOptions) ? watchOptions.filter((path) => typeof path === "string") : watchOptions;
4390
+ const watchPaths = typeof watchOptions === "boolean" ? defaultTarget : Array.isArray(watchOptions) ? watchOptions.filter(
4391
+ (path) => typeof path === "string"
4392
+ ) : watchOptions;
4389
4393
  (0, import_core8.log)(
4390
4394
  `Watching for changes in ${Array.isArray(watchPaths) ? watchPaths.map((v) => '"' + v + '"').join(" | ") : '"' + watchPaths + '"'}`
4391
4395
  );
@@ -4398,38 +4402,53 @@ var startWatcher = async (watchOptions, watchFn, defaultTarget = ".") => {
4398
4402
  try {
4399
4403
  await watchFn();
4400
4404
  } catch (e) {
4401
- (0, import_core8.log)(import_chalk3.default.red(e));
4405
+ (0, import_core8.logError)(e);
4402
4406
  }
4403
4407
  });
4404
4408
  };
4405
4409
 
4406
4410
  // src/write-specs.ts
4407
4411
  var import_core10 = require("@orval/core");
4408
- var import_chalk5 = __toESM(require("chalk"));
4412
+ var import_chalk4 = __toESM(require("chalk"));
4409
4413
  var import_execa2 = __toESM(require("execa"));
4410
4414
  var import_fs_extra5 = __toESM(require("fs-extra"));
4411
4415
  var import_lodash2 = __toESM(require("lodash.uniq"));
4412
4416
 
4413
4417
  // src/utils/executeHook.ts
4414
4418
  var import_core9 = require("@orval/core");
4415
- var import_chalk4 = __toESM(require("chalk"));
4419
+ var import_chalk3 = __toESM(require("chalk"));
4416
4420
  var import_execa = __toESM(require("execa"));
4417
4421
  var import_string_argv = require("string-argv");
4418
4422
  var executeHook = async (name, commands = [], args = []) => {
4419
- (0, import_core9.log)(import_chalk4.default.white(`Running ${name} hook...`));
4423
+ (0, import_core9.log)(import_chalk3.default.white(`Running ${name} hook...`));
4420
4424
  for (const command of commands) {
4421
- if ((0, import_core9.isString)(command)) {
4422
- const [cmd, ..._args] = [...(0, import_string_argv.parseArgsStringToArgv)(command), ...args];
4423
- try {
4424
- await (0, import_execa.default)(cmd, _args);
4425
- } catch (e) {
4426
- (0, import_core9.log)(import_chalk4.default.red(`\u{1F6D1} Failed to run ${name} hook: ${e}`));
4425
+ try {
4426
+ if ((0, import_core9.isString)(command)) {
4427
+ await executeCommand(command, args);
4428
+ } else if ((0, import_core9.isFunction)(command)) {
4429
+ await command(args);
4430
+ } else if ((0, import_core9.isObject)(command)) {
4431
+ await executeObjectCommand(command, args);
4427
4432
  }
4428
- } else if ((0, import_core9.isFunction)(command)) {
4429
- await command(args);
4433
+ } catch (e) {
4434
+ (0, import_core9.logError)(e, `Failed to run ${name} hook`);
4430
4435
  }
4431
4436
  }
4432
4437
  };
4438
+ async function executeCommand(command, args) {
4439
+ const [cmd, ..._args] = [...(0, import_string_argv.parseArgsStringToArgv)(command), ...args];
4440
+ await (0, import_execa.default)(cmd, _args);
4441
+ }
4442
+ async function executeObjectCommand(command, args) {
4443
+ if (command.injectGeneratedDirsAndFiles === false) {
4444
+ args = [];
4445
+ }
4446
+ if ((0, import_core9.isString)(command.command)) {
4447
+ await executeCommand(command.command, args);
4448
+ } else if ((0, import_core9.isFunction)(command.command)) {
4449
+ await command.command();
4450
+ }
4451
+ }
4433
4452
 
4434
4453
  // src/write-specs.ts
4435
4454
  var getHeader = (option, info) => {
@@ -4443,12 +4462,15 @@ var writeSpecs = async (builder, workspace, options, projectName) => {
4443
4462
  const { info = { title: "", version: 0 }, schemas, target } = builder;
4444
4463
  const { output } = options;
4445
4464
  const projectTitle = projectName || info.title;
4446
- const specsName = Object.keys(schemas).reduce((acc, specKey) => {
4447
- const basePath = import_core10.upath.getSpecName(specKey, target);
4448
- const name = basePath.slice(1).split("/").join("-");
4449
- acc[specKey] = name;
4450
- return acc;
4451
- }, {});
4465
+ const specsName = Object.keys(schemas).reduce(
4466
+ (acc, specKey) => {
4467
+ const basePath = import_core10.upath.getSpecName(specKey, target);
4468
+ const name = basePath.slice(1).split("/").join("-");
4469
+ acc[specKey] = name;
4470
+ return acc;
4471
+ },
4472
+ {}
4473
+ );
4452
4474
  const header = getHeader(output.override.header, info);
4453
4475
  if (output.schemas) {
4454
4476
  const rootSchemaPath = output.schemas;
@@ -4529,7 +4551,7 @@ var writeSpecs = async (builder, workspace, options, projectName) => {
4529
4551
  await (0, import_execa2.default)("prettier", ["--write", ...paths]);
4530
4552
  } catch (e) {
4531
4553
  (0, import_core10.log)(
4532
- import_chalk5.default.yellow(
4554
+ import_chalk4.default.yellow(
4533
4555
  `\u26A0\uFE0F ${projectTitle ? `${projectTitle} - ` : ""}Prettier not found`
4534
4556
  )
4535
4557
  );
@@ -4579,11 +4601,11 @@ var generateSpecs = async (config, workspace, projectName) => {
4579
4601
  try {
4580
4602
  await generateSpec(workspace, options, projectName);
4581
4603
  } catch (e) {
4582
- (0, import_core11.log)(import_chalk6.default.red(`\u{1F6D1} ${projectName ? `${projectName} - ` : ""}${e}`));
4604
+ (0, import_core11.logError)(e, projectName);
4583
4605
  process.exit(1);
4584
4606
  }
4585
4607
  } else {
4586
- (0, import_core11.errorMessage)("Project not found");
4608
+ (0, import_core11.logError)("Project not found");
4587
4609
  process.exit(1);
4588
4610
  }
4589
4611
  return;
@@ -4596,7 +4618,7 @@ var generateSpecs = async (config, workspace, projectName) => {
4596
4618
  acc.push(await generateSpec(workspace, options, projectName2));
4597
4619
  } catch (e) {
4598
4620
  hasErrors = true;
4599
- (0, import_core11.log)(import_chalk6.default.red(`\u{1F6D1} ${projectName2 ? `${projectName2} - ` : ""}${e}`));
4621
+ (0, import_core11.logError)(e, projectName2);
4600
4622
  }
4601
4623
  return acc;
4602
4624
  },
@@ -4680,7 +4702,7 @@ cli.command(
4680
4702
  try {
4681
4703
  await generateSpec(process.cwd(), normalizedOptions);
4682
4704
  } catch (e) {
4683
- (0, import_core12.log)(import_chalk7.default.red(`\u{1F6D1} ${e}`));
4705
+ (0, import_core12.logError)(e);
4684
4706
  }
4685
4707
  },
4686
4708
  normalizedOptions.input.target
@@ -4689,7 +4711,7 @@ cli.command(
4689
4711
  try {
4690
4712
  await generateSpec(process.cwd(), normalizedOptions);
4691
4713
  } catch (e) {
4692
- (0, import_core12.log)(import_chalk7.default.red(`\u{1F6D1} ${e}`));
4714
+ (0, import_core12.logError)(e);
4693
4715
  }
4694
4716
  }
4695
4717
  } else {
@@ -4715,3 +4737,4 @@ cli.parse(process.argv);
4715
4737
  js-yaml/dist/js-yaml.mjs:
4716
4738
  (*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT *)
4717
4739
  */
4740
+ //# sourceMappingURL=orval.js.map