From 8f9351f4159cfb2b31b5fd23a4e010e116b9a0c8 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Tue, 9 Apr 2024 22:29:35 -0700 Subject: [PATCH] Use posix.join --- generate-routes.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/generate-routes.ts b/generate-routes.ts index bdcaae4d..ed03f5bf 100644 --- a/generate-routes.ts +++ b/generate-routes.ts @@ -1,5 +1,5 @@ import { readFile, writeFile } from 'node:fs/promises' -import { dirname, resolve } from 'node:path' +import { dirname, resolve, posix } from 'node:path' import { fileURLToPath } from 'node:url' import { openapi } from '@seamapi/types/connect' @@ -8,24 +8,33 @@ import { deleteAsync } from 'del' import { ESLint } from 'eslint' import { format, resolveConfig } from 'prettier' -const rootPath = resolve( - dirname(fileURLToPath(import.meta.url)), +const rootPathParts = [ 'src', 'lib', 'seam', 'connect', +] + +const routeOutputPathParts = [ + 'routes' +] + +const rootPath = resolve( + dirname(fileURLToPath(import.meta.url)), + ...rootPathParts ) const rootClassPath = resolve(rootPath, 'seam-http.ts') -const routeOutputPath = resolve(rootPath, 'routes') +const routeOutputPath = resolve(rootPath, ...routeOutputPathParts) async function main(): Promise { const routes = createRoutes() const routeNames = await Promise.all(routes.map(writeRoute)) const routeIndexName = await writeRoutesIndex(routes) + const outputPathParts = [...rootPathParts, routeOutputPathParts] await deleteAsync([ - `${routeOutputPath}/**`, - `!${routeOutputPath}/${routeIndexName}`, - ...routeNames.map((name) => `!${routeOutputPath}/${name}`), + posix.join(...outputPathParts, '*') + `!${posix.join(...outputPathParts, routeIndexName)}`, + ...routeNames.map((name) => `!${posix.join(...outputPathParts, name)}`), ]) }