This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
114 lines (100 loc) · 3.23 KB
/
build.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { resolve, join, dirname } from "path";
import { fileURLToPath } from "url";
import handlebars from "handlebars";
import fs from "fs-extra";
import { updateHTML } from "./populate.js";
import { getConfig, outDir } from "./utils.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const assetDir = resolve(`${__dirname}/assets/`);
const config = join(outDir, "config.json");
/**
* Creates the stylesheet used by the site from a template stylesheet.
*
* Theme styles are added to the new stylesheet depending on command line
* arguments.
*/
async function populateCSS({
theme = "light",
background = "https://source.unsplash.com/1280x720/?wallpaper",
} = {}) {
// Get the theme the user requests. Defaults to 'light'
theme = `${theme}.css`;
const template = resolve(assetDir, "index.css");
const stylesheet = join(outDir, "index.css");
try {
await fs.access(outDir, fs.constants.F_OK);
} catch (error) {
await fs.mkdir(outDir);
}
// Copy over the template CSS stylesheet
await fs.copyFile(template, stylesheet);
// Get an array of every available theme
const themes = await fs.readdir(join(assetDir, "themes"));
if (!themes.includes(theme)) {
console.error('Error: Requested theme not found. Defaulting to "light".');
theme = "light";
}
// Read in the theme stylesheet
let themeSource = fs.readFileSync(join(assetDir, "themes", theme));
themeSource = themeSource.toString("utf-8");
const themeTemplate = handlebars.compile(themeSource);
const styles = themeTemplate({
background: `${background}`,
});
// Add the user-specified styles to the new stylesheet
await fs.appendFile(stylesheet, styles);
// Update the config file with the user's theme choice
const data = await getConfig();
data[0].theme = theme;
await fs.writeFile(config, JSON.stringify(data, null, " "));
}
async function populateConfig(opts) {
const data = await getConfig();
Object.assign(data[0], opts);
await fs.writeFile(config, JSON.stringify(data, null, " "));
}
async function buildCommand(username, program) {
await populateCSS(program);
let types;
if (!program.include || !program.include.length) {
types = ["all"];
} else {
types = program.include;
}
const opts = {
sort: program.sort,
order: program.order,
includeFork: Boolean(program.fork),
types,
codepen: program.codepen,
dev: program.dev,
discord: program.discord,
dribbble: program.dribbble,
email: program.email,
facebook: program.facebook,
gradient: program.gradient,
initials: program.initials,
instagram: program.instagram,
keybase: program.keybase,
linkedin: program.linkedin,
medium: program.medium,
paypal: program.paypal,
pinterest: program.pinterest,
reddit: program.reddit,
snapchat: program.snapchat,
stackexchange: program.stackexchange,
steam: program.steam,
telegram: program.telegram,
threads: program.threads,
tvtime: program.tvtime,
tumblr: program.tumblr,
twitch: program.twitch,
x: program.x,
xda: program.xda,
youtube: program.youtube,
};
await populateConfig(opts);
updateHTML(("%s", username), opts);
}
export { buildCommand, populateCSS, populateConfig };