Skip to content

Commit def7e0c

Browse files
committed
Update config standard paths
Implements UCF v1.0 spec as defined here: https://github.com/screepers/screepers-standards/blob/master/SS3-Unified_Credentials_File.md
1 parent 5c30ecd commit def7e0c

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ User/pass auth will stop working February 1, 2018!
2020

2121
As of 1.7.0, a small CLI program (`screeps-api`) is included.
2222

23-
Server config is specified via a `.screeps.yml` file conforming to the [Unified Credentials File format](https://github.com/screepers/screepers-standards/blob/34bd4e6e5c8250fa0794d915d9f78d3c45326076/SS3-Unified_Credentials_File.md) (Pending [screepers-standard PR #8](https://github.com/screepers/screepers-standards/pull/8))
23+
Server config is specified via a `.screeps.yml` file conforming to the [Unified Credentials File format](https://github.com/screepers/screepers-standards/blob/master/SS3-Unified_Credentials_File.md)
2424

2525
```
2626
screeps-api

src/ScreepsAPI.js

+24-11
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,34 @@ const DEFAULTS = {
1616

1717
export class ScreepsAPI extends RawAPI {
1818
static async fromConfig (server = 'main', config = false, opts = {}) {
19-
const paths = [
20-
join(__dirname, '.screeps.yaml'),
21-
join(__dirname, '.screeps.yml'),
22-
'./.screeps.yaml',
23-
'./.screeps.yml'
24-
]
25-
if (process.env.HOME) {
26-
paths.push(join(process.env.HOME, '.screeps.yaml'))
27-
paths.push(join(process.env.HOME, '.screeps.yml'))
19+
const paths = []
20+
if (process.env.SCREEPS_CONFIG) {
21+
paths.push(process.env.SCREEPS_CONFIG)
22+
}
23+
paths.push(join(__dirname, '.screeps.yaml'))
24+
paths.push(join(__dirname, '.screeps.yml'))
25+
paths.push('./.screeps.yaml')
26+
paths.push('./.screeps.yml')
27+
if (process.platform === 'win32') {
28+
paths.push(join(process.env.APPDATA, 'screeps/config.yaml'))
29+
paths.push(join(process.env.APPDATA, 'screeps/config.yml'))
30+
} else {
31+
if (process.env.XDG_CONFIG_PATH) {
32+
paths.push(join(process.env.XDG_CONFIG_HOME, 'screeps/config.yaml'))
33+
paths.push(join(process.env.XDG_CONFIG_HOME, 'screeps/config.yml'))
34+
}
35+
if (process.env.HOME) {
36+
paths.push(join(process.env.HOME, '.config/screeps/config.yaml'))
37+
paths.push(join(process.env.HOME, '.config/screeps/config.yml'))
38+
paths.push(join(process.env.HOME, '.screeps.yaml'))
39+
paths.push(join(process.env.HOME, '.screeps.yml'))
40+
}
2841
}
2942
for (const path of paths) {
3043
const data = await loadConfig(path)
3144
if (data) {
3245
if (!data.servers) {
33-
throw new Error(`Invalid .screeps.yml: servers doesn't exist in ${path}`)
46+
throw new Error(`Invalid config: 'servers' object does not exist in '${path}'`)
3447
}
3548
if (!data.servers[server]) {
3649
throw new Error(`Server '${server}' does not exist in '${path}'`)
@@ -49,7 +62,7 @@ export class ScreepsAPI extends RawAPI {
4962
return api
5063
}
5164
}
52-
throw new Error('No valid .screeps.yaml found')
65+
throw new Error('No valid config found')
5366
}
5467
constructor (opts) {
5568
opts = Object.assign({}, DEFAULTS, opts)

0 commit comments

Comments
 (0)