Skip to content

Commit

Permalink
fix: some typescript adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jul 10, 2019
1 parent feb2457 commit 4ba6eaf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,15 @@ export const writeNotFound = async () => {
const writeGatsbyConfig = async ({ args, isDoczRepo }: ServerMachineCtx) => {
const outputPath = path.join(paths.docz, 'gatsby-config.js')
const config = omit(['plugins'], args)
const newConfig = JSON.stringify({ ...config, root: paths.docz })
const newConfig = {
...config,
root: paths.docz,
}

await outputFileFromTemplate('gatsby-config.tpl.js', outputPath, {
isDoczRepo,
config: newConfig,
opts: JSON.stringify(newConfig),
})
}

Expand Down
20 changes: 10 additions & 10 deletions core/docz-core/templates/gatsby-config.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ const config = {
plugins: [
{
resolve: 'gatsby-theme-docz',
options: <%- config %>
},
<% if (isDoczRepo) {%>{
options: <%- opts %>
},<% if (config.typescript) {%>
{
resolve: 'gatsby-plugin-typescript',
options: {
isTSX: true,
allExtensions: true
}
},<%}%><% if (isDoczRepo) {%>
{
resolve: 'gatsby-plugin-eslint',
options: {
test: /\.js$|\.jsx$/,
Expand All @@ -35,13 +42,6 @@ const config = {
modules: ['docz', 'gatsby-theme-docz'],
},
},<%}%>
<% if (config.typescript) {%>{
resolve: 'gatsby-plugin-typescript',
options: {
isTSX: true,
allExtensions: true
}
}<%}%>
],
}

Expand Down
8 changes: 8 additions & 0 deletions core/gatsby-theme-docz/lib/onCreateWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ module.exports = async (params, opts) => {
const run = Plugin.runPluginsMethod(args.plugins)
const config = getConfig()

if (args.typescript) {
actions.setWebpackConfig({
resolve: {
extensions: config.resolve.extensions.concat(['.ts', '.tsx']),
},
})
}

if (hasParentNodeModules && stage === 'develop') {
actions.setWebpackConfig({
resolve: {
Expand Down
4 changes: 2 additions & 2 deletions examples/typescript/src/components/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export interface AlertProps {
kind: 'info' | 'positive' | 'negative' | 'warning'
}

const AlertStyled = styled('div')`
const AlertStyled = styled('div')<AlertProps>`
padding: 15px 20px;
background: white;
border-radius: 3px;
color: white;
background: ${({ kind = 'info' }: AlertProps) => kinds[kind]};
background: ${({ kind = 'info' }) => kinds[kind]};
`

export const Alert: SFC<AlertProps> = ({ kind, ...props }) => (
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript/src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const getScale = ({ scale = 'normal' }: ButtonProps) => scales[scale]
const getKind = ({ kind = 'primary', outline = false }: ButtonProps) =>
kinds(outline)[kind]

const ButtonStyled = styled('button')`
const ButtonStyled = styled('button')<ButtonProps>`
${getKind};
${getScale};
cursor: pointer;
Expand Down

0 comments on commit 4ba6eaf

Please sign in to comment.