diff --git a/plop/commands/testCommand.ts b/plop/commands/testCommand.ts index d679ece..ebd897b 100644 --- a/plop/commands/testCommand.ts +++ b/plop/commands/testCommand.ts @@ -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' @@ -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] diff --git a/plop/commands/updateCommand.ts b/plop/commands/updateCommand.ts index 0edb929..bb24072 100644 --- a/plop/commands/updateCommand.ts +++ b/plop/commands/updateCommand.ts @@ -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' @@ -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}` diff --git a/plop/commands/util/getBot.ts b/plop/commands/util/getBot.ts index 6f8ce27..fece361 100644 --- a/plop/commands/util/getBot.ts +++ b/plop/commands/util/getBot.ts @@ -1,5 +1,7 @@ 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, @@ -7,8 +9,18 @@ import { type GobotOptions, } from '../../../src/api' -export async function getBot(appPath: string, options?: Partial) { - 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) { + 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 diff --git a/src/util/getApp.ts b/src/util/getApp.ts index 396ce25..0045325 100644 --- a/src/util/getApp.ts +++ b/src/util/getApp.ts @@ -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 {