mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-02 22:59:31 +08:00
66 lines
1.7 KiB
Text
66 lines
1.7 KiB
Text
import path__default from 'path';
|
|
import { $ } from './index.js';
|
|
import 'url';
|
|
|
|
/**
|
|
* Get the prefix for the `runtime` directory, for use with import declarations
|
|
* @param {import('types').ValidatedKitConfig} config
|
|
*/
|
|
function get_runtime_prefix(config) {
|
|
{
|
|
return posixify_path(path__default.join(config.outDir, 'runtime'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the resolved path of the `runtime` directory
|
|
* @param {import('types').ValidatedKitConfig} config
|
|
*/
|
|
function get_runtime_directory(config) {
|
|
{
|
|
return path__default.join(config.outDir, 'runtime');
|
|
}
|
|
}
|
|
|
|
/** @param {string} str */
|
|
function posixify_path(str) {
|
|
const parsed = path__default.parse(str);
|
|
return `/${parsed.dir.slice(parsed.root.length).split(path__default.sep).join('/')}/${parsed.base}`;
|
|
}
|
|
|
|
function noop() {}
|
|
|
|
/** @param {{ verbose: boolean }} opts */
|
|
function logger({ verbose }) {
|
|
/** @type {import('types').Logger} */
|
|
const log = (msg) => console.log(msg.replace(/^/gm, ' '));
|
|
|
|
/** @param {string} msg */
|
|
const err = (msg) => console.error(msg.replace(/^/gm, ' '));
|
|
|
|
log.success = (msg) => log($.green(`✔ ${msg}`));
|
|
log.error = (msg) => err($.bold().red(msg));
|
|
log.warn = (msg) => log($.bold().yellow(msg));
|
|
|
|
log.minor = verbose ? (msg) => log($.grey(msg)) : noop;
|
|
log.info = verbose ? log : noop;
|
|
|
|
return log;
|
|
}
|
|
|
|
/** @param {import('types').ManifestData} manifest_data */
|
|
function get_mime_lookup(manifest_data) {
|
|
/** @type {Record<string, string>} */
|
|
const mime = {};
|
|
|
|
manifest_data.assets.forEach((asset) => {
|
|
if (asset.type) {
|
|
const ext = path__default.extname(asset.file);
|
|
mime[ext] = asset.type;
|
|
}
|
|
});
|
|
|
|
return mime;
|
|
}
|
|
|
|
export { get_runtime_prefix as a, get_mime_lookup as b, get_runtime_directory as g, logger as l };
|