This repository has been archived by the owner on Oct 2, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
90 lines (82 loc) · 2.09 KB
/
functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* global process:true */
const $current_path = process.cwd();
/**
* Handles Parsing JS Args.
*/
class JS_Parse_Args {
constructor( $args = {}, $defaults = {}, $is_nested = false ) {
this.args = $args;
this.defaults = $defaults;
this.nested = $is_nested;
this.parse();
return this.args;
}
parse() {
for( let $_key in this.defaults ) {
if( this.defaults.hasOwnProperty( $_key ) ) {
if( true === this.nested && typeof this.defaults[ $_key ] === 'object' ) {
this.args[ $_key ] = new JS_Parse_Args( this.args[ $_key ], this.defaults[ $_key ], this.nested );
} else {
if( typeof this.args[ $_key ] === 'undefined' ) {
this.args[ $_key ] = this.defaults[ $_key ];
}
}
}
}
}
}
/**
* Parses Args.
* @param $args
* @param $defaults
* @param $is_deep
* @returns {JS_Parse_Args}
*/
const parse_args = ( $args = {}, $defaults = {}, $is_deep = false ) => new JS_Parse_Args( $args, $defaults, $is_deep );
/**
* Loads A Module.
* @param $module
* @param $defaults
* @returns {boolean|*}
*/
const vsp_load_module = ( $module, $defaults = false ) => {
try {
$module = require( $module );
} catch( e ) {
return $defaults;
}
return $module;
};
/**
* Returns Config JSON.
* @returns {boolean|*}
*/
const get_user_config = () => {
let $config = vsp_load_module( $current_path + '/config.js' );
if( false === $config ) {
$config = vsp_load_module( $current_path + '/gulp-config.js' );
}
return $config;
};
/**
* Returns Default Config.
* @type {boolean|*}
*/
const get_default_config = vsp_load_module( './default-config.js' );
/**
* Returns Final Config.
*/
const get_config = () => {
let $config = get_user_config();
let $default = get_default_config;
let $new_config = {};
$new_config.files = $config.files;
$new_config.config = parse_args( $config.config, $default.config, false );
return $new_config;
};
module.exports = {
get_config: get_config,
vsp_load_module: vsp_load_module,
parse_args: parse_args,
current_path: $current_path,
};