diff --git a/.changeset/1762.md b/.changeset/1762.md new file mode 100644 index 00000000000..810df06d210 --- /dev/null +++ b/.changeset/1762.md @@ -0,0 +1,9 @@ +--- +'@asyncapi/cli': patch +--- + +fix: working on windows installation issue + +- d02b929: Working on windows installation issue + + diff --git a/package.json b/package.json index 0fd3f58646f..3be049ffaf7 100644 --- a/package.json +++ b/package.json @@ -160,7 +160,7 @@ "pack:macos": "oclif pack macos && npm run pack:rename", "pack:linux": "oclif pack deb && npm run pack:rename", "pack:tarballs": "oclif pack tarballs -t linux-x64 && npm run pack:rename", - "pack:windows": "oclif pack win && npm run pack:rename", + "pack:windows": "node scripts/pack-windows-fix.js", "pack:rename": "node scripts/releasePackagesRename.js", "prepublishOnly": "npm run build", "pretest": "npm run build", diff --git a/scripts/pack-windows-fix.js b/scripts/pack-windows-fix.js new file mode 100644 index 00000000000..db3677e7e6a --- /dev/null +++ b/scripts/pack-windows-fix.js @@ -0,0 +1,67 @@ +const { spawnSync } = require('child_process'); +const fs = require('fs'); +const path = require('path'); +const packageJson = require('../package.json'); +const version = packageJson.version; + +console.log(`Packaging AsyncAPI CLI version ${version} for Windows...`); + +const targetFile = path.resolve('node_modules/oclif/lib/tarballs/build.js'); + +if (!fs.existsSync(targetFile)) { + console.error(`File not found: ${targetFile}`); + throw error; +} + +console.log(`Found target file: ${targetFile}`); + +const backupPath = `${targetFile}.backup`; +if (!fs.existsSync(backupPath)) { + fs.copyFileSync(targetFile, backupPath); + console.log(`Backed up original file to: ${backupPath}`); +} + +let fileContent = fs.readFileSync(targetFile, 'utf8'); + +if (fileContent.includes('--force-local')) { + console.log('Patching file to remove --force-local flag'); + fileContent = fileContent.replace(/--force-local/g, ''); + fs.writeFileSync(targetFile, fileContent); + console.log('File patched successfully'); +} else { + console.log('No --force-local flag found in the file. It may have been already patched.'); +} + +try { + console.log('Running oclif pack win...'); + const oclifResult = spawnSync('oclif', ['pack', 'win'], { + stdio: 'inherit', + shell: true + }); + + if (oclifResult.status !== 0) { + console.error('Oclif packaging failed with status:', oclifResult.status); + throw error; + } + + console.log('Running rename script...'); + const renameResult = spawnSync('node', ['scripts/releasePackagesRename.js'], { + stdio: 'inherit', + shell: true + }); + + if (renameResult.status !== 0) { + console.error('Rename script failed with status:', renameResult.status); + throw error; + } + console.log('Windows packaging completed successfully!'); +} catch (err) { + console.error('Error during packaging:', err); +} finally { + if (fs.existsSync(backupPath)) { + fs.copyFileSync(backupPath, targetFile); + console.log('Restored original file'); + fs.unlinkSync(backupPath); + console.log('Removed backup file'); + } +} diff --git a/scripts/releasePackagesRename.js b/scripts/releasePackagesRename.js index 01d1b3f8b91..ca6982ddcf8 100644 --- a/scripts/releasePackagesRename.js +++ b/scripts/releasePackagesRename.js @@ -49,12 +49,78 @@ async function renameTar({version, name, sha}) { await checkAndRenameFile(generatedPath, newPath); } +// async function renameWindows({version, name, sha, arch}) { +// const dist = 'dist/win32'; + +// const generatedPath = path.resolve(dist, `${name}-v${version}-${sha}-${arch}.exe`); +// const newPath = path.resolve(dist, `asyncapi.${arch}.exe`); +// await checkAndRenameFile(generatedPath, newPath); +// } + async function renameWindows({version, name, sha, arch}) { const dist = 'dist/win32'; + // Ensure directory exists + await createDirectory(dist); + const generatedPath = path.resolve(dist, `${name}-v${version}-${sha}-${arch}.exe`); const newPath = path.resolve(dist, `asyncapi.${arch}.exe`); - await checkAndRenameFile(generatedPath, newPath); + + try { + console.log(`Checking for Windows installer at: ${generatedPath}`); + + // Create Windows-specific configuration + const configDir = path.resolve('dist', 'config'); + await createDirectory(configDir); + + // Create installer configuration to use shorter paths + const winConfig = { + installPath: 'C:\\AsyncAPI', + shortPaths: true, + useShortDirectoryNames: true, + maxPathLength: 200 // Set a safe path limit + }; + + fs.writeFileSync( + path.resolve(configDir, 'win-install-config.json'), + JSON.stringify(winConfig, null, 2) + ); + + // Create nsis custom script to handle long paths + const nsisScript = ` +!include LogicLib.nsh +!include FileFunc.nsh + +Function HandleLongPaths + ${If} $INSTDIR == "" + StrCpy $INSTDIR "C:\\AsyncAPI" + ${EndIf} + + ; Enable long paths in registry + WriteRegDWORD HKLM "SYSTEM\\CurrentControlSet\\Control\\FileSystem" "LongPathsEnabled" 1 +FunctionEnd + +!define USE_LONG_PATHS +!define MUI_CUSTOMFUNCTION_GUIINIT HandleLongPaths +`; + + fs.writeFileSync( + path.resolve(configDir, 'windows-longpaths.nsh'), + nsisScript + ); + + // Rename the installer if it exists + if (await fileExists(generatedPath)) { + console.log(`Found Windows installer, renaming to: ${newPath}`); + await rename(generatedPath, newPath); + return true; + } + console.warn(`Warning: Windows installer not found at ${generatedPath}`); + return false; + } catch (err) { + console.error(`Error processing Windows installer: ${err.message}`); + return false; + } } async function renamePkg({version, name, sha, arch}) {