1
- import fs from 'fs' ;
2
- import path from 'path' ;
3
- import { parse } from 'postcss-values-parser' ;
1
+ import fs from 'fs'
2
+ import path from 'path'
3
+ import { parse } from 'postcss-values-parser'
4
4
5
5
/**
6
6
* Import Custom Properties from Object
@@ -11,13 +11,13 @@ function importEnvironmentVariablesFromObject(object) {
11
11
const environmentVariables = Object . assign (
12
12
{ } ,
13
13
Object ( object ) . environmentVariables || Object ( object ) [ 'environment-variables' ]
14
- ) ;
14
+ )
15
15
16
16
for ( const key in environmentVariables ) {
17
- environmentVariables [ key ] = parse ( environmentVariables [ key ] ) . nodes ;
17
+ environmentVariables [ key ] = parse ( environmentVariables [ key ] ) . nodes
18
18
}
19
19
20
- return environmentVariables ;
20
+ return environmentVariables
21
21
}
22
22
23
23
/**
@@ -26,9 +26,9 @@ function importEnvironmentVariablesFromObject(object) {
26
26
* @returns {Promise<Record<string, import('postcss-values-parser').Root>> }
27
27
*/
28
28
async function importEnvironmentVariablesFromJSONFile ( from ) {
29
- const object = await readJSON ( path . resolve ( from ) ) ;
29
+ const object = await readJSON ( path . resolve ( from ) )
30
30
31
- return importEnvironmentVariablesFromObject ( object ) ;
31
+ return importEnvironmentVariablesFromObject ( object )
32
32
}
33
33
34
34
/**
@@ -37,9 +37,9 @@ async function importEnvironmentVariablesFromJSONFile(from) {
37
37
* @returns {Promise<Record<string, import('postcss-values-parser').Root>> }
38
38
*/
39
39
async function importEnvironmentVariablesFromJSFile ( from ) {
40
- const object = await import ( path . resolve ( from ) ) ;
40
+ const object = await import ( path . resolve ( from ) )
41
41
42
- return importEnvironmentVariablesFromObject ( object ) ;
42
+ return importEnvironmentVariablesFromObject ( object )
43
43
}
44
44
45
45
/**
@@ -50,39 +50,39 @@ async function importEnvironmentVariablesFromJSFile(from) {
50
50
export default function importEnvironmentVariablesFromSources ( sources ) {
51
51
return sources . map ( source => {
52
52
if ( source instanceof Promise ) {
53
- return source ;
53
+ return source
54
54
} else if ( source instanceof Function ) {
55
- return source ( ) ;
55
+ return source ( )
56
56
}
57
57
58
58
// read the source as an object
59
- const opts = source === Object ( source ) ? source : { from : String ( source ) } ;
59
+ const opts = source === Object ( source ) ? source : { from : String ( source ) }
60
60
61
61
// skip objects with Custom Properties
62
62
if ( opts . environmentVariables || opts [ 'environment-variables' ] ) {
63
63
return opts
64
64
}
65
65
66
66
// source pathname
67
- const from = String ( opts . from || '' ) ;
67
+ const from = String ( opts . from || '' )
68
68
69
69
// type of file being read from
70
- const type = ( opts . type || path . extname ( from ) . slice ( 1 ) ) . toLowerCase ( ) ;
70
+ const type = ( opts . type || path . extname ( from ) . slice ( 1 ) ) . toLowerCase ( )
71
71
72
- return { type, from } ;
72
+ return { type, from }
73
73
} ) . reduce ( async ( environmentVariables , source ) => {
74
- const { type, from } = await source ;
74
+ const { type, from } = await source
75
75
76
76
if ( type === 'js' || type === 'cjs' ) {
77
- return Object . assign ( environmentVariables , await importEnvironmentVariablesFromJSFile ( from ) ) ;
77
+ return Object . assign ( environmentVariables , await importEnvironmentVariablesFromJSFile ( from ) )
78
78
}
79
79
80
80
if ( type === 'json' ) {
81
- return Object . assign ( environmentVariables , await importEnvironmentVariablesFromJSONFile ( from ) ) ;
81
+ return Object . assign ( environmentVariables , await importEnvironmentVariablesFromJSONFile ( from ) )
82
82
}
83
83
84
- return Object . assign ( environmentVariables , importEnvironmentVariablesFromObject ( await source ) ) ;
85
- } , { } ) ;
84
+ return Object . assign ( environmentVariables , importEnvironmentVariablesFromObject ( await source ) )
85
+ } , { } )
86
86
}
87
87
88
88
/* Helper utilities
@@ -95,11 +95,11 @@ export default function importEnvironmentVariablesFromSources(sources) {
95
95
const readFile = from => new Promise ( ( resolve , reject ) => {
96
96
fs . readFile ( from , 'utf8' , ( error , result ) => {
97
97
if ( error ) {
98
- reject ( error ) ;
98
+ reject ( error )
99
99
} else {
100
- resolve ( result ) ;
100
+ resolve ( result )
101
101
}
102
- } ) ;
103
- } ) ;
102
+ } )
103
+ } )
104
104
105
- const readJSON = async from => JSON . parse ( await readFile ( from ) ) ;
105
+ const readJSON = async from => JSON . parse ( await readFile ( from ) )
0 commit comments