├── .gitignore ├── .travis.yml ├── README.md ├── index.js ├── package.json └── rebuild.sh /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | package-lock.json 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | cache: 3 | directories: 4 | - node_modules 5 | notifications: 6 | email: true 7 | node_js: 8 | - '6' 9 | before_script: 10 | - npm prune 11 | after_success: 12 | - npm run semantic-release 13 | branches: 14 | except: 15 | - /^v\d+\.\d+\.\d+$/ 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rebuild-node-sass 2 | 3 | > Rebuilds node-sass but only if needed 4 | 5 | [![NPM][npm-icon] ][npm-url] 6 | 7 | [![Build status][ci-image] ][ci-url] 8 | [![semantic-release][semantic-image] ][semantic-url] 9 | 10 | ## Use 11 | 12 | ```sh 13 | npm install --save-dev rebuild-node-sass node-sass 14 | ``` 15 | 16 | Then before build (when `node-sass` is probably used), call `rebuild-node-sass` 17 | to make sure it is ready 18 | 19 | ```json 20 | { 21 | "scripts": { 22 | "prebuild": "rebuild-node-sass", 23 | "build": "..." 24 | } 25 | } 26 | ``` 27 | 28 | ## Testing 29 | 30 | To execute in a different environment, for example when working on Mac, we 31 | can install Mac Sass binary `npm install` and then switch to Docker 32 | 33 | ```sh 34 | docker run -v $PWD:/src -w /src -it node /bin/bash 35 | ``` 36 | 37 | which produces the following output (abridged) 38 | 39 | ```sh 40 | root@0d0cd593e320:/src# ./rebuild.sh 41 | npm info it worked if it ends with ok 42 | npm info using npm@5.0.0 43 | npm info using node@v8.0.0 44 | npm info ok 45 | /src/node_modules/node-sass/lib/binding.js:15 46 | throw new Error(errors.missingBinary()); 47 | ... 48 | Binary found at /src/node_modules/node-sass/vendor/linux-x64-57/binding.node 49 | Testing binary 50 | Binary is fine 51 | node-sass@4.5.3 /src/node_modules/node-sass 52 | ``` 53 | 54 | [npm-icon]: https://nodei.co/npm/rebuild-node-sass.svg?downloads=true 55 | [npm-url]: https://npmjs.org/package/rebuild-node-sass 56 | [ci-image]: https://travis-ci.org/bahmutov/rebuild-node-sass.svg?branch=master 57 | [ci-url]: https://travis-ci.org/bahmutov/rebuild-node-sass 58 | [semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg 59 | [semantic-url]: https://github.com/semantic-release/semantic-release 60 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const execa = require('execa') 4 | 5 | function rebuildNodeSass() { 6 | console.log('rebuilding node-sass') 7 | return execa('npm', ['rebuild', 'node-sass']) 8 | .catch(e => { 9 | console.error('Could not rebuild node-sass') 10 | console.error(e.message) 11 | process.exit(-1) 12 | }) 13 | } 14 | 15 | execa('node-sass', ['--version']) 16 | .catch(rebuildNodeSass) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rebuild-node-sass", 3 | "version": "0.0.0-development", 4 | "description": "Rebuilds node-sass but only if needed", 5 | "main": "index.js", 6 | "bin": { 7 | "rebuild-node-sass": "index.js" 8 | }, 9 | "scripts": { 10 | "test": "./rebuild.sh", 11 | "semantic-release": "semantic-release pre && npm publish && semantic-release post" 12 | }, 13 | "files": [ 14 | "index.js" 15 | ], 16 | "keywords": [ 17 | "sass", 18 | "node-sass", 19 | "util" 20 | ], 21 | "author": "Gleb Bahmutov ", 22 | "license": "ISC", 23 | "devDependencies": { 24 | "node-sass": "^4.5.3", 25 | "semantic-release": "^6.3.6" 26 | }, 27 | "repository": { 28 | "type": "git", 29 | "url": "https://github.com/bahmutov/rebuild-node-sass.git" 30 | }, 31 | "dependencies": { 32 | "execa": "^0.8.0" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rebuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | $(npm bin)/node-sass --version >> /dev/null || npm rebuild node-sass 4 | --------------------------------------------------------------------------------