Skip to content

Commit

Permalink
fix: update mapeo-settings-builder call
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
luandro committed Jun 4, 2024
1 parent b031d27 commit 41a9b3a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions pages/api/build/[...id].ts
Original file line number Diff line number Diff line change
@@ -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<void>;
// const settingsBuilder = require('mapeo-settings-builder/commands/build_lint.js') as (options: { output: string }, outputDir: string) => Promise<void>;
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) {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 41a9b3a

Please sign in to comment.