UNPKG

2.88 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3/*
4 Copyright 2019 Google LLC
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 https://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17*/
18
19var bl = require("./lib/package/bundleLinter.js");
20var program = require("commander");
21var pkj = require('./package.json');
22var bundleType = require('./lib/package/BundleTypes.js')
23
24program
25 .version(pkj.version)
26 .option("-s, --path <path>", "Path of the proxies")
27 .option("-f, --formatter [value]", "Specify formatters (default json.js)")
28 .option("-w, --write [value]", "file path to write results")
29 .option(
30 "-d, --destPath [value]",
31 "Provide the host and path to upload linter results"
32 )
33 .option("-e, --excluded [value]", "The comma separated list of tests to be excluded")
34 .option("--maxWarnings [value]", "Number of warnings to trigger nonzero exit code - default: -1")
35 .option("-u, --user [value]", "Apigee user account")
36 .option("-p, --password [value]", "Apigee password")
37 .option("-o, --organization [value]", "Apigee organization")
38 .option("-x, --externalPluginsDirectory [value]", "Relative or full path to an external plugins directory");
39
40program.on("--help", function() {
41 console.log("\nExample: apigeelint -s sampleProxy/ -f table.js");
42 console.log("");
43});
44
45program.parse(process.argv);
46
47var configuration = {
48 debug: true,
49 source: {
50 type: "filesystem",
51 path: program.path,
52 bundleType: program.path.includes(bundleType.BundleType.SHAREDFLOW) ? bundleType.BundleType.SHAREDFLOW : bundleType.BundleType.APIPROXY
53 },
54 externalPluginsDirectory: program.externalPluginsDirectory,
55 excluded: {},
56 maxWarnings: -1
57};
58
59if(!isNaN(program.maxWarnings)){
60 configuration.maxWarnings = Number.parseInt(program.maxWarnings);
61}
62
63if (program.formatter) {
64 configuration.formatter = program.formatter || "json.js";
65}
66
67if (program.excluded && typeof(program.excluded) === "string") {
68 var excluded = program.excluded.split(",");
69 configuration.excluded = configuration.excluded || {};
70 for (var i in excluded)
71 {
72 configuration.excluded[excluded[i]] = true;
73 }
74}
75
76if (program.user) {
77 //check for required fields
78 configuration.apiUpload = {
79 destPath:
80 program.destPath || "https://csdata-test.apigee.net/v1/lintresults",
81 user: program.user,
82 password: program.password,
83 organization: program.organization
84 };
85}
86
87if (program.write) {
88 configuration.writePath = program.write;
89}
90
91bl.lint(configuration);