Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
benallfree committed Apr 23, 2024
1 parent 6859428 commit 2abd1b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
20 changes: 0 additions & 20 deletions plop/plopfile.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { findUpSync } from 'find-up'
import { existsSync } from 'fs'
import 'node-fetch'
import { dirname, join } from 'path'
import type { NodePlopAPI } from 'plop'
import { fileURLToPath } from 'url'
import { appsRoot } from '../src/util/getApp'
import { stringify } from '../src/util/stringify'
import { buildCommand } from './commands/buildCommand'
import { cleanCommand } from './commands/cleanCommand'
Expand All @@ -15,21 +10,6 @@ import { publishCommand } from './commands/publishCommand'
import { testCommand } from './commands/testCommand'
import { updateCommand } from './commands/updateCommand'

const __dirname = dirname(fileURLToPath(import.meta.url))

const ROOT = findUpSync(`package.json`, {
cwd: __dirname,
})
if (!ROOT) {
throw new Error(`Can't find package.json in any parent path`)
}
const APPS_ROOT = join(dirname(ROOT), 'dist', 'apps')
if (!existsSync(APPS_ROOT)) {
console.warn(`Warning: can't find ${APPS_ROOT}`)
}

appsRoot(APPS_ROOT)

export default async function (plop: NodePlopAPI) {
plop.setHelper('stringify', function (context) {
return stringify(context)
Expand Down
24 changes: 18 additions & 6 deletions src/util/getApp.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
import { findUpSync } from 'find-up'
import { existsSync } from 'fs'
import { globSync } from 'glob'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
import type { AppInfo } from '../apps/'
import { dbge } from './log'
import { mkSetting } from './mkSetting'

const __dirname = dirname(fileURLToPath(import.meta.url))
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

export const appsRoot = mkSetting(join(__dirname, `..`, `apps`))
export const PACKAGE_ROOT = findUpSync(`package.json`, {
cwd: __dirname,
})
if (!PACKAGE_ROOT) {
throw new Error(`Can't find package.json in any parent path`)
}

export const APPS_ROOT = join(dirname(PACKAGE_ROOT), 'dist', 'apps')
if (!existsSync(APPS_ROOT)) {
console.warn(`Warning: can't find ${APPS_ROOT}`)
}

export const getApp = async (slug: string) => {
try {
console.log({ slug, appsRoot: appsRoot() })
console.log(globSync(join(appsRoot(), '**')))
const path = join(appsRoot(), slug, 'index.js')
console.log({ slug, APPS_ROOT })
console.log(globSync(join(APPS_ROOT, '**')))
const path = join(APPS_ROOT, slug, 'index.js')
const module = await import(path)
return module[slug] as AppInfo
} catch (e) {
Expand Down

0 comments on commit 2abd1b1

Please sign in to comment.