11import { resolve } from 'path'
2- import { readFileSync , writeFileSync } from 'fs'
2+ import { existsSync , readFileSync , statSync , writeFileSync } from 'fs'
33import openapiTS , { astToString , COMMENT_HEADER } from 'openapi-typescript'
44import { defineNuxtConfig } from 'nuxt/config'
55import { parse } from 'yaml'
@@ -8,8 +8,9 @@ import setupApp from './src/server/extension.setup'
88
99const SESAME_APP_API_URL = process . env . SESAME_APP_API_URL || 'http://localhost:4002'
1010const SESAME_ALLOWED_HOSTS = process . env . SESAME_ALLOWED_HOSTS ? process . env . SESAME_ALLOWED_HOSTS . split ( ',' ) : [ ]
11+ const IS_DEV = process . env . NODE_ENV === 'development'
1112
12- if ( SESAME_ALLOWED_HOSTS . length === 0 && ! / l o c a l h o s t / . test ( SESAME_APP_API_URL ) && process . env . NODE_ENV === 'development' ) {
13+ if ( SESAME_ALLOWED_HOSTS . length === 0 && ! / l o c a l h o s t / . test ( SESAME_APP_API_URL ) && IS_DEV ) {
1314 SESAME_ALLOWED_HOSTS . push ( new URL ( SESAME_APP_API_URL ) . hostname )
1415}
1516
@@ -53,9 +54,9 @@ export default defineNuxtConfig({
5354 ...sslCfg ,
5455 } ,
5556 devtools : {
56- enabled : process . env . NODE_ENV === 'development' ,
57+ enabled : IS_DEV ,
5758 timeline : {
58- enabled : true ,
59+ enabled : IS_DEV ,
5960 } ,
6061 } ,
6162 css : [ '~/assets/sass/global.sass' ] ,
@@ -86,7 +87,7 @@ export default defineNuxtConfig({
8687 'nuxt-quasar-ui' ,
8788 '@vueuse/nuxt' ,
8889 'dayjs-nuxt' ,
89- '@nuxt/devtools' ,
90+ ... ( IS_DEV ? [ '@nuxt/devtools' ] : [ ] ) ,
9091 'nuxt-monaco-editor' ,
9192 ...setupApp ( ) ,
9293 ] ,
@@ -219,7 +220,7 @@ export default defineNuxtConfig({
219220 template : {
220221 preprocessOptions : {
221222 pug : {
222- pretty : true ,
223+ pretty : IS_DEV ,
223224 } ,
224225 } ,
225226 } ,
@@ -279,10 +280,22 @@ export default defineNuxtConfig({
279280 console . debug ( '[Nuxt] Error while reading identities-columns.yml' , error )
280281 }
281282
283+ const forceOpenapiRefresh = / t r u e | o n | y e s | 1 / i. test ( `${ process . env . SESAME_FORCE_OPENAPI_TYPES_REFRESH } ` )
284+ const openapiTypesPath = '.nuxt/types/service-api.d.ts'
285+ const maxOpenapiTypesAgeMs = 1000 * 60 * 15
286+
287+ if ( ! forceOpenapiRefresh && existsSync ( openapiTypesPath ) ) {
288+ const ageMs = Date . now ( ) - statSync ( openapiTypesPath ) . mtimeMs
289+ if ( ageMs < maxOpenapiTypesAgeMs ) {
290+ console . log ( '[OpenapiTS] Skip generation (cache still fresh).' )
291+ return
292+ }
293+ }
294+
282295 console . log ( '[OpenapiTS] Generating .nuxt/types/service-api.d.ts...' )
283296 try {
284297 const fileData = await openapiTS ( `${ SESAME_APP_API_URL } /swagger/json` )
285- writeFileSync ( '.nuxt/types/service-api.d.ts' , `${ COMMENT_HEADER } ${ astToString ( fileData ) } ` )
298+ writeFileSync ( openapiTypesPath , `${ COMMENT_HEADER } ${ astToString ( fileData ) } ` )
286299 console . log ( '[OpenapiTS] Generated .nuxt/types/service-api.d.ts !' )
287300 } catch ( error ) {
288301 console . debug ( '[OpenapiTS] Error while generating .nuxt/types/service-api.d.ts' , error )
0 commit comments