Skip to content

Commit 79078ef

Browse files
Merge pull request #2752 from SalesforceCommerceCloud/t/commerce/W-18979555/updatingReadMeFile
@W-18979555 - Updated CreateAppGuidelines tool to handle the truncating of JSON
2 parents e1306dc + 0880af3 commit 79078ef

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

packages/pwa-storefront-mcp/src/utils/pwa-create-app-guideline-tool.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7+
import os from 'os'
78
import path from 'path'
9+
import {exec} from 'child_process'
10+
import fs from 'fs/promises'
811

912
// Project dependencies
10-
import {EmptyJsonSchema, isMonoRepo, runCommand} from './utils'
11-
12-
// const CREATE_APP_VERSION = 'latest'
13-
const CREATE_APP_VERSION = '3.11.0-nightly-20250630080227'
14-
const CREATE_APP_COMMAND = isMonoRepo()
15-
? path.resolve(
16-
`${process.env.WORKSPACE_FOLDER_PATHS}/packages/pwa-kit-create-app/scripts/create-mobify-app.js`
17-
)
18-
: `@salesforce/pwa-kit-create-app@${CREATE_APP_VERSION}`
13+
import {EmptyJsonSchema, runNpxCommand} from './utils'
14+
15+
//const CREATE_APP_VERSION = 'latest'
16+
//const CREATE_APP_VERSION = '3.11.0-nightly-20250630080227'
17+
const CREATE_APP_COMMAND = '@salesforce/pwa-kit-create-app@3.11.0-nightly-20250630080227'
1918
const DISPLAY_PROGRAM_COMMAND = '--displayProgram'
2019
const NPX_COMMAND = 'npx'
2120

@@ -76,10 +75,11 @@ export default {
7675

7776
// Run the display program and get the output.
7877
try {
79-
programOutput = await runCommand(NPX_COMMAND, [
78+
programOutput = await runNpxCommand(
79+
NPX_COMMAND,
8080
CREATE_APP_COMMAND,
8181
DISPLAY_PROGRAM_COMMAND
82-
])
82+
)
8383
} catch (err) {
8484
console.error('Failed to run display program:', err)
8585
}

packages/pwa-storefront-mcp/src/utils/utils.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import path from 'path'
99
import {spawn} from 'cross-spawn'
1010
import {zodToJsonSchema} from 'zod-to-json-schema'
1111
import {z} from 'zod'
12+
import os from 'os'
13+
import {exec} from 'child_process'
1214

1315
// Private schema used to generate the JSON schema
1416
const emptySchema = z.object({}).strict()
@@ -83,3 +85,29 @@ export function isMonoRepo() {
8385
const lernaPath = path.resolve(__dirname, '../../../..', 'lerna.json')
8486
return fs.existsSync(lernaPath)
8587
}
88+
89+
/**
90+
* Runs an NPX command and captures its output.
91+
*
92+
* @returns {Promise<string>} - Resolves with the command output.
93+
*/
94+
export async function runNpxCommand(NPX_COMMAND, CREATE_APP_COMMAND, DISPLAY_PROGRAM_COMMAND) {
95+
return new Promise((resolve, reject) => {
96+
const tempDir = os.tmpdir()
97+
const outputFilePath = path.join(tempDir, 'npx-output.json')
98+
const errorFilePath = path.join(tempDir, 'npx-error.log')
99+
const command = `${NPX_COMMAND} ${CREATE_APP_COMMAND} ${DISPLAY_PROGRAM_COMMAND} > ${outputFilePath} 2> ${errorFilePath}`
100+
101+
exec(command, (error) => {
102+
if (error) {
103+
reject(error)
104+
return
105+
}
106+
107+
fs.promises
108+
.readFile(outputFilePath, 'utf-8')
109+
.then((data) => resolve(data))
110+
.catch((err) => reject(err))
111+
})
112+
})
113+
}

0 commit comments

Comments
 (0)