@@ -6,42 +6,51 @@ const path = require('path');
6
6
console . log ( "INFO: Adding the required localized resource configuration to the config.json file." ) ;
7
7
8
8
// Get the current directory
9
- const crntDir = __dirname ;
9
+ const crntDir = path . resolve ( __dirname ) ;
10
10
// Split the whole directory path
11
- const nesting = crntDir . split ( "/" ) ;
11
+ let nesting = crntDir . split ( "/" ) ;
12
+ // Windows split
13
+ if ( nesting . length <= 1 ) {
14
+ nesting = crntDir . split ( "\\" ) ;
15
+ }
12
16
// Check if correctly splitted
13
17
if ( nesting . length > 0 ) {
14
- // Find the first node_modules folder location
15
- const idx = nesting . indexOf ( "node_modules" ) ;
16
- // Slice unnecessary nodes
17
- const nest = nesting . slice ( idx ) ;
18
- if ( nest && nest . length > 0 ) {
19
- const paths = nest . map ( m => ".." ) ;
20
- // Get the path of the projects root location
21
- const rootDir = path . resolve ( path . join ( __dirname , paths . join ( '/' ) ) ) ;
22
- const fileLoc = `${ rootDir } /config/config.json` ;
23
- // Check if config.json file exists
24
- if ( fs . existsSync ( fileLoc ) ) {
25
- // Get the config file
26
- const config = fs . readFileSync ( fileLoc , "utf8" ) ;
27
- if ( config && typeof config === "string" ) {
28
- const contents = JSON . parse ( config ) ;
29
- if ( contents && contents . localizedResources && ! contents . localizedResources . ControlStrings ) {
30
- contents . localizedResources [ "ControlStrings" ] = "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js" ;
31
- // Update the file
32
- fs . writeFileSync ( fileLoc , JSON . stringify ( contents , null , 2 ) ) ;
33
- console . log ( "INFO: Localized resource added." ) ;
18
+ // Find the first node_modules folder index
19
+ let idx = nesting . indexOf ( "node_modules" ) ;
20
+ // Check if index of the folder was found
21
+ if ( idx !== - 1 ) {
22
+ // Slice unnecessary nodes
23
+ const nest = nesting . slice ( idx ) ;
24
+ if ( nest && nest . length > 0 ) {
25
+ const paths = nest . map ( m => ".." ) ;
26
+ // Get the path of the projects root location
27
+ const rootDir = path . resolve ( path . join ( __dirname , paths . join ( '/' ) ) ) ;
28
+ const fileLoc = `${ rootDir } /config/config.json` ;
29
+ // Check if config.json file exists
30
+ if ( fs . existsSync ( fileLoc ) ) {
31
+ // Get the config file
32
+ const config = fs . readFileSync ( fileLoc , "utf8" ) ;
33
+ if ( config && typeof config === "string" ) {
34
+ const contents = JSON . parse ( config ) ;
35
+ if ( contents && contents . localizedResources && ! contents . localizedResources . ControlStrings ) {
36
+ contents . localizedResources [ "ControlStrings" ] = "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js" ;
37
+ // Update the file
38
+ fs . writeFileSync ( fileLoc , JSON . stringify ( contents , null , 2 ) ) ;
39
+ console . log ( "INFO: Localized resource added." ) ;
40
+ } else {
41
+ console . warn ( `WARNING: it seems something is wrong with the config.json file or the "ControlStrings" reference was already set.` ) ;
42
+ }
34
43
} else {
35
- console . warn ( ` WARNING: it seems something is wrong with the config.json file or the "ControlStrings" reference was already set.` ) ;
44
+ console . warn ( " WARNING: the config.json file was not correctly retrieved." ) ;
36
45
}
37
46
} else {
38
- console . warn ( "WARNING: the config.json file was not correctly retrieved ." ) ;
47
+ console . warn ( "WARNING: the config.json file does not exist ." ) ;
39
48
}
40
49
} else {
41
- console . warn ( "WARNING: the config.json file does not exist ." ) ;
50
+ console . warn ( "WARNING: something is wrong with the installation path ." ) ;
42
51
}
43
52
} else {
44
- console . warn ( "WARNING: something is wrong with the installation path ." ) ;
53
+ console . warn ( "WARNING: something when wrong during with retrieving the project its root location ." ) ;
45
54
}
46
55
} else {
47
56
console . warn ( "WARNING: something is wrong with the installation path." ) ;
0 commit comments