fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2210 from hey-api/fix/bin-watch

fix(cli): correctly handle watch mode

authored by

Lubos and committed by
GitHub
69665af4 c778f692

+28 -27
+5
.changeset/young-years-push.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix(cli): correctly detect watch mode
-1
packages/openapi-ts-tests/test/openapi-ts.config.ts
··· 69 69 // project: 'upload-openapi-spec', 70 70 validate_EXPERIMENTAL: true, 71 71 // version: '1.0.0', 72 - // watch: 5_000, 73 72 // watch: { 74 73 // enabled: true, 75 74 // interval: 500,
+7 -1
packages/openapi-ts/bin/index.cjs
··· 129 129 } 130 130 131 131 const context = await createClient(userConfig); 132 - if (!context[0] || !context[0].config.watch) { 132 + if ( 133 + !context[0] || 134 + !context[0].config || 135 + !context[0].config.input || 136 + !context[0].config.input.watch || 137 + !context[0].config.input.watch.enabled 138 + ) { 133 139 process.exit(0); 134 140 } 135 141 } catch {
+16 -25
packages/openapi-ts/src/createClient.ts
··· 132 132 return result; 133 133 }; 134 134 135 - const logInputPath = ({ 136 - config, 137 - inputPath, 138 - watch, 139 - }: { 140 - config: Config; 141 - inputPath: ReturnType<typeof compileInputPath>; 142 - watch?: boolean; 143 - }) => { 144 - if (config.logs.level === 'silent') { 145 - return; 146 - } 147 - 148 - if (watch) { 149 - console.clear(); 150 - } 151 - 152 - const baseString = watch 153 - ? colors.magenta('Input changed, generating from') 154 - : colors.cyan('Generating from'); 135 + const logInputPath = (inputPath: ReturnType<typeof compileInputPath>) => { 136 + const baseString = colors.cyan('Generating from'); 155 137 156 138 if (typeof inputPath.path === 'string') { 157 139 const baseInput = isPlatformPath(inputPath.path) ··· 192 174 }: { 193 175 config: Config; 194 176 templates: Templates; 177 + /** 178 + * Always falsy on the first run, truthy on subsequent runs. 179 + */ 195 180 watch?: WatchValues; 196 181 }) => { 197 182 const inputPath = compileInputPath(config.input); ··· 199 184 200 185 const watch: WatchValues = _watch || { headers: new Headers() }; 201 186 202 - logInputPath({ 203 - config, 204 - inputPath, 205 - watch: Boolean(_watch), 206 - }); 187 + // on first run, print the message as soon as possible 188 + if (config.logs.level !== 'silent' && !_watch) { 189 + logInputPath(inputPath); 190 + } 207 191 208 192 Performance.start('spec'); 209 193 const { data, error, response } = await getSpec({ ··· 227 211 let context: IR.Context | undefined; 228 212 229 213 if (data) { 214 + // on subsequent runs in watch mode, print the mssage only if we know we're 215 + // generating the output 216 + if (config.logs.level !== 'silent' && _watch) { 217 + console.clear(); 218 + logInputPath(inputPath); 219 + } 220 + 230 221 Performance.start('input.patch'); 231 222 patchOpenApiSpec({ patchOptions: config.input.patch, spec: data }); 232 223 Performance.end('input.patch');