Skip to content

Commit

Permalink
Fix structure's page logic. Page.path is absolute.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterp committed Jan 17, 2021
1 parent fdade5f commit 8fd92cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
10 changes: 6 additions & 4 deletions packages/internal/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ export interface Paths {
}

export interface PagesDependency {
/** the variable to which the import is assigned */
importName: string
/** absolute path without extension */
importPath: string
const: string
/** absolute path with extension */
path: string
/** const ${importName} = { ...data structure for async imports... } */
importStatement: string
}

Expand Down Expand Up @@ -161,15 +164,14 @@ export const processPagesDir = (
const pagePaths = glob.sync('**/**/*Page.{js,jsx,tsx}', { cwd: webPagesDir })
return pagePaths.map((pagePath) => {
const p = path.parse(pagePath)
// converts `admin/DeleteUserPage` -> `adminDeleteUserPage`

const importName = p.dir.replace(path.sep, '')
const importPath = path.join(webPagesDir, p.dir, p.name)
const importStatement = `const ${importName} = { name: '${importName}', loader: import('${importPath}') }`
return {
importName,
const: importName,
importPath,
path: importPath,
path: path.join(webPagesDir, pagePath),
importStatement,
}
})
Expand Down
9 changes: 2 additions & 7 deletions packages/structure/src/model/RWPage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { existsSync } from 'fs'
import { dirname } from 'path'

import * as tsm from 'ts-morph'

import { FileNode } from '../ide'
import { lazy } from '../x/decorators'
import { directoryNameResolver } from '../x/path'

import { RWProject } from './RWProject'

Expand All @@ -17,12 +17,7 @@ export class RWPage extends FileNode {
super()
}
@lazy() get filePath() {
const f = directoryNameResolver(this.path)
if (!f)
throw new Error(
`could not resolve index filename for directory '${this.path}' using dirname convention`
)
return f
return this.path
}
@lazy() get route() {
return this.parent.router.routes.find(
Expand Down

0 comments on commit 8fd92cf

Please sign in to comment.