Closed ednevsky closed 3 months ago
Thanks for your efforts and for the suggestion!
I've made changes to notehost to run js instead of bash for prebuild. I don't have a windows machine to test on, but hopefully if you run the latest version - it should work out of the box for you :)
I'm on Windows, wasn't working for me until I changed the script to .js with the help of gpt-4 turbo. Here's the full advice:
--
The build-page-script-js-string.sh script takes the contents of the JavaScript file ./src/page-script.js, escapes all backslashes, and wraps the result in a template string. This content is then exported as a TypeScript constant in a file named _page-script-js-string.ts.
Let's translate this script to make it compatible across different environments. You can choose to convert this script into a Node.js script since you're working within a Node project environment. This would provide better compatibility and control when running across multiple platforms.
Creating a Node.js Script Create a new file, say build-page-script-js-string.js, and write the following JavaScript code to mimic the behavior of your shell script:
const fs = require('fs'); const path = require('path');
const outFilePath = path.join(__dirname, 'src', '_page-script-js-string.ts'); const pageScriptPath = path.join(__dirname, 'src', 'page-script.js');
try { const pageScriptContent = fs.readFileSync(pageScriptPath, 'utf8'); const escapedContent = pageScriptContent.replace(/\/g, '\\'); const finalContent =
export const PAGE_SCRIPT_JS_STRING = \
`;`;fs.writeFileSync(outFilePath, finalContent); console.log('Page script was built successfully!'); } catch (error) { console.error('Failed to build page script:', error); } Updating package.json Modify your package.json under the scripts section, replacing the shell script with this new JavaScript file:
"scripts": { "prebuild": "node build-page-script-js-string.js", "deploy": "npm run prebuild && npx --yes wrangler@latest deploy" } Running the Script Now, using either PowerShell, Command Prompt, or Git Bash, you can run your deploy script:
npm run deploy This should successfully build the page script and proceed with the deployment without facing the issue you experienced with the shell script.
This Node.js script will also make your project more portable and easier to maintain when working across various operating systems. If you have any more questions or need additional assistance, feel free to ask!