@hv/celestial
Version:
A styleguide for documenting your Astro-components
63 lines (62 loc) • 2.52 kB
JavaScript
import path from "node:path";
import { copy, outputFile } from "fs-extra";
import { getConfig } from "./config.js";
import { CELESTIAL_DIR, CELESTIAL_TMP_SUBDIR, ORIG_DIR, STYLEGUIDE_DIR, STYLEGUIDE_LAYOUT_DIR, STYLEGUIDE_SRC_DIR } from "./constants.js";
import { layoutMainTemplate } from "../templates/LayoutMain.template.js";
export function copyStaticFiles() {
const sourcePath = path.join(CELESTIAL_DIR, 'static');
const targetPath = STYLEGUIDE_SRC_DIR;
return new Promise(resolve => {
copy(sourcePath, targetPath, () => resolve());
});
}
export async function copyAdditionalFilesAndFolders() {
const config = getConfig();
if (!config.copyAdditional) {
return;
}
const folders = Array.isArray(config.copyAdditional) ? config.copyAdditional : [config.copyAdditional];
const promises = folders.map(folderName => {
const sourcePath = path.join(ORIG_DIR, folderName);
const targetPath = path.join(CELESTIAL_TMP_SUBDIR, folderName);
return new Promise(resolve => {
copy(sourcePath, targetPath, () => resolve());
});
});
return Promise.all(promises);
}
export function copyPublicFiles() {
// TODO: read custom path from astro config
const sourcePath = path.join(ORIG_DIR, 'public');
const targetPath = path.join(CELESTIAL_TMP_SUBDIR, 'public');
return new Promise(resolve => {
copy(sourcePath, targetPath, () => resolve());
});
}
export function generateLayoutMain() {
const template = layoutMainTemplate();
const fileName = path.join(STYLEGUIDE_LAYOUT_DIR, 'LayoutMain.astro');
return new Promise(resolve => {
outputFile(fileName, template, () => resolve());
});
}
export function generateAstroConfig() {
const config = getConfig();
// TODO: auto-guess config extension / make name configurable
const importPath = path.relative(STYLEGUIDE_DIR, path.join(ORIG_DIR, config.astroConfig || 'astro.config.mjs'));
const outputFileName = path.join(STYLEGUIDE_DIR, 'astro.config.mjs');
const template = `import { defineConfig } from 'astro/config';
import originalConfig from '${importPath}';
export default defineConfig({
...originalConfig,
output: 'static',
outDir: '../${config.outDir}',
cacheDir: './.cache',
server: { port: ${config.port} },
devToolbar: { enabled: false }
});`;
return new Promise(resolve => {
outputFile(outputFileName, template, () => resolve());
});
}
//# sourceMappingURL=setup.js.map