Skip to content

Add support for different baseURLs #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/push-dist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Push dist

on:
push:
branches:
- main
- vite

jobs:
push-dist:
name: Push dist
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4
- run: npm i -g pnpm && pnpm i
- uses: kategengler/put-built-npm-package-contents-on-branch@v2.1.0
with:
branch: dist-kolay
token: ${{ secrets.GITHUB_TOKEN }}
working-directory: .
- uses: kategengler/put-built-npm-package-contents-on-branch@v2.1.0
with:
branch: dist-kolay-ui
token: ${{ secrets.GITHUB_TOKEN }}
working-directory: ./ui
19,675 changes: 8,776 additions & 10,899 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions src/plugins/api-docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,23 @@ export const apiDocs = (options) => {
return `${options.dest ?? 'docs'}/${pkgName.replace('/', '__')}.json`;
}

let baseUrl = '/';

return {
name,

vite: {
configResolved(resolvedConfig) {
baseUrl = resolvedConfig.base;
},
configureServer(server) {
return () => {
server.middlewares.use(async (req, res, next) => {
if (req.originalUrl && req.originalUrl.length > 1) {
const assetUrl = req.originalUrl.split('?')[0];

const pkg = options.packages.find((pkgName) => {
let dest = '/' + getDest(pkgName);
let dest = baseUrl + getDest(pkgName);

return dest === assetUrl;
});
Expand Down Expand Up @@ -92,19 +97,19 @@ export const apiDocs = (options) => {
},
...virtualFile({
importPath: SECRET_INTERNAL_IMPORT,
content: stripIndent`
get content() { return stripIndent`
export const packageNames = [
${options.packages.map((raw) => `'${raw}',`).join('\n ')}
];

export const loadApiDocs = {
${options.packages
.map((name) => {
return `'${name}': () => fetch('/${getDest(name)}'),`;
return `'${name}': () => fetch('${baseUrl}${getDest(name)}'),`;
})
.join('\n ')}
};
`,
`},
}),
};
};
1 change: 1 addition & 0 deletions src/plugins/api-docs/typedoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export async function generateTypeDocJSON({ packageName }) {
cleanOutputDir: false,
pretty: false,
excludeInternal: false,
excludeExternals: true,
skipErrorChecking: true,
plugin: ['@zamiell/typedoc-plugin-not-exported'],
});
Expand Down
20 changes: 12 additions & 8 deletions src/plugins/markdown-pages/markdown-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const markdownPages = (options) => {
* @type {import('vite').ViteDevServer}
*/
let server;
let baseUrl = '/';

return {
name: 'kolay:markdown-docs',
Expand All @@ -48,6 +49,9 @@ export const markdownPages = (options) => {
});
}
},
configResolved(resolvedConfig) {
baseUrl = resolvedConfig.base;
},
configureServer(s) {
server = s;

Expand All @@ -56,16 +60,16 @@ export const markdownPages = (options) => {
if (req.originalUrl && req.originalUrl.length > 1) {
const assetUrl = req.originalUrl.split('?')[0] || '';

if (assetUrl === `/${destination}/${name}`) {
const reshaped = await discover({ src, groups });
if (assetUrl === `${baseUrl}${destination}/${name}`) {
const reshaped = await discover({ src, groups, baseUrl });

res.setHeader('content-type', 'application/json');

return res.end(JSON.stringify(reshaped, null, 2));
}

if (groups && assetUrl.startsWith('/docs')) {
const groupName = assetUrl.split('/')[2];
if (groups && assetUrl.slice(baseUrl.length - 1).startsWith('/docs')) {
const groupName = assetUrl.slice(baseUrl.length - 1).split('/')[2];
const g = groups.find((group) => {
// discover mutates the groups array
if (group.name === 'root') return;
Expand Down Expand Up @@ -98,7 +102,7 @@ export const markdownPages = (options) => {

if (server) return;

const reshaped = await discover({ src, groups });
const reshaped = await discover({ src, groups, baseUrl });

if (groups) {
groups.forEach((group) => {
Expand Down Expand Up @@ -140,17 +144,17 @@ export const markdownPages = (options) => {

...virtualFile({
importPath: SECRET_INTERNAL_IMPORT,
content: stripIndent`
get content() { return stripIndent`
export const load = async () => {
let request = await fetch('/${fileName}', {
let request = await fetch('${baseUrl || '/'}${fileName}', {
headers: {
Accept: 'application/json',
},
});
let json = await request.json();
return json;
}
`,
`},
}),
};
};
10 changes: 9 additions & 1 deletion ui/src/services/kolay/request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { cached } from '@glimmer/tracking';
import { getOwner } from '@ember/owner';
import { service } from '@ember/service';

import { use } from 'ember-resources';
Expand All @@ -23,6 +24,11 @@ export class MDRequest {

@service('kolay/docs') declare docs: DocsService;

get config() {
// @ts-ignore
return getOwner(this).resolveRegistration('config:environment')
}

/**
* TODO: use a private property when we move to spec-decorators
*/
Expand Down Expand Up @@ -50,7 +56,9 @@ export class MDRequest {
@cached
private get _doesPageExist() {
let url = this.urlFn();
let pagePath = url.replace(OUTPUT_PREFIX_REGEX, '/');
let pagePath = url
.slice(this.config.rootURL.length - 1)
.replace(OUTPUT_PREFIX_REGEX, '/');
let group = this.docs.groupForURL(pagePath);

return Boolean(group);
Expand Down
8 changes: 7 additions & 1 deletion ui/src/services/kolay/selected.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getOwner } from '@ember/owner';
import Service, { service } from '@ember/service';

import { use } from 'ember-resources';
Expand Down Expand Up @@ -45,14 +46,19 @@ export default class Selected extends Service {
@service declare router: RouterService;
@service('kolay/docs') declare docs: DocsService;

get config() {
// @ts-ignore
return getOwner(this).resolveRegistration('config:environment')
}

/*********************************************************************
* These load the files from /public and handle loading / error state.
*
* When the path changes for each of these, the previous request will
* be cancelled if it was still pending.
*******************************************************************/

@link request = new MDRequest(() => `/docs${this.path}.md`);
@link request = new MDRequest(() => `${this.config.rootURL}docs${this.path}.md`);
@link compiled = new Prose(() => this.request.lastSuccessful);

get proseCompiled() {
Expand Down