1
- console . log ( ' Starting' ) ;
1
+ console . log ( " Starting" ) ;
2
2
3
3
console . log ( `meta path: ${ import . meta. path } ` ) ;
4
4
console . log ( `meta dir: ${ import . meta. dir } ` ) ;
@@ -8,72 +8,74 @@ console.log(`Bun.env.PWD: ${Bun.env.PWD}`);
8
8
// https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
9
9
10
10
// import { $ } from 'bun';
11
- import { readdir } from 'node:fs/promises' ;
12
- import { urls , automatic , manual } from './commands.ts' ;
13
-
14
- const branches = {
15
- sdxl : {
16
- name : 'Stable Diffusion XL' ,
17
- } ,
18
- pdxl : {
19
- name : 'Pony Diffusion XL' ,
20
- } ,
21
- } ;
11
+ import { readdir } from "node:fs/promises" ;
12
+ import { join } from "node:path" ;
13
+ import { automatic , manual , urls } from "./commands.ts" ;
14
+
15
+ // const branches = {
16
+ // sdxl: {
17
+ // name: "Stable Diffusion XL",
18
+ // },
19
+ // pdxl: {
20
+ // name: "Pony Diffusion XL",
21
+ // },
22
+ // };
22
23
23
24
// if (!Bun.env.GITHUB_REPOSITORY || !Bun.env.GITHUB_REF_NAME || !Bun.env.GITHUB_API_URL) {
24
25
// console.log('This script must be run in a GitHub Action environment');
25
26
// process.exit(1);
26
27
// }
27
28
28
- const repoOwner = Bun . env . GITHUB_REPOSITORY ?. split ( '/' ) [ 0 ] ;
29
- const repoName = Bun . env . GITHUB_REPOSITORY ?. split ( '/' ) [ 1 ] ;
30
- const branchName = Bun . env . GITHUB_REF_NAME || ' sdxl' ;
31
- const apiURL = Bun . env . GITHUB_API_URL ;
29
+ const repoOwner = Bun . env . GITHUB_REPOSITORY ?. split ( "/" ) [ 0 ] ;
30
+ const repoName = Bun . env . GITHUB_REPOSITORY ?. split ( "/" ) [ 1 ] ;
31
+ const branchName = Bun . env . GITHUB_REF_NAME || " sdxl" ;
32
+ // const apiURL = Bun.env.GITHUB_API_URL;
32
33
const rawUrl = `https://raw.githubusercontent.com/${ repoOwner } /${ repoName } /${ branchName } /wildcards/` ;
33
34
const archiveUrl = `https://github.com/${ repoOwner } /${ repoName } /releases/latest/download/${ repoName } -${ branchName } .zip` ;
34
35
35
36
const path = Bun . env . GITHUB_REPOSITORY ? Bun . env . PWD : import . meta. dir ;
36
37
37
38
const wildcards = await readdir ( `${ path } /wildcards` ) ;
38
- const sanitizedUrl = rawUrl . endsWith ( '/' ) ? rawUrl . slice ( 0 , - 1 ) : rawUrl ;
39
- const filesList = `${ wildcards . map ( ( w ) => `- [${ w . split ( '.' ) [ 0 ] } ](${ sanitizedUrl } /${ w } )\n` ) . join ( '' ) } \n` ;
39
+ const sanitizedUrl = rawUrl . endsWith ( "/" ) ? rawUrl . slice ( 0 , - 1 ) : rawUrl ;
40
+ const filesList = `${ wildcards . map ( ( w ) => `- [${ w . split ( "." ) [ 0 ] } ](${ sanitizedUrl } /${ w } )\n` ) . join ( "" ) } \n` ;
40
41
41
42
const downloadMethod = ( method : { type : string ; tools : string [ ] ; commands : string [ ] } ) => {
42
- const header = `### Download${ method . type === 'automatic' ? ' automatically' : '' } with ${ method . tools . map ( ( tool ) => `[${ tool . toUpperCase ( ) } ](${ urls [ tool ] } )` ) . join ( ' and ' ) } \n\n` ;
43
- const code = `\`\`\`bash\n${ method . commands . join ( ' && ' ) } \n\`\`\`\n` ;
43
+ const header = `### Download${ method . type === "automatic" ? " automatically" : "" } with ${
44
+ method . tools . map ( ( tool ) => `[${ tool . toUpperCase ( ) } ](${ urls [ tool ] } )` ) . join ( " and " )
45
+ } \n\n`;
46
+ const code = `\`\`\`bash\n${ method . commands . join ( " && " ) } \n\`\`\`\n` ;
44
47
45
48
return header + code ;
46
49
} ;
47
50
48
51
const wrapInDetails = ( content : string ) => {
49
- const parts = content . split ( ' ###' ) ;
52
+ const parts = content . split ( " ###" ) ;
50
53
if ( parts . length < 3 ) return content ;
51
54
52
55
return (
53
56
parts [ 0 ] +
54
- ' ###' +
57
+ " ###" +
55
58
parts [ 1 ] +
56
- ' <details>\n<summary>Show more commands</summary>\n\n###' +
57
- parts . slice ( 2 ) . join ( ' ###' ) +
58
- ' \n\nYou can find more ways to download the wildcards in [DOWNLOAD.md](docs/DOWNLOAD.md) file.\n\n</details>'
59
+ " <details>\n<summary>Show more commands</summary>\n\n###" +
60
+ parts . slice ( 2 ) . join ( " ###" ) +
61
+ " \n\nYou can find more ways to download the wildcards in [DOWNLOAD.md](docs/DOWNLOAD.md) file.\n\n</details>"
59
62
) ;
60
63
} ;
61
64
62
65
// I need to use \\s in the middle of the regex because with one slash prettier removes it
63
- const emptyLinesInMarkdownLists = new RegExp ( ' (?<=^- .*\n)\\s*\n(?=- )' , 'gm' ) ;
66
+ const emptyLinesInMarkdownLists = new RegExp ( " (?<=^- .*\n)\\s*\n(?=- )" , "gm" ) ;
64
67
65
68
const replaceNonBranchContent = ( content : string ) => {
66
- const commentRegex = new RegExp ( '<!--[^]*?-->' , 'gm' ) ;
67
69
const regex = new RegExp (
68
- `<!--\\s*(?! ${ branchName } )(\\w+)\\s* -->([\\s\\S] *?)<!--\\s*/\\1\\s* -->` ,
69
- 'gm' ,
70
+ `<!-- ${ branchName } -->(. *?)<!-- \/ ${ branchName } -->` ,
71
+ "gms" ,
70
72
) ;
71
- return content . replace ( regex , '' ) . replace ( commentRegex , '' ) ;
73
+ return content . replace ( regex , "" ) . replace ( / \n { 2 , } / g , "\n" ) ;
72
74
} ;
73
75
74
- const automaticMethods = automatic . map ( ( m ) => downloadMethod ( m ) ) . join ( '\n' ) ;
76
+ const automaticMethods = automatic . map ( ( m ) => downloadMethod ( m ) ) . join ( "\n" ) ;
75
77
76
- const manualMethods = manual . map ( ( m ) => downloadMethod ( m ) ) . join ( '\n' ) ;
78
+ const manualMethods = manual . map ( ( m ) => downloadMethod ( m ) ) . join ( "\n" ) ;
77
79
78
80
const docsFiles = await readdir ( `${ path } /src` ) ;
79
81
@@ -84,25 +86,25 @@ docsFiles.forEach(async (file) => {
84
86
85
87
let processedAutomaticMethods = automaticMethods ;
86
88
87
- if ( file === ' README.md' ) {
89
+ if ( file === " README.md" ) {
88
90
processedAutomaticMethods = wrapInDetails ( automaticMethods ) ;
89
91
}
90
92
91
93
const processed = content
92
- . replaceAll ( ' {{filesList}}' , filesList )
93
- . replaceAll ( ' {{archiveUrl}}' , archiveUrl )
94
- . replaceAll ( ' {{branch}}' , branchName )
95
- . replaceAll ( ' {{automaticMethods}}' , processedAutomaticMethods )
96
- . replaceAll ( ' {{manualMethods}}' , manualMethods )
97
- . replaceAll ( ' {{amount}}' , wildcards . length . toString ( ) )
98
- . replace ( emptyLinesInMarkdownLists , '' )
99
- . replace ( / ^ \n { 2 , } / gm, '\n' ) ;
100
-
101
- if ( file === ' README.md' ) {
94
+ . replaceAll ( " {{filesList}}" , filesList )
95
+ . replaceAll ( " {{archiveUrl}}" , archiveUrl )
96
+ . replaceAll ( " {{branch}}" , branchName )
97
+ . replaceAll ( " {{automaticMethods}}" , processedAutomaticMethods )
98
+ . replaceAll ( " {{manualMethods}}" , manualMethods )
99
+ . replaceAll ( " {{amount}}" , wildcards . length . toString ( ) )
100
+ . replace ( emptyLinesInMarkdownLists , "" )
101
+ . replace ( / ^ \n { 2 , } / gm, "\n" ) ;
102
+
103
+ if ( file === " README.md" ) {
102
104
await Bun . write ( `${ path } /${ file } ` , processed ) ;
103
105
} else {
104
106
await Bun . write ( `${ path } /docs/${ file } ` , processed ) ;
105
107
}
106
108
} ) ;
107
109
108
- console . log ( ' Done' ) ;
110
+ console . log ( " Done" ) ;
0 commit comments