@@ -7,7 +7,10 @@ import { OrganizationMember, fetchOrganizationMembers } from '../../api/members'
77import { upperCase } from 'lodash'
88import { createHash } from 'crypto'
99import path from 'path'
10- import { fetchAllCompletedOrArchivedFeatures } from '../../api/features'
10+ import {
11+ fetchAllCompletedOrArchivedFeatures ,
12+ fetchFeatures ,
13+ } from '../../api/features'
1114import { fetchCustomProperties } from '../../api/customProperties'
1215
1316const reactImports = ( oldRepos : boolean , strictCustomData : boolean ) => {
@@ -176,10 +179,23 @@ export default class GenerateTypes extends Base {
176179 )
177180 }
178181
179- this . features = await fetchAllCompletedOrArchivedFeatures (
180- this . authToken ,
181- this . projectKey ,
182- )
182+ if ( this . project . settings ?. staleness ?. enabled ) {
183+ const [ completedFeatures , staleFeatures ] = await Promise . all ( [
184+ fetchAllCompletedOrArchivedFeatures (
185+ this . authToken ,
186+ this . projectKey ,
187+ ) ,
188+ fetchFeatures ( this . authToken , this . projectKey , {
189+ staleness : 'all' ,
190+ } ) ,
191+ ] )
192+ this . features = [ ...completedFeatures , ...staleFeatures ]
193+ } else {
194+ this . features = await fetchAllCompletedOrArchivedFeatures (
195+ this . authToken ,
196+ this . projectKey ,
197+ )
198+ }
183199
184200 const variables = await fetchAllVariables (
185201 this . authToken ,
@@ -294,19 +310,33 @@ export default class GenerateTypes extends Base {
294310 const createdDate = variable . createdAt . split ( 'T' ) [ 0 ]
295311
296312 const deprecationInfo = isVariableDeprecated ( variable , this . features )
313+
297314 const isDeprecated =
298315 this . includeDeprecationWarnings && deprecationInfo . deprecated
299316 const deprecationWarning = isDeprecated
300317 ? `@deprecated This variable is part of ${ deprecationInfo . feature ?. status } feature "${ deprecationInfo . feature ?. name } " and should be cleaned up.\n`
301318 : ''
302319
320+ let staleWarning = ''
321+ if ( this . project . settings ?. staleness ?. enabled ) {
322+ const staleInfo = isVariableStale ( variable , this . features )
323+ const recommendedValue = getRecommendedValueForStale (
324+ variable ,
325+ staleInfo . feature as Feature ,
326+ )
327+ staleWarning = staleInfo . stale
328+ ? `@stale This variable is part of "${ staleInfo . feature ?. name } " feature with stale reason: ${ staleInfo . feature ?. staleness ?. reason } . ${ recommendedValue ? `Recommended value to set it to: ${ recommendedValue } ` : '' } \n`
329+ : ''
330+ }
331+
303332 return blockComment (
304333 descriptionText ,
305334 creator ,
306335 createdDate ,
307336 indent ,
308337 ! this . obfuscate ? variable . key : undefined ,
309338 deprecationWarning ,
339+ staleWarning ,
310340 )
311341 }
312342
@@ -385,6 +415,7 @@ export const blockComment = (
385415 indent : boolean ,
386416 key ?: string ,
387417 deprecationWarning ?: string ,
418+ staleWarning ?: string ,
388419) => {
389420 const indentString = indent ? ' ' : ''
390421 return (
@@ -399,6 +430,7 @@ export const blockComment = (
399430 ( deprecationWarning
400431 ? `${ indentString } * ${ deprecationWarning } \n`
401432 : '' ) +
433+ ( staleWarning ? `${ indentString } * ${ staleWarning } \n` : '' ) +
402434 indentString +
403435 '*/'
404436 )
@@ -430,6 +462,39 @@ function isVariableDeprecated(variable: Variable, features: Feature[]) {
430462 return { deprecated : feature && feature . status !== 'active' , feature }
431463}
432464
465+ function isVariableStale ( variable : Variable , features : Feature [ ] ) {
466+ if ( ! variable . _feature || variable . persistent ) return { stale : false }
467+ const feature = features . find ( ( f ) => f . _id === variable . _feature )
468+ return { stale : feature && feature . staleness , feature }
469+ }
470+
471+ function getRecommendedValueForStale ( variable : Variable , feature : Feature ) {
472+ if ( ! feature ) {
473+ return variable . defaultValue
474+ }
475+ const reason = feature . staleness ?. reason
476+ if ( reason === 'unused' ) {
477+ return variable . defaultValue
478+ } else if ( reason === 'released' ) {
479+ if ( feature . staleness ?. metaData ?. releaseVariation ) {
480+ const stalenessMetaData = feature . staleness ?. metaData
481+ ?. releaseVariation as {
482+ _variation : string
483+ variationKey : string
484+ variationName : string
485+ }
486+ const releaseVariation = feature . variations ?. find (
487+ ( v ) => v . _id === stalenessMetaData . _variation ,
488+ )
489+ return (
490+ releaseVariation ?. variables ?. [ variable . key ] ||
491+ variable . defaultValue
492+ )
493+ }
494+ }
495+ return variable . defaultValue
496+ }
497+
433498const generateCustomDataType = (
434499 customProperties : CustomProperty [ ] ,
435500 strict : boolean ,
0 commit comments