Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
benallfree committed Apr 26, 2024
1 parent a6e5fe5 commit 747f319
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2,765 deletions.
13 changes: 8 additions & 5 deletions plop/commands/buildCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { globSync } from 'glob'
import { join } from 'path'
import type { NodePlopAPI } from 'plop'
import { pathToFileURL } from 'url'
import { cliForApp, type AppInfoMeta } from '../../src/api'
import { program } from '../../src/cliCommands'
import { pwd } from '../../src/util/shell'
Expand Down Expand Up @@ -182,11 +183,13 @@ export const buildCommand = (plop: NodePlopAPI) => {
pattern: /##CLI##/,
templateFile: `templates/readme/cli.helper.md.hbs`,
data: async () => {
const appInfo = (
await import(
join(pwd(), `/src/apps/${slug}/helper/dist/api.js`)
)
).meta as AppInfoMeta
const appHelperMetaPath = join(
pwd(),
`/src/apps/${slug}/helper/dist/api.js`,
)
const appHelperMetaUrl = pathToFileURL(appHelperMetaPath).href
const appInfo = (await import(appHelperMetaUrl))
.meta as AppInfoMeta
const program = cliForApp(appInfo)
const serialized = JSON.parse(stringify(program))
return { program: serialized, global: serialized }
Expand Down
11 changes: 6 additions & 5 deletions plop/commands/util/getBot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isFunction } from '@s-libs/micro-dash'
import { existsSync } from 'fs'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
import { fileURLToPath, pathToFileURL } from 'url'
import {
GithubReleaseProvider,
Gobot,
Expand All @@ -14,12 +14,13 @@ const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

export async function getBot(appSlug: string, options?: Partial<GobotOptions>) {
const appPath = join(SRC_APPS_ROOT, appSlug)
console.log({ appPath }, existsSync(appPath))
const module = await import(appPath).catch(console.error)
const appFilePath = join(SRC_APPS_ROOT, appSlug)
const appUrlPath = pathToFileURL(appFilePath).href
console.log({ appUrlPath }, existsSync(appFilePath))
const module = await import(appUrlPath).catch(console.error)
const appInfo = module[appSlug] as AppInfo
const { factory } = appInfo
const cachePath = join(appPath, `test-data`)
const cachePath = join(appFilePath, `test-data`)
const bot = (() => {
if (isFunction(factory)) {
return factory({ ...options, cachePath, env: process.env })
Expand Down
4 changes: 3 additions & 1 deletion plop/commands/util/loadTestModule.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { join } from 'path'
import { pathToFileURL } from 'url'
import { type TestConfig } from '../../../src/TestConfig'
import { mergeConfig } from '../../../src/api'

export async function loadTestModule(appPath: string) {
const testConfigPath = join(appPath, `test-config.ts`)
const module = await import(testConfigPath).catch((e) => {
const testConfigUrl = pathToFileURL(testConfigPath).href
const module = await import(testConfigUrl).catch((e) => {
//Noop, if module is not found
})
return mergeConfig<TestConfig>(
Expand Down
Loading

0 comments on commit 747f319

Please sign in to comment.