Skip to content

Commit

Permalink
Add mirror directory stub.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterp committed May 12, 2021
1 parent c722e19 commit f225eba
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
21 changes: 21 additions & 0 deletions packages/internal/src/__tests__/dev.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import path from 'path'

import { generateCellTypes } from '../dev'

const FIXTURE_PATH = path.resolve(
__dirname,
'../../../../__fixtures__/example-todo-main'
)

beforeAll(() => {
process.env.__REDWOOD__CONFIG_PATH = FIXTURE_PATH
})
afterAll(() => {
delete process.env.__REDWOOD__CONFIG_PATH
})

it('generates the correct types mirror types for cells', () => {
//

generateCellTypes()
})
33 changes: 33 additions & 0 deletions packages/internal/src/dev.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
import fs from 'fs'
import path from 'path'

import kill from 'kill-port'

import { findCells } from './findFiles'
import { getPaths } from './paths'

export const shutdownPort = (port: number, method: 'tcp' | 'udp' = 'tcp') => {
return kill(port, method)
}

export const generateDirectoryNamedModuleTypes = () => {}

export const getTypesMirrorDir = () => {
const p = getPaths().typesMirrorDir
fs.mkdirSync(p, { recursive: true })
return p
}

export const generateCellTypes = () => {
// we will first generate them all
// but there must be a better way...

const typesMirrorDir = getTypesMirrorDir()
const rwjsPaths = getPaths()
const cellPaths = findCells()

for (const p of cellPaths) {
// I think these must be named `index.d.ts`
const mirrorCellPath = path.join(
typesMirrorDir,
p.replace(rwjsPaths.base, '')
)

mirrorCellPath //?
}
}
4 changes: 2 additions & 2 deletions packages/internal/src/findFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const findCells = (webSrcDir: string = getPaths().web.src) => {
.map((p) => {
const code = fs.readFileSync(p, 'utf-8')
const exports = getNamedExports(code)
const exportedQUERY = exports.findIndex((v) => v.name === 'QUERY') !== -1 //?
const exportedQUERY = exports.findIndex((v) => v.name === 'QUERY') !== -1
const exportedSuccess =
exports.findIndex((v) => v.name === 'Success') !== -1 //?
exports.findIndex((v) => v.name === 'Success') !== -1
if (exportedQUERY && exportedSuccess) {
return p
}
Expand Down
2 changes: 2 additions & 0 deletions packages/internal/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface BrowserTargetPaths {

export interface Paths {
cache: string
typesMirrorDir: string
types: string
globals: string
base: string
Expand Down Expand Up @@ -144,6 +145,7 @@ export const getPaths = (BASE_DIR: string = getBaseDir()): Paths => {
return {
base: BASE_DIR,
cache,
typesMirrorDir: path.join(BASE_DIR, '.redwood/mirror'),
types,
globals,
api: {
Expand Down

0 comments on commit f225eba

Please sign in to comment.