Skip to content
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

WIP Feat/strapi migration changesv2 #111

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
6 changes: 6 additions & 0 deletions .next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
webpack(config) {
config.infrastructureLogging = { debug: /PackFileCache/ }
return config;
}
}
26 changes: 0 additions & 26 deletions .vscode/launch.json

This file was deleted.

41 changes: 21 additions & 20 deletions configs/createPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
StrapiFrontPageNavigation,
StrapiFrontPageNavigationSubnavigation,
StrapiContentPage,
StrapiActivityGroupLocalizations,
StrapiAgeGroupActivity_Groups,
} from '../graphql-types';
import { getActivityGroup } from '../src/queries/activityGroup';
Expand Down Expand Up @@ -71,7 +70,7 @@ function mergePageCreationResults(...results: PageCreationResults[]): PageCreati
}

async function handleActivity(
activity: Pick<StrapiActivity, 'id' | 'title' | 'localizations' | 'locale'>,
activity: Pick<StrapiActivity, 'id' | 'title' | 'locale' | 'strapi_id'>,
activityGroupPath: string,
createPage: Actions['createPage'],
): Promise<PageCreationResults> {
Expand All @@ -88,9 +87,9 @@ async function handleActivity(
component: path.resolve(`src/templates/activityTemplate/index.tsx`),
context: {
type: 'activity',
localizations: activity.localizations?.map((x) => x?.id) || [],
locale: activity.locale,
id: activity.id,
strapi_id: activity.strapi_id,
},
};

Expand All @@ -112,7 +111,7 @@ async function graphqlWithErrors<T>(graphql: CreatePagesArgs['graphql'], query:
}

async function handleActivityGroup(
activityGroup: Pick<StrapiAgeGroupActivity_Groups, 'id' | 'title' | 'age_group'>,
activityGroup: Pick<StrapiAgeGroupActivity_Groups, 'id' | 'title' | 'age_group' | 'strapi_id' | 'locale'>,
ageGroupPath: string,
graphql: CreatePagesArgs['graphql'],
createPage: Actions['createPage'],
Expand All @@ -125,8 +124,7 @@ async function handleActivityGroup(

const { data } = await graphqlWithErrors<{
strapiActivityGroup: {
activities: Pick<StrapiActivity, 'id' | 'title' | 'localizations' | 'locale'>[];
localizations: StrapiActivityGroupLocalizations[];
activities: Pick<StrapiActivity, 'id' | 'title' | 'locale' | 'strapi_id'>[];
locale?: string;
};
}>(graphql, getActivityGroup, {
Expand All @@ -147,10 +145,10 @@ async function handleActivityGroup(
component: path.resolve(`src/templates/activityGroupTemplate/index.tsx`),
context: {
type: 'activityGroup',
localizations: activityGroupData!.localizations?.map((x) => x?.id) || [],
locale: activityGroupData?.locale,
id: activityGroup!.id,
ageGroupId: activityGroup.age_group,
locale: activityGroup?.locale,
id: activityGroup?.id,
strapi_id: activityGroup?.strapi_id,
ageGroupId: activityGroup?.age_group,
},
};

Expand All @@ -169,7 +167,7 @@ async function handleActivityGroup(
}

async function handleAgeGroup(
ageGroup: Pick<StrapiAgeGroup, 'id' | 'strapiId' | 'title' | 'activity_groups' | 'localizations' | 'locale'>,
ageGroup: Pick<StrapiAgeGroup, 'id' | 'strapi_id' | 'title' | 'activity_groups' | 'locale'>,
graphql: CreatePagesArgs['graphql'],
createPage: Actions['createPage'],
): Promise<PageCreationResults> {
Expand All @@ -187,9 +185,9 @@ async function handleAgeGroup(
component: path.resolve(`src/templates/ageGroupTemplate/index.tsx`),
context: {
type: 'ageGroup',
localizations: ageGroup.localizations?.map((x) => x?.id) || [],
locale: ageGroup.locale,
id: ageGroup.strapiId,
locale: ageGroup?.locale,
id: ageGroup.id,
strapi_id: ageGroup.strapi_id,
},
};

Expand Down Expand Up @@ -243,15 +241,18 @@ async function handleContentPages(
graphql,
getAllFrontPages,
);


frontPageResponse.data?.allStrapiFrontPage.nodes.forEach((frontPage) => {
const locale = frontPage.locale;
createPage({
path: locale === 'fi' ? '/' : `/${locale}/`,
component: path.resolve(`src/templates/frontPageTemplate/index.tsx`),
context: {
type: 'frontPage',
locale,
id: frontPage.strapiId,
locale: frontPage.locale,
id: frontPage.id,
strapi_id: frontPage.strapi_id,
},
});
});
Expand Down Expand Up @@ -346,17 +347,17 @@ async function createContentPage(
pagePath: string,
): Promise<PageCreationResults> {
const pageDataResponse = await graphqlWithErrors<{ strapiContentPage: StrapiContentPage }>(graphql, getContentPage, {
id,
id
});

const page = {
path: pagePath,
component: path.resolve(`src/templates/contentPageTemplate/index.tsx`),
context: {
type: 'contentPage',
localizations: pageDataResponse.data?.strapiContentPage.localizations?.map((x) => x?.id) || [],
locale: pageDataResponse.data?.strapiContentPage.locale,
id: pageDataResponse?.data?.strapiContentPage.strapiId,
id: pageDataResponse?.data?.strapiContentPage.id,
strapi_id: pageDataResponse?.data?.strapiContentPage.strapi_id,
},
};

Expand All @@ -379,4 +380,4 @@ const createPages = async ({ graphql, actions }: CreatePagesArgs) => {
printPageCreationResults(finalResults);
};

export default createPages;
export default createPages;
Loading