From 0b5d9863a9e8d3c84ff666cf8f43b696a33e3204 Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Sat, 27 May 2017 15:49:52 -0300 Subject: [PATCH] Make launch script's Go prep compatible with Windows --- pokemon-showdown | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pokemon-showdown b/pokemon-showdown index 22d77cec4d28d..164f2bf69a3ca 100755 --- a/pokemon-showdown +++ b/pokemon-showdown @@ -55,7 +55,7 @@ if (config && config.golang) { let stat; let needsSrcDir = false; try { - stat = fs.lstatSync(path.resolve(GOPATH, 'src/github.com/Zarel')); + stat = fs.lstatSync(path.resolve(GOPATH, 'src/github.com/Zarel/Pokemon-Showdown')); } catch (e) { needsSrcDir = true; } finally { @@ -67,6 +67,7 @@ if (config && config.golang) { if (needsSrcDir) { try { fs.mkdirSync(path.resolve(GOPATH, 'src/github.com/Zarel')); + fs.mkdirSync(path.resolve(GOPATH, 'src/github.com/Zarel/Pokemon-Showdown')); } catch (e) { console.error(`Cannot make go source directory for the sockets library files! Symlink them manually from ${__dirname} to ${path.resolve(GOPATH, 'src/github.com/Zarel/Pokemon-Showdown/')}`); process.exit(0); @@ -74,16 +75,20 @@ if (config && config.golang) { } try { - stat = fs.lstatSync(path.resolve(GOPATH, 'src/github.com/Zarel/Pokemon-Showdown')); + stat = fs.lstatSync(path.resolve(GOPATH, 'src/github.com/Zarel/Pokemon-Showdown/sockets')); } catch (e) {} if (!stat || !stat.isSymbolicLink()) { + let srcPath = path.resolve(__dirname, 'sockets'); + let tarPath = path.resolve(GOPATH, 'src/github.com/Zarel/Pokemon-Showdown/sockets'); try { - // FIXME: does this even work on Windows? Check to see if `mklink /J` - // might be needed instead - fs.symlink(__dirname, path.resolve(GOPATH, 'src/github.com/Zarel/Pokemon-Showdown')); + if (process.platform === 'win32') { + child_process.execSync(`mklink /J ${tarPath} ${srcPath}`, {stdio: 'inherit'}); + } else { + fs.symlink(srcPath, tarPath); + } } catch (e) { - console.error(`Cannot make go source directory for the sockets library files! Symlink them manually from ${__dirname} to ${path.resolve(GOPATH, './src/github.com/Zarel/Pokemon-Showdown/')}`); + console.error(`Cannot make go source directory for the sockets library files! Symlink them manually from ${srcPath} to ${tarPath}`); process.exit(0); } }