From 41a9b3ae788b3896e0c5f2ada93f2d8cad7926c3 Mon Sep 17 00:00:00 2001 From: luandro Date: Tue, 4 Jun 2024 12:33:34 -0300 Subject: [PATCH] fix: update mapeo-settings-builder call This commit updates the call to mapeo-settings-builder to use the shell command instead of the require statement. This change was made to address an issue where the require statement was not working correctly when the project was deployed to a production environment. The shell command provides a more reliable way to execute the mapeo-settings-builder command. --- pages/api/build/[...id].ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/pages/api/build/[...id].ts b/pages/api/build/[...id].ts index cb6a18f..a7873c2 100644 --- a/pages/api/build/[...id].ts +++ b/pages/api/build/[...id].ts @@ -1,10 +1,28 @@ import type { NextApiRequest, NextApiResponse } from "next"; import path from 'path' -const settingsBuilder = require('mapeo-settings-builder/commands/build_lint.js') as (options: { output: string }, outputDir: string) => Promise; +// const settingsBuilder = require('mapeo-settings-builder/commands/build_lint.js') as (options: { output: string }, outputDir: string) => Promise; +import { exec } from 'child_process'; +import { promisify } from 'util'; import getOutputDir from "../../../lib/getOutputDir"; import generateDefault from "../../../lib/generateDefault" import fs from 'fs' +const execAsync = promisify(exec); + +async function runShellCommand(command: string) { + try { + const { stdout, stderr } = await execAsync(command); + if (stderr) { + console.error(`Error: ${stderr}`); + } + return stdout; + } catch (error) { + console.error(`Execution failed: ${error}`); + throw error; + } +} + + function bumpVersion(version: string, bumpType: 'major' | 'minor' | 'patch' = 'patch') { let versionParts = version.split('.'); switch (bumpType) { @@ -68,7 +86,8 @@ const handler = async ( fs.writeFileSync(path.join(outputDir, 'metadata.json'), JSON.stringify(metadata, null, 2), 'utf8'); // update defaults await generateDefault(outputDir) - const build = await settingsBuilder({ output: outputFile }, outputDir) + // const build = await settingsBuilder({ output: outputFile }, outputDir) + runShellCommand(`cd ${outputDir} && mapeo-settings-builder build --output ${outputFile}`) } catch (err) { console.error(err) }