ry-blocks/.storybook/purescript-indexer-ts.ts
Mark Eibes 8049bd80dc
rip (#4)
* Port Storybook

* Remove extrablatt

* Improve cluster

* Magic Johnson

* Remove mentions of Plumage

And delete some unnecessary stuff

* Hä

* I have changed the code files

* Reexports for typeahead

* Bring Select back

* Fix dark mode of select

* Move out react-aria

* Export select properly

* Make select work I guess
2022-11-25 13:38:19 +01:00

28 lines
1.3 KiB
TypeScript

import { promises } from "fs"
import { loadCsf, CsfFile, CsfOptions } from '@storybook/csf-tools';
export const adjustSourceForStorybook = (source: string): string => {
// regex for var $$default = unsafeCoerce({ ... })
// we need to remove the unsafeCoerce part so that the parser can read
// the info about the story
const defaultVariableRecordRegex = /^var \$\$default =[^\{]+\{((?:.*\n)+?)(^\}\);)/gm;
// $ has a special meaning so to produce two dollar signs we need $$$$
const replacement = "var $$$$default = { $1 };";
return source.replace(defaultVariableRecordRegex, replacement);
}
export const justLoad = async (fileName: string, opts: CsfOptions): Promise<string> => {
const fileContent: string = await promises.readFile(fileName, 'utf-8');
const fixedFileContent: string = adjustSourceForStorybook(fileContent);
return fixedFileContent;
}
export const indexer = async (fileName: string, opts: CsfOptions): Promise<CsfFile> => {
console.log("File name: ", fileName);
const fileContent: string = await promises.readFile(fileName, 'utf-8');
const fixedFileContent: string = adjustSourceForStorybook(fileContent);
const parseResult: CsfFile = loadCsf(fixedFileContent, { ...opts, fileName }).parse();
parseResult._stories
return parseResult
}