2023-11-29 14:08:18 +00:00
import { codeBlock } from 'common-tags' ;
2021-12-09 20:12:49 +00:00
import type { RenovateConfig } from '../../lib/config/types' ;
2023-07-24 20:44:12 +00:00
import type { Category } from '../../lib/constants' ;
2022-03-03 09:35:26 +00:00
import { getManagers } from '../../lib/modules/manager' ;
2023-08-15 17:12:54 +00:00
import {
getCustomManagers ,
isCustomManager ,
} from '../../lib/modules/manager/custom' ;
2021-12-09 20:12:49 +00:00
import { readFile , updateFile } from '../utils' ;
2023-03-13 05:57:26 +00:00
import { OpenItems , generateFeatureAndBugMarkdown } from './github-query-items' ;
2023-03-29 10:41:05 +00:00
import {
formatUrls ,
getDisplayName ,
2023-11-10 08:33:13 +00:00
getModuleLink ,
2023-03-29 10:41:05 +00:00
getNameWithUrl ,
replaceContent ,
} from './utils' ;
2021-12-09 20:12:49 +00:00
2023-07-24 20:44:12 +00:00
const noCategoryID = 'no-category' ;
const noCategoryDisplayName = 'No Category' ;
2023-07-04 09:41:19 +00:00
2023-11-29 14:08:18 +00:00
function getTitle (
manager : string ,
displayName : string ,
isCustomMgr : boolean ,
) : string {
if ( isCustomMgr ) {
2023-08-15 17:12:54 +00:00
return ` Custom Manager Support using ${ displayName } ` ;
2021-12-09 20:12:49 +00:00
}
return ` Automated Dependency Updates for ${ displayName } ` ;
}
function getManagerLink ( manager : string ) : string {
2023-11-13 14:36:40 +00:00
return getModuleLink ( manager , ` \` ${ manager } \` ` ) ;
2021-12-09 20:12:49 +00:00
}
2023-07-24 20:44:12 +00:00
export const CategoryNames : Record < Category , string > = {
ansible : 'Ansible' ,
batect : 'Batect' ,
bazel : 'Bazel' ,
c : 'C and C++' ,
cd : 'Continuous Delivery' ,
ci : 'Continuous Integration' ,
2024-05-29 15:17:58 +00:00
custom : 'Custom Managers' ,
2023-07-24 20:44:12 +00:00
dart : 'Dart' ,
docker : 'Docker' ,
dotnet : '.NET' ,
elixir : 'Elixir' ,
golang : 'Go' ,
helm : 'Helm' ,
iac : 'Infrastructure as Code' ,
java : 'Java' ,
js : 'JavaScript' ,
kubernetes : 'Kubernetes' ,
node : 'Node.js' ,
2023-08-10 09:33:58 +00:00
perl : 'Perl' ,
2023-07-24 20:44:12 +00:00
php : 'PHP' ,
python : 'Python' ,
ruby : 'Ruby' ,
rust : 'Rust' ,
swift : 'Swift' ,
terraform : 'Terraform' ,
} ;
2023-03-13 05:57:26 +00:00
export async function generateManagers (
dist : string ,
2023-11-07 15:50:29 +00:00
managerIssuesMap : OpenItems ,
2023-03-13 05:57:26 +00:00
) : Promise < void > {
2023-08-15 17:12:54 +00:00
const allManagers = [ . . . getManagers ( ) , . . . getCustomManagers ( ) ] ;
2023-03-13 05:57:26 +00:00
2023-07-04 09:41:19 +00:00
const allCategories : Record < string , string [ ] > = { } ;
2023-08-15 17:12:54 +00:00
for ( const [ manager , definition ] of allManagers ) {
2023-03-29 10:41:05 +00:00
const { defaultConfig , supportedDatasources , urls } = definition ;
2021-12-09 20:12:49 +00:00
const { fileMatch } = defaultConfig as RenovateConfig ;
const displayName = getDisplayName ( manager , definition ) ;
2023-11-29 14:08:18 +00:00
const isCustomMgr = isCustomManager ( manager ) ;
2023-07-04 09:41:19 +00:00
2023-07-24 20:44:12 +00:00
const categories = definition . categories ? ? [ noCategoryID ] ;
2023-07-04 09:41:19 +00:00
for ( const category of categories ) {
allCategories [ category ] ? ? = [ ] ;
allCategories [ category ] . push ( manager ) ;
}
2023-11-29 14:08:18 +00:00
let md = codeBlock `
-- -
title : $ { getTitle ( manager , displayName , isCustomMgr ) }
sidebar_label : $ { displayName }
edit_url : https : //github.com/renovatebot/renovate/edit/main/lib/modules/manager/${
isCustomMgr ? ` custom/ ${ manager } ` : manager
} / readme . md
-- -
` ;
md += '\n\n' ;
2023-07-04 09:41:19 +00:00
md += '**Categories**: ' ;
if ( categories . length ) {
for ( let i = 0 ; i < categories . length ; i ++ ) {
const category = categories [ i ] ;
if ( i < categories . length - 1 ) {
md += ` \` ${ category } \` , ` ;
} else {
md += ` \` ${ category } \` ` ;
}
}
}
md += '\n\n' ;
2023-11-29 14:08:18 +00:00
if ( ! isCustomMgr ) {
2021-12-09 20:12:49 +00:00
const nameWithUrl = getNameWithUrl ( manager , definition ) ;
md += ` Renovate supports updating ${ nameWithUrl } dependencies. \ n \ n ` ;
if ( defaultConfig . enabled === false ) {
md += '## Enabling\n\n' ;
2022-12-05 15:19:32 +00:00
md += ` ${ displayName } functionality is currently in beta testing, so you must opt-in to test it. To enable it, add a configuration like this to either your bot config or your \` renovate.json \` : \ n \ n ` ;
2021-12-09 20:12:49 +00:00
md += '```\n' ;
md += ` { \ n " ${ manager } ": { \ n "enabled": true \ n } \ n} ` ;
md += '\n```\n\n' ;
md +=
2022-12-05 15:19:32 +00:00
'If you find any bugs, please [create a new discussion first](https://github.com/renovatebot/renovate/discussions/new). If you find that it works well, then let us know too.\n\n' ;
2021-12-09 20:12:49 +00:00
}
md += '## File Matching\n\n' ;
if ( ! Array . isArray ( fileMatch ) || fileMatch . length === 0 ) {
md += ` Because file names for \` ${ manager } \` cannot be easily determined automatically, Renovate will not attempt to match any \` ${ manager } \` files by default. ` ;
} else {
md += ` By default, Renovate will check any files matching ` ;
if ( fileMatch . length === 1 ) {
md += ` the following regular expression: \` ${ fileMatch [ 0 ] } \` . \ n \ n ` ;
} else {
md += ` any of the following regular expressions: \ n \ n ` ;
md += '```\n' ;
md += fileMatch . join ( '\n' ) ;
md += '\n```\n\n' ;
}
}
2023-11-10 10:01:46 +00:00
md += ` For details on how to extend a manager's \` fileMatch \` value, please follow [this link](../index.md#file-matching). \ n \ n ` ;
2022-01-19 08:06:21 +00:00
md += '## Supported datasources\n\n' ;
const escapedDatasources = ( supportedDatasources || [ ] )
. map (
( datasource ) = >
2023-11-10 08:33:13 +00:00
` [ \` ${ datasource } \` ](../../datasource/ ${ datasource } /index.md) ` ,
2022-01-19 08:06:21 +00:00
)
. join ( ', ' ) ;
md += ` This manager supports extracting the following datasources: ${ escapedDatasources } . \ n \ n ` ;
2022-12-04 16:40:23 +00:00
2023-05-08 06:32:46 +00:00
if ( urls ? . length ) {
md += '## References' ;
md += formatUrls ( urls ) . replace ( '**References**:' , '' ) ;
}
2022-12-04 16:40:23 +00:00
md += '## Default config\n\n' ;
md += '```json\n' ;
md += JSON . stringify ( definition . defaultConfig , null , 2 ) + '\n' ;
md += '```\n\n' ;
2021-12-09 20:12:49 +00:00
}
const managerReadmeContent = await readFile (
2023-08-06 11:00:47 +00:00
` lib/modules/manager/ ${
2023-11-29 14:08:18 +00:00
isCustomMgr ? ` custom/ ${ manager } ` : manager
2023-11-07 15:50:29 +00:00
} / readme . md ` ,
2021-12-09 20:12:49 +00:00
) ;
2023-11-29 14:08:18 +00:00
if ( ! isCustomMgr ) {
2021-12-09 20:12:49 +00:00
md += '\n## Additional Information\n\n' ;
}
2023-03-13 05:57:26 +00:00
md += managerReadmeContent ;
2022-06-10 04:48:51 +00:00
2023-03-13 05:57:26 +00:00
md += generateFeatureAndBugMarkdown ( managerIssuesMap , manager ) ;
2022-06-10 04:48:51 +00:00
2021-12-09 20:12:49 +00:00
await updateFile ( ` ${ dist } /modules/manager/ ${ manager } /index.md ` , md ) ;
}
2023-07-04 09:41:19 +00:00
// add noCategoryDisplayName as last option
const categories = Object . keys ( allCategories ) . filter (
2023-11-07 15:50:29 +00:00
( category ) = > category !== noCategoryID ,
2021-12-09 20:12:49 +00:00
) ;
2023-07-04 09:41:19 +00:00
categories . sort ( ) ;
2023-07-24 20:44:12 +00:00
categories . push ( noCategoryID ) ;
2023-07-04 09:41:19 +00:00
let categoryText = '\n' ;
2021-12-09 20:12:49 +00:00
2023-07-24 20:44:12 +00:00
categoryText += '| Group | Category ID | Managers |\n' ;
categoryText += '| :-- | :-- | :-- |\n' ;
2023-07-04 09:41:19 +00:00
for ( const category of categories ) {
2023-07-24 20:44:12 +00:00
const managerLinkList = allCategories [ category ]
. map ( getManagerLink )
. join ( ', ' ) ;
const displayName =
CategoryNames [ category as Category ] ? ? noCategoryDisplayName ;
const massagedCategory =
category === noCategoryID ? 'n/a' : ` \` ${ category } \` ` ;
categoryText += ` | ${ displayName } | ${ massagedCategory } | ${ managerLinkList } | \ n ` ;
2021-12-09 20:12:49 +00:00
}
2023-07-24 20:44:12 +00:00
2022-12-05 11:57:57 +00:00
let indexContent = await readFile ( ` docs/usage/modules/manager/index.md ` ) ;
2023-07-04 09:41:19 +00:00
indexContent = replaceContent ( indexContent , categoryText ) ;
2022-12-05 11:57:57 +00:00
await updateFile ( ` ${ dist } /modules/manager/index.md ` , indexContent ) ;
2021-12-09 20:12:49 +00:00
}