Skip to content

Commit 5e649b3

Browse files
committed
0.0.2 release - added a custom message
1 parent 49cfa3c commit 5e649b3

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typhonjs-npm-scripts-runner",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"homepage": "https://github.com/typhonjs-node-npm-scripts/typhonjs-npm-scripts-runner",
55
"description": "Provides an NPM module and script which will load a JSON file searching for an Array entry then executes the scripts.",
66
"license": "MPL-2.0",

scripts/runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ if (typeof process.argv[3] !== 'string')
2222
throw new TypeError('typhonjs-npm-scripts-runner error: argument `script entry` is missing or not a `string`.');
2323
}
2424

25-
runner.run(process.argv[2], process.argv[3]);
25+
runner.run(process.argv[2], process.argv[3], process.argv[4]);

src/runner.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@ var stripJsonComments = require('strip-json-comments');
1212
* ```
1313
* (string) filePath - The path to a JSON formatted file.
1414
* (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`.
1516
* ```
1617
*/
17-
module.exports.run = function(filePath, scriptEntry)
18+
module.exports.run = function(filePath, scriptEntry, messagePrepend)
1819
{
20+
messagePrepend = typeof messagePrepend === 'string' ? messagePrepend : 'typhonjs-npm-scripts-runner';
21+
1922
if (typeof filePath !== 'string')
2023
{
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`.');
2225
}
2326

2427
if (typeof scriptEntry !== 'string')
2528
{
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`.');
2730
}
2831

2932
var relativeFilePath = path.resolve(process.cwd(), filePath);
@@ -39,7 +42,7 @@ module.exports.run = function(filePath, scriptEntry)
3942
}
4043
catch (err)
4144
{
42-
throw new Error("typhonjs-npm-scripts-runner error: " + err);
45+
throw new Error(messagePrepend + ' error: ' + err);
4346
}
4447

4548
// Load `filePath` as JSON stripping any comments.
@@ -52,7 +55,7 @@ module.exports.run = function(filePath, scriptEntry)
5255
}
5356
catch (err)
5457
{
55-
throw new Error("typhonjs-npm-scripts-runner error: " + err);
58+
throw new Error(messagePrepend + ' error: ' + err);
5659
}
5760

5861
var entries = scriptEntry.split('.');
@@ -69,17 +72,15 @@ module.exports.run = function(filePath, scriptEntry)
6972
{
7073
if (typeof objectWalker[entries[cntr]] !== 'object')
7174
{
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 `'
7476
+ filePath + '`.');
7577
}
7678
}
7779
else
7880
{
7981
if (!Array.isArray(objectWalker[entries[cntr]]))
8082
{
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 `'
8384
+ filePath + '`.');
8485
}
8586
}
@@ -93,8 +94,7 @@ module.exports.run = function(filePath, scriptEntry)
9394
/* istanbul ignore if */
9495
if (typeof objectWalker[cntr] !== 'string')
9596
{
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]
9898
+ '` at index `' + cntr +'` is not a `string` in `' + filePath + '`.');
9999
}
100100
}
@@ -106,7 +106,7 @@ module.exports.run = function(filePath, scriptEntry)
106106
var exec = objectWalker[cntr];
107107

108108
// 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');
110110
cp.execSync(exec, { stdio: 'inherit' });
111111
}
112112
};

test/scripts/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,7 @@ catch (err)
6363
throw new Error('typhonjs-npm-scripts-runner test error: ' + err);
6464
}
6565

66+
// Test the message prepend
67+
runner.run('./test/data/.scriptrc', 'test.data.scripts', 'A custom message -');
68+
6669
fs.emptyDirSync('./test/fixture');

0 commit comments

Comments
 (0)