-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·37 lines (30 loc) · 1.31 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env node
const program = require('commander');
const pkg = require('./package.json');
program
.version(pkg.version)
.option('-t, --template-path [templatePath]')
.option('--no-write-file', 'Only outputs the rendered template to the console.', 'false')
//.option('-s --silent', 'Output nothing to the command line.', 'false')
.option('--output-filename [outputFilename]', 'The filename to write the template yaml.', 'template.yaml')
.option('--starting-path [startingPath]', 'The path to start searching for function.json files.', '.')
.option('--api-definition-file [apiDefinitionFile]', 'Api definition file. If not specified package.json is used.')
.parse(process.argv);
const SamHelper = require('./SamHelper');
async function doWork() {
const funcDefs = await SamHelper.loadFunctionDefinitions(program.startingPath);
const apiDefs = await SamHelper.loadApiDefinitions(
{
usePackageJson: !program.apiDefinitionFile,
apiDefinitionFile: program.apiDefinitionFile
});
const samHelper = new SamHelper(apiDefs, funcDefs, {
outputFilename: program.outputFilename,
writeFile: program.writeFile,
templatePath: program.templatePath
});
const samTemplate = await samHelper.render();
console.log('Generated sam template:\r\n');
console.log(samTemplate);
}
doWork();