diff --git a/package.json b/package.json index bc257152..01f428c9 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "gulp-watch": "^5.0.0", "jquery": "^3.2.1", "lodash": "^4.17.4", + "node-gyp": "^3.6.2", "node-sass": "^4.7.2", "pump": "^2.0.0", "sass-loader": "^6.0.6", @@ -49,6 +50,7 @@ "watch_client": "npm run watch --prefix client", "watch_core": "npm run watch --prefix core", "lint": "eslint -f unix client/src core/src csseditor/src", - "test": "npm run build && npm run lint" + "test": "npm run build && npm run lint", + "build_node-sass": "node scripts/build-node-sass.js" } } diff --git a/scripts/build-node-sass-darwin.sh b/scripts/build-node-sass-darwin.sh new file mode 100755 index 00000000..948dde48 --- /dev/null +++ b/scripts/build-node-sass-darwin.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +PLATFORM="darwin" +ARCH="x64" +NODE_API_VERSION="53" +ELECTRON_VERSION="1.6.15" + +scripts/build-node-sass.sh $PLATFORM $ARCH $NODE_API_VERSION $ELECTRON_VERSION diff --git a/scripts/build-node-sass-linux.sh b/scripts/build-node-sass-linux.sh new file mode 100755 index 00000000..73d8f6eb --- /dev/null +++ b/scripts/build-node-sass-linux.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +PLATFORM="linux" +ARCH="x64" +NODE_API_VERSION="53" +ELECTRON_VERSION="1.6.15" + +scripts/build-node-sass.sh $PLATFORM $ARCH $NODE_API_VERSION $ELECTRON_VERSION diff --git a/scripts/build-node-sass.js b/scripts/build-node-sass.js new file mode 100644 index 00000000..aa18a53a --- /dev/null +++ b/scripts/build-node-sass.js @@ -0,0 +1,19 @@ +const process = require('process'); +const child_process = require('child_process'); + +switch (process.platform) { + case 'darwin': + case 'linux': + child_process.execSync(`scripts/build-node-sass-${process.platform}.sh`, { + stdio: 'inherit' + }); + break; + case 'win32': + child_process.execSync(`scripts/rebuild-node-sass.bat`, { + stdio: 'inherit' + }); + break; + default: + console.log(`Unknown platform ${process.platform}`); + process.exit(1); +} diff --git a/scripts/build-node-sass.sh b/scripts/build-node-sass.sh new file mode 100755 index 00000000..2859610d --- /dev/null +++ b/scripts/build-node-sass.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +PLATFORM="$1" +ARCH="$2" +NODE_API_VERSION="$3" +ELECTRON_VERSION="$4" +ELECTRON_URL="https://atom.io/download/electron" + +DIRECTORY="vendor/$PLATFORM-$ARCH-$NODE_API_VERSION" + +if [ `node -p 'process.platform'` != "$PLATFORM" ]; then + echo "You must be running on $PLATFORM to build node-sass for it." + exit 1 +fi + +cd node_modules/node-sass + +if [ -f $DIRECTORY/binding.node ]; then + echo "A binding already exists at $DIRECTORY/binding.node - deleting it" + rm $DIRECTORY/binding.node +fi + +# Build the node-sass binding +# This will be placed at build/Release/binding.node +echo "Building node-sass for $PLATFORM-$ARCH with Node.js API version $NODE_API_VERSION for Electron $ELECTRON_VERSION" +../.bin/node-gyp rebuild --target=$ELECTRON_VERSION --arch $ARCH --dist-url=$ELECTRON_URL + +# Move it to the right place +echo "Moving binding.node to $DIRECTORY" +mkdir -p $DIRECTORY +cp build/Release/binding.node $DIRECTORY/binding.node +rm -rf build