-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
900 additions
and
636 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* eslint-disable */ | ||
// @ts-nocheck | ||
/* -------------------------------------------------------------------------- */ | ||
/* GENERATED FILE, DO NOT EDIT MANUALLY! */ | ||
/* -------------------------------------------------------------------------- */ | ||
|
||
import { lazy, type LazyExoticComponent, type ReactElement } from "react"; | ||
|
||
interface Preview { | ||
component: LazyExoticComponent<() => ReactElement>; | ||
} | ||
|
||
export const Previews: Record<string, Preview> = { | ||
"buttons/docs/button/preview": { | ||
component: lazy(() => import("@/../../packages/components/src/buttons/docs/button/preview.tsx")) | ||
}, | ||
"buttons/docs/button/variant": { | ||
component: lazy(() => import("@/../../packages/components/src/buttons/docs/button/variant.tsx")) | ||
}, | ||
"buttons/docs/button/size": { | ||
component: lazy(() => import("@/../../packages/components/src/buttons/docs/button/size.tsx")) | ||
}, | ||
"buttons/docs/button/state": { | ||
component: lazy(() => import("@/../../packages/components/src/buttons/docs/button/state.tsx")) | ||
}, | ||
"buttons/docs/button/loading": { | ||
component: lazy(() => import("@/../../packages/components/src/buttons/docs/button/loading.tsx")) | ||
}, | ||
"buttons/docs/button/layout": { | ||
component: lazy(() => import("@/../../packages/components/src/buttons/docs/button/layout.tsx")) | ||
}, | ||
"buttons/docs/button/icon": { | ||
component: lazy(() => import("@/../../packages/components/src/buttons/docs/button/icon.tsx")) | ||
}, | ||
"buttons/docs/button/icons": { | ||
component: lazy(() => import("@/../../packages/components/src/buttons/docs/button/icons.tsx")) | ||
}, | ||
"buttons/docs/button/endIcon": { | ||
component: lazy(() => import("@/../../packages/components/src/buttons/docs/button/endIcon.tsx")) | ||
}, | ||
"buttons/docs/button/asLink": { | ||
component: lazy(() => import("@/../../packages/components/src/buttons/docs/button/asLink.tsx")) | ||
}, | ||
"buttons/docs/button/reactRouterLink": { | ||
component: lazy(() => import("@/../../packages/components/src/buttons/docs/button/reactRouterLink.tsx")) | ||
}, | ||
"buttons/docs/button/advancedCustomization": { | ||
component: lazy(() => import("@/../../packages/components/src/buttons/docs/button/advancedCustomization.tsx")) | ||
}, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import glob from "glob"; | ||
|
||
const CONTENT_FILES = path.join(process.cwd(), "content", "components", "**", "*.mdx"); | ||
const OUTPUT_FILE = "Preview.ts"; | ||
const OUTPUT_DIR = "examples"; | ||
|
||
function getExamplePath(filePath: string[]) { | ||
const srcValues: string[] = []; | ||
|
||
filePath.forEach(file => { | ||
const content = fs.readFileSync(file, 'utf-8'); | ||
const regex = /<Example\s+(?:[^>]*?\s+)?src="([^"]*)"/g; | ||
let match; | ||
while ((match = regex.exec(content)) !== null) { | ||
srcValues.push(match[1]); | ||
} | ||
}); | ||
|
||
return srcValues; | ||
} | ||
|
||
function getMdxFiles() { | ||
return glob.sync(CONTENT_FILES); | ||
} | ||
|
||
function generateDemoFile(content?: string) { | ||
const dirPath = path.join(process.cwd(), OUTPUT_DIR); | ||
const filePath = path.join(dirPath, OUTPUT_FILE); | ||
|
||
if (!fs.existsSync(dirPath)) { | ||
fs.mkdirSync(dirPath); | ||
} | ||
|
||
fs.writeFileSync(filePath, content || ''); | ||
} | ||
|
||
function generatePreviewRef() { | ||
console.log('Start generation Preview references...'); | ||
const files = getMdxFiles(); | ||
const examplePaths = getExamplePath(files); | ||
|
||
let previewEntries = ""; | ||
for (const path of examplePaths) { | ||
previewEntries += ` | ||
"${path}": { | ||
component: lazy(() => import("@/../../packages/components/src/${path}.tsx")) | ||
},`; | ||
} | ||
|
||
const previewContent = `/* eslint-disable */ | ||
// @ts-nocheck | ||
/* -------------------------------------------------------------------------- */ | ||
/* GENERATED FILE, DO NOT EDIT MANUALLY! */ | ||
/* -------------------------------------------------------------------------- */ | ||
import { lazy, type LazyExoticComponent, type ReactElement } from "react"; | ||
interface Preview { | ||
component: LazyExoticComponent<() => ReactElement>; | ||
} | ||
export const Previews: Record<string, Preview> = {${previewEntries} | ||
}; | ||
` | ||
|
||
generateDemoFile(previewContent) | ||
console.log('🎉 Success') | ||
} | ||
|
||
generatePreviewRef(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.