Skip to content

Commit c226c52

Browse files
committed
Add starting point for migrations docs
1 parent bd54d12 commit c226c52

File tree

7 files changed

+253
-19
lines changed

7 files changed

+253
-19
lines changed

polaris-migrator/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ Codemod transformations to help upgrade your Polaris codebase.
1010
npx @shopify/polaris-migrator <transform> <path>
1111
```
1212

13-
- `transform` - name of transform, see available transforms below.
14-
- `path` - files or directory to transform
13+
- `transform` - name of migration, see available migrations on the docs site below.
14+
- `path` - files or directory to perform migration
1515
- `--dry` Do a dry-run, no code will be edited
1616
- `--print` Prints the changed output for comparison
17+
- `--force` Ignores the safety check for a clean git status
1718

1819
## Documentation
1920

20-
Visit [polaris.shopify.com/docs/advanced-features/migrations](https://polaris.shopify.com/docs/advanced-features/migrations) to view available migrations.
21+
Visit [polaris.shopify.com/docs/advanced-features/migrations](https://polaris.shopify.com/docs/migrations) to view available migrations.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Getting started
3+
description:
4+
keywords:
5+
- getting started
6+
- installing
7+
- setup
8+
---
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: Migrations
3+
description: Polaris provides Codemod migrations to help upgrade your codebase when a feature is deprecated.
4+
keywords:
5+
- codemod
6+
- migration
7+
- migrator
8+
- upgrade
9+
- updated
10+
- version
11+
- components
12+
- transform
13+
---
14+
15+
Polaris provides Codemod migrations to help upgrade your codebase.
16+
17+
Codemods are transformations that run on your codebase programmatically. This allows for a large amount of changes to be applied without having to manually go through every file.
18+
19+
## Usage
20+
21+
`npx @shopify/polaris-migrator <migration> <path>`
22+
23+
- `migration` - name of migration, see available migrations below.
24+
- `path` - files or directory to perform migration (supports globs)
25+
- `--dry` Do a dry-run, no code will be edited
26+
- `--print` Prints the changed output for comparison
27+
- `--force` Ignores the safety check for a clean git status
28+
29+
## Polaris v10
30+
31+
### `replace-text-component`
32+
33+
Replaces legacy text components `DisplayText`, `Heading`, `Subheading`, `Caption`, `TextStyle`, `VisuallyHidden` with the new `Text` component. This migration will include the proper styling props to match the replaced component.
34+
35+
For example:
36+
37+
```jsx
38+
import {DisplayText, TextStyle} from '@shopify/react';
39+
40+
export default function App() {
41+
return (
42+
<>
43+
<DisplayText size="medium">
44+
Get started with finances on Shopify
45+
</DisplayText>
46+
<p>
47+
<TextStyle variation="subdued">
48+
Start getting the most from your store’s finances by completing these
49+
tasks.
50+
</TextStyle>
51+
</p>
52+
</>
53+
);
54+
}
55+
```
56+
57+
Transforms to:
58+
59+
```jsx
60+
import {Text} from '@shopify/react';
61+
62+
export default function App() {
63+
return (
64+
<>
65+
<Text variation="heading2xl" as="p">
66+
Get started with finances on Shopify
67+
</Text>
68+
<p>
69+
<Text variant="bodyMd" as="span" color="subdued">
70+
Start getting the most from your store’s finances by completing these
71+
tasks.
72+
</Text>
73+
</p>
74+
</>
75+
);
76+
}
77+
```
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import type {GetStaticPaths, GetStaticProps, NextPage} from 'next';
2+
import fs from 'fs';
3+
import path from 'path';
4+
import globby from 'globby';
5+
6+
import Layout from '../../src/components/Layout';
7+
import Longform from '../../src/components/Longform';
8+
import Markdown from '../../src/components/Markdown';
9+
import PageMeta from '../../src/components/PageMeta';
10+
import {docsNavItems} from '../../src/data/navItems';
11+
import {parseMarkdown} from '../../src/utils/markdown.mjs';
12+
import {MarkdownFile} from '../../src/types';
13+
14+
interface Props {
15+
readme: MarkdownFile['readme'];
16+
title: string;
17+
description?: string;
18+
}
19+
20+
const docsDirectory = path.join(process.cwd(), 'content/docs');
21+
22+
const Documentation: NextPage<Props> = ({
23+
readme,
24+
title,
25+
description,
26+
}: Props) => {
27+
return (
28+
<Layout navItems={docsNavItems} title={title}>
29+
<PageMeta title={title} description={description} />
30+
31+
<Longform>
32+
{description ? <Markdown text={description} /> : null}
33+
<Markdown text={readme} />
34+
</Longform>
35+
</Layout>
36+
);
37+
};
38+
39+
export const getStaticProps: GetStaticProps<Props, {doc: string}> = async ({
40+
params,
41+
}) => {
42+
const mdFilePath = path.resolve(
43+
process.cwd(),
44+
`${docsDirectory}/${params?.doc || ''}/index.md`,
45+
);
46+
47+
if (fs.existsSync(mdFilePath)) {
48+
const markdown = fs.readFileSync(mdFilePath, 'utf-8');
49+
const {readme, frontMatter}: MarkdownFile = parseMarkdown(markdown);
50+
const {title, description} = frontMatter;
51+
const props: Props = {
52+
title,
53+
description: description || null,
54+
readme,
55+
};
56+
57+
return {props};
58+
} else {
59+
return {notFound: true};
60+
}
61+
};
62+
63+
export const getStaticPaths: GetStaticPaths = async () => {
64+
const globPath = path.resolve(process.cwd(), 'content/docs/*/*.md');
65+
const paths = globby.sync(globPath).map((fileName: string) => {
66+
return fileName
67+
.replace(`${process.cwd()}/content`, '')
68+
.replace('/index.md', '');
69+
});
70+
71+
return {
72+
paths,
73+
fallback: false,
74+
};
75+
};
76+
77+
export default Documentation;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import type {GetStaticProps, NextPage} from 'next';
2+
import fs from 'fs';
3+
import path from 'path';
4+
5+
import Layout from '../../src/components/Layout';
6+
import Longform from '../../src/components/Longform';
7+
import Markdown from '../../src/components/Markdown';
8+
import {docsNavItems} from '../../src/data/navItems';
9+
import {parseMarkdown} from '../../src/utils/markdown.mjs';
10+
import {MarkdownFile} from '../../src/types';
11+
import PageMeta from '../../src/components/PageMeta';
12+
13+
interface Props {
14+
title: string;
15+
description: string;
16+
readme: MarkdownFile['readme'];
17+
}
18+
19+
const Documentation: NextPage<Props> = ({readme, description, title}) => {
20+
return (
21+
<Layout title={title} navItems={docsNavItems}>
22+
<PageMeta title={title} />
23+
24+
<Longform>
25+
<Markdown text={description} />
26+
<Markdown text={readme} />
27+
</Longform>
28+
</Layout>
29+
);
30+
};
31+
32+
const docsDirectory = path.join(process.cwd(), 'content/docs');
33+
34+
export const getStaticProps: GetStaticProps<
35+
Props,
36+
{category: string; doc: string}
37+
> = async () => {
38+
const fullPath = path.join(docsDirectory, 'index.md');
39+
const content = fs.readFileSync(fullPath, 'utf-8');
40+
const {readme, frontMatter}: MarkdownFile = parseMarkdown(content);
41+
const {title, description} = frontMatter;
42+
43+
if (content) {
44+
const props: Props = {
45+
readme,
46+
title,
47+
description,
48+
};
49+
50+
return {props};
51+
}
52+
53+
throw new Error(`Attempted to load this path but it was not found: ${path}`);
54+
};
55+
56+
export default Documentation;

polaris.shopify.com/src/components/Longform/Longform.module.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
display: none;
135135
}
136136

137-
p code {
137+
*:not(pre) > code {
138138
font-family: var(--font-family-mono);
139139
font-size: 0.9em;
140140
font-weight: var(--font-weight-500);
@@ -173,7 +173,7 @@
173173

174174
th,
175175
td {
176-
padding: 0.6rem .70588rem;
176+
padding: 0.6rem 0.70588rem;
177177
border-bottom: 1px solid var(--border-color-light);
178178

179179
&:first-child {
@@ -193,7 +193,6 @@
193193
padding-right: 2.8rem;
194194
}
195195
}
196-
197196
}
198197

199198
tbody {

polaris.shopify.com/src/data/navItems.ts

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ export const foundationsNavItems: NavItemWithIcon[] = [
1414
title: 'Foundations',
1515
children: [
1616
{
17-
title: "About Polaris",
18-
url: "/foundations/foundations/about-polaris",
19-
icon: "HintMajor",
17+
title: 'About Polaris',
18+
url: '/foundations/foundations/about-polaris',
19+
icon: 'HintMajor',
2020
description:
2121
"Learn what the Polaris design system is and how it's used by designers and developers to build world-class Shopify admin experiences.",
2222
},
2323
{
24-
title: "Experience values",
25-
url: "/foundations/foundations/experience-values",
26-
icon: "HeartMajor",
24+
title: 'Experience values',
25+
url: '/foundations/foundations/experience-values',
26+
icon: 'HeartMajor',
2727
description:
2828
'At Shopify, we empower commerce at a global scale. We build products, tools, and services for people to start, manage, and scale their businesses. We manage enormous complexity for commerce giants, and give new entrepreneurs the best chance to succeed.',
2929
},
@@ -200,16 +200,16 @@ export const foundationsNavItems: NavItemWithIcon[] = [
200200
title: 'Patterns',
201201
children: [
202202
{
203-
title: "Design Patterns",
204-
url: "/foundations/patterns/design-patterns",
205-
icon: "RefreshMajor",
203+
title: 'Design Patterns',
204+
url: '/foundations/patterns/design-patterns',
205+
icon: 'RefreshMajor',
206206
description:
207-
"Design patterns provide repeatable UX solutions to common merchant situations.",
207+
'Design patterns provide repeatable UX solutions to common merchant situations.',
208208
},
209209
{
210-
title: "Loading",
211-
url: "/foundations/patterns/loading",
212-
icon: "ClockMajor",
210+
title: 'Loading',
211+
url: '/foundations/patterns/loading',
212+
icon: 'ClockMajor',
213213
description:
214214
"Navigating the Shopify admin should be fast, meaningful, and focused, but unintentional loading can get in the way and break a merchant's flow. To deliver a continuous experience, we need to consider loading states when planning and prototyping.",
215215
},
@@ -316,3 +316,19 @@ export const contributingNavItems = [
316316
],
317317
},
318318
];
319+
320+
export const docsNavItems = [
321+
{
322+
title: 'Documention',
323+
children: [
324+
{
325+
title: 'Getting started',
326+
url: '/docs',
327+
},
328+
{
329+
title: 'Migrations',
330+
url: '/docs/migrations',
331+
},
332+
],
333+
},
334+
];

0 commit comments

Comments
 (0)