@@ -3,31 +3,40 @@ const fs = require('fs')
3
3
const isHyper = require ( 'is-hyper' ) ( )
4
4
const debug = require ( 'debug' ) ( 'hyperlayout' )
5
5
6
- const command = process . argv [ 2 ]
7
6
// Read json file
8
7
const readJson = ( dir , file ) => JSON . parse ( fs . readFileSync ( `${ dir } /${ file } ` , 'utf8' ) )
9
8
10
9
// Get config file by reading `.hyperlayout` and `package.json`
11
- const getConfig = presetName => {
10
+ const getConfig = ( ) => {
12
11
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
+ }
24
32
}
25
33
try {
26
34
const subConfig = readJson ( process . env . HOME , '.hyperlayout' )
27
35
config = config || subConfig
28
36
} catch ( err ) {
29
37
debug ( 'No .hyperlayout found in home directory' )
30
38
}
39
+
31
40
if ( config ) {
32
41
// Check if command is given
33
42
if ( presetName ) {
@@ -64,7 +73,7 @@ function start() {
64
73
}
65
74
66
75
const data = {
67
- config : getConfig ( command ) ,
76
+ config : getConfig ( ) ,
68
77
cwd : process . cwd ( )
69
78
}
70
79
0 commit comments