forked from orval-labs/orval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
66 lines (61 loc) · 1.68 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import chalk from 'chalk';
import { generateConfig, generateSpec } from './generate';
import { GlobalOptions, Options, OptionsExport } from './types';
import { isString } from './utils/is';
import { log } from './utils/messages/logs';
import { defineConfig, normalizeOptions } from './utils/options';
import { startWatcher } from './utils/watcher';
const generate = async (
optionsExport?: string | OptionsExport,
workspace = process.cwd(),
options?: GlobalOptions,
) => {
if (!optionsExport || isString(optionsExport)) {
return generateConfig(optionsExport, options);
}
const normalizedOptions = await normalizeOptions(
optionsExport,
workspace,
options,
);
if (options?.watch) {
startWatcher(
options?.watch,
async () => {
try {
await generateSpec(workspace, normalizedOptions);
} catch (e) {
log(
chalk.red(
`🛑 ${
options?.projectName ? `${options?.projectName} - ` : ''
}${e}`,
),
);
}
},
normalizedOptions.input.target as string,
);
} else {
try {
return await generateSpec(workspace, normalizedOptions);
} catch (e) {
log(
chalk.red(
`🛑 ${options?.projectName ? `${options?.projectName} - ` : ''}${e}`,
),
);
}
}
};
export * from './constants';
export * from './types/generator';
export * from './core/generators/imports';
export * from './core/generators/options';
export * from './utils/tsconfig';
export * from './utils/string';
export * from './utils/case';
export { defineConfig };
export { Options };
export { generate };
export default generate;