@@ -12,18 +12,21 @@ var stripJsonComments = require('strip-json-comments');
12
12
* ```
13
13
* (string) filePath - The path to a JSON formatted file.
14
14
* (string) scriptEntry - A entry path separated by `.` relative to the root of the JSON file that is an `Array`.
15
+ * (string) messagePrepend - An optional message to prepend instead of the default: `typhonjs-npm-scripts-runner`.
15
16
* ```
16
17
*/
17
- module . exports . run = function ( filePath , scriptEntry )
18
+ module . exports . run = function ( filePath , scriptEntry , messagePrepend )
18
19
{
20
+ messagePrepend = typeof messagePrepend === 'string' ? messagePrepend : 'typhonjs-npm-scripts-runner' ;
21
+
19
22
if ( typeof filePath !== 'string' )
20
23
{
21
- throw new TypeError ( 'typhonjs-npm-scripts-runner error: filePath is not a `string`.') ;
24
+ throw new TypeError ( messagePrepend + ' error: filePath is not a `string`.') ;
22
25
}
23
26
24
27
if ( typeof scriptEntry !== 'string' )
25
28
{
26
- throw new TypeError ( 'typhonjs-npm-scripts-runner error: scriptEntry is not a `string`.') ;
29
+ throw new TypeError ( messagePrepend + ' error: scriptEntry is not a `string`.') ;
27
30
}
28
31
29
32
var relativeFilePath = path . resolve ( process . cwd ( ) , filePath ) ;
@@ -39,7 +42,7 @@ module.exports.run = function(filePath, scriptEntry)
39
42
}
40
43
catch ( err )
41
44
{
42
- throw new Error ( "typhonjs-npm-scripts-runner error: " + err ) ;
45
+ throw new Error ( messagePrepend + ' error: ' + err ) ;
43
46
}
44
47
45
48
// Load `filePath` as JSON stripping any comments.
@@ -52,7 +55,7 @@ module.exports.run = function(filePath, scriptEntry)
52
55
}
53
56
catch ( err )
54
57
{
55
- throw new Error ( "typhonjs-npm-scripts-runner error: " + err ) ;
58
+ throw new Error ( messagePrepend + ' error: ' + err ) ;
56
59
}
57
60
58
61
var entries = scriptEntry . split ( '.' ) ;
@@ -69,17 +72,15 @@ module.exports.run = function(filePath, scriptEntry)
69
72
{
70
73
if ( typeof objectWalker [ entries [ cntr ] ] !== 'object' )
71
74
{
72
- throw new Error (
73
- 'typhonjs-npm-scripts-runner error: `' + entryWalker + '` entry is not an object or is missing in `'
75
+ throw new Error ( messagePrepend + ' error: `' + entryWalker + '` entry is not an object or is missing in `'
74
76
+ filePath + '`.' ) ;
75
77
}
76
78
}
77
79
else
78
80
{
79
81
if ( ! Array . isArray ( objectWalker [ entries [ cntr ] ] ) )
80
82
{
81
- throw new Error (
82
- 'typhonjs-npm-scripts-runner error: `' + entryWalker + '` entry is not an Array or is missing in `'
83
+ throw new Error ( messagePrepend + ' error: `' + entryWalker + '` entry is not an Array or is missing in `'
83
84
+ filePath + '`.' ) ;
84
85
}
85
86
}
@@ -93,8 +94,7 @@ module.exports.run = function(filePath, scriptEntry)
93
94
/* istanbul ignore if */
94
95
if ( typeof objectWalker [ cntr ] !== 'string' )
95
96
{
96
- throw new Error (
97
- 'typhonjs-npm-scripts-runner error: `' + entryWalker + '` array entry `' + objectWalker [ cntr ]
97
+ throw new Error ( messagePrepend + ' error: `' + entryWalker + '` array entry `' + objectWalker [ cntr ]
98
98
+ '` at index `' + cntr + '` is not a `string` in `' + filePath + '`.' ) ;
99
99
}
100
100
}
@@ -106,7 +106,7 @@ module.exports.run = function(filePath, scriptEntry)
106
106
var exec = objectWalker [ cntr ] ;
107
107
108
108
// Notify what command is being executed then execute it.
109
- process . stdout . write ( 'typhonjs-npm-scripts-runner executing: ' + exec + '\n' ) ;
109
+ process . stdout . write ( messagePrepend + ' executing: ' + exec + '\n' ) ;
110
110
cp . execSync ( exec , { stdio : 'inherit' } ) ;
111
111
}
112
112
} ;
0 commit comments