-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into release/v2
* master: Prepare for release 2.1.0. Support multi-line script. Skip workflow for markdown file changes. Reference Article
- Loading branch information
Showing
10 changed files
with
121 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as parser from '../src/script-parser'; | ||
|
||
describe('script parser tests', () => { | ||
it('Scripts are trimmed', () => { | ||
const script = ` command \n`; | ||
expect(parser.parseScript(script)).toEqual(['command']); | ||
}); | ||
|
||
it('Commented lines are filtered out', () => { | ||
const script = ` | ||
# command1 | ||
command2 | ||
# command3 | ||
command4 | ||
`; | ||
expect(parser.parseScript(script)).toEqual(['command2', 'command4']); | ||
}); | ||
|
||
it('Throws if parsed scripts array is empty', () => { | ||
const func = () => { | ||
const script = ` | ||
# command1 | ||
# command2 | ||
`; | ||
const result = parser.parseScript(script); | ||
console.log(`Result: ${result}`); | ||
}; | ||
expect(func).toThrowError(`No valid script found.`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Convert a (potentially multi-line) script to an array of single-line script(s). | ||
*/ | ||
function parseScript(rawScript) { | ||
const scripts = rawScript | ||
.trim() | ||
.split(/\r\n|\n|\r/) | ||
.map((value) => value.trim()) | ||
.filter((value) => { | ||
return !value.startsWith('#') && value.length > 0; | ||
}); | ||
if (scripts.length == 0) { | ||
throw new Error(`No valid script found.`); | ||
} | ||
return scripts; | ||
} | ||
exports.parseScript = parseScript; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Convert a (potentially multi-line) script to an array of single-line script(s). | ||
*/ | ||
export function parseScript(rawScript: string): Array<string> { | ||
const scripts: Array<string> = rawScript | ||
.trim() | ||
.split(/\r\n|\n|\r/) | ||
.map((value: string) => value.trim()) | ||
.filter((value: string) => { | ||
return !value.startsWith('#') && value.length > 0; | ||
}); | ||
|
||
if (scripts.length == 0) { | ||
throw new Error(`No valid script found.`); | ||
} | ||
|
||
return scripts; | ||
} |