Skip to content

Commit

Permalink
Fix specialMethod detection (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
aralroca authored Mar 24, 2020
1 parent 0639694 commit a182c35
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions cli/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {
function readDirR(dir) {
return fs.statSync(dir).isDirectory()
? Array.prototype.concat(
...fs.readdirSync(dir).map(f => readDirR(path.join(dir, f)))
...fs.readdirSync(dir).map((f) => readDirR(path.join(dir, f)))
)
: dir
}
Expand All @@ -32,7 +32,7 @@ createPagesDir(allLanguages)
async function createPagesDir(langs = []) {
execSync(`rm -rf ${finalPagesDir} && mkdir ${finalPagesDir}`)

langs.forEach(async lang => {
langs.forEach(async (lang) => {
execSync(`mkdir ${finalPagesDir}/${lang}`)
})

Expand Down Expand Up @@ -62,7 +62,7 @@ function clearPageExt(page) {
* STEP 2: Read each page namespaces
*/
function readPageNamespaces(langs) {
readDirR(currentPagesDir).forEach(async page => {
readDirR(currentPagesDir).forEach(async (page) => {
const pageId = clearPageExt(page.replace(currentPagesDir, '')) || '/'
const namespaces = await getPageNamespaces({ pages }, pageId)

Expand All @@ -75,7 +75,9 @@ function readPageNamespaces(langs) {
}

function hasSpecialMethod(data, name) {
return data.match(new RegExp(`export (const|var|let|function) ${name}`))
return data.match(
new RegExp(`export (const|var|let|async function|function) ${name}`)
)
}

function specialMethod(name, lang) {
Expand Down Expand Up @@ -160,7 +162,7 @@ function buildPageInAllLocales(pagePath, namespaces, langs) {
}

// For each lang
langs.forEach(lang => {
langs.forEach((lang) => {
buildPageLocale({
lang,
namespaces,
Expand Down
6 changes: 3 additions & 3 deletions examples/static-site/pages_/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export default function Home(props) {
}

// @ts-ignore
export const getStaticProps = async ({ lang }) => ({
props: { getStaticPropsWorks: true, lang },
})
export async function getStaticProps({ lang }) {
return { props: { getStaticPropsWorks: true, lang } }
}
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.13.0-canary.1",
"version": "0.13.0-canary.2",
"description": "Next.js utility to translate pages without the need of a server (static i18n pages generator).",
"license": "MIT",
"keywords": [
Expand Down

0 comments on commit a182c35

Please sign in to comment.