Skip to content

Commit fb225ff

Browse files
committed
Global layouts can be forced now
`hyperlayout global [preset]`
1 parent feb91d2 commit fb225ff

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

bin/hyperlayout

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,40 @@ const fs = require('fs')
33
const isHyper = require('is-hyper')()
44
const debug = require('debug')('hyperlayout')
55

6-
const command = process.argv[2]
76
// Read json file
87
const readJson = (dir, file) => JSON.parse(fs.readFileSync(`${dir}/${file}`, 'utf8'))
98

109
// Get config file by reading `.hyperlayout` and `package.json`
11-
const getConfig = presetName => {
10+
const getConfig = () => {
1211
let config
13-
try {
14-
const subConfig = readJson(process.cwd(), '.hyperlayout')
15-
config = config || subConfig
16-
} catch (err) {
17-
debug('No .hyperlayout found in directory')
18-
}
19-
try {
20-
const {hyperlayout} = readJson(process.cwd(), 'package.json')
21-
config = config || hyperlayout
22-
} catch (err) {
23-
debug('No package.json found in directory', err)
12+
13+
const flag = process.argv[2]
14+
const isGlobal = flag === 'global' || flag === 'g'
15+
const presetName = isGlobal ? process.argv[3] : flag
16+
17+
if (isGlobal) {
18+
debug('Global configuration forced')
19+
} else {
20+
try {
21+
const subConfig = readJson(process.cwd(), '.hyperlayout')
22+
config = config || subConfig
23+
} catch (err) {
24+
debug('No .hyperlayout found in directory')
25+
}
26+
try {
27+
const {hyperlayout} = readJson(process.cwd(), 'package.json')
28+
config = config || hyperlayout
29+
} catch (err) {
30+
debug('No package.json found in directory')
31+
}
2432
}
2533
try {
2634
const subConfig = readJson(process.env.HOME, '.hyperlayout')
2735
config = config || subConfig
2836
} catch (err) {
2937
debug('No .hyperlayout found in home directory')
3038
}
39+
3140
if (config) {
3241
// Check if command is given
3342
if (presetName) {
@@ -64,7 +73,7 @@ function start() {
6473
}
6574

6675
const data = {
67-
config: getConfig(command),
76+
config: getConfig(),
6877
cwd: process.cwd()
6978
}
7079

0 commit comments

Comments
 (0)