-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater.js
92 lines (81 loc) · 3.18 KB
/
updater.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
import { readFileSync, writeFileSync } from 'fs';
import handlebars from 'handlebars';
import GithubUser from './src/github.js';
import SVGO from 'svgo'; // 🔶
// import nunjucks from 'nunjucks';
//* nunjucks.configure({ autoescape: true });
// import { networkInterfaces } from 'os';
// console.log("✅ networkInterfaces:", networkInterfaces)
// console.log("✅ process.env:", process.env)
// console.log("✅ process.argv:", process.argv)
console.log("✅ process.env.CI:", process.env.CI)
const args = process.argv.slice(2); //🔶 Remove node and script paths
const argSvgo = String(args.includes('-svgo'));
const useSvgo = argSvgo ? argSvgo : ''; //
console.info("✅ useSvgo:", useSvgo)
let username = process.argv[2];
let user = new GithubUser(username);
let templateOverview = readFileSync("templates/overview.svg", 'utf-8');
let templateLanguages = readFileSync("templates/languages.svg", 'utf-8');
user.fetchContent()
.then(() => {
let overviewTemplate = handlebars.compile(templateOverview);
let overviewString = overviewTemplate({ data: user })
// Optimize overview SVG
if (useSvgo === 'true') {
overviewString = SVGO.optimize(overviewString, {
path: './generated/overview.svg', // For debugging, optional
multipass: true,
plugins: [
'convertStyleToAttrs',
'minifyStyles',
'convertColors',
'removeUselessStrokeAndFill',
'collapseGroups',
'reusePaths',
'convertTransform',
'removeEmptyContainers',
'removeDeprecatedAttrs',
'convertTransform',
'sortAttrs'
]
}).data;
}
writeFileSync("./generated/overview.svg", overviewString);
let languageTemplate = handlebars.compile(templateLanguages);
let languageString = languageTemplate({ data: user });
// Modify the language SVG string directly
languageString = languageString
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/=/g, "=")
.replace(/"/g, '"');
// Optimize languages SVG
if (useSvgo === 'true') {
languageString = SVGO.optimize(languageString, {
path: './generated/languages.svg', // For debugging, optional
multipass: true,
plugins: [
'minifyStyles',
'convertColors',
'removeUselessStrokeAndFill',
'collapseGroups',
'reusePaths',
'convertTransform',
'removeEmptyContainers',
'removeDeprecatedAttrs',
'convertTransform',
'sortAttrs'
]
}).data;
}
writeFileSync('./generated/languages.svg', languageString);
})
.catch((error) => {
console.error("Error fetching content:", error);
});
/*
let overviewString = nunjucks.renderString(templateOverview, {
data: user
});
*/