mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.1 KiB
72 lines
2.1 KiB
2 years ago
|
#!/usr/bin/env node
|
||
4 years ago
|
import fastGlob from 'fast-glob';
|
||
3 years ago
|
import {optimize} from 'svgo';
|
||
2 years ago
|
import {parse} from 'node:path';
|
||
|
import {readFile, writeFile, mkdir} from 'node:fs/promises';
|
||
|
import {fileURLToPath} from 'node:url';
|
||
9 months ago
|
import {exit} from 'node:process';
|
||
4 years ago
|
|
||
2 years ago
|
const glob = (pattern) => fastGlob.sync(pattern, {
|
||
|
cwd: fileURLToPath(new URL('..', import.meta.url)),
|
||
|
absolute: true,
|
||
|
});
|
||
4 years ago
|
|
||
9 months ago
|
function doExit(err) {
|
||
4 years ago
|
if (err) console.error(err);
|
||
9 months ago
|
exit(err ? 1 : 0);
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
async function processFile(file, {prefix, fullName} = {}) {
|
||
|
let name;
|
||
|
if (fullName) {
|
||
|
name = fullName;
|
||
|
} else {
|
||
|
name = parse(file).name;
|
||
|
if (prefix) name = `${prefix}-${name}`;
|
||
|
if (prefix === 'octicon') name = name.replace(/-[0-9]+$/, ''); // chop of '-16' on octicons
|
||
|
}
|
||
4 years ago
|
|
||
2 years ago
|
// Set the `xmlns` attribute so that the files are displayable in standalone documents
|
||
|
// The svg backend module will strip the attribute during startup for inline display
|
||
4 years ago
|
const {data} = optimize(await readFile(file, 'utf8'), {
|
||
3 years ago
|
plugins: [
|
||
|
{name: 'preset-default'},
|
||
|
{name: 'removeDimensions'},
|
||
3 years ago
|
{name: 'prefixIds', params: {prefix: () => name}},
|
||
3 years ago
|
{name: 'addClassesToSVGElement', params: {classNames: ['svg', name]}},
|
||
2 years ago
|
{
|
||
|
name: 'addAttributesToSVGElement', params: {
|
||
|
attributes: [
|
||
|
{'xmlns': 'http://www.w3.org/2000/svg'},
|
||
|
{'width': '16'}, {'height': '16'}, {'aria-hidden': 'true'},
|
||
|
]
|
||
|
}
|
||
|
},
|
||
3 years ago
|
],
|
||
4 years ago
|
});
|
||
2 years ago
|
|
||
1 year ago
|
await writeFile(fileURLToPath(new URL(`../public/assets/img/svg/${name}.svg`, import.meta.url)), data);
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
function processFiles(pattern, opts) {
|
||
|
return glob(pattern).map((file) => processFile(file, opts));
|
||
|
}
|
||
|
|
||
4 years ago
|
async function main() {
|
||
|
try {
|
||
1 year ago
|
await mkdir(fileURLToPath(new URL('../public/assets/img/svg', import.meta.url)), {recursive: true});
|
||
4 years ago
|
} catch {}
|
||
|
|
||
4 years ago
|
await Promise.all([
|
||
2 years ago
|
...processFiles('node_modules/@primer/octicons/build/svg/*-16.svg', {prefix: 'octicon'}),
|
||
|
...processFiles('web_src/svg/*.svg'),
|
||
1 year ago
|
...processFiles('public/assets/img/gitea.svg', {fullName: 'gitea-gitea'}),
|
||
4 years ago
|
]);
|
||
4 years ago
|
}
|
||
|
|
||
9 months ago
|
try {
|
||
9 months ago
|
doExit(await main());
|
||
9 months ago
|
} catch (err) {
|
||
9 months ago
|
doExit(err);
|
||
9 months ago
|
}
|