vueless
Version:
Vue Styleless UI Component Library, powered by Tailwind CSS.
67 lines (53 loc) • 2.31 kB
JavaScript
import path from "node:path";
import { cwd } from "node:process";
import { existsSync, promises as fsPromises } from "node:fs";
import { vuelessConfig } from "./vuelessConfig.js";
import { COMPONENTS, VUELESS_DIR, VUELESS_LOCAL_DIR, STORYBOOK_DIR } from "../../constants.js";
export async function hideHiddenStories(isVuelessEnv) {
const srcDir = isVuelessEnv ? VUELESS_LOCAL_DIR : VUELESS_DIR;
for await (const [componentName, componentDir] of Object.entries(COMPONENTS)) {
const componentGlobalConfig = vuelessConfig.components?.[componentName];
const isHiddenStories = componentGlobalConfig && componentGlobalConfig.storybook === false;
if (isHiddenStories) {
await hideComponentStories(path.join(cwd(), srcDir, componentDir, STORYBOOK_DIR));
}
}
}
export async function showHiddenStories(isVuelessEnv) {
if (typeof window !== "undefined") return;
const srcDir = isVuelessEnv ? VUELESS_LOCAL_DIR : VUELESS_DIR;
for await (const componentDir of Object.values(COMPONENTS)) {
await showComponentStories(path.join(cwd(), srcDir, componentDir, STORYBOOK_DIR));
}
}
async function hideComponentStories(storybookPath) {
if (existsSync(storybookPath)) {
const storyFiles = await fsPromises.readdir(storybookPath);
const visibleFiles = storyFiles.filter((storybookFile) => !storybookFile.includes("hidden"));
await Promise.all(
visibleFiles.map((storybookFile) => {
const [fileName, extension] = storybookFile.split(".");
return fsPromises.rename(
path.join(storybookPath, storybookFile),
path.join(storybookPath, `${fileName}_hidden.${extension}`),
);
}),
);
}
}
async function showComponentStories(storybookPath) {
if (existsSync(storybookPath)) {
const storyFiles = await fsPromises.readdir(storybookPath);
const hiddenFiles = storyFiles.filter((storybookFile) => storybookFile.includes("hidden"));
await Promise.all(
hiddenFiles.map((storybookFile) => {
const [fileName, extension] = storybookFile.split(".");
const [originalFileName] = fileName.split("_");
return fsPromises.rename(
path.join(storybookPath, storybookFile),
path.join(storybookPath, `${originalFileName}.${extension}`),
);
}),
);
}
}