diff --git a/index.js b/index.js index 9c02d0f..9385e69 100644 --- a/index.js +++ b/index.js @@ -5,16 +5,10 @@ var fs = require('fs'); var path = require('path'); var verifyFile = require('./lib/verify-file'); +var readVersion = require('./lib/read-version'); var platform = os.platform() + '-' + os.arch(); - -var packageName = '@ffmpeg-installer/' + platform; -var version = require('./package.json').optionalDependencies[packageName]; - -if (!version) { - console.error('Unsupported platform/architecture:', platform); - process.exit(1); -} +var version = readVersion(platform); var binary = os.platform() === 'win32' ? 'ffmpeg.exe' : 'ffmpeg'; diff --git a/lib/read-version.js b/lib/read-version.js new file mode 100644 index 0000000..2401687 --- /dev/null +++ b/lib/read-version.js @@ -0,0 +1,15 @@ +'use strict'; + +function readVersion(platform) { + var packageName = '@ffmpeg-installer/' + platform; + var version = require('../package.json').optionalDependencies[packageName]; + + if (!version) { + console.error('ERROR: Unsupported platform/architecture:', platform); + process.exit(1); + } + + return version; +} + +module.exports = readVersion; diff --git a/package.json b/package.json index 68c1579..e852291 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,8 @@ "version": "1.0.3", "main": "index.js", "scripts": { + "preinstall": "scripts/pre-install.js", + "postinstall": "scripts/post-install.js", "lint": "jshint *.js", "preversion": "npm run lint" }, diff --git a/scripts/post-install.js b/scripts/post-install.js new file mode 100644 index 0000000..5622c34 --- /dev/null +++ b/scripts/post-install.js @@ -0,0 +1,10 @@ +#!/usr/bin/env node + +var verifyFile = require('../lib/verify-file'); +var ffmpeg = require('../'); + +var successfulInstall = verifyFile(ffmpeg.path); +if (!successfulInstall) { + console.error('ERROR: Installed path does not exist:', ffmpeg.path); + process.exit(1); +} diff --git a/scripts/pre-install.js b/scripts/pre-install.js new file mode 100644 index 0000000..0f6bea4 --- /dev/null +++ b/scripts/pre-install.js @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +var os = require('os'); +var readVersion = require('../lib/read-version'); + +var platform = os.platform() + '-' + os.arch(); +readVersion(platform); +