Refactor folder structure

This commit is contained in:
venashial
2022-06-17 19:58:01 -07:00
parent 8204139df8
commit 137fbb638b
110 changed files with 45 additions and 52 deletions

View File

@@ -10,7 +10,7 @@ Requires Node v16.5+.
## Developing
The library lives in the `src/package` folder, and the documentation lives in the `src/routes` folder.
The library lives in the `package/` folder, and the documentation lives in the `docs/` folder.
```bash
pnpm install # Install dependencies
@@ -21,12 +21,12 @@ pnpm dev # Run dev server
> Replace `ComponentName` with your component name in the steps below
1. Create a `ComponentName.svelte` file in `src/package/components`
2. Add an export for your component in [./src/package/index.ts](./src/package/index.ts)
1. Create a `ComponentName.svelte` file in `package/components`
2. Add an export for your component in [./package/index.ts](./package/index.ts)
```
export { default as ComponentName } from './components/ComponentName.svelte'
```
3. Create a `ComponentName.md` file for documentation in `src/routes/components`
3. Create a `ComponentName.md` file for documentation in `docs/routes/components`
4. Add an example of your component in your `ComponentName.md` file, like so:
````md

View File

View File

Before

Width:  |  Height:  |  Size: 747 B

After

Width:  |  Height:  |  Size: 747 B

View File

@@ -3,12 +3,12 @@
import IconMenu from 'virtual:icons/lucide/menu'
const components = Object.keys(import.meta.glob('../../routes/components/**'))
.map((it) => it.replace('../../routes/components/', '').replace('.md', ''))
const components = Object.keys(import.meta.glob('../routes/components/**'))
.map((it) => it.replace('../routes/components/', '').replace('.md', ''))
.sort()
const classes = Object.keys(import.meta.glob('../../routes/classes/**'))
.map((it) => it.replace('../../routes/classes/', '').replace('.md', ''))
const classes = Object.keys(import.meta.glob('../routes/classes/**'))
.map((it) => it.replace('../routes/classes/', '').replace('.md', ''))
.sort()
let slideIn = false

View File

View File

@@ -12,14 +12,14 @@
export let description = 'Learn about Omorphia, the component & style library'
let editUrl = `https://github.com/modrinth/omorphia/edit/main/src/routes/${
let editUrl = `https://github.com/modrinth/omorphia/edit/main/docs/routes/${
$page.url.pathname.replace('/', '') || 'index'
}.md`
let api
if ($page.url.pathname.includes('components')) {
if (import.meta.env.DEV) {
import(`../../package/components/${title}.svelte?raw&sveld`).then(
import(`../../src/components/${title}.svelte?raw&sveld`).then(
(output) => (api = output.default)
)
} else {

View File

@@ -2,7 +2,7 @@ import { ComponentParser } from 'sveld'
import * as svelte from 'svelte/compiler'
import fs from 'fs/promises'
import path from 'path'
import { preprocess } from '../src/package/config/svelte.config.js'
import { preprocess } from '../../src/config/svelte.config.js'
export default function sveld() {
return {
@@ -23,21 +23,21 @@ export default function sveld() {
async buildStart() {
const output = {}
const componentFiles = await fs.readdir(path.resolve('./src/package/components'))
const componentFiles = await fs.readdir(path.resolve('./src/components'))
for (const fileName of componentFiles.filter((name) => name.endsWith('.svelte'))) {
const filePath = path.resolve('./src/package/components', fileName)
const filePath = path.resolve('./src/components', fileName)
const raw = (await fs.readFile(filePath)).toString()
output[fileName] = await parseRaw(raw, filePath)
}
try {
await fs.mkdir(path.resolve('./src/generated'))
await fs.mkdir(path.resolve('./generated'))
} catch {
// Do nothing, directory already exists
}
await fs.writeFile(path.resolve('./src/generated/COMPONENT_API.json'), JSON.stringify(output))
await fs.writeFile(path.resolve('./generated/COMPONENT_API.json'), JSON.stringify(output))
},
}
}

View File

@@ -9,11 +9,11 @@
</script>
<script lang="ts">
import '$package/styles.postcss'
import '../docs/styles/prism-one-dark.css'
import '../docs/styles/gh-markdown.postcss'
import Sidebar from '../docs/components/Sidebar.svelte'
import Header from '../docs/components/Header.svelte'
import 'omorphia/styles.postcss'
import '../styles/prism-one-dark.css'
import '../styles/gh-markdown.postcss'
import Sidebar from '../components/Sidebar.svelte'
import Header from '../components/Header.svelte'
</script>
<div class="app theme-light">

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -14,7 +14,7 @@ const config = defineConfig({
examples,
{
defaults: {
Wrapper: path.resolve('./src/docs/components/Example.svelte'),
Wrapper: path.resolve('./docs/components/Example.svelte'),
},
},
],
@@ -22,7 +22,7 @@ const config = defineConfig({
rehypePlugins: [],
layout: {
_: './src/docs/layout/page.svelte',
_: './docs/layout/page.svelte',
},
})

View File

@@ -1 +1 @@
module.exports = require('./src/package/config/postcss.config.cjs')
module.exports = require('./src/config/postcss.config.cjs')

View File

@@ -22,16 +22,6 @@ export default function Generator(options) {
} catch {
// File doesn't exist, create folder
await fs.mkdir('./generated', { recursive: true })
await fs.writeFile(
'./generated/state.json',
JSON.stringify(
{
options,
},
null,
2
)
)
}
// Don't generate if the last generation was less than TTL and the options are the same
@@ -43,16 +33,16 @@ export default function Generator(options) {
return
}
if (options.tags) await tags(API_URL)
if (options.landingPage) await landingPage(API_URL)
if (options.gameVersions) await gameVersions(API_URL)
if (options.projectColors) await projectColors(API_URL)
// Write new state
state.lastGenerated = new Date().toISOString()
state.options = options
await fs.writeFile('./generated/state.json', JSON.stringify(state, null, 2))
if (options.tags) await tags(API_URL)
if (options.landingPage) await landingPage(API_URL)
if (options.gameVersions) await gameVersions(API_URL)
if (options.projectColors) await projectColors(API_URL)
},
}
}

Some files were not shown because too many files have changed in this diff Show More