ts-node-client 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,196 +1,196 @@
1
- #!/usr/bin/env node
2
-
3
- /* eslint-disable */
4
- /**************************************************************
5
- * Copyright (c) 2017. Enterprise Architecture Group, EACG GmbH
6
- *
7
- * SPDX-License-Identifier: Apache-2.0
8
- *************************************************************/
9
- /* eslint-enable */
10
- const fs = require('fs');
11
- const yargs = require('yargs');
12
- const pckgJson = require('../package.json');
13
-
14
- const URL = 'https://app.trustsource.io';
15
- const CRED_FILENAME = '/.tsrc.json';
16
- const FILL = ' ';
17
- const execute = require('../lib/cli');
18
-
19
- const getOptions = () => {
20
- let options = yargs
21
- .options({
22
- apiKey: {
23
- alias: 'k',
24
- default: null,
25
- describe: 'apiKey'
26
- },
27
- project: {
28
- alias: 'p',
29
- default: null,
30
- describe: 'Project name'
31
- },
32
- branch: {
33
- alias: 'b',
34
- default: null,
35
- describe: 'Scan branch'
36
- },
37
- tag: {
38
- alias: 't',
39
- default: null,
40
- describe: 'Scan tag'
41
- },
42
- binaryLinks: {
43
- default: null,
44
- describe: 'Binary links separated by comma'
45
- },
46
- url: {
47
- default: null,
48
- describe: 'url'
49
- },
50
- config: {
51
- alias: 'c',
52
- default: null,
53
- describe: 'Config path'
54
- },
55
- proxy: {
56
- default: null,
57
- describe: 'Proxy url like \'https://user:password@host:port\''
58
- },
59
- saveAs: {
60
- alias: 'o',
61
- default: null,
62
- describe: 'Save as file (file name prefix)'
63
- },
64
- saveAsFormat: {
65
- alias: 'f',
66
- default: null,
67
- describe: 'Save as format (scan / cydx / spdx)'
68
- },
69
- debug: {
70
- default: null,
71
- describe: 'debug'
72
- },
73
- simulate: {
74
- default: null,
75
- describe: 'simulate'
76
- },
77
- meteor: {
78
- default: null,
79
- describe: 'meteor'
80
- },
81
- breakOnWarnings: {
82
- default: null,
83
- describe: 'breakOnWarnings'
84
- },
85
- breakOnViolations: {
86
- default: null,
87
- describe: 'breakOnViolations'
88
- },
89
- includeDevDependencies: {
90
- default: null,
91
- describe: 'includeDevDependencies'
92
- }
93
- })
94
- .version()
95
- .usage(pckgJson.description)
96
- .help('help', 'Prints a usage statement')
97
- .fail((msg, err, yargsObject) => {
98
- if (err) throw err; // preserve stack
99
- console.error('Please check', yargsObject.help());
100
- process.exit(1);
101
- })
102
- .argv;
103
- if (options.version) {
104
- console.info(`${pckgJson.name} version ${pckgJson.version}`);
105
- process.exit(0);
106
- }
107
- options = (({
108
- // eslint-disable-next-line max-len
109
- apiKey, project, branch, tag, binaryLinks, config, debug, saveAs, saveAsFormat, simulate, meteor, url, proxy, breakOnWarnings, breakOnViolations, includeDevDependencies
110
- }) => ({
111
- // eslint-disable-next-line max-len
112
- apiKey, project, branch, tag, binaryLinks, config, debug, saveAs, saveAsFormat, simulate, scanMeteor: meteor, url, proxy, breakOnWarnings, breakOnViolations, includeDevDependencies
113
- }))(options);
114
- Object.keys(options).forEach((key) => options[key] === null && delete options[key]);
115
- return options;
116
- };
117
-
118
- const loadConfig = (options) => {
119
- const values = [
120
- options.config ? options.config.replace('~', process.env.HOME) : null,
121
- process.cwd(),
122
- ((process.env.USERPROFILE || process.env.HOME) + CRED_FILENAME)
123
- ].map((value) => {
124
- let result = null;
125
- if (fs.existsSync(value) && fs.lstatSync(value).isDirectory() && fs.existsSync(`${value}${CRED_FILENAME}`)) {
126
- result = `${value}${CRED_FILENAME}`;
127
- } else if (fs.existsSync(value) && fs.lstatSync(value).isFile()) {
128
- result = value;
129
- }
130
- return !result || result.match(/^([a-zA-Z]:)?(\/|\\)/) ? result : `../../../${result}`;
131
- }).filter((value) => value);
132
- /* eslint-disable global-require, import/no-dynamic-require */
133
- return values[0] ? require(values[0]) : {};
134
- /* eslint-enable global-require, import/no-dynamic-require */
135
- };
136
-
137
- const validateOptions = (options) => {
138
- if (!options.apiKey) {
139
- throw new Error('Please provide a \'apiKey\' property in credentials file.');
140
- }
141
-
142
- if (!options.project) {
143
- throw new Error('Please provide a \'project\' property in credentials file.');
144
- }
145
- };
146
-
147
- let options = getOptions();
148
- options = { url: URL, ...loadConfig(options), ...options };
149
- validateOptions(options);
150
-
151
- if (options.debug) {
152
- console.log('invoking ts-node-client: ');
153
- console.log(`${FILL}debug = %s`, options.debug);
154
- console.log(`${FILL}simulate = %s`, options.simulate);
155
- console.log(`${FILL}includeDevDependencies = %s`, options.includeDevDependencies);
156
- console.log(`${FILL}scanMeteor = %s`, options.scanMeteor);
157
- console.log(`${FILL}saveAs = %s`, options.saveAs);
158
- console.log(`${FILL}saveAsFormat = %s`, options.saveAsFormat);
159
- console.log(`${FILL}breakOnViolations = %s`, options.breakOnViolations);
160
- console.log(`${FILL}breakOnWarnings = %s`, options.breakOnWarnings);
161
- console.log(`${FILL}apiKey = %s`, options.apiKey);
162
- console.log(`${FILL}project = %s`, options.project);
163
- console.log(`${FILL}branch = %s`, options.branch);
164
- console.log(`${FILL}tag = %s`, options.tag);
165
- console.log(`${FILL}binaryLinks = %s`, options.binaryLinks);
166
- console.log(`${FILL}url = %s`, options.url);
167
- console.log(`${FILL}proxy = %s`, options.proxy);
168
- }
169
-
170
- let exitCode = 0;
171
-
172
- process.on('uncaughtException', (err) => {
173
- console.error('Oops! Something went wrong! :(', err, options.debug ? err.stack : '');
174
- process.exit(1);
175
- });
176
-
177
- process.on('SIGINT', () => {
178
- console.error('Oops! SIGINT received! :( -> exiting...');
179
- process.exit(1);
180
- });
181
-
182
- process.on('exit', (code) => {
183
- console.log('Exitting normal exitCode=', code || exitCode);
184
- process.exit(code || exitCode);
185
- });
186
-
187
-
188
- try {
189
- execute(options, (ok) => {
190
- exitCode = ok ? 0 : 1;
191
- });
192
- console.log('cli.execute()', exitCode);
193
- } catch (error) {
194
- console.error('Error catched by cmdline interface:', error);
195
- exitCode = 1;
196
- }
1
+ #!/usr/bin/env node
2
+
3
+ /* eslint-disable */
4
+ /**************************************************************
5
+ * Copyright (c) 2017. Enterprise Architecture Group, EACG GmbH
6
+ *
7
+ * SPDX-License-Identifier: Apache-2.0
8
+ *************************************************************/
9
+ /* eslint-enable */
10
+ const fs = require('fs');
11
+ const yargs = require('yargs');
12
+ const pckgJson = require('../package.json');
13
+
14
+ const URL = 'https://app.trustsource.io';
15
+ const CRED_FILENAME = '/.tsrc.json';
16
+ const FILL = ' ';
17
+ const execute = require('../lib/cli');
18
+
19
+ const getOptions = () => {
20
+ let options = yargs
21
+ .options({
22
+ apiKey: {
23
+ alias: 'k',
24
+ default: null,
25
+ describe: 'apiKey'
26
+ },
27
+ project: {
28
+ alias: 'p',
29
+ default: null,
30
+ describe: 'Project name'
31
+ },
32
+ branch: {
33
+ alias: 'b',
34
+ default: null,
35
+ describe: 'Scan branch'
36
+ },
37
+ tag: {
38
+ alias: 't',
39
+ default: null,
40
+ describe: 'Scan tag'
41
+ },
42
+ binaryLinks: {
43
+ default: null,
44
+ describe: 'Binary links separated by comma'
45
+ },
46
+ url: {
47
+ default: null,
48
+ describe: 'url'
49
+ },
50
+ config: {
51
+ alias: 'c',
52
+ default: null,
53
+ describe: 'Config path'
54
+ },
55
+ proxy: {
56
+ default: null,
57
+ describe: 'Proxy url like \'https://user:password@host:port\''
58
+ },
59
+ saveAs: {
60
+ alias: 'o',
61
+ default: null,
62
+ describe: 'Save as file (file name prefix)'
63
+ },
64
+ saveAsFormat: {
65
+ alias: 'f',
66
+ default: null,
67
+ describe: 'Save as format (scan / cydx / spdx)'
68
+ },
69
+ debug: {
70
+ default: null,
71
+ describe: 'debug'
72
+ },
73
+ simulate: {
74
+ default: null,
75
+ describe: 'simulate'
76
+ },
77
+ meteor: {
78
+ default: null,
79
+ describe: 'meteor'
80
+ },
81
+ breakOnWarnings: {
82
+ default: null,
83
+ describe: 'breakOnWarnings'
84
+ },
85
+ breakOnViolations: {
86
+ default: null,
87
+ describe: 'breakOnViolations'
88
+ },
89
+ includeDevDependencies: {
90
+ default: null,
91
+ describe: 'includeDevDependencies'
92
+ }
93
+ })
94
+ .version()
95
+ .usage(pckgJson.description)
96
+ .help('help', 'Prints a usage statement')
97
+ .fail((msg, err, yargsObject) => {
98
+ if (err) throw err; // preserve stack
99
+ console.error('Please check', yargsObject.help());
100
+ process.exit(1);
101
+ })
102
+ .argv;
103
+ if (options.version) {
104
+ console.info(`${pckgJson.name} version ${pckgJson.version}`);
105
+ process.exit(0);
106
+ }
107
+ options = (({
108
+ // eslint-disable-next-line max-len
109
+ apiKey, project, branch, tag, binaryLinks, config, debug, saveAs, saveAsFormat, simulate, meteor, url, proxy, breakOnWarnings, breakOnViolations, includeDevDependencies
110
+ }) => ({
111
+ // eslint-disable-next-line max-len
112
+ apiKey, project, branch, tag, binaryLinks, config, debug, saveAs, saveAsFormat, simulate, scanMeteor: meteor, url, proxy, breakOnWarnings, breakOnViolations, includeDevDependencies
113
+ }))(options);
114
+ Object.keys(options).forEach((key) => options[key] === null && delete options[key]);
115
+ return options;
116
+ };
117
+
118
+ const loadConfig = (options) => {
119
+ const values = [
120
+ options.config ? options.config.replace('~', process.env.HOME) : null,
121
+ process.cwd(),
122
+ ((process.env.USERPROFILE || process.env.HOME) + CRED_FILENAME)
123
+ ].map((value) => {
124
+ let result = null;
125
+ if (fs.existsSync(value) && fs.lstatSync(value).isDirectory() && fs.existsSync(`${value}${CRED_FILENAME}`)) {
126
+ result = `${value}${CRED_FILENAME}`;
127
+ } else if (fs.existsSync(value) && fs.lstatSync(value).isFile()) {
128
+ result = value;
129
+ }
130
+ return !result || result.match(/^([a-zA-Z]:)?(\/|\\)/) ? result : `../../../${result}`;
131
+ }).filter((value) => value);
132
+ /* eslint-disable global-require, import/no-dynamic-require */
133
+ return values[0] ? require(values[0]) : {};
134
+ /* eslint-enable global-require, import/no-dynamic-require */
135
+ };
136
+
137
+ const validateOptions = (options) => {
138
+ if (!options.apiKey) {
139
+ throw new Error('Please provide a \'apiKey\' property in credentials file.');
140
+ }
141
+
142
+ if (!options.project) {
143
+ throw new Error('Please provide a \'project\' property in credentials file.');
144
+ }
145
+ };
146
+
147
+ let options = getOptions();
148
+ options = { url: URL, ...loadConfig(options), ...options };
149
+ validateOptions(options);
150
+
151
+ if (options.debug) {
152
+ console.log('invoking ts-node-client: ');
153
+ console.log(`${FILL}debug = %s`, options.debug);
154
+ console.log(`${FILL}simulate = %s`, options.simulate);
155
+ console.log(`${FILL}includeDevDependencies = %s`, options.includeDevDependencies);
156
+ console.log(`${FILL}scanMeteor = %s`, options.scanMeteor);
157
+ console.log(`${FILL}saveAs = %s`, options.saveAs);
158
+ console.log(`${FILL}saveAsFormat = %s`, options.saveAsFormat);
159
+ console.log(`${FILL}breakOnViolations = %s`, options.breakOnViolations);
160
+ console.log(`${FILL}breakOnWarnings = %s`, options.breakOnWarnings);
161
+ console.log(`${FILL}apiKey = %s`, options.apiKey);
162
+ console.log(`${FILL}project = %s`, options.project);
163
+ console.log(`${FILL}branch = %s`, options.branch);
164
+ console.log(`${FILL}tag = %s`, options.tag);
165
+ console.log(`${FILL}binaryLinks = %s`, options.binaryLinks);
166
+ console.log(`${FILL}url = %s`, options.url);
167
+ console.log(`${FILL}proxy = %s`, options.proxy);
168
+ }
169
+
170
+ let exitCode = 0;
171
+
172
+ process.on('uncaughtException', (err) => {
173
+ console.error('Oops! Something went wrong! :(', err, options.debug ? err.stack : '');
174
+ process.exit(1);
175
+ });
176
+
177
+ process.on('SIGINT', () => {
178
+ console.error('Oops! SIGINT received! :( -> exiting...');
179
+ process.exit(1);
180
+ });
181
+
182
+ process.on('exit', (code) => {
183
+ console.log('Exitting normal exitCode=', code || exitCode);
184
+ process.exit(code || exitCode);
185
+ });
186
+
187
+
188
+ try {
189
+ execute(options, (ok) => {
190
+ exitCode = ok ? 0 : 1;
191
+ });
192
+ console.log('cli.execute()', exitCode);
193
+ } catch (error) {
194
+ console.error('Error catched by cmdline interface:', error);
195
+ exitCode = 1;
196
+ }