jitsu-cli 0.0.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.
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/bin/jitsu-cli +3 -0
- package/lib/cli/extension/build.d.ts +2 -0
- package/lib/cli/extension/build.js +137 -0
- package/lib/cli/extension/create.d.ts +2 -0
- package/lib/cli/extension/create.js +92 -0
- package/lib/cli/extension/exec.d.ts +3 -0
- package/lib/cli/extension/exec.js +296 -0
- package/lib/cli/extension/index.d.ts +9 -0
- package/lib/cli/extension/index.js +147 -0
- package/lib/cli/extension/template.d.ts +30 -0
- package/lib/cli/extension/template.js +237 -0
- package/lib/cli/extension/test.d.ts +2 -0
- package/lib/cli/extension/test.js +34 -0
- package/lib/cli/extension/validate-config.d.ts +2 -0
- package/lib/cli/extension/validate-config.js +62 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +7 -0
- package/lib/lib/chalk-code-highlight.d.ts +14 -0
- package/lib/lib/chalk-code-highlight.js +41 -0
- package/lib/lib/command/index.d.ts +3 -0
- package/lib/lib/command/index.js +118 -0
- package/lib/lib/errors.d.ts +1 -0
- package/lib/lib/errors.js +18 -0
- package/lib/lib/indent.d.ts +9 -0
- package/lib/lib/indent.js +41 -0
- package/lib/lib/log.d.ts +8 -0
- package/lib/lib/log.js +35 -0
- package/lib/lib/template.d.ts +5 -0
- package/lib/lib/template.js +36 -0
- package/lib/lib/validation.d.ts +2 -0
- package/lib/lib/validation.js +23 -0
- package/lib/lib/version.d.ts +5 -0
- package/lib/lib/version.js +35 -0
- package/lib/package.json +73 -0
- package/lib/run.d.ts +1 -0
- package/lib/run.js +37 -0
- package/lib/tests.d.ts +2 -0
- package/lib/tests.js +10 -0
- package/package.json +73 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadBuild = exports.getConfigJson = exports.getDistFile = exports.validateTsConfig = exports.extensionCommands = exports.help = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
|
+
const chalk_code_highlight_1 = require("../../lib/chalk-code-highlight");
|
|
7
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
8
|
+
const indent_1 = require("../../lib/indent");
|
|
9
|
+
const create_1 = require("./create");
|
|
10
|
+
const build_1 = require("./build");
|
|
11
|
+
const test_1 = require("./test");
|
|
12
|
+
const validate_config_1 = require("./validate-config");
|
|
13
|
+
const template_1 = require("./template");
|
|
14
|
+
const json5_1 = tslib_1.__importDefault(require("json5"));
|
|
15
|
+
const exec_1 = require("./exec");
|
|
16
|
+
const readline = tslib_1.__importStar(require("readline"));
|
|
17
|
+
const sandbox_1 = require("@jitsu/node-bridge/sandbox");
|
|
18
|
+
global.fetch = require("cross-fetch");
|
|
19
|
+
const usage = `
|
|
20
|
+
· ${chalk_1.default.bold("jitsu-cli extension create")}
|
|
21
|
+
|
|
22
|
+
Create a project for jitsu plugin with placeholder implementation for all components.
|
|
23
|
+
|
|
24
|
+
· ${chalk_1.default.bold("jitsu-cli extension build <directory>")}
|
|
25
|
+
|
|
26
|
+
Build project located in <directory>. If <directory> is not provided current directory is used.
|
|
27
|
+
|
|
28
|
+
· ${chalk_1.default.bold("jitsu-cli extension test <directory>")}
|
|
29
|
+
|
|
30
|
+
Run tests for project in <directory>/__test__. If <directory> is not provided current directory is used.
|
|
31
|
+
|
|
32
|
+
· ${chalk_1.default.bold("jitsu-cli extension validate-config -f file or -j {json}")}
|
|
33
|
+
|
|
34
|
+
Validates configuration json object. ${chalk_1.default.bold("Note:")} run \`jitsu-cli extension build\` beforehand
|
|
35
|
+
|
|
36
|
+
· ${chalk_1.default.bold("jitsu-cli extension help")}
|
|
37
|
+
|
|
38
|
+
Show this help
|
|
39
|
+
`;
|
|
40
|
+
exports.help = `
|
|
41
|
+
|
|
42
|
+
${chalk_1.default.bold("DESCRIPTION")}
|
|
43
|
+
|
|
44
|
+
The command will build jitsu extension and bundle a single JS file that will
|
|
45
|
+
placed to a location defined in main parameter of package.json (if not set, the bundle
|
|
46
|
+
will be placed in dist/index.js
|
|
47
|
+
|
|
48
|
+
You can (and should!) call \`jitsu-cli extension build\` in package.json. Example: ${chalk_code_highlight_1.chalkCode.json((0, indent_1.align)(JSON.stringify((0, template_1.packageJsonTemplate)({
|
|
49
|
+
packageName: "test-package",
|
|
50
|
+
type: "destination",
|
|
51
|
+
}), null, 2), { indent: 4, lnBefore: 2 }))}
|
|
52
|
+
|
|
53
|
+
The code should be located in ./src folder. src/index.js (or ts) should be present
|
|
54
|
+
|
|
55
|
+
${chalk_1.default.bold("TYPESCRIPT")}
|
|
56
|
+
|
|
57
|
+
Typescript is supported out of the box. Just add tsconfig.json to the root of the project
|
|
58
|
+
|
|
59
|
+
${chalk_1.default.bold("COMMANDS")} ${(0, indent_1.align)(usage, { indent: 2, lnBefore: 2 })}
|
|
60
|
+
`;
|
|
61
|
+
exports.extensionCommands = {
|
|
62
|
+
exec: {
|
|
63
|
+
exec: exec_1.execDestinationExtension,
|
|
64
|
+
description: "Execute destination extension on a test dataset",
|
|
65
|
+
help: "",
|
|
66
|
+
},
|
|
67
|
+
"exec-src": {
|
|
68
|
+
exec: exec_1.execSourceExtension,
|
|
69
|
+
description: "Builds and execute source connector extension with a test credentials and output data",
|
|
70
|
+
help: "",
|
|
71
|
+
},
|
|
72
|
+
test: {
|
|
73
|
+
exec: test_1.test,
|
|
74
|
+
description: "Execute test on extension",
|
|
75
|
+
help: "Tests should be located in ./__test__ folder and follow *.test.ts pattern",
|
|
76
|
+
},
|
|
77
|
+
build: {
|
|
78
|
+
exec: build_1.build,
|
|
79
|
+
description: "Builds Jitsu extension",
|
|
80
|
+
help: "",
|
|
81
|
+
},
|
|
82
|
+
create: {
|
|
83
|
+
exec: create_1.create,
|
|
84
|
+
description: "Creates an empty project",
|
|
85
|
+
help: "",
|
|
86
|
+
},
|
|
87
|
+
"validate-config": {
|
|
88
|
+
exec: validate_config_1.validateConfig,
|
|
89
|
+
description: `Verifies a configuration. ${chalk_1.default.bold("Note:")} run \`jitsu-cli extension build\` first!`,
|
|
90
|
+
help: "",
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
function validateTsConfig(tsConfigPath) {
|
|
94
|
+
let tsConfig;
|
|
95
|
+
try {
|
|
96
|
+
tsConfig = json5_1.default.parse(fs.readFileSync(tsConfigPath, "utf8"));
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
throw new Error(`${chalk_1.default.bold(tsConfigPath)} - syntax error: ${e.message}`);
|
|
100
|
+
}
|
|
101
|
+
if (tsConfig?.compilerOptions?.module !== "ES2020") {
|
|
102
|
+
throw new Error(`${chalk_1.default.bold(tsConfigPath)} error: compilerOptions.module should be set to ES2020!`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.validateTsConfig = validateTsConfig;
|
|
106
|
+
function getDistFile(packageJson) {
|
|
107
|
+
return packageJson.main || "dist/index.js";
|
|
108
|
+
}
|
|
109
|
+
exports.getDistFile = getDistFile;
|
|
110
|
+
async function getFirstLine(pathToFile) {
|
|
111
|
+
const readable = fs.createReadStream(pathToFile);
|
|
112
|
+
const reader = readline.createInterface({ input: readable });
|
|
113
|
+
const line = await new Promise(resolve => {
|
|
114
|
+
reader.on("line", line => {
|
|
115
|
+
reader.close();
|
|
116
|
+
resolve(line);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
readable.close();
|
|
120
|
+
return line;
|
|
121
|
+
}
|
|
122
|
+
function getConfigJson(jsonOrFile) {
|
|
123
|
+
if (jsonOrFile.trim().startsWith("{") && jsonOrFile.trim().endsWith("}")) {
|
|
124
|
+
return json5_1.default.parse(jsonOrFile.trim());
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
if (!fs.existsSync(jsonOrFile)) {
|
|
128
|
+
throw new Error(`File ${jsonOrFile} does not exist!`);
|
|
129
|
+
}
|
|
130
|
+
return json5_1.default.parse(fs.readFileSync(jsonOrFile, "utf8"));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.getConfigJson = getConfigJson;
|
|
134
|
+
async function loadBuild(file) {
|
|
135
|
+
let formatDefinition = await getFirstLine(file);
|
|
136
|
+
if (formatDefinition.trim() === "//format=es" || formatDefinition.trim() === "//format=esm") {
|
|
137
|
+
return Promise.resolve().then(() => tslib_1.__importStar(require(file)));
|
|
138
|
+
}
|
|
139
|
+
else if (formatDefinition.trim() === "//format=cjs" || formatDefinition.trim() === "//format=commonjs") {
|
|
140
|
+
const vm = (0, sandbox_1.sandbox)({ file });
|
|
141
|
+
return vm.runFile(file);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
throw new Error(`Unsupported build format - ${formatDefinition}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.loadBuild = loadBuild;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ProjectTemplate } from "../../lib/template";
|
|
2
|
+
export declare type TemplateVars = {
|
|
3
|
+
license?: "MIT" | "Other";
|
|
4
|
+
packageName: string;
|
|
5
|
+
type: "destination" | "source" | "transform";
|
|
6
|
+
jitsuVersion?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const packageJsonTemplate: ({ packageName, type, jitsuVersion }: TemplateVars) => {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
description: string;
|
|
12
|
+
main: string;
|
|
13
|
+
scripts: {
|
|
14
|
+
clean: string;
|
|
15
|
+
build: string;
|
|
16
|
+
test: string;
|
|
17
|
+
"validate-config": string;
|
|
18
|
+
execute: string;
|
|
19
|
+
};
|
|
20
|
+
devDependencies: {
|
|
21
|
+
"@jitsu/types": string;
|
|
22
|
+
"@jitsu/jlib": string;
|
|
23
|
+
"ts-jest": string;
|
|
24
|
+
"jitsu-cli": string;
|
|
25
|
+
tslib: string;
|
|
26
|
+
typescript: string;
|
|
27
|
+
};
|
|
28
|
+
dependencies: {};
|
|
29
|
+
};
|
|
30
|
+
export declare const extensionProjectTemplate: ProjectTemplate<TemplateVars>;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extensionProjectTemplate = exports.packageJsonTemplate = void 0;
|
|
4
|
+
const version_1 = require("../../lib/version");
|
|
5
|
+
const packageJsonTemplate = ({ packageName, type, jitsuVersion = undefined }) => ({
|
|
6
|
+
name: `${packageName}`,
|
|
7
|
+
version: "0.0.1",
|
|
8
|
+
description: `Jitsu ${type} - ${packageName}`,
|
|
9
|
+
main: `dist/${packageName}.js`,
|
|
10
|
+
scripts: {
|
|
11
|
+
clean: "rm -rf ./dist",
|
|
12
|
+
build: "jitsu-cli extension build",
|
|
13
|
+
test: "jitsu-cli extension test",
|
|
14
|
+
"validate-config": "jitsu-cli extension validate-config",
|
|
15
|
+
execute: `jitsu-cli extension ${type == "destination" ? "exec" : "exec-src"}`,
|
|
16
|
+
},
|
|
17
|
+
devDependencies: {
|
|
18
|
+
"@jitsu/types": `${jitsuVersion || "^" + version_1.jitsuCliVersion}`,
|
|
19
|
+
"@jitsu/jlib": `${jitsuVersion || "^" + version_1.jitsuCliVersion}`,
|
|
20
|
+
"ts-jest": "^27.0.7",
|
|
21
|
+
"jitsu-cli": `${jitsuVersion || "^" + version_1.jitsuCliVersion}`,
|
|
22
|
+
tslib: "^2.3.1",
|
|
23
|
+
typescript: "^4.5.2",
|
|
24
|
+
},
|
|
25
|
+
dependencies: {},
|
|
26
|
+
});
|
|
27
|
+
exports.packageJsonTemplate = packageJsonTemplate;
|
|
28
|
+
let destinationTest = ({ type = "destination" }) => {
|
|
29
|
+
if (type !== "destination") {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return `
|
|
33
|
+
import { JitsuDestinationContext } from "@jitsu/types/extension"
|
|
34
|
+
import { testDestination } from "jitsu-cli/lib/tests"
|
|
35
|
+
import { destination } from "../src"
|
|
36
|
+
|
|
37
|
+
testDestination({
|
|
38
|
+
name: "basic",
|
|
39
|
+
context: {
|
|
40
|
+
destinationId: "test",
|
|
41
|
+
destinationType: "mydest",
|
|
42
|
+
config: {}
|
|
43
|
+
},
|
|
44
|
+
destination: destination,
|
|
45
|
+
event: {
|
|
46
|
+
event_type: 'test',
|
|
47
|
+
a: 1
|
|
48
|
+
},
|
|
49
|
+
expectedResult: {
|
|
50
|
+
method: "POST",
|
|
51
|
+
url: "https://test.com",
|
|
52
|
+
body: { a: 2 },
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
`;
|
|
56
|
+
};
|
|
57
|
+
let destinationCode = () => {
|
|
58
|
+
return `
|
|
59
|
+
import { DestinationFunction, DestinationMessage, JitsuDestinationContext, ConfigValidator} from "@jitsu/types/extension";
|
|
60
|
+
import { DefaultJitsuEvent } from "@jitsu/types/event";
|
|
61
|
+
|
|
62
|
+
export type DestinationConfig = {
|
|
63
|
+
exampleParam: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const validator: ConfigValidator<DestinationConfig> = async (config: DestinationConfig) => {
|
|
67
|
+
if (config.exampleParam !== 'valid-config') {
|
|
68
|
+
return \`Invalid config: exampleParam expected to be 'valid-config', but actual value is: \${config.exampleParam}\`;
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const destination: DestinationFunction = (event: DefaultJitsuEvent, dstContext: JitsuDestinationContext<DestinationConfig>) => {
|
|
74
|
+
return { url: "https://test.com", method: "POST", body: { a: (event.a || 0) + 1 } };
|
|
75
|
+
};
|
|
76
|
+
`;
|
|
77
|
+
};
|
|
78
|
+
let sourceCode = () => {
|
|
79
|
+
return `
|
|
80
|
+
import { SourceCatalog, StateService, StreamReader, StreamSink, StreamConfiguration } from "@jitsu/types/sources";
|
|
81
|
+
import { ConfigValidationResult, ExtensionDescriptor } from "@jitsu/types/extension";
|
|
82
|
+
|
|
83
|
+
export interface SourceConfig {
|
|
84
|
+
user_id: string
|
|
85
|
+
my_source_param: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface StreamConfig {
|
|
89
|
+
my_stream_param: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function validator(config: SourceConfig): Promise<ConfigValidationResult> {
|
|
93
|
+
//TODO: Check that provided config data allows to connect to third party API
|
|
94
|
+
console.log("validator is not yet implemented");
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const descriptor: ExtensionDescriptor<SourceConfig> = {
|
|
99
|
+
id: "my_source",
|
|
100
|
+
displayName: "Source Example",
|
|
101
|
+
description:
|
|
102
|
+
"Example source that produces row with run number and source/stream configuration.",
|
|
103
|
+
configurationParameters: [
|
|
104
|
+
{
|
|
105
|
+
displayName: "User ID",
|
|
106
|
+
id: "user_id",
|
|
107
|
+
type: "string",
|
|
108
|
+
required: true,
|
|
109
|
+
documentation: "User Id",
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
displayName: "Example Parameter",
|
|
113
|
+
id: "my_source_param",
|
|
114
|
+
required: true,
|
|
115
|
+
type: "string",
|
|
116
|
+
documentation: \`
|
|
117
|
+
<div>
|
|
118
|
+
Example Parameter
|
|
119
|
+
</div>
|
|
120
|
+
\`,
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const sourceCatalog: SourceCatalog<SourceConfig, StreamConfig> = async config => {
|
|
126
|
+
return [
|
|
127
|
+
{
|
|
128
|
+
type: "my_source_runs",
|
|
129
|
+
supportedModes: ["incremental"],
|
|
130
|
+
params: [
|
|
131
|
+
{
|
|
132
|
+
id: "my_stream_param",
|
|
133
|
+
displayName: "Stream Parameter",
|
|
134
|
+
type: "string",
|
|
135
|
+
documentation: \`
|
|
136
|
+
<div>
|
|
137
|
+
Stream Parameter example.
|
|
138
|
+
</div>
|
|
139
|
+
\`,
|
|
140
|
+
required: true,
|
|
141
|
+
},
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
];
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const streamReader: StreamReader<SourceConfig, StreamConfig> = async (
|
|
148
|
+
sourceConfig: SourceConfig,
|
|
149
|
+
streamType: string,
|
|
150
|
+
streamConfiguration: StreamConfiguration<StreamConfig>,
|
|
151
|
+
streamSink: StreamSink,
|
|
152
|
+
services: { state: StateService }
|
|
153
|
+
) => {
|
|
154
|
+
//Example of saved state usage. Read previous run number:
|
|
155
|
+
let runNumber = services.state.get("run_number") || 0;
|
|
156
|
+
runNumber++
|
|
157
|
+
streamSink.log("INFO", "Run number: " + runNumber);
|
|
158
|
+
streamSink.addRecord({
|
|
159
|
+
$id: runNumber,
|
|
160
|
+
$recordTimestamp: new Date(),
|
|
161
|
+
type: streamType,
|
|
162
|
+
...sourceConfig,
|
|
163
|
+
...streamConfiguration.parameters
|
|
164
|
+
});
|
|
165
|
+
//Save last run number to state
|
|
166
|
+
services.state.set("run_number", runNumber);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export { streamReader, sourceCatalog, descriptor, validator };
|
|
170
|
+
`;
|
|
171
|
+
};
|
|
172
|
+
let transformCode = () => {
|
|
173
|
+
return `
|
|
174
|
+
import {Destination, DestinationMessage, JitsuDestinationContext} from "@jitsu/types/destination";
|
|
175
|
+
import {DefaultJitsuEvent} from "@jitsu/types/event";
|
|
176
|
+
|
|
177
|
+
//duplicate events
|
|
178
|
+
const transform: TransformationFunction = (event: DefaultJitsuEvent) => {
|
|
179
|
+
return [event, {...event, eventn_ctx_event_id: event.eventn_ctx_event_id + "_2"}]
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export default jitsuAdapter;
|
|
183
|
+
`;
|
|
184
|
+
};
|
|
185
|
+
let descriptor = {};
|
|
186
|
+
descriptor["destination"] = (vars) => `
|
|
187
|
+
import {ExtensionDescriptor} from "@jitsu/types/extension";
|
|
188
|
+
import {destination, validator, DestinationConfig} from "./destination";
|
|
189
|
+
|
|
190
|
+
const descriptor: ExtensionDescriptor = {
|
|
191
|
+
id: "${vars.packageName}",
|
|
192
|
+
displayName: "${vars.packageName}",
|
|
193
|
+
icon: "",
|
|
194
|
+
description: "Jitsu destination - ${vars.packageName} (generated by 'jitsu-cli extension create')",
|
|
195
|
+
configurationParameters: [
|
|
196
|
+
{id: "exampleParam", type: "string", required: true, displayName: "Example param", documentation: "Documentation"}
|
|
197
|
+
],
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export { descriptor, destination, validator };
|
|
201
|
+
`;
|
|
202
|
+
descriptor["transform"] = (vars) => `
|
|
203
|
+
import {DestinationAdapter, DestinationDescriptor} from "@jitsu/types/destination";
|
|
204
|
+
import jitsuAdapter from "./adapter";
|
|
205
|
+
|
|
206
|
+
const adapter: DestinationAdapter = jitsuAdapter
|
|
207
|
+
|
|
208
|
+
const descriptor: DestinationDescriptor = {
|
|
209
|
+
type: "${vars.packageName}",
|
|
210
|
+
displayName: "${vars.packageName}",
|
|
211
|
+
icon: "",
|
|
212
|
+
description: "Jitsu ${vars.type} - ${vars.packageName} (generated by 'jitsu-cli extension create)'",
|
|
213
|
+
configurationParameters: [
|
|
214
|
+
//put configuration here
|
|
215
|
+
]
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export {descriptor, adapter}
|
|
219
|
+
`;
|
|
220
|
+
exports.extensionProjectTemplate = {
|
|
221
|
+
"__test__/destination.test.ts": destinationTest,
|
|
222
|
+
"src/destination.ts": vars => vars.type == "destination" && destinationCode(),
|
|
223
|
+
"src/transform.ts": vars => vars.type == "transform" && transformCode(),
|
|
224
|
+
"src/index.ts": vars => (vars.type == "source" ? sourceCode() : descriptor[vars.type](vars)),
|
|
225
|
+
"package.json": exports.packageJsonTemplate,
|
|
226
|
+
"tsconfig.json": {
|
|
227
|
+
compilerOptions: {
|
|
228
|
+
module: "ES2020",
|
|
229
|
+
target: "ES2021",
|
|
230
|
+
moduleResolution: "Node",
|
|
231
|
+
esModuleInterop: true,
|
|
232
|
+
outDir: "./dist",
|
|
233
|
+
rootDir: "./",
|
|
234
|
+
},
|
|
235
|
+
include: ["./src", "__test__"],
|
|
236
|
+
},
|
|
237
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.test = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
|
+
const log_1 = tslib_1.__importDefault(require("../../lib/log"));
|
|
7
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
8
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
9
|
+
const jest_cli_1 = require("jest-cli");
|
|
10
|
+
const _1 = require("./");
|
|
11
|
+
async function test(args) {
|
|
12
|
+
const directory = args?.[0] || "";
|
|
13
|
+
let projectBase = path_1.default.isAbsolute(directory) ? directory : path_1.default.resolve(process.cwd() + "/" + directory);
|
|
14
|
+
(0, log_1.default)().info("🛂 Running tests for " + chalk_1.default.bold(projectBase));
|
|
15
|
+
let tsConfigPath = path_1.default.resolve(projectBase, "tsconfig.json");
|
|
16
|
+
const typescriptEnabled = fs_1.default.existsSync(tsConfigPath);
|
|
17
|
+
if (typescriptEnabled) {
|
|
18
|
+
(0, log_1.default)().info(`ℹ️ Found ${chalk_1.default.bold("tsconfig.json")}, typescript will be enabled`);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return {
|
|
22
|
+
success: false,
|
|
23
|
+
message: `${chalk_1.default.bold("tsconfig.json")} is not found in the root of the project. Pure JS extensions are not supported yet`,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
(0, _1.validateTsConfig)(tsConfigPath);
|
|
27
|
+
const jestArgs = ["--passWithNoTests", "--projects", projectBase];
|
|
28
|
+
if (typescriptEnabled) {
|
|
29
|
+
jestArgs.push("--preset", "ts-jest");
|
|
30
|
+
}
|
|
31
|
+
await (0, jest_cli_1.run)(jestArgs);
|
|
32
|
+
return { success: true };
|
|
33
|
+
}
|
|
34
|
+
exports.test = test;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateConfig = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const commander_1 = tslib_1.__importDefault(require("commander"));
|
|
6
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
9
|
+
const json5_1 = tslib_1.__importDefault(require("json5"));
|
|
10
|
+
const log_1 = tslib_1.__importDefault(require("../../lib/log"));
|
|
11
|
+
const index_1 = require("./index");
|
|
12
|
+
const validation_1 = require("../../lib/validation");
|
|
13
|
+
async function validateConfig(args) {
|
|
14
|
+
const program = new commander_1.default.Command();
|
|
15
|
+
program.option("-d, --dir <project_dir>", "Project directory");
|
|
16
|
+
program.option("-c, --config <config_file_or_json>", "Configuration file path or inline extension configuration JSON");
|
|
17
|
+
program.argument("[project_dir]");
|
|
18
|
+
program.parse(["dummy", "dummy", ...args]);
|
|
19
|
+
const opts = program.opts();
|
|
20
|
+
if (!opts.config) {
|
|
21
|
+
return {
|
|
22
|
+
success: false,
|
|
23
|
+
message: "Please define config object -c json_file_path or -c '{json_object:}'",
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
let configObj;
|
|
27
|
+
try {
|
|
28
|
+
configObj = (0, index_1.getConfigJson)(opts.config);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
return {
|
|
32
|
+
success: false,
|
|
33
|
+
message: `Can't parse config JSON: '${opts.config}' ${e.message})`,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
let projectDir = opts.dir || ".";
|
|
37
|
+
(0, log_1.default)().info("Project dir: " + projectDir);
|
|
38
|
+
let packageFile = path_1.default.resolve(projectDir, "package.json");
|
|
39
|
+
if (!fs_1.default.existsSync(packageFile)) {
|
|
40
|
+
return { success: false, message: `Can't find package file ${packageFile}` };
|
|
41
|
+
}
|
|
42
|
+
let packageObj = json5_1.default.parse(fs_1.default.readFileSync(packageFile, "utf8"));
|
|
43
|
+
let distFile = path_1.default.resolve(projectDir, (0, index_1.getDistFile)(packageObj));
|
|
44
|
+
(0, log_1.default)().info("Dist file: " + distFile);
|
|
45
|
+
if (!fs_1.default.existsSync(distFile)) {
|
|
46
|
+
return { success: false, message: `Can't find dist file (${distFile}). Forgot to run jitsu-cli extension build ?` };
|
|
47
|
+
}
|
|
48
|
+
(0, log_1.default)().info("🤔 Loading build from " + chalk_1.default.bold(distFile));
|
|
49
|
+
let build = await (0, index_1.loadBuild)(distFile);
|
|
50
|
+
(0, log_1.default)().info("👍 Module loaded!");
|
|
51
|
+
if (!build.validator) {
|
|
52
|
+
return { success: false, message: "Build doesn't export validator symbol" };
|
|
53
|
+
}
|
|
54
|
+
(0, log_1.default)().info("🤔 Validating configuration " + JSON.stringify(configObj));
|
|
55
|
+
let validationError = await (0, validation_1.validateConfiguration)(configObj, build.validator);
|
|
56
|
+
if (validationError) {
|
|
57
|
+
return { success: false, message: `❌ ${validationError}` };
|
|
58
|
+
}
|
|
59
|
+
(0, log_1.default)().info("✅ Config is valid. Hooray!");
|
|
60
|
+
return { success: true };
|
|
61
|
+
}
|
|
62
|
+
exports.validateConfig = validateConfig;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Grammar } from "prismjs";
|
|
2
|
+
export declare type ColorScheme = Record<string, string | null>;
|
|
3
|
+
export declare const defaultColorScheme: {
|
|
4
|
+
punctuation: string;
|
|
5
|
+
operator: string;
|
|
6
|
+
string: string;
|
|
7
|
+
keyword: string;
|
|
8
|
+
"function-variable": null;
|
|
9
|
+
};
|
|
10
|
+
export declare function chalkCode(code: string, lang: Grammar, colorScheme?: ColorScheme): string;
|
|
11
|
+
export declare namespace chalkCode {
|
|
12
|
+
var typescript: (code: string | TemplateStringsArray, colorScheme?: ColorScheme) => string;
|
|
13
|
+
var json: (code: string | TemplateStringsArray, colorScheme?: ColorScheme) => string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.chalkCode = exports.defaultColorScheme = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const prismjs_1 = tslib_1.__importDefault(require("prismjs"));
|
|
6
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
|
+
exports.defaultColorScheme = {
|
|
8
|
+
punctuation: "#999",
|
|
9
|
+
operator: "#9a6e3a",
|
|
10
|
+
string: "#9a6e3a",
|
|
11
|
+
keyword: "b#07a",
|
|
12
|
+
"function-variable": null,
|
|
13
|
+
};
|
|
14
|
+
function chalkString(expr, str) {
|
|
15
|
+
if (expr.startsWith("b")) {
|
|
16
|
+
return chalk_1.default.bold(chalkString(expr.substring(1), str));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return chalk_1.default.hex(expr)(str);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function chalkCode(code, lang, colorScheme = exports.defaultColorScheme) {
|
|
23
|
+
return prismjs_1.default.tokenize(code, prismjs_1.default.languages.javascript)
|
|
24
|
+
.map(element => {
|
|
25
|
+
if (typeof element === "string") {
|
|
26
|
+
return element;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
let highlight = colorScheme[element.type];
|
|
30
|
+
return highlight ? chalkString(highlight, element.content.toString()) : `${element.content}`;
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
.join("");
|
|
34
|
+
}
|
|
35
|
+
exports.chalkCode = chalkCode;
|
|
36
|
+
chalkCode.typescript = (code, colorScheme = exports.defaultColorScheme) => {
|
|
37
|
+
return chalkCode(typeof code === "string" ? code : code.join("\n"), prismjs_1.default.languages.typescript, colorScheme);
|
|
38
|
+
};
|
|
39
|
+
chalkCode.json = (code, colorScheme = exports.defaultColorScheme) => {
|
|
40
|
+
return chalkCode(typeof code === "string" ? code : code.join("\n"), prismjs_1.default.languages.json, colorScheme);
|
|
41
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Command, CommandRegistry, CommandResult, HelpOptions } from "./types";
|
|
2
|
+
export declare const executeCommand: (commands: CommandRegistry, args: string[], helpOpts: HelpOptions) => Promise<CommandResult>;
|
|
3
|
+
export declare function subcommands(commands: CommandRegistry, helpOpts: HelpOptions): Command;
|