Skip to content

Commit

Permalink
feat: ceate base-integration package
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 13, 2021
1 parent de2faf1 commit 965c83c
Show file tree
Hide file tree
Showing 72 changed files with 596 additions and 851 deletions.
28 changes: 18 additions & 10 deletions core/routes/src/routes/docs-index-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import {
} from '@component-controls/core';
import { getUniquesByField } from './docs-pages';
export interface DocHomePagesPath {
type: DocType;
type?: DocType;
path: string;
docId?: string;
storyId?: string;
lastModified?: string;
docIndex?: boolean;
}

export const getHomePages = (store?: Store): DocHomePagesPath[] => {
Expand Down Expand Up @@ -45,25 +46,32 @@ export const getHomePages = (store?: Store): DocHomePagesPath[] => {
const storyId: string | undefined = docStories.length
? docStories[0]
: undefined;
return {
lastModified: doc?.dateModified
? new Date(doc?.dateModified).toISOString()
: undefined,
const result: DocHomePagesPath = {
type,
path,
docId,
storyId,
docIndex: true,
};
if (docId) {
result.docId = docId;
}
if (storyId) {
result.storyId = storyId;
}
const lastModified = doc?.dateModified
? new Date(doc?.dateModified).toISOString()
: undefined;
if (lastModified) {
result.lastModified = lastModified;
}
return result;
})
.filter(({ path }) => path);
const categoryPaths: DocHomePagesPath[] = categories
.map(category => {
const uniques = getUniquesByField(store, category);
return {
lastModified: undefined,
type: category,
docId: undefined,
storyId: undefined,
docIndex: true,
path: Object.keys(uniques).length
? getCategoryPath(store, category)
: '',
Expand Down
28 changes: 19 additions & 9 deletions core/routes/src/routes/docs-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const getUniquesByField = (
};

export interface DocPagesPath {
type: DocType;
type?: DocType;
path: string;
query?: string;
lastModified?: string;
Expand Down Expand Up @@ -99,17 +99,27 @@ export const getDocPages = (store?: Store): DocPagesPath[] => {
route,
);
if (!docPaths.find(p => p.path === path)) {
docPaths.push({
lastModified: doc.dateModified
? new Date(doc.dateModified).toISOString()
: undefined,
const result: DocPagesPath = {
path,
query,
type: docType,
activeTab: route,
docId: doc.title,
storyId,
});
};
if (storyId) {
result.storyId = storyId;
}
if (route) {
result.activeTab = route;
}
const lastModified = doc.dateModified
? new Date(doc.dateModified).toISOString()
: undefined;
if (lastModified) {
result.lastModified = lastModified;
}
if (query) {
result.query = query;
}
docPaths.push(result);
}
});
}
Expand Down
28 changes: 18 additions & 10 deletions core/routes/src/routes/index-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@component-controls/core';

export interface HomePageInfo {
type: string;
type?: string;
docId?: string;
storyId?: string;
path: string;
Expand All @@ -29,18 +29,26 @@ export const getIndexPage = (store?: Store): HomePageInfo => {
const docId = homePage?.title;
const docStories: string[] =
docId && store.docs[docId] ? store.docs[docId].stories || [] : [];
const storyId: string | undefined = docStories.length
? docStories[0]
: undefined;
return {
lastModified: homePage?.dateModified
? new Date(homePage?.dateModified).toISOString()
: undefined,
const result: HomePageInfo = {
path: homePath,
storyId,
docId,
type: homePage?.type || defDocType,
};
const lastModified = homePage?.dateModified
? new Date(homePage?.dateModified).toISOString()
: undefined;
if (lastModified) {
result.lastModified = lastModified;
}
const storyId: string | undefined = docStories.length
? docStories[0]
: undefined;
if (storyId) {
result.storyId = storyId;
}
if (docId) {
result.docId = docId;
}
return result;
}
return {
type: defDocType,
Expand Down
26 changes: 26 additions & 0 deletions core/routes/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
import { Store } from '@component-controls/core';
import { getHomePages, DocHomePagesPath } from './docs-index-pages';
import { getDocPages, DocPagesPath } from './docs-pages';
import { getIndexPage, HomePageInfo } from './index-page';

export * from './docs-index-pages';
export * from './docs-pages';
export * from './index-page';

export type RoutePath = DocHomePagesPath & DocPagesPath & HomePageInfo;

export const getRoutes = (store: Store): RoutePath[] => {
const routes = [];
//home page
const index = getIndexPage(store) || {};
routes.push(index);
//docs index pages
const homePages = getHomePages(store);
homePages.forEach(page => {
routes.push(page);
});

//document pages
const docPages = getDocPages(store);
docPages.forEach(page => {
routes.push(page);
});
return routes;
};
1 change: 0 additions & 1 deletion core/store/loader.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion core/store/loader.js

This file was deleted.

4 changes: 1 addition & 3 deletions core/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"static_store.js",
"static_store.d.ts",
"controls-store.js",
"controls-store.d.ts",
"loader.js",
"loader.d.ts"
"controls-store.d.ts"
],
"scripts": {
"build": "yarn cross-env NODE_ENV=production rollup -c",
Expand Down
35 changes: 0 additions & 35 deletions core/store/src/webpack/loader.ts

This file was deleted.

1 change: 0 additions & 1 deletion examples/nextjs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ module.exports = withStories({
webpack5: true,
},
configPath: '.config',
distDir: 'dist',
});
8 changes: 3 additions & 5 deletions examples/nextjs/pages/[doctype].tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import React from 'react';
import { GetStaticProps, GetStaticPaths } from 'next';
import {
DocHomeTemplate,
NextLayout,
store,
getHomePagesPaths,
getDocHomePage,
} from '@component-controls/nextjs-plugin';

const DocHome: typeof DocHomeTemplate = props => <DocHomeTemplate {...props} />;
const DocHome: typeof NextLayout = props => <NextLayout {...props} />;

export const getStaticPaths: GetStaticPaths = async () => {
return { paths: getHomePagesPaths(store), fallback: false };
};

export const getStaticProps: GetStaticProps = async ({ params }) => {
const { doctype: basepath } = params as { doctype: string };
const page = getDocHomePage(store, basepath);
const { type = null, docId = null, storyId = null } = page || {};
return { props: { docId, storyId, type } };
return { props: getDocHomePage(store, basepath) };
};

export default DocHome;
14 changes: 3 additions & 11 deletions examples/nextjs/pages/[doctype]/[...docid].tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
import React from 'react';
import { GetStaticProps, GetStaticPaths } from 'next';
import {
DocPageTemplate,
NextLayout,
store,
getDocPagesPaths,
getDocPage,
} from '@component-controls/nextjs-plugin';

const DocPage: typeof DocPageTemplate = props => <DocPageTemplate {...props} />;
const DocPage: typeof NextLayout = props => <NextLayout {...props} />;

export const getStaticPaths: GetStaticPaths = async () => {
return { paths: getDocPagesPaths(store), fallback: false };
};

export const getStaticProps: GetStaticProps = async ({ params }) => {
const { doctype, docid } = params as { doctype: string; docid: string[] };
const page = getDocPage(store, doctype, docid);
const {
type = null,
docId = null,
storyId = null,
category = null,
activeTab = null,
} = page || {};
return { props: { docId, type, storyId, category, activeTab } };
return { props: getDocPage(store, doctype, docid) };
};

export default DocPage;
10 changes: 3 additions & 7 deletions examples/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import React from 'react';
import { GetStaticProps } from 'next';
import {
DocPageTemplate,
NextLayout,
store,
getIndexPage,
} from '@component-controls/nextjs-plugin';

const HomePage: typeof DocPageTemplate = props => (
<DocPageTemplate {...props} />
);
const HomePage: typeof NextLayout = props => <NextLayout {...props} />;

export const getStaticProps: GetStaticProps = async () => {
const homePage = getIndexPage(store);
const { docId = null, type = null, storyId = null } = homePage;
return { props: { docId, type, storyId } };
return { props: getIndexPage(store) };
};

export default HomePage;
1 change: 0 additions & 1 deletion examples/react-webpack/webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,5 @@ module.exports = withComponentControls({
options: {
configPath: '.config',
distFolder: publicPath,
fastRefresh: false,
},
});
1 change: 0 additions & 1 deletion examples/simple/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ module.exports = withStories({
webpack5: true,
},
configPath: 'docs',
distDir: 'dist',
});
1 change: 1 addition & 0 deletions examples/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"@component-controls/gatsby-theme-stories": "^3.3.0",
"@component-controls/nextjs-plugin": "^3.3.0",
"gatsby": "^3.0.0",
"next": "^10.0.7",
"react": "^17.0.1",
Expand Down
8 changes: 3 additions & 5 deletions examples/simple/pages/[doctype].tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import React from 'react';
import { GetStaticProps, GetStaticPaths } from 'next';
import {
DocHomeTemplate,
NextLayout,
store,
getHomePagesPaths,
getDocHomePage,
} from '@component-controls/nextjs-plugin';

const DocHome: typeof DocHomeTemplate = props => <DocHomeTemplate {...props} />;
const DocHome: typeof NextLayout = props => <NextLayout {...props} />;

export const getStaticPaths: GetStaticPaths = async () => {
return { paths: getHomePagesPaths(store), fallback: false };
};

export const getStaticProps: GetStaticProps = async ({ params }) => {
const { doctype: basepath } = params as { doctype: string };
const page = getDocHomePage(store, basepath);
const { type = null, docId = null, storyId = null } = page || {};
return { props: { docId, storyId, type } };
return { props: getDocHomePage(store, basepath) };
};

export default DocHome;
14 changes: 3 additions & 11 deletions examples/simple/pages/[doctype]/[...docid].tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
import React from 'react';
import { GetStaticProps, GetStaticPaths } from 'next';
import {
DocPageTemplate,
NextLayout,
store,
getDocPagesPaths,
getDocPage,
} from '@component-controls/nextjs-plugin';

const DocPage: typeof DocPageTemplate = props => <DocPageTemplate {...props} />;
const DocPage: typeof NextLayout = props => <NextLayout {...props} />;

export const getStaticPaths: GetStaticPaths = async () => {
return { paths: getDocPagesPaths(store), fallback: false };
};

export const getStaticProps: GetStaticProps = async ({ params }) => {
const { doctype, docid } = params as { doctype: string; docid: string[] };
const page = getDocPage(store, doctype, docid);
const {
type = null,
docId = null,
storyId = null,
category = null,
activeTab = null,
} = page || {};
return { props: { docId, type, storyId, category, activeTab } };
return { props: getDocPage(store, doctype, docid) };
};

export default DocPage;
Loading

0 comments on commit 965c83c

Please sign in to comment.