diff --git a/generate/templates/templates/binding.gyp b/generate/templates/templates/binding.gyp index e6f1141cb..c15a7ec55 100644 --- a/generate/templates/templates/binding.gyp +++ b/generate/templates/templates/binding.gyp @@ -1,21 +1,13 @@ { - "conditions": [ - ["(OS=='win' and node_root_dir.split('\\\\')[-1].startswith('iojs')) or (OS=='mac' and node_root_dir.split('/')[-1].startswith('iojs'))", { - "variables": { - "is_electron%": "1", - } - }, { - "variables": { - "is_electron%": "0", - } - }] - ], + "variables": { + "is_electron%": " arr[arr.length - 1]; +const sep = process.platform === "win32" ? "\\\\" : "/"; +const [, , nodeRootDir] = process.argv; + +let isElectron = last(nodeRootDir.split(sep)).startsWith("iojs"); + +if (!isElectron) { + try { + // Not ideal, would love it if there were a full featured gyp package to do this operation instead. + const { variables: { built_with_electron } } = JSON5.parse( + fs.readFileSync( + path.resolve(nodeRootDir, "include", "node", "config.gypi"), + "utf8" + ) + ); + + if (built_with_electron) { + isElectron = true; + } + } catch (e) {} +} + +fs.writeFileSync("was_electron", isElectron ? "1" : "0"); +process.stdout.write(isElectron ? "1" : "0");