Skip to content

Commit

Permalink
move installDir to opts
Browse files Browse the repository at this point in the history
  • Loading branch information
zrisher committed Apr 13, 2017
1 parent 6254a20 commit 4036ffc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
13 changes: 7 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var _ = {}
_.defaults = require('lodash.defaults')

var defaultOptions = {
appDir: path.join(__dirname, 'steamcmd_bin'),
asyncDelay: 3000,
binDir: path.join(__dirname, 'steamcmd_bin'),
retries: 3,
Expand Down Expand Up @@ -185,13 +186,13 @@ var getAppInfo = function (appID, opts) {
return promiseToRetry(getAppInfoOnce, [appID, opts], opts)
}

var updateAppOnce = function (appId, installDir, opts) {
var updateAppOnce = function (appId, opts) {
opts = _.defaults(opts, defaultOptions)
if (!path.isAbsolute(installDir)) {
if (!path.isAbsolute(opts.appDir)) {
// throw an error immediately because it's invalid data, not a failure
throw new TypeError('installDir must be an absolute path in updateApp')
throw new TypeError('opts.appDir must be an absolute path')
}
var commands = ['@ShutdownOnFailedCommand 0', 'login anonymous', 'force_install_dir ' + installDir, 'app_update ' + appId]
var commands = ['@ShutdownOnFailedCommand 0', 'login anonymous', 'force_install_dir ' + opts.appDir, 'app_update ' + appId]
return run(commands, opts)
.then(function (proc) {
if (proc.stdout.indexOf('Success! App \'' + appId + '\' fully installed') !== -1) {
Expand All @@ -206,8 +207,8 @@ var updateAppOnce = function (appId, installDir, opts) {
})
}

var updateApp = function (appId, installDir, opts) {
return promiseToRetry(updateAppOnce, [appId, installDir, opts], opts)
var updateApp = function (appId, opts) {
return promiseToRetry(updateAppOnce, [appId, opts], opts)
}

var prep = function (opts) {
Expand Down
16 changes: 13 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,26 @@ Runs `download([opts])`, waits briefly to avoid `EBUSY`, then runs
### steamcmd.getAppInfo(appid[, opts])
Asks SteamCMD to get the latest app info for the given app.

### steamcmd.updateApp(appid, installDir[, opts])
Asks SteamCMD to install/update the given app to the given **absolute**
directory. Throws a `TypeError` if `installDir` is not absolute.
### steamcmd.updateApp(appid[, opts])
Returns `true` if the update succeeded or `false` if it wasn't required.
If SteamCMD's stdout isn't recognized, throws it as an error.

## Configuration

All functions take an optional options parameter.

#### appDir

type: string
default: `path.join(__dirname, 'steamcmd_bin')`

The absolute path to directory where steam can manage apps. This can be the
same directory as binDir. Installed apps can be found in
`appDir/steamapps/common/app_full_name`.

For example, on Windows app `1007` installs to
`appDir/steamapps/common/Steamworks SDK Redist`.

#### asyncDelay

type: int
Expand Down
21 changes: 11 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ test.beforeEach(t => {
const binDirParent = tempfile('/')
mkdirp.sync(binDirParent)
const binDir = path.join(binDirParent, 'steamcmd_bin')
const opts = {binDir}
const appDir = binDir
const opts = {appDir, binDir}
t.context = {binDirParent, binDir, opts}
})

Expand Down Expand Up @@ -70,34 +71,34 @@ test('repeated calls to getAppInfo', async t => {

test('updateApp with a relative path', async t => {
var {opts} = t.context
opts.appDir = './relative/path'
await steamcmd.prep(opts)
t.throws(() => steamcmd.updateApp(1007, 'bad_steamworks', opts))
t.throws(() => fs.statSync('bad_steamworks'))
t.throws(() => steamcmd.updateApp(1007, opts))
t.throws(() => fs.statSync(opts.appDir))
})

test('updateApp with a nonexistent app', async t => {
var {opts} = t.context
await steamcmd.prep(opts)
t.throws(steamcmd.updateApp(4, path.resolve('test_data', 'nonexistent_app'), opts))
t.throws(steamcmd.updateApp(4, opts))
})

test('updateApp with valid parameters', async t => {
var {opts} = t.context
await steamcmd.prep(opts)
t.true(await steamcmd.updateApp(1007, path.resolve('test_data', 'steamworks'), opts))
t.true(await steamcmd.updateApp(1007, opts))
})

test('updateApp with HLDS workaround', async t => {
var {opts} = t.context
await steamcmd.prep(opts)
t.true(await steamcmd.updateApp(90, path.resolve('test_data', 'hlds'), opts))
t.true(await steamcmd.updateApp(90, opts))
})

test('updateApp on already up-to-date app returns false', async t => {
var {binDirParent, opts} = t.context
var {opts} = t.context
const appId = 1007
const installDir = path.join(binDirParent, 'app')
await steamcmd.prep(opts)
await steamcmd.updateApp(appId, installDir, opts)
t.false(await steamcmd.updateApp(appId, installDir, opts))
await steamcmd.updateApp(appId, opts)
t.false(await steamcmd.updateApp(appId, opts))
})

0 comments on commit 4036ffc

Please sign in to comment.