Skip to content

Commit dbd5767

Browse files
committed
support an assets dir
1 parent 3c0e422 commit dbd5767

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# 00001 - Support an assets folder
2+
3+
## Abstract
4+
5+
Adding an assets folder to the `adr` directory would help organize assets, but we don't
6+
want those to be included in the auto-incrementation of the ADRs or be included in the README.
7+
8+
## Context and Problem Statement
9+
10+
A lot of ADRs have assets associated with them and users need a place to store those assets, ideally alongside the ADRs.
11+
12+
## Considered Options
13+
14+
- Store the assets in the same `adr` directory.
15+
- Store the assets in a subdirectory
16+
- Store the assets in a dot-subdirectory.
17+
18+
## Decision Outcome
19+
20+
Store the assets in a subdirectory
21+
22+
<!-- Add additional information here, comparison of options, research, etc -->
23+

adr/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ If you need to regenerate this readme without creating a new ADR, please use `ad
99

1010
## Contents
1111

12-
- [README](./README.md)
12+
- [00001-Support-an-assets-folder](./00001-Support-an-assets-folder.md)
1313
- [00000-Use-Deno](./00000-Use-Deno.md)
1414

15-
Last generated 2024-11-16T17:08:26.792Z
15+
Last generated 2024-11-20T23:37:05.656Z

main.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import * 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+
2028
async function makeNewADR(
2129
adrdir: string,
2230
n: number,
@@ -48,10 +56,7 @@ async function makeNewADR(
4856

4957
async 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

Comments
 (0)