This repository was archived by the owner on Feb 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
45 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
env: { | ||
node: true | ||
}, | ||
extends: [ | ||
'eslint-config-digitalbazaar' | ||
] | ||
}; |
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,34 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const util = require('util'); | ||
|
||
const exec = util.promisify(require('child_process').exec); | ||
|
||
async function generate(file, options) { | ||
options = options || {}; | ||
const filePath = path.join(__dirname, 'input', `${file}.httpMessage`); | ||
const date = options.date || new Date().toGMTString(); | ||
const latestDate = `date: ${date}`; | ||
let args = ''; | ||
for(const key in options.args) { | ||
let value = options.args[key]; | ||
if(Array.isArray(value)) { | ||
value = `--${key} "${value.join(' ')}" `; | ||
} else { | ||
value = `--${key} ${value} `; | ||
} | ||
args += value; | ||
} | ||
// this cat filePath - the dash is the last pipe op | ||
const httpMessage = `echo ${latestDate} | cat ${filePath} - | `; | ||
const generate = `${options.generator} ${options.command} `; | ||
const {stdout, stderr} = await exec(httpMessage + generate + args); | ||
if(stderr) { | ||
throw new Error(stderr); | ||
} | ||
return stdout; | ||
} | ||
|
||
module.exports = { | ||
generate | ||
}; |