-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use minimist instead of yargs to get rid of dependencies (#23)
* Use minimist instead of yargs Using yargs causes 'critical dependency' warning in Electron, adapt it to minimist to get rid of the warning
- Loading branch information
Showing
8 changed files
with
785 additions
and
1,361 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,16 @@ | ||
module.exports = { | ||
matchArgv: function(s) { | ||
// ref: https://stackoverflow.com/questions/366202/regex-for-splitting-a-string-using-space-when-not-surrounded-by-single-or-double | ||
return s | ||
.replace(/\\\n/g, ' ') | ||
.match(/"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|[^\s]+/g) | ||
.map((s) => { | ||
if ((s.startsWith(`'`) && s.endsWith(`'`)) || (s.startsWith(`"`) && s.endsWith(`"`))) { | ||
// remove quotes on both sides | ||
return s.substring(1, s.length - 1) | ||
} else { | ||
return s | ||
} | ||
}) | ||
} | ||
} |
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,3 @@ | ||
const proc = require('node:process') | ||
|
||
console.log(JSON.stringify(proc.argv.slice(2))); |
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 @@ | ||
var assert = require('assert'); | ||
const matcher = require('../src/matcher'); | ||
const testDataList = require('./data.test'); | ||
const fs = require('fs'); | ||
|
||
const childProcess = require('child_process'); | ||
|
||
describe('matcher.matchArgv test', function () { | ||
testDataList.forEach(element => { | ||
|
||
it(`${element.name || 'Test case '}`, function () { | ||
childProcess.exec(`node ./test/argv.js ${element.curl.trim()}`, function(error, stdout, buffer){ | ||
const parsedArgv = JSON.stringify(matcher.matchArgv(element.curl)); | ||
const answer = stdout; | ||
assert.equal(parsedArgv.trim(), answer.trim()); | ||
}); | ||
}); | ||
}) | ||
}); |
Oops, something went wrong.