Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
benallfree committed Apr 25, 2024
1 parent 29b436c commit 1b84f1f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
5 changes: 2 additions & 3 deletions plop/commands/testCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import type { ActionType, NodePlopAPI } from 'plop'
import pkg from '../../package.json'
import type { ArchKey, PlatformKey } from '../../src/Gobot'
import { Flags } from '../../src/util/flags'
import { APPS_SRC_ROOT } from '../../src/util/getApp'
import { cleanVerdaccioPackages } from './helpers/cleanVerdaccioPackages'
import { exec } from './helpers/exec'
import { rimraf } from './helpers/rimraf'
import { getBot } from './util/getBot'
import { APPS_SRC_ROOT, getBot } from './util/getBot'
import { getSlugsFromFileSystem } from './util/getSlugsFromFileSystem'
import { loadTestModule } from './util/loadTestModule'
import { matchSnapshot } from './util/matchSnapshot'
Expand Down Expand Up @@ -67,7 +66,7 @@ export function testCommand(plop: NodePlopAPI) {

const appHelperPath = join(appPath, `helper`)

const { bot } = await getBot(appPath)
const { bot } = await getBot(slug)

const shouldRun = async () =>
!!(await bot.releases())[0]?.archives[platform()]?.[arch() as ArchKey]
Expand Down
5 changes: 1 addition & 4 deletions plop/commands/updateCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { join } from 'path'
import type { NodePlopAPI } from 'plop'
import { APPS_SRC_ROOT } from '../../src/util/getApp'
import { getBot } from './util/getBot'
import { getSlugsFromFileSystem } from './util/getSlugsFromFileSystem'
import { mkSubcommander, type Subcommands } from './util/mkSubcommander'
Expand All @@ -13,9 +11,8 @@ export const updateCommand = (plop: NodePlopAPI) => {
gen: [
async (answers, cfg, plop) => {
const { onProgress } = cfg
const appPath = join(APPS_SRC_ROOT, slug)
onProgress(`initializing ${slug} bot`)
const { bot } = await getBot(appPath)
const { bot } = await getBot(slug)
onProgress(`updating ${slug}`)
await bot.update()
return `updated ${slug}`
Expand Down
18 changes: 15 additions & 3 deletions plop/commands/util/getBot.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import { isFunction } from '@s-libs/micro-dash'
import { basename, join } from 'path'
import { existsSync } from 'fs'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
import {
GithubReleaseProvider,
Gobot,
type AppInfo,
type GobotOptions,
} from '../../../src/api'

export async function getBot(appPath: string, options?: Partial<GobotOptions>) {
const appSlug = basename(appPath)
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

export const APPS_SRC_ROOT = join(__dirname, '..', 'src', 'apps')
if (!existsSync(APPS_SRC_ROOT)) {
throw new Error(`Can't find ${APPS_SRC_ROOT}`)
}

console.log({ APPS_SRC_ROOT })

export async function getBot(appSlug: string, options?: Partial<GobotOptions>) {
const appPath = join(APPS_SRC_ROOT, appSlug)
const module = await import(join(appPath)).catch(console.error)
const appInfo = module[appSlug] as AppInfo
const { factory } = appInfo
Expand Down
7 changes: 1 addition & 6 deletions src/util/getApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ if (!existsSync(APPS_DIST_ROOT)) {
console.warn(`Warning: can't find ${APPS_DIST_ROOT}`)
}

export const APPS_SRC_ROOT = join(PACKAGE_ROOT, 'src', 'apps')
if (!existsSync(APPS_SRC_ROOT)) {
throw new Error(`Can't find ${APPS_SRC_ROOT}`)
}

console.log({ PACKAGE_ROOT, APPS_DIST_ROOT, APPS_SRC_ROOT })
console.log({ PACKAGE_ROOT, APPS_DIST_ROOT })

export const getApp = async (slug: string) => {
try {
Expand Down

0 comments on commit 1b84f1f

Please sign in to comment.