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

Fix type checks #74

Merged
merged 1 commit into from
Mar 11, 2020
Merged
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
12 changes: 6 additions & 6 deletions __tests__/builder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ describe('builder', () => {
expect(pages[1]).toContain('_app.js')

expect(pages[2]).toContain('ca')
expect(pages[3]).toContain('index.tsx')
expect(pages[3]).toContain('index.js')
expect(pages[4]).toContain('more-examples')
expect(pages[5]).toContain('dynamic-namespace.js')
expect(pages[6]).toContain('index.js')

expect(pages[7]).toContain('en')
expect(pages[8]).toContain('index.tsx')
expect(pages[8]).toContain('index.js')
expect(pages[9]).toContain('more-examples')
expect(pages[10]).toContain('dynamic-namespace.js')
expect(pages[11]).toContain('index.js')

expect(pages[12]).toContain('es')
expect(pages[13]).toContain('index.tsx')
expect(pages[13]).toContain('index.js')
expect(pages[14]).toContain('more-examples')
expect(pages[15]).toContain('dynamic-namespace.js')
expect(pages[16]).toContain('index.js')

expect(pages[17]).toContain('index.tsx')
expect(pages[17]).toContain('index.js')
expect(pages[18]).toContain('more-examples')
expect(pages[19]).toContain('dynamic-namespace.js')
expect(pages[20]).toContain('index.js')
Expand All @@ -66,9 +66,9 @@ describe('builder', () => {
})

describe('index.js', () => {
test('Should NOT be the same than the pages_/index.tsx', () => {
test('Should NOT be the same than the pages_/index.js', () => {
const pages_ = fs.readFileSync('examples/static-site/pages_/index.tsx')
const pages = fs.readFileSync('examples/static-site/pages/index.tsx')
const pages = fs.readFileSync('examples/static-site/pages/index.js')

expect(pages_.equals(pages)).toBe(false)
expect(pages.toString()).toContain('I18nProvider')
Expand Down
6 changes: 2 additions & 4 deletions cli/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function readPageNamespaces(langs) {
* STEP 3: Build page in each lang path
*/
function getPageTemplate(prefix, page, lang, namespaces) {
return `// @ts-ignore
return `// @ts-nocheck
import I18nProvider from 'next-translate/I18nProvider'
import React from 'react'
import C from '${prefix}/${clearPageExt(page)}'
Expand All @@ -87,7 +87,6 @@ const namespaces = { ${namespaces
.map((ns, i) => `'${ns}': ns${i}`)
.join(', ')} }

// @ts-ignore
export default function Page(p){
return (
<I18nProvider lang="${lang}" namespaces={namespaces} >
Expand All @@ -96,7 +95,6 @@ export default function Page(p){
)
}

// @ts-ignore
Page = Object.assign(Page, { ...C })
`
}
Expand All @@ -107,7 +105,7 @@ function buildPageLocale({ prefix, pagePath, namespaces, lang, path }) {
const [filename] = finalPath.split('/').reverse()
const dirs = finalPath.replace(`/${filename}`, '')
execSync(`mkdir -p ${dirs}`)
fs.writeFileSync(finalPath, template)
fs.writeFileSync(finalPath.replace(/(\.tsx|\.ts)$/, '.js'), template)
}

function buildPageInAllLocales(pagePath, namespaces, langs) {
Expand Down
3 changes: 3 additions & 0 deletions examples/static-site/pages_/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react'
import Link from 'next/link'

// @ts-ignore
import useTranslation from 'next-translate/useTranslation'
// @ts-ignore
import Header from '../components/header'

export default function Home() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-translate",
"version": "0.10.4",
"version": "0.10.5",
"description": "Next.js utility to translate pages without the need of a server (static i18n pages generator).",
"license": "MIT",
"keywords": [
Expand Down