From 37c381ba1b955b74c0c6288ceff563a7e77ec7fb Mon Sep 17 00:00:00 2001 From: "Guilherme J. Tramontina" Date: Wed, 30 Mar 2016 22:40:37 +1100 Subject: [PATCH] fix(build): Build package prior to installing Using node to check whether running `npm run build` is required. Closes #63 --- bin/install | 24 ++++++++++++++++++++++-- package.json | 4 +++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/bin/install b/bin/install index 515869c..5e8873c 100755 --- a/bin/install +++ b/bin/install @@ -1,3 +1,23 @@ #!/usr/bin/env node -const install = require('../dist/install') -install() +const exists = require('path-exists') +const exec = require('execa') + +function isBuilt() { + return exists('./dist') +} + +function build() { + return exec('npm', ['run', 'build']) +} + +function install() { + require('../dist/install')() +} + +isBuilt().then(function built(yes) { + if (yes) { + install() + } else { + build().then(install) + } +}) diff --git a/package.json b/package.json index 9384aa1..abd6ec2 100644 --- a/package.json +++ b/package.json @@ -29,14 +29,16 @@ "report-coverage": "cat ./coverage/lcov.info | codecov", "validate": "npm t && npm run check-coverage", "commit": "git-cz", - "install": "opt --out ghooks-install --exec \"[ ! -d \"./dist\" ] && npm run build; node ./bin/install\"", + "install": "opt --out ghooks-install --exec \"node ./bin/install\"", "semantic-release": "semantic-release pre && npm publish && semantic-release post" }, "dependencies": { + "execa": "^0.2.2", "findup": "0.1.5", "lodash.clone": "4.3.2", "manage-path": "2.0.0", "opt-cli": "1.4.0", + "path-exists": "^2.1.0", "spawn-command": "0.0.2" }, "devDependencies": {