11import * as path from "jsr:@std/path" ;
22
3- async function getAllFilesInDir ( path : string ) {
4- const files = [ ] ;
3+ async function ensureDirExists ( path : string ) {
54 try {
65 await Deno . lstat ( path ) ;
76 } catch ( error ) {
87 if ( error && error instanceof Deno . errors . NotFound ) {
98 await Deno . mkdir ( path ) ;
109 }
1110 }
11+ }
12+
13+ async function getAllFilesInDir ( path : string ) {
14+ const files = [ ] ;
15+ await ensureDirExists ( path ) ;
1216 const walker = Deno . readDir ( path ) ;
1317 for await ( const f of walker ) {
1418 files . push ( f ) ;
@@ -17,6 +21,10 @@ async function getAllFilesInDir(path: string) {
1721 return files ;
1822}
1923
24+ async function ensureAssetsDirExists ( adrdir : string ) {
25+ await ensureDirExists ( path . join ( adrdir , "assets" ) ) ;
26+ }
27+
2028async function makeNewADR (
2129 adrdir : string ,
2230 n : number ,
@@ -48,10 +56,7 @@ async function makeNewADR(
4856
4957async function rebuildReadme ( adrDirPath : string , files : Array < Deno . DirEntry > ) {
5058 files . sort ( ( a , b ) => {
51- if ( a . name . startsWith ( "README" ) ) {
52- return - 9999999 ;
53- }
54- return parseInt ( a . name . substring ( 0 , 6 ) ) - parseInt ( b . name . substring ( 0 , 6 ) ) ;
59+ return parseInt ( a . name . substring ( 0 , 5 ) ) - parseInt ( b . name . substring ( 0 , 5 ) ) ;
5560 } ) ;
5661 await Deno . writeTextFile (
5762 path . join ( adrDirPath , "README.md" ) ,
@@ -67,7 +72,7 @@ If you need to regenerate this readme without creating a new ADR, please use \`a
6772## Contents
6873
6974${
70- files . filter ( ( f ) => f . isFile ) . map ( ( f ) => {
75+ files . filter ( ( f ) => f . isFile && ! f . name . startsWith ( "README" ) ) . map ( ( f ) => {
7176 const noExt = f . name . substring ( 0 , f . name . lastIndexOf ( "." ) ) ;
7277 return `- [${ noExt } ](./${ f . name } )` ;
7378 } ) . join ( "\n" )
@@ -87,6 +92,7 @@ if (import.meta.main) {
8792 }
8893
8994 const files = await getAllFilesInDir ( adrdir ) ;
95+ await ensureAssetsDirExists ( adrdir ) ;
9096 const adrsOnly = files . filter ( ( f ) => / ^ \d { 5 } - .* $ / . test ( f . name ) ) ;
9197 const action = Deno . args [ 0 ] ;
9298
0 commit comments