Skip to content

Commit 22511e4

Browse files
committed
feat: make web folder in script
1 parent 9bd39c8 commit 22511e4

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "The Codebreeze website",
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1",
7-
"build": "npx tsc && mkdir -p web && node dist/fetch-contents-from-trello.js"
7+
"build": "node dist/render-website.js",
8+
"postinstall": "npx tsc"
89
},
910
"repository": {
1011
"type": "git",
@@ -57,5 +58,9 @@
5758
"tslint --project ./tsconfig.json --fix",
5859
"git add"
5960
]
61+
},
62+
"engines": {
63+
"node": ">=10.0.0",
64+
"npm": ">=6.0.0"
6065
}
6166
}

src/fetch-contents-from-trello.ts renamed to src/render-website.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const apiKey = process.env.API_KEY!;
1010
const apiToken = process.env.API_TOKEN!;
1111
const websiteContentList = process.env.WEBSITE_CONTENT_LIST!;
1212

13+
const srcDir = path.join(__dirname, '..', 'src');
14+
const webDir = path.join(__dirname, '..', 'web');
15+
1316
const fetchContentFromTrello = async () => {
1417
const cards = await trelloApi({ apiKey, apiToken }).lists.cards({
1518
list: websiteContentList,
@@ -23,11 +26,14 @@ fetchContentFromTrello()
2326
)
2427
.then(content => new showdown.Converter().makeHtml(content))
2528
.then(async contentAsMarkdown => {
26-
const tpl = await fs.readFile(
27-
path.join(__dirname, '..', 'src', 'index.html'),
28-
'utf-8',
29-
);
30-
const targetFile = path.join(__dirname, '..', 'web', 'index.html');
29+
try {
30+
await fs.stat(webDir);
31+
} catch {
32+
await fs.mkdir(webDir);
33+
}
34+
35+
const tpl = await fs.readFile(path.join(srcDir, 'index.html'), 'utf-8');
36+
const targetFile = path.join(webDir, 'index.html');
3137
await fs.writeFile(
3238
targetFile,
3339
tpl.replace('{{content}}', contentAsMarkdown),

0 commit comments

Comments
 (0)