-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.mjs
71 lines (62 loc) · 1.96 KB
/
setup.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { promises as fs } from 'fs';
import path from 'path';
import dotenv from 'dotenv';
const template = `---
title: 'Hello, World!'
publishedAt: '2023-01-01'
summary: 'This is your first blog post.'
---
Hello, World!`;
const homePage = `export default function Page() {
return (
<section>
<h1 className="font-medium text-2xl mb-8 tracking-tighter">my portfolio</h1>
<p className="prose prose-neutral dark:prose-invert">
This is your new portfolio.
</p>
</section>
);
}
`;
const workPage = `export default function Page() {
return (
<section>
<h1 className="font-medium text-2xl mb-8 tracking-tighter">my work</h1>
<p className="prose prose-neutral dark:prose-invert">
This is where your work experience goes.
</p>
</section>
);
}
`;
const deleteFolderRecursive = async (path) => {
const stat = await fs.stat(path);
if (stat.isDirectory()) {
const files = await fs.readdir(path);
await Promise.all(
files.map((file) => deleteFolderRecursive(`${path}/${file}`))
);
await fs.rmdir(path);
} else {
await fs.unlink(path);
}
};
(async () => {
dotenv.config();
if (process.env.IS_TEMPLATE === 'false') {
// This means it's not the template, it's my legit site
// I orderride the env variable for my site. This means that when
// folks clone this repo for the first time, it will delete my personal content
return;
}
const contentDir = path.join(process.cwd(), 'content');
const imagesDir = path.join(process.cwd(), 'public', 'images');
const appDir = path.join(process.cwd(), 'app');
const workDir = path.join(process.cwd(), 'app', 'work');
await deleteFolderRecursive(contentDir);
await deleteFolderRecursive(imagesDir);
await fs.mkdir(contentDir);
await fs.writeFile(path.join(contentDir, 'hello-world.mdx'), template);
await fs.writeFile(path.join(appDir, 'page.tsx'), homePage);
await fs.writeFile(path.join(workDir, 'page.tsx'), workPage);
})();