@conduit-client/tools 5.67.0-dev1
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.
- package/LICENSE.txt +82 -0
- package/lib/commands/__tests__/generate.spec.js +43 -0
- package/lib/commands/generate.js +88 -0
- package/lib/index.js +1 -0
- package/package.json +45 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Terms of Use
|
|
2
|
+
|
|
3
|
+
Copyright 2022 Salesforce, Inc. All rights reserved.
|
|
4
|
+
|
|
5
|
+
These Terms of Use govern the download, installation, and/or use of this
|
|
6
|
+
software provided by Salesforce, Inc. ("Salesforce") (the "Software"), were
|
|
7
|
+
last updated on April 15, 2022, and constitute a legally binding
|
|
8
|
+
agreement between you and Salesforce. If you do not agree to these Terms of
|
|
9
|
+
Use, do not install or use the Software.
|
|
10
|
+
|
|
11
|
+
Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free
|
|
12
|
+
copyright license to reproduce, prepare derivative works of, publicly
|
|
13
|
+
display, publicly perform, sublicense, and distribute the Software and
|
|
14
|
+
derivative works subject to these Terms. These Terms shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
Subject to the limited rights expressly granted hereunder, Salesforce
|
|
18
|
+
reserves all rights, title, and interest in and to all intellectual
|
|
19
|
+
property subsisting in the Software. No rights are granted to you hereunder
|
|
20
|
+
other than as expressly set forth herein. Users residing in countries on
|
|
21
|
+
the United States Office of Foreign Assets Control sanction list, or which
|
|
22
|
+
are otherwise subject to a US export embargo, may not use the Software.
|
|
23
|
+
|
|
24
|
+
Implementation of the Software may require development work, for which you
|
|
25
|
+
are responsible. The Software may contain bugs, errors and
|
|
26
|
+
incompatibilities and is made available on an AS IS basis without support,
|
|
27
|
+
updates, or service level commitments.
|
|
28
|
+
|
|
29
|
+
Salesforce reserves the right at any time to modify, suspend, or
|
|
30
|
+
discontinue, the Software (or any part thereof) with or without notice. You
|
|
31
|
+
agree that Salesforce shall not be liable to you or to any third party for
|
|
32
|
+
any modification, suspension, or discontinuance.
|
|
33
|
+
|
|
34
|
+
You agree to defend Salesforce against any claim, demand, suit or
|
|
35
|
+
proceeding made or brought against Salesforce by a third party arising out
|
|
36
|
+
of or accruing from (a) your use of the Software, and (b) any application
|
|
37
|
+
you develop with the Software that infringes any copyright, trademark,
|
|
38
|
+
trade secret, trade dress, patent, or other intellectual property right of
|
|
39
|
+
any person or defames any person or violates their rights of publicity or
|
|
40
|
+
privacy (each a "Claim Against Salesforce"), and will indemnify Salesforce
|
|
41
|
+
from any damages, attorney fees, and costs finally awarded against
|
|
42
|
+
Salesforce as a result of, or for any amounts paid by Salesforce under a
|
|
43
|
+
settlement approved by you in writing of, a Claim Against Salesforce,
|
|
44
|
+
provided Salesforce (x) promptly gives you written notice of the Claim
|
|
45
|
+
Against Salesforce, (y) gives you sole control of the defense and
|
|
46
|
+
settlement of the Claim Against Salesforce (except that you may not settle
|
|
47
|
+
any Claim Against Salesforce unless it unconditionally releases Salesforce
|
|
48
|
+
of all liability), and (z) gives you all reasonable assistance, at your
|
|
49
|
+
expense.
|
|
50
|
+
|
|
51
|
+
WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT
|
|
52
|
+
SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
53
|
+
IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES,
|
|
54
|
+
INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
|
55
|
+
PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA,
|
|
56
|
+
OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN
|
|
57
|
+
CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU
|
|
58
|
+
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
59
|
+
|
|
60
|
+
These Terms of Use shall be governed exclusively by the internal laws of
|
|
61
|
+
the State of California, without regard to its conflicts of laws
|
|
62
|
+
rules. Each party hereby consents to the exclusive jurisdiction of the
|
|
63
|
+
state and federal courts located in San Francisco County, California to
|
|
64
|
+
adjudicate any dispute arising out of or relating to these Terms of Use and
|
|
65
|
+
the download, installation, and/or use of the Software. Except as expressly
|
|
66
|
+
stated herein, these Terms of Use constitute the entire agreement between
|
|
67
|
+
the parties, and supersede all prior and contemporaneous agreements,
|
|
68
|
+
proposals, or representations, written or oral, concerning their subject
|
|
69
|
+
matter. No modification, amendment, or waiver of any provision of these
|
|
70
|
+
Terms of Use shall be effective unless it is by an update to these Terms of
|
|
71
|
+
Use that Salesforce makes available, or is in writing and signed by the
|
|
72
|
+
party against whom the modification, amendment, or waiver is to be
|
|
73
|
+
asserted.
|
|
74
|
+
|
|
75
|
+
Data Privacy: Salesforce may collect, process, and store device,
|
|
76
|
+
system, and other information related to your use of the Software. This
|
|
77
|
+
information includes, but is not limited to, IP address, user metrics, and
|
|
78
|
+
other data ("Usage Data"). Salesforce may use Usage Data for analytics,
|
|
79
|
+
product development, and marketing purposes. You acknowledge that files
|
|
80
|
+
generated in conjunction with the Software may contain sensitive or
|
|
81
|
+
confidential data, and you are solely responsible for anonymizing and
|
|
82
|
+
protecting such data.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { buildIncludeExclude, coerce } from '../generate';
|
|
3
|
+
// this is not cooperating with vitest
|
|
4
|
+
vi.mock('chalk', () => {
|
|
5
|
+
return {
|
|
6
|
+
default: vi.fn(),
|
|
7
|
+
};
|
|
8
|
+
});
|
|
9
|
+
describe('buildIncludeExclude', () => {
|
|
10
|
+
it('should return an IncludeExclude object with properties corresponding to return values of coerce', () => {
|
|
11
|
+
const result = buildIncludeExclude(['abc', 'def.*'], ['^ghi$']);
|
|
12
|
+
expect(result).toEqual({ include: [/abc/, /def.*/], exclude: [/^ghi$/] });
|
|
13
|
+
});
|
|
14
|
+
it('should return empty arrays when given empty arrays', () => {
|
|
15
|
+
const result = buildIncludeExclude([], []);
|
|
16
|
+
expect(result).toEqual({ include: [], exclude: [] });
|
|
17
|
+
});
|
|
18
|
+
it('should return only includes when excludes is undefined or null', () => {
|
|
19
|
+
let result = buildIncludeExclude(['abc', 'def.*'], undefined);
|
|
20
|
+
expect(result).toEqual({ include: [/abc/, /def.*/] });
|
|
21
|
+
result = buildIncludeExclude(['abc', 'def.*'], null);
|
|
22
|
+
expect(result).toEqual({ include: [/abc/, /def.*/] });
|
|
23
|
+
});
|
|
24
|
+
it('should return only excludes when includes is undefined or null', () => {
|
|
25
|
+
let result = buildIncludeExclude(undefined, ['^ghi$']);
|
|
26
|
+
expect(result).toEqual({ exclude: [/^ghi$/] });
|
|
27
|
+
result = buildIncludeExclude(null, ['^ghi$']);
|
|
28
|
+
expect(result).toEqual({ exclude: [/^ghi$/] });
|
|
29
|
+
});
|
|
30
|
+
it('should return an empty object when both are undefined or null', () => {
|
|
31
|
+
let result = buildIncludeExclude(undefined, undefined);
|
|
32
|
+
expect(result).toEqual({});
|
|
33
|
+
result = buildIncludeExclude(null, null);
|
|
34
|
+
expect(result).toEqual({});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('coerce', () => {
|
|
38
|
+
it('should return an array of RegExp', () => {
|
|
39
|
+
const input = ['abc', 'def.*', '^ghi$'];
|
|
40
|
+
const output = [/abc/, /def.*/, /^ghi$/];
|
|
41
|
+
expect(coerce(input)).toEqual(output);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Args, Command, Flags } from '@oclif/core';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { generate } from '@conduit-client/tools-core';
|
|
4
|
+
import { LogLevelMap, loggerService as loggerServiceFactory } from '@conduit-client/utils';
|
|
5
|
+
/**
|
|
6
|
+
* Maps an array of strings into an array of
|
|
7
|
+
* regular expressions
|
|
8
|
+
*
|
|
9
|
+
* @param configArray array of strings
|
|
10
|
+
* @returns array of RegExp
|
|
11
|
+
*/
|
|
12
|
+
export function coerce(configArray) {
|
|
13
|
+
const mapped = configArray.map((i) => {
|
|
14
|
+
return new RegExp(i);
|
|
15
|
+
});
|
|
16
|
+
return mapped;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generates an IncludeExclude object based on arrays of strings
|
|
20
|
+
*
|
|
21
|
+
* @param include array of strings from --include options
|
|
22
|
+
* @param exclude array of strings from --exclude options
|
|
23
|
+
* @returns IncludeExclude object
|
|
24
|
+
*/
|
|
25
|
+
export function buildIncludeExclude(include, exclude) {
|
|
26
|
+
const includeExclude = {};
|
|
27
|
+
if (include) {
|
|
28
|
+
includeExclude.include = coerce(include);
|
|
29
|
+
}
|
|
30
|
+
if (exclude) {
|
|
31
|
+
includeExclude.exclude = coerce(exclude);
|
|
32
|
+
}
|
|
33
|
+
return includeExclude;
|
|
34
|
+
}
|
|
35
|
+
export class Generate extends Command {
|
|
36
|
+
async run() {
|
|
37
|
+
const { args, flags } = await this.parse(Generate);
|
|
38
|
+
const { input: inputFile, outputDir } = args;
|
|
39
|
+
const filePerType = flags.filePerType || false;
|
|
40
|
+
const loggerService = buildLoggerService(flags.logLevel);
|
|
41
|
+
try {
|
|
42
|
+
const includeExclude = buildIncludeExclude(flags.include, flags.exclude);
|
|
43
|
+
await generate(inputFile, outputDir, {
|
|
44
|
+
loggerService,
|
|
45
|
+
filePerType,
|
|
46
|
+
includeExclude,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
const message = err instanceof Error ? err.message : `Unknown error: ${JSON.stringify(err)}`;
|
|
51
|
+
loggerService.error(`${chalk.redBright('FATAL')}: ${message || 'Previous errors caused early program termination'}`);
|
|
52
|
+
if (err instanceof Error && err.stack) {
|
|
53
|
+
loggerService.trace(`Error stack:\n${err.stack}`);
|
|
54
|
+
}
|
|
55
|
+
this.exit(1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
Generate.description = 'generates luvio resource code from an api description file';
|
|
60
|
+
Generate.examples = [`$ luvio-tools generate [inputFile] [outputDir]`];
|
|
61
|
+
Generate.args = {
|
|
62
|
+
input: Args.file({ exists: true, required: true, description: 'input file' }),
|
|
63
|
+
outputDir: Args.directory({ required: true, description: 'output directory' }),
|
|
64
|
+
};
|
|
65
|
+
Generate.flags = {
|
|
66
|
+
logLevel: Flags.string({ default: 'WARN' }),
|
|
67
|
+
filePerType: Flags.boolean({ default: false }),
|
|
68
|
+
include: Flags.string({ multiple: true, char: 'n' }),
|
|
69
|
+
exclude: Flags.string({ multiple: true, char: 'x' }),
|
|
70
|
+
};
|
|
71
|
+
function buildLoggerService(level) {
|
|
72
|
+
let logLevel = level.toUpperCase();
|
|
73
|
+
const loggerService = loggerServiceFactory(logLevel in LogLevelMap ? logLevel : undefined, undefined, formatLogs);
|
|
74
|
+
if (!(logLevel in LogLevelMap)) {
|
|
75
|
+
loggerService.warn(`Log level ${logLevel} not known. Must be one of ${Object.keys(LogLevelMap)}. Defaulting to WARN.`);
|
|
76
|
+
}
|
|
77
|
+
return loggerService;
|
|
78
|
+
}
|
|
79
|
+
const logLevelColorMap = {
|
|
80
|
+
TRACE: chalk.white,
|
|
81
|
+
DEBUG: chalk.white,
|
|
82
|
+
INFO: chalk.white,
|
|
83
|
+
WARN: chalk.yellow,
|
|
84
|
+
ERROR: chalk.red,
|
|
85
|
+
};
|
|
86
|
+
function formatLogs(level, message) {
|
|
87
|
+
return `${logLevelColorMap[level](level)}: ${message}`;
|
|
88
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { run } from '@oclif/core';
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@conduit-client/tools",
|
|
3
|
+
"version": "5.67.0-dev1",
|
|
4
|
+
"description": "CLI for Luvio Code Generation",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"oclif"
|
|
7
|
+
],
|
|
8
|
+
"homepage": "https://github.com/salesforce-experience-platform-emu/luvio-next",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/salesforce-experience-platform-emu/luvio-next.git",
|
|
12
|
+
"directory": "packages/@conduit-client/generation/tools"
|
|
13
|
+
},
|
|
14
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "lib/index.js",
|
|
17
|
+
"types": "lib/index.d.ts",
|
|
18
|
+
"bin": {
|
|
19
|
+
"luvio-tools": "./bin/run.js"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"/bin",
|
|
23
|
+
"/lib"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"clean": "rm -rf lib",
|
|
28
|
+
"test": "vitest run"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@conduit-client/tools-core": "5.67.0-dev1",
|
|
32
|
+
"@oclif/core": "2.6.4",
|
|
33
|
+
"chalk": "^5.2.0"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=8.0.0"
|
|
37
|
+
},
|
|
38
|
+
"volta": {
|
|
39
|
+
"extends": "../../../../package.json"
|
|
40
|
+
},
|
|
41
|
+
"oclif": {
|
|
42
|
+
"commands": "./lib/commands",
|
|
43
|
+
"bin": "luvio-tools"
|
|
44
|
+
}
|
|
45
|
+
}
|