Skip to content

Commit

Permalink
Merge branch 'main' of github.com:magidoc-org/magidoc
Browse files Browse the repository at this point in the history
  • Loading branch information
pelletier197 committed Apr 1, 2024
2 parents 99ec778 + 569af77 commit 6464b1a
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 72 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Expand Up @@ -38,7 +38,7 @@
"commander": "^12.0.0",
"extract-zip": "^2.0.1",
"fs-extra": "^11.2.0",
"listr2": "^8.1.2",
"listr2": "^8.1.3",
"lodash": "^4.17.21",
"sirv": "^2.0.4",
"zod": "^3.22.4"
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/svelte-marked/package.json
Expand Up @@ -48,8 +48,8 @@
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@types/marked": "^6.0.0",
"@types/prismjs": "^1.26.3",
"svelte-check": "^3.6.8",
"svelte2tsx": "^0.7.5",
"svelte-check": "^3.6.9",
"svelte2tsx": "^0.7.6",
"tslib": "^2.6.2",
"typescript": "~5.4.3",
"vite": "^5.2.7"
Expand Down
4 changes: 0 additions & 4 deletions packages/plugins/svelte-marked/svelte.config.js
Expand Up @@ -6,10 +6,6 @@ const config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
alias: {
$lib: './src/lib',
'$lib/*': './src/lib/*',
},
},
}

Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/svelte-prismjs/package.json
Expand Up @@ -48,8 +48,8 @@
"@sveltejs/package": "2.3.0",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@types/prismjs": "^1.26.3",
"svelte-check": "^3.6.8",
"svelte2tsx": "^0.7.5",
"svelte-check": "^3.6.9",
"svelte2tsx": "^0.7.6",
"tslib": "^2.6.2",
"typescript": "^5.4.3",
"vite": "^5.2.7"
Expand Down
4 changes: 0 additions & 4 deletions packages/plugins/svelte-prismjs/svelte.config.js
Expand Up @@ -6,10 +6,6 @@ const config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
alias: {
$lib: 'src/lib',
'$lib/*': 'src/lib/*',
},
},
}

Expand Down
1 change: 1 addition & 0 deletions packages/starters/carbon-multi-page/magidoc.config.js
Expand Up @@ -30,5 +30,6 @@ export function loadVariables() {
return {}
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(fs.readFileSync(ENV_FILE_LOCATION))
}
2 changes: 1 addition & 1 deletion packages/starters/carbon-multi-page/package.json
Expand Up @@ -48,7 +48,7 @@
"prism-svelte": "^0.5.0",
"prismjs": "^1.29.0",
"svelte": "^4.2.12",
"svelte-check": "^3.6.8",
"svelte-check": "^3.6.9",
"svelte-markdown": "^0.4.1",
"tslib": "^2.6.2",
"typescript": "^5.4.3",
Expand Down
@@ -1,5 +1,4 @@
<script lang="ts">
import { base } from '$app/paths'
import { Link } from 'carbon-components-svelte'
import { urlUtils } from '@magidoc/plugin-svelte-marked'
import {
Expand All @@ -8,6 +7,7 @@
isNamedType,
isNonNullType,
} from 'graphql'
import { getSiteRoot } from '$lib/variables'
export let type: GraphQLType
</script>
Expand All @@ -17,7 +17,7 @@
{:else if isNonNullType(type)}
<svelte:self type={type.ofType} />!
{:else if isNamedType(type)}
<Link href={urlUtils.joinUrlPaths(base, `/types/${String(type.name)}`)}
<Link href={urlUtils.joinUrlPaths(getSiteRoot(), 'types', String(type.name))}
>{type.name}</Link
>
{/if}
@@ -1,5 +1,4 @@
<script lang="ts">
import { base } from '$app/paths'
import MarkdownCode from './code/MarkdownCode.svelte'
import MarkdownCodeSpan from './code/MarkdownCodeSpan.svelte'
import MarkdownBloquote from './text/MarkdownBloquote.svelte'
Expand All @@ -13,10 +12,11 @@
import MarkdownTags from './containers/tags/MarkdownTags.svelte'
import MarkdownHeading from './text/MarkdownHeading.svelte'
import Markdown from '@magidoc/plugin-svelte-marked'
import { getSiteRoot } from '$lib/variables'
export let source: string | undefined | null
const castedBase = base as `/${string}`
const castedBase = getSiteRoot() as `/${string}`
</script>

{#if source}
Expand Down
@@ -1,5 +1,5 @@
<script lang="ts">
import { base } from '$app/paths'
import { getSiteRoot } from '$lib/variables'
import {
getAllowedArgumentsByDirective,
isAllowedDirective,
Expand Down Expand Up @@ -89,7 +89,10 @@
{#if shouldShowDirective()}
<Tag type="blue">
<a
href={urlUtils.joinUrlPaths(base, `/directives/${directive.name.value}`)}
href={urlUtils.joinUrlPaths(
getSiteRoot(),
`/directives/${directive.name.value}`,
)}
class="override-tooltip-width"
>
<TooltipDefinition tooltipText={text} direction="top" align="center">
Expand Down
Expand Up @@ -4,8 +4,8 @@
import { ClickableTile } from 'carbon-components-svelte'
import AppSearchHighlight from './AppSearchHighlight.svelte'
import HeaderCrumb from './HeaderCrumb.svelte'
import { base } from '$app/paths'
import { urlUtils } from '@magidoc/plugin-svelte-marked'
import { getSiteRoot } from '$lib/variables'
export let item: GraphQLSearchResult
Expand All @@ -15,16 +15,25 @@
$: {
if (item.result.type === SearchResultType.QUERY) {
href = urlUtils.joinUrlPaths(base, `/queries/${item.result.name}`)
href = urlUtils.joinUrlPaths(
getSiteRoot(),
`/queries/${item.result.name}`,
)
section = 'Queries'
} else if (item.result.type === SearchResultType.MUTATION) {
href = urlUtils.joinUrlPaths(base, `/mutations/${item.result.name}`)
href = urlUtils.joinUrlPaths(
getSiteRoot(),
`/mutations/${item.result.name}`,
)
section = 'Mutations'
} else if (item.result.type === SearchResultType.SUBSCRIPTION) {
href = urlUtils.joinUrlPaths(base, `/subscriptions/${item.result.name}`)
href = urlUtils.joinUrlPaths(
getSiteRoot(),
`/subscriptions/${item.result.name}`,
)
section = 'Subscriptions'
} else if (item.result.type === SearchResultType.TYPE) {
href = urlUtils.joinUrlPaths(base, `/types/${item.result.name}`)
href = urlUtils.joinUrlPaths(getSiteRoot(), `/types/${item.result.name}`)
section = 'Types'
}
}
Expand Down
13 changes: 8 additions & 5 deletions packages/starters/carbon-multi-page/src/lib/model.ts
Expand Up @@ -14,13 +14,12 @@ import {
import _ from 'lodash'
import schemaRaw from '../_schema.graphqls?raw'
import type { Maybe } from 'graphql/jsutils/Maybe'
import { base } from '$app/paths'
import { urlUtils } from '@magidoc/plugin-svelte-marked'
import {
createReverseMapping,
type TypeReverseMapping,
} from '@magidoc/plugin-reverse-schema-mapper'
import { getOrDefault } from './variables'
import { getOrDefault, getSiteRoot } from './variables'
import {
templates,
type AllowedDirective,
Expand Down Expand Up @@ -111,7 +110,11 @@ function createWebsiteContentFromFields(
title: field.name,
section: title,
deprecated: !!field.deprecationReason,
href: urlUtils.joinUrlPaths(base, title.toLocaleLowerCase(), field.name),
href: urlUtils.joinUrlPaths(
getSiteRoot(),
title.toLocaleLowerCase(),
field.name,
),
})),
}
}
Expand All @@ -129,7 +132,7 @@ function createTypesWebsiteContent(): PageTree | null {
type: 'page',
title: type.name,
section: 'Types',
href: urlUtils.joinUrlPaths(base, 'types', type.name),
href: urlUtils.joinUrlPaths(getSiteRoot(), 'types', type.name),
})),
}
}
Expand Down Expand Up @@ -267,7 +270,7 @@ function createDirectiveWebsiteContent(): PageTree | null {
children: allowed.map((directive) => ({
type: 'page',
title: directive.name,
href: urlUtils.joinUrlPaths(base, 'directives', directive.name),
href: urlUtils.joinUrlPaths(getSiteRoot(), 'directives', directive.name),
section: 'Directives',
})),
}
Expand Down
9 changes: 6 additions & 3 deletions packages/starters/carbon-multi-page/src/lib/pages.ts
Expand Up @@ -2,9 +2,8 @@ import {
templates,
type Page as VariablePage,
} from '@magidoc/plugin-starter-variables'
import { base } from '$app/paths'
import { createModelContent } from './model'
import { getOrDefault } from './variables'
import { getOrDefault, getSiteRoot } from './variables'
import { urlUtils } from '@magidoc/plugin-svelte-marked'
import Slugger from 'github-slugger'
import type { PageTree, Page } from '@magidoc/plugin-starter-common'
Expand Down Expand Up @@ -110,7 +109,11 @@ function asCustomContent(path: string[], page: VariablePage): PageTree {
type: 'page',
title: page.title,
content: page.content,
href: urlUtils.joinUrlPaths(base, ...path, generatePath(page.title)),
href: urlUtils.joinUrlPaths(
getSiteRoot(),
...path,
generatePath(page.title),
),
}
}

Expand Down
9 changes: 8 additions & 1 deletion packages/starters/carbon-multi-page/src/lib/variables.ts
@@ -1,5 +1,6 @@
import type { Variable } from '@magidoc/plugin-starter-variables'
import { templates, type Variable } from '@magidoc/plugin-starter-variables'
import _variables from '../_variables.json'
import { base } from '$app/paths'

export function get<T>(target: Variable<T>): T | null {
return target.get(_variables as Record<string, unknown>)
Expand All @@ -8,3 +9,9 @@ export function get<T>(target: Variable<T>): T | null {
export function getOrDefault<T>(target: Variable<T>, def: T) {
return target.getOrDefault(_variables as Record<string, unknown>, def)
}

export function getSiteRoot() {
// Using $app/paths sometimes return an empty string for an unknown reason, which causes the build to fail.
//
return getOrDefault(templates.SITE_ROOT, base)
}
11 changes: 4 additions & 7 deletions packages/starters/carbon-multi-page/svelte.config.js
@@ -1,11 +1,12 @@
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
import adapter from '@sveltejs/adapter-static'
import { optimizeImports } from 'carbon-preprocess-svelte'
import _ from 'lodash'
import { templates } from '@magidoc/plugin-starter-variables'
import { loadVariables } from './magidoc.config.js'

const variables = loadVariables()
const base = templates.SITE_ROOT.getOrDefault(variables, '')

/**
* @type {import('@sveltejs/kit').Config}
Expand All @@ -14,15 +15,11 @@ const config = {
preprocess: [vitePreprocess(), optimizeImports()],
kit: {
adapter: adapter({
strict: false
strict: false,
}),
paths: {
base: templates.SITE_ROOT.getOrDefault(variables, ''),
base,
},
alias: {
"$lib": "./src/lib",
"$lib/*": "./src/lib/*",
}
},
}

Expand Down
10 changes: 3 additions & 7 deletions packages/starters/carbon-multi-page/tsconfig.json
@@ -1,16 +1,12 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"moduleResolution": "node",
"module": "es2020",
"lib": ["es2020", "DOM"],
"target": "es2020",
"moduleResolution": "bundler",
"strict": true,
"resolveJsonModule": true,
"sourceMap": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
},
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.ts", "src/**/*.svelte"]
"forceConsistentCasingInFileNames": true
}
}
4 changes: 2 additions & 2 deletions packages/starters/carbon-multi-page/vite.config.ts
Expand Up @@ -3,7 +3,7 @@ import { parseGraphQLSchema } from '@magidoc/rollup-plugin-gql-schema'
import { magidoc } from '@magidoc/plugin-starter-variables'
import { ENV_FILE_LOCATION, loadVariables } from './magidoc.config.js'
import fs from 'fs'
import { defineConfig } from 'vite'
import { defineConfig, type HmrContext } from 'vite'

const variables = loadVariables()

Expand All @@ -27,7 +27,7 @@ export default defineConfig({
sveltekit(),
{
name: 'variables-change-handler',
handleHotUpdate(ctx) {
handleHotUpdate(ctx: HmrContext) {
const isVariables = ctx.file.includes(
ENV_FILE_LOCATION.replace('./', ''),
)
Expand Down

0 comments on commit 6464b1a

Please sign in to comment.