|
| 1 | +export async function fetchResumeJson() { |
| 2 | + const os = await import('node:os'); |
| 3 | + const fs = await import('node:fs/promises'); |
| 4 | + const path = await import('node:path'); |
| 5 | + const useTailoredResume = |
| 6 | + process.env['VITE_IS_TAILORED_RESUME'] === 'true' ? true : false; |
| 7 | + const resumeSource = |
| 8 | + process.env['VITE_RESUME_SOURCE'] || |
| 9 | + 'https://neviaumi.github.io/portfolio/resume.json'; |
| 10 | + if (useTailoredResume) { |
| 11 | + return fs |
| 12 | + .readFile(path.join(os.tmpdir(), resumeSource), { |
| 13 | + encoding: 'utf8', |
| 14 | + }) |
| 15 | + .then(JSON.parse); |
| 16 | + } |
| 17 | + return fetch(resumeSource).then(res => res.json()); |
| 18 | +} |
| 19 | + |
1 | 20 | export function resumeToLatex(resume) {
|
2 | 21 | function escapes(source) {
|
3 | 22 | return source.replaceAll('&', '\\&');
|
@@ -121,37 +140,23 @@ ${education.map(edu => ` \\item[-] ${edu.studyType} in ${edu.area}, ${edu
|
121 | 140 | \\end{document}`;
|
122 | 141 | }
|
123 | 142 |
|
124 |
| -async function fetchResumeJson() { |
125 |
| - const os = await import('node:os'); |
126 |
| - const fs = await import('node:fs/promises'); |
127 |
| - const path = await import('node:path'); |
128 |
| - const useTailoredResume = |
129 |
| - process.env['VITE_IS_TAILORED_RESUME'] === 'true' ? true : false; |
130 |
| - const resumeSource = |
131 |
| - process.env['VITE_RESUME_SOURCE'] || |
132 |
| - 'https://neviaumi.github.io/portfolio/resume.json'; |
133 |
| - if (useTailoredResume) { |
134 |
| - return fs |
135 |
| - .readFile(path.join(os.tmpdir(), resumeSource), { |
136 |
| - encoding: 'utf8', |
137 |
| - }) |
138 |
| - .then(JSON.parse); |
139 |
| - } |
140 |
| - return fetch(resumeSource).then(res => res.json()); |
| 143 | +const isMainExecution = |
| 144 | + import.meta.url === new URL(process.argv[1], 'file://').toString(); |
| 145 | +if (isMainExecution) { |
| 146 | + fetchResumeJson() |
| 147 | + .then(resumeToLatex) |
| 148 | + .then(async latexText => { |
| 149 | + const workspace = await import('./workspace.js'); |
| 150 | + const fs = await import('node:fs/promises'); |
| 151 | + const fileName = await (async () => { |
| 152 | + const useTailoredResume = process.env['VITE_IS_TAILORED_RESUME'] |
| 153 | + ? true |
| 154 | + : false; |
| 155 | + if (!useTailoredResume) return 'resume.tex'; |
| 156 | + const resumeJson = await fetchResumeJson(); |
| 157 | + return resumeJson.meta.id + '.tex'; |
| 158 | + })(); |
| 159 | + await fs.writeFile(`${workspace.PUBLIC_FOLDER}/${fileName}`, latexText); |
| 160 | + return latexText; |
| 161 | + }); |
141 | 162 | }
|
142 |
| -fetchResumeJson() |
143 |
| - .then(resumeToLatex) |
144 |
| - .then(async latexText => { |
145 |
| - const workspace = await import('./workspace.js'); |
146 |
| - const fs = await import('node:fs/promises'); |
147 |
| - const fileName = await (async () => { |
148 |
| - const useTailoredResume = process.env['VITE_IS_TAILORED_RESUME'] |
149 |
| - ? true |
150 |
| - : false; |
151 |
| - if (!useTailoredResume) return 'resume.tex'; |
152 |
| - const resumeJson = await fetchResumeJson(); |
153 |
| - return resumeJson.meta.id + '.tex'; |
154 |
| - })(); |
155 |
| - await fs.writeFile(`${workspace.PUBLIC_FOLDER}/${fileName}`, latexText); |
156 |
| - return latexText; |
157 |
| - }); |
|
0 commit comments