jitsu-cli 0.6.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Jitsu Labs, Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # Jitsu CLI
2
+
3
+ #### Quick start
4
+
5
+ ```
6
+ npx jitsu-cli --help
7
+ ```
8
+
9
+ Submodule of [Jitsu SDK](https://github.com/jitsucom/jitsu-sdk).
10
+
11
+ [Read more →](https://github.com/jitsucom/jitsu-sdk).
package/bin/jitsu-cli ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ require("../lib/index.js");
@@ -0,0 +1,2 @@
1
+ import { CommandResult } from "../../lib/command/types";
2
+ export declare function build(args: string[]): Promise<CommandResult>;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.build = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
6
+ const log_1 = (0, tslib_1.__importDefault)(require("../../lib/log"));
7
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
8
+ const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
9
+ const errors_1 = require("../../lib/errors");
10
+ const rollup_1 = require("rollup");
11
+ const rollup_plugin_typescript2_1 = (0, tslib_1.__importDefault)(require("rollup-plugin-typescript2"));
12
+ const plugin_multi_entry_1 = (0, tslib_1.__importDefault)(require("@rollup/plugin-multi-entry"));
13
+ const plugin_node_resolve_1 = (0, tslib_1.__importDefault)(require("@rollup/plugin-node-resolve"));
14
+ const plugin_commonjs_1 = (0, tslib_1.__importDefault)(require("@rollup/plugin-commonjs"));
15
+ const version_1 = require("../../lib/version");
16
+ const _1 = require("./");
17
+ const JSON5_1 = (0, tslib_1.__importDefault)(require("JSON5"));
18
+ async function build(args) {
19
+ const directory = args?.[0] || "";
20
+ let projectBase = path_1.default.isAbsolute(directory) ? directory : path_1.default.resolve(process.cwd() + "/" + directory);
21
+ (0, log_1.default)().info("🔨 Building project in " + chalk_1.default.bold(projectBase));
22
+ if (!fs_1.default.existsSync(projectBase)) {
23
+ throw new Error(`Path ${projectBase} does not exist`);
24
+ }
25
+ let packageFile = path_1.default.resolve(projectBase, "package.json");
26
+ if (!fs_1.default.existsSync(packageFile)) {
27
+ return { success: false, message: "Can't find package.json in " + projectBase };
28
+ }
29
+ let packageJson;
30
+ try {
31
+ packageJson = JSON5_1.default.parse(fs_1.default.readFileSync(packageFile, "utf8"));
32
+ }
33
+ catch (e) {
34
+ throw new Error((0, errors_1.appendError)(`Failed to parse package.json at ${projectBase}`, e));
35
+ }
36
+ let distFile = (0, _1.getDistFile)(packageJson);
37
+ let fullOutputPath = path_1.default.resolve(projectBase, distFile);
38
+ (0, log_1.default)().info("📦 Bundle will be written to " + chalk_1.default.bold(fullOutputPath));
39
+ let tsConfigPath = path_1.default.resolve(projectBase, "tsconfig.json");
40
+ const typescriptEnabled = fs_1.default.existsSync(tsConfigPath);
41
+ if (typescriptEnabled) {
42
+ (0, log_1.default)().info(`Found ${chalk_1.default.bold("tsconfig.json")}, typescript will be enabled`);
43
+ }
44
+ else {
45
+ return {
46
+ success: false,
47
+ message: `${chalk_1.default.bold("tsconfig.json")} is not found in the root of the project. Pure JS extensions are not supported yet`,
48
+ };
49
+ }
50
+ (0, _1.validateTsConfig)(tsConfigPath);
51
+ (0, log_1.default)().info("Building project");
52
+ try {
53
+ let indexFile = path_1.default.resolve(projectBase, "src/index.ts");
54
+ if (!fs_1.default.existsSync(indexFile)) {
55
+ return { success: false, message: `Project should have src/index.ts file. Can't find it at ${indexFile}` };
56
+ }
57
+ const bundle = await (0, rollup_1.rollup)({
58
+ input: [indexFile],
59
+ plugins: [typescriptEnabled && (0, rollup_plugin_typescript2_1.default)({ cwd: projectBase }), (0, plugin_multi_entry_1.default)(), (0, plugin_node_resolve_1.default)(), (0, plugin_commonjs_1.default)()],
60
+ });
61
+ (0, log_1.default)().info("Generating bundle");
62
+ let output = await bundle.generate({
63
+ generatedCode: "es2015",
64
+ format: "cjs",
65
+ });
66
+ (0, log_1.default)().info("Validating build");
67
+ let code = output.output[0].code;
68
+ code += `\nexports.buildInfo = {sdkVersion: "${version_1.jitsuCliVersion}", sdkPackage: "${version_1.jitsuPackageName}", buildTimestamp: "${new Date().toISOString()}"}`;
69
+ const exports = (0, _1.loadBuild)(code);
70
+ if (!exports.destination && !exports.transform) {
71
+ return {
72
+ success: false,
73
+ message: `${chalk_1.default.bold(indexFile)} should export ${chalk_1.default.italic("destination")} or ${chalk_1.default.italic("transform")} symbol. It exports: ` + Object.keys(exports).join(", "),
74
+ };
75
+ }
76
+ else if (exports.destination && exports.transform) {
77
+ return {
78
+ success: false,
79
+ message: `${chalk_1.default.bold(indexFile)} exports both ${chalk_1.default.italic("destination")} and ${chalk_1.default.italic("transform")} symbol. It should export either of them` + Object.keys(exports).join(", "),
80
+ };
81
+ }
82
+ fs_1.default.mkdirSync(path_1.default.dirname(fullOutputPath), { recursive: true });
83
+ fs_1.default.writeFileSync(fullOutputPath, code);
84
+ }
85
+ catch (e) {
86
+ if (e.id && e.loc && e.frame) {
87
+ return {
88
+ success: false,
89
+ message: "Build failed: " +
90
+ e.message +
91
+ `\n\n See: ${e.loc.file}:${e.loc.line}\n\n` +
92
+ `${e.frame
93
+ .split("\n")
94
+ .map(ln => " " + chalk_1.default.bgRed(" ") + " " + ln)
95
+ .join("\n")}`,
96
+ };
97
+ }
98
+ return { success: false, message: (0, errors_1.appendError)("Build failed", e), details: e?.stack };
99
+ }
100
+ return { success: true };
101
+ }
102
+ exports.build = build;
@@ -0,0 +1,2 @@
1
+ import { CommandResult } from "../../lib/command/types";
2
+ export declare function create(args: string[]): Promise<CommandResult>;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.create = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const commander_1 = (0, tslib_1.__importDefault)(require("commander"));
6
+ const validate_npm_package_name_1 = (0, tslib_1.__importDefault)(require("validate-npm-package-name"));
7
+ const inquirer_1 = (0, tslib_1.__importDefault)(require("inquirer"));
8
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
9
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
10
+ const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
11
+ const log_1 = (0, tslib_1.__importDefault)(require("../../lib/log"));
12
+ const template_1 = require("../../lib/template");
13
+ const template_2 = require("./template");
14
+ async function create(args) {
15
+ const program = new commander_1.default.Command();
16
+ program.option("-t, --type <project type>", "project type (destination or transform)");
17
+ program.option("-d, --dir <project_dir>", "project dir");
18
+ program.option("-n, --name <project_name>", "project name");
19
+ program.option("-j, --jitsu-version <jitsu_version>", "Jitsu version");
20
+ program.parse(["dummy", "dummy", ...args]);
21
+ let cliOpts = program.opts();
22
+ if (cliOpts.name) {
23
+ let isValid = (0, validate_npm_package_name_1.default)(cliOpts.name);
24
+ if (!isValid.validForNewPackages) {
25
+ return { success: false, message: `Can't use ${cliOpts.name} as package name: ${isValid.errors}` };
26
+ }
27
+ }
28
+ let packageType = cliOpts.type ||
29
+ (await inquirer_1.default.prompt([
30
+ {
31
+ type: "list",
32
+ name: "package",
33
+ message: [
34
+ `What is the type of extension?`,
35
+ ` ${chalk_1.default.bold("destination")} adds a new type of HTTP-based destination to Jitsu`,
36
+ ` ${chalk_1.default.bold("transform")} adds a transformation logic`,
37
+ ].join("\n"),
38
+ choices: ["destination", "transform"],
39
+ },
40
+ ])).package;
41
+ let packageName = cliOpts.name ||
42
+ (await inquirer_1.default.prompt([
43
+ {
44
+ type: "input",
45
+ name: "package",
46
+ message: "Please, provide project name:",
47
+ validate: input => {
48
+ let isValid = (0, validate_npm_package_name_1.default)(input);
49
+ if (!isValid.validForNewPackages) {
50
+ return `Can't use ${input} as package name: ${isValid.errors}`;
51
+ }
52
+ return true;
53
+ },
54
+ },
55
+ ])).package;
56
+ let projectDir = cliOpts.dir ||
57
+ (await inquirer_1.default.prompt([
58
+ {
59
+ type: "input",
60
+ name: "directory",
61
+ message: "Project directory:",
62
+ default: path_1.default.resolve(".", packageName),
63
+ validate: input => {
64
+ let projectBase = path_1.default.resolve(input);
65
+ if (fs_1.default.existsSync(projectBase)) {
66
+ if (!fs_1.default.lstatSync(projectBase).isDirectory() || fs_1.default.readdirSync(projectBase).length > 0) {
67
+ return `${input} should be an non-existent or empty directory`;
68
+ }
69
+ }
70
+ return true;
71
+ },
72
+ },
73
+ ])).directory;
74
+ projectDir = path_1.default.resolve(projectDir);
75
+ (0, log_1.default)().info("Creating new jitsu project in " + chalk_1.default.bold(projectDir));
76
+ if (fs_1.default.existsSync(projectDir)) {
77
+ if (!fs_1.default.lstatSync(projectDir).isDirectory() || fs_1.default.readdirSync(projectDir).length > 0) {
78
+ return { success: false, message: `${projectDir} should be an empty directory` };
79
+ }
80
+ }
81
+ else {
82
+ (0, log_1.default)().info("Project directory doesn't exist, creating it!");
83
+ fs_1.default.mkdirSync(projectDir, { recursive: true });
84
+ }
85
+ (0, template_1.write)(projectDir, template_2.extensionProjectTemplate, {
86
+ packageName: packageName,
87
+ jitsuVersion: cliOpts.jitsuVersion,
88
+ type: packageType,
89
+ });
90
+ return { success: true };
91
+ }
92
+ exports.create = create;
@@ -0,0 +1,8 @@
1
+ import { CommandRegistry } from "../../lib/command/types";
2
+ import { JitsuExtensionExport } from "@jitsu/types/extension";
3
+ import { Partial } from "rollup-plugin-typescript2/dist/partial";
4
+ export declare const help: string;
5
+ export declare const extensionCommands: CommandRegistry<"test" | "build" | "create" | "validate-config">;
6
+ export declare function validateTsConfig(tsConfigPath: string): void;
7
+ export declare function getDistFile(packageJson: any): any;
8
+ export declare function loadBuild(code: string): Partial<JitsuExtensionExport>;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadBuild = exports.getDistFile = exports.validateTsConfig = exports.extensionCommands = exports.help = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
6
+ const chalk_code_highlight_1 = require("../../lib/chalk-code-highlight");
7
+ const fs = (0, 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 = (0, tslib_1.__importDefault)(require("JSON5"));
15
+ global.fetch = require("cross-fetch");
16
+ const usage = `
17
+ · ${chalk_1.default.bold("jitsu-cli extension create")}
18
+
19
+ Create a project for jitsu plugin with placeholder implementation for all components.
20
+
21
+ · ${chalk_1.default.bold("jitsu-cli extension build <directory>")}
22
+
23
+ Build project located in <directory>. If <directory> is not provided current directory is used.
24
+
25
+ · ${chalk_1.default.bold("jitsu-cli extension test <directory>")}
26
+
27
+ Run tests for project in <directory>/__test__. If <directory> is not provided current directory is used.
28
+
29
+ · ${chalk_1.default.bold("jitsu-cli extension validate-config -f file or -j {json}")}
30
+
31
+ Validates configuration json object. ${chalk_1.default.bold("Note:")} run \`jitsu-cli extension build\` beforehand
32
+
33
+ · ${chalk_1.default.bold("jitsu-cli extension help")}
34
+
35
+ Show this help
36
+ `;
37
+ exports.help = `
38
+
39
+ ${chalk_1.default.bold("DESCRIPTION")}
40
+
41
+ The command will build jitsu extension and bundle a single JS file that will
42
+ placed to a location defined in main parameter of package.json (if not set, the bundle
43
+ will be placed in dist/index.js
44
+
45
+ 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)({
46
+ packageName: "test-package",
47
+ type: "destination",
48
+ }), null, 2), { indent: 4, lnBefore: 2 }))}
49
+
50
+ The code should be located in ./src folder. src/index.js (or ts) should be present
51
+
52
+ ${chalk_1.default.bold("TYPESCRIPT")}
53
+
54
+ Typescript is supported out of the box. Just add tsconfig.json to the root of the project
55
+
56
+ ${chalk_1.default.bold("COMMANDS")} ${(0, indent_1.align)(usage, { indent: 2, lnBefore: 2 })}
57
+ `;
58
+ exports.extensionCommands = {
59
+ test: {
60
+ exec: test_1.test,
61
+ description: "Execute test on extension",
62
+ help: "Tests should be located in ./__test__ folder and follow *.test.ts pattern",
63
+ },
64
+ build: {
65
+ exec: build_1.build,
66
+ description: "Builds Jitsu extension",
67
+ help: "",
68
+ },
69
+ create: {
70
+ exec: create_1.create,
71
+ description: "Creates an empty project",
72
+ help: "",
73
+ },
74
+ "validate-config": {
75
+ exec: validate_config_1.validateConfig,
76
+ description: `Verifies a configuration. ${chalk_1.default.bold("Note:")} run \`jitsu-cli extension build\` first!`,
77
+ help: "",
78
+ },
79
+ };
80
+ function validateTsConfig(tsConfigPath) {
81
+ let tsConfig;
82
+ try {
83
+ tsConfig = JSON5_1.default.parse(fs.readFileSync(tsConfigPath, "utf8"));
84
+ }
85
+ catch (e) {
86
+ throw new Error(`${chalk_1.default.bold(tsConfigPath)} - syntax error: ${e.message}`);
87
+ }
88
+ if (tsConfig?.compilerOptions?.module !== "ES2020") {
89
+ throw new Error(`${chalk_1.default.bold(tsConfigPath)} error: compilerOptions.module should be set to ES2020!`);
90
+ }
91
+ }
92
+ exports.validateTsConfig = validateTsConfig;
93
+ function getDistFile(packageJson) {
94
+ return packageJson.main || "dist/index.js";
95
+ }
96
+ exports.getDistFile = getDistFile;
97
+ function loadBuild(code) {
98
+ let f = new Function("exports", code);
99
+ let exports = {};
100
+ f(exports);
101
+ return exports;
102
+ }
103
+ exports.loadBuild = loadBuild;
@@ -0,0 +1,27 @@
1
+ import { ProjectTemplate } from "../../lib/template";
2
+ export declare type DestinationTemplateVars = {
3
+ license?: "MIT" | "Other";
4
+ packageName: string;
5
+ type: "destination" | "transform";
6
+ jitsuVersion?: string;
7
+ };
8
+ export declare const packageJsonTemplate: ({ packageName, type, jitsuVersion }: DestinationTemplateVars) => {
9
+ name: string;
10
+ version: string;
11
+ description: string;
12
+ main: string;
13
+ scripts: {
14
+ build: string;
15
+ test: string;
16
+ "validate-config": string;
17
+ };
18
+ devDependencies: {
19
+ "@jitsu/types": string;
20
+ typescript: string;
21
+ };
22
+ dependencies: {
23
+ "jitsu-cli": string;
24
+ tslib: string;
25
+ };
26
+ };
27
+ export declare const extensionProjectTemplate: ProjectTemplate<DestinationTemplateVars>;
@@ -0,0 +1,140 @@
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
+ build: "jitsu-cli extension build",
12
+ test: "jitsu-cli extension test",
13
+ "validate-config": "jitsu-cli extension validate-config",
14
+ },
15
+ devDependencies: {
16
+ "@jitsu/types": `${jitsuVersion || "^" + version_1.jitsuCliVersion}`,
17
+ typescript: "^4.5.2",
18
+ },
19
+ dependencies: {
20
+ "jitsu-cli": `${jitsuVersion || "^" + version_1.jitsuCliVersion}`,
21
+ tslib: "^2.3.1",
22
+ },
23
+ });
24
+ exports.packageJsonTemplate = packageJsonTemplate;
25
+ let destinationTest = ({ type = "destination" }) => {
26
+ if (type !== "destination") {
27
+ return undefined;
28
+ }
29
+ return `
30
+ import { JitsuDestinationContext } from "@jitsu/types/extension"
31
+ import { testDestination } from "jitsu-cli/lib/tests"
32
+ import { destination } from "../src"
33
+
34
+ testDestination({
35
+ name: "basic",
36
+ context: {
37
+ destinationId: "test",
38
+ destinationType: "mydest",
39
+ config: {}
40
+ },
41
+ destination: destination,
42
+ event: {
43
+ event_type: 'test',
44
+ a: 1
45
+ },
46
+ expectedResult: {
47
+ method: "POST",
48
+ url: "https://test.com",
49
+ body: { a: 2 },
50
+ },
51
+ })
52
+ `;
53
+ };
54
+ let destinationCode = () => {
55
+ return `
56
+ import { DestinationFunction, DestinationMessage, JitsuDestinationContext, ConfigValidator} from "@jitsu/types/extension";
57
+ import { DefaultJitsuEvent } from "@jitsu/types/event";
58
+
59
+ export type DestinationConfig = {
60
+ exampleParam: string
61
+ }
62
+
63
+ export const validator: ConfigValidator<DestinationConfig> = async (config: DestinationConfig) => {
64
+ if (config.exampleParam !== 'valid-config') {
65
+ return \`Invalid config: exampleParam expected to be 'valid-config', but actual value is: \${config.exampleParam}\`;
66
+ }
67
+ return true;
68
+ }
69
+
70
+ export const destination: DestinationFunction = (event: DefaultJitsuEvent, dstContext: JitsuDestinationContext<DestinationConfig>) => {
71
+ return { url: "https://test.com", method: "POST", body: { a: (event.a || 0) + 1 } };
72
+ };
73
+ `;
74
+ };
75
+ let transformCode = () => {
76
+ return `
77
+ import {Destination, DestinationMessage, JitsuDestinationContext} from "@jitsu/types/destination";
78
+ import {DefaultJitsuEvent} from "@jitsu/types/event";
79
+
80
+ //duplicate events
81
+ const transform: TransformationFunction = (event: DefaultJitsuEvent) => {
82
+ return [event, {...event, eventn_ctx_event_id: event.eventn_ctx_event_id + "_2"}]
83
+ }
84
+
85
+ export default jitsuAdapter;
86
+ `;
87
+ };
88
+ let descriptor = {};
89
+ descriptor["destination"] = (vars) => `
90
+ import {ExtensionDescriptor} from "@jitsu/types/extension";
91
+ import {destination, validator, DestinationConfig} from "./destination";
92
+
93
+ const descriptor: ExtensionDescriptor = {
94
+ id: "${vars.packageName}",
95
+ displayName: "${vars.packageName}",
96
+ icon: "",
97
+ description: "Jitsu destination - ${vars.packageName} (generated by 'jitsu-cli extension create')",
98
+ configurationParameters: [
99
+ {id: "exampleParam", type: "string", required: true, displayName: "Example param", documentation: "Documentation"}
100
+ ],
101
+ };
102
+
103
+ export { descriptor, destination, validator };
104
+ `;
105
+ descriptor["transform"] = (vars) => `
106
+ import {DestinationAdapter, DestinationDescriptor} from "@jitsu/types/destination";
107
+ import jitsuAdapter from "./adapter";
108
+
109
+ const adapter: DestinationAdapter = jitsuAdapter
110
+
111
+ const descriptor: DestinationDescriptor = {
112
+ type: "${vars.packageName}",
113
+ displayName: "${vars.packageName}",
114
+ icon: "",
115
+ description: "Jitsu ${vars.type} - ${vars.packageName} (generated by 'jitsu-cli extension create)'",
116
+ configurationParameters: [
117
+ //put configuration here
118
+ ]
119
+ }
120
+
121
+ export {descriptor, adapter}
122
+ `;
123
+ exports.extensionProjectTemplate = {
124
+ "__test__/destination.test.ts": destinationTest,
125
+ "src/destination.ts": vars => vars.type == "destination" && destinationCode(),
126
+ "src/transform.ts": vars => vars.type == "transform" && transformCode(),
127
+ "src/index.ts": vars => descriptor[vars.type](vars),
128
+ "package.json": exports.packageJsonTemplate,
129
+ "tsconfig.json": {
130
+ compilerOptions: {
131
+ module: "ES2020",
132
+ target: "ES2021",
133
+ moduleResolution: "Node",
134
+ esModuleInterop: true,
135
+ outDir: "./dist",
136
+ rootDir: "./",
137
+ },
138
+ include: ["./src", "__test__"],
139
+ },
140
+ };
@@ -0,0 +1,2 @@
1
+ import { CommandResult } from "../../lib/command/types";
2
+ export declare function test(args: string[]): Promise<CommandResult>;
@@ -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 = (0, tslib_1.__importDefault)(require("path"));
6
+ const log_1 = (0, tslib_1.__importDefault)(require("../../lib/log"));
7
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
8
+ const fs_1 = (0, 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
+ let 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,2 @@
1
+ import { CommandResult } from "../../lib/command/types";
2
+ export declare function validateConfig(args: string[]): Promise<CommandResult>;
@@ -0,0 +1,79 @@
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 = (0, tslib_1.__importDefault)(require("commander"));
6
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
7
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
8
+ const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
9
+ const JSON5_1 = (0, tslib_1.__importDefault)(require("JSON5"));
10
+ const log_1 = (0, tslib_1.__importDefault)(require("../../lib/log"));
11
+ const index_1 = require("./index");
12
+ async function validateConfig(args) {
13
+ const program = new commander_1.default.Command();
14
+ program.option("-d, --dir <project_dir>", "Project directory");
15
+ program.option("-f, --file <config_file>", "Configuration file");
16
+ program.option("-j, --json <config_json>", "Inline extension configuration JSON");
17
+ program.argument("[project_dir]");
18
+ program.parse(["dummy", "dummy", ...args]);
19
+ const opts = program.opts();
20
+ if (!opts.json && !opts.file) {
21
+ return {
22
+ success: false,
23
+ message: 'Please define config object either with -j "{embedded json}", or with -f json_file',
24
+ };
25
+ }
26
+ let configObj;
27
+ if (opts.json) {
28
+ try {
29
+ configObj = JSON5_1.default.parse(opts.json);
30
+ }
31
+ catch (e) {
32
+ return { success: false, message: `Malformed json (-j): ${e.message}` };
33
+ }
34
+ }
35
+ else {
36
+ if (!fs_1.default.existsSync(opts.file)) {
37
+ return { success: false, message: `${opts.file} (-f) doesn't exist!` };
38
+ }
39
+ try {
40
+ configObj = JSON5_1.default.parse(fs_1.default.readFileSync(opts.file, "utf8"));
41
+ }
42
+ catch (e) {
43
+ return { success: false, message: `Malformed json in file ${opts.file} (-f): ${e.message}` };
44
+ }
45
+ }
46
+ let projectDir = opts.dir || ".";
47
+ (0, log_1.default)().info("Project dir: " + projectDir);
48
+ let packageFile = path_1.default.resolve(projectDir, "package.json");
49
+ if (!fs_1.default.existsSync(packageFile)) {
50
+ return { success: false, message: `Can't find package file ${packageFile}` };
51
+ }
52
+ let packageObj = JSON5_1.default.parse(fs_1.default.readFileSync(packageFile, "utf8"));
53
+ let distFile = path_1.default.resolve(projectDir, (0, index_1.getDistFile)(packageObj));
54
+ (0, log_1.default)().info("Dist file: " + distFile);
55
+ if (!fs_1.default.existsSync(distFile)) {
56
+ return { success: false, message: `Can't find dist file (${distFile}). Forgot to run jitsu-cli extension build ?` };
57
+ }
58
+ (0, log_1.default)().info("🤔 Loading build from " + chalk_1.default.bold(distFile));
59
+ let build = (0, index_1.loadBuild)(fs_1.default.readFileSync(distFile, "utf8"));
60
+ (0, log_1.default)().info("👍 Module loaded!");
61
+ if (!build.validator) {
62
+ return { success: false, message: "Build doesn't export validator symbol" };
63
+ }
64
+ (0, log_1.default)().info("🤔 Validating configuration " +
65
+ (opts.file ? `from file ${path_1.default.resolve(projectDir, opts.file)}` : JSON.stringify(configObj)));
66
+ let validationResult = await build.validator(configObj);
67
+ if (typeof validationResult === "boolean" && !validationResult) {
68
+ return { success: false, message: "❌ Config is not valid, an exact reason isn't specified by validator" };
69
+ }
70
+ else if (typeof validationResult === "string") {
71
+ return { success: false, message: "❌ Config is not valid: " + validationResult };
72
+ }
73
+ else if (typeof validationResult === "object" && !validationResult.ok) {
74
+ return { success: false, message: "❌ Config is not valid: " + validationResult.message };
75
+ }
76
+ (0, log_1.default)().info("✅ Config is valid. Hooray!");
77
+ return { success: true };
78
+ }
79
+ exports.validateConfig = validateConfig;
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const run_1 = require("./run");
5
+ const log_1 = (0, tslib_1.__importDefault)(require("./lib/log"));
6
+ (async function () {
7
+ (0, log_1.default)().info("Args: " + process.argv);
8
+ const args = [...process.argv.slice(2)];
9
+ process.exit(await (0, run_1.run)(args));
10
+ })();
@@ -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 = (0, tslib_1.__importDefault)(require("prismjs"));
6
+ const chalk_1 = (0, 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;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.subcommands = exports.executeCommand = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
6
+ const version_1 = require("../version");
7
+ function captureCommand(command, args) {
8
+ let commandParts = command.split(" ");
9
+ if (commandParts.length > args.length) {
10
+ return undefined;
11
+ }
12
+ for (let i = 0; i < commandParts.length; i++) {
13
+ if (commandParts[i] !== args[i]) {
14
+ return undefined;
15
+ }
16
+ }
17
+ return args.slice(commandParts.length);
18
+ }
19
+ function isHelpOption(arg) {
20
+ return arg === "-help" || arg === "--help" || arg === "help" || arg === "-?" || arg === "--?";
21
+ }
22
+ function isVersionOption(arg) {
23
+ return arg === "-version" || arg === "--version" || arg === "version" || arg === "-v" || arg === "--?";
24
+ }
25
+ function displayHelp(commands, helpOpts, cmd) {
26
+ if (helpOpts.customHelp) {
27
+ console.error(helpOpts.customHelp);
28
+ return;
29
+ }
30
+ if (!cmd) {
31
+ console.error("");
32
+ console.error(chalk_1.default.bold(`${helpOpts.binPrefix} <command> ...args — `) + `${helpOpts.description}`);
33
+ console.error("");
34
+ console.error("Available commands: ");
35
+ console.error("");
36
+ console.error(Object.keys(commands)
37
+ .map(cmd => {
38
+ return ` ${helpOpts.binPrefix} ${cmd} <options> - ${commands[cmd].description}`;
39
+ })
40
+ .join("\n"));
41
+ console.error("");
42
+ console.error(`To get help run ${chalk_1.default.bold(helpOpts.binPrefix + " <command> help")}:`);
43
+ console.error("");
44
+ console.error(Object.keys(commands)
45
+ .map(cmd => {
46
+ return ` ${helpOpts.binPrefix} ${cmd} help`;
47
+ })
48
+ .join("\n"));
49
+ console.error("");
50
+ }
51
+ else {
52
+ console.error("");
53
+ let command = commands[cmd];
54
+ if (!command) {
55
+ console.error(chalk_1.default.bold.red("Error!") + " Command " + chalk_1.default.bold(cmd) + " not found!");
56
+ }
57
+ else {
58
+ console.error(chalk_1.default.bold(`SYNOPSIS`));
59
+ console.error("");
60
+ console.error(chalk_1.default.bold(` jitsu-cli ${cmd}`) + " - " + command.description);
61
+ if (command.help) {
62
+ console.error("");
63
+ console.error(command.help
64
+ .trim()
65
+ .split("\n")
66
+ .map(ln => `${ln}`)
67
+ .join("\n"));
68
+ }
69
+ console.error("");
70
+ }
71
+ }
72
+ }
73
+ const executeCommand = async (commands, args, helpOpts) => {
74
+ let newVersion = await (0, version_1.hasNewerVersion)();
75
+ if (newVersion) {
76
+ console.log((0, version_1.getUpgradeMessage)(newVersion));
77
+ }
78
+ if (args.length === 0 || isHelpOption(args[0])) {
79
+ displayHelp(commands, helpOpts);
80
+ return { success: true };
81
+ }
82
+ else if (args.length > 0 && isVersionOption(args[0])) {
83
+ console.error(`Jitsu CLI v${version_1.jitsuCliVersion}`);
84
+ return { success: true };
85
+ }
86
+ for (const [commandName, cmd] of Object.entries(commands)) {
87
+ let commandArgs = captureCommand(commandName, [...args]);
88
+ if (commandArgs) {
89
+ if (commandArgs.length > 0 && isHelpOption(commandArgs[0])) {
90
+ displayHelp(commands, helpOpts, commandName);
91
+ return { success: true };
92
+ }
93
+ else {
94
+ try {
95
+ return await cmd.exec(commandArgs);
96
+ }
97
+ catch (e) {
98
+ return { success: false, message: e?.message || "unknown error", details: e?.stack };
99
+ }
100
+ }
101
+ }
102
+ }
103
+ let error = `unknown command '${chalk_1.default.bold(args.join(" "))}'. Run ${chalk_1.default.bold(helpOpts.binPrefix + " help")} to see available options`;
104
+ return { success: false, message: error };
105
+ };
106
+ exports.executeCommand = executeCommand;
107
+ function subcommands(commands, helpOpts) {
108
+ return {
109
+ description: helpOpts.description,
110
+ exec(args) {
111
+ return (0, exports.executeCommand)(commands, args, helpOpts);
112
+ },
113
+ help: helpOpts.customHelp || `Run ${helpOpts.binPrefix} help to see all available options`,
114
+ };
115
+ }
116
+ exports.subcommands = subcommands;
@@ -0,0 +1 @@
1
+ export declare function appendError(msg: string, cause: any): string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.appendError = void 0;
4
+ function appendError(msg, cause) {
5
+ if (cause && cause.message) {
6
+ return `${msg}: ${cause.message}`;
7
+ }
8
+ else if (cause && typeof cause === "string") {
9
+ return `${msg}: ${cause}`;
10
+ }
11
+ else if (cause) {
12
+ return `${msg}: ${cause.toString()}`;
13
+ }
14
+ else {
15
+ return msg;
16
+ }
17
+ }
18
+ exports.appendError = appendError;
@@ -0,0 +1,8 @@
1
+ export declare function removeIndentation(text: string, { trimLines }?: {
2
+ trimLines?: boolean | undefined;
3
+ }): string;
4
+ export declare function align(text: string, { indent, lnBefore, lnAfter }?: {
5
+ indent?: number | undefined;
6
+ lnBefore?: number | undefined;
7
+ lnAfter?: number | undefined;
8
+ }): string;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.align = exports.removeIndentation = void 0;
4
+ function getIndentSize(line) {
5
+ let idx = 0;
6
+ for (; line.charAt(idx) === " " && idx < line.length; idx++) { }
7
+ return idx;
8
+ }
9
+ function removeIndentation(text, { trimLines = true } = {}) {
10
+ let lines = text.split("\n");
11
+ if (trimLines) {
12
+ let start = 0, end = lines.length - 1;
13
+ for (; lines[start].trim().length == 0 && start <= end; start++) { }
14
+ for (; lines[end].trim().length == 0 && end >= start; end--) { }
15
+ lines = lines.slice(start, end + 1);
16
+ }
17
+ let commonIndent = Math.min(...lines.filter(ln => ln.trim().length > 0).map(getIndentSize));
18
+ return lines.map(ln => ln.substring(commonIndent)).join("\n");
19
+ }
20
+ exports.removeIndentation = removeIndentation;
21
+ function align(text, { indent = 0, lnBefore = 0, lnAfter = 0 } = {}) {
22
+ const cleanText = removeIndentation(text, { trimLines: true });
23
+ return [
24
+ ...new Array(lnBefore).fill(""),
25
+ ...cleanText.split("\n").map(ln => " ".repeat(indent) + ln),
26
+ ...new Array(lnAfter).fill(""),
27
+ ].join("\n");
28
+ }
29
+ exports.align = align;
@@ -0,0 +1,7 @@
1
+ export declare type Log = {
2
+ debug: (msg?: string, ...args: any[]) => void;
3
+ info: (msg?: string, ...args: any[]) => void;
4
+ spinInfo: (...args: string[]) => void;
5
+ error: (...args: string[]) => void;
6
+ };
7
+ export default function getLog(): Log;
package/lib/lib/log.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
5
+ function log(delegate, styling, msg, args) {
6
+ if (!msg) {
7
+ delegate("");
8
+ return;
9
+ }
10
+ let consoleMsg = chalk_1.default[styling.color](`[${styling.prefix}]`) + " - " + msg;
11
+ if (args.length > 0) {
12
+ delegate(consoleMsg, args);
13
+ }
14
+ else {
15
+ delegate(consoleMsg);
16
+ }
17
+ }
18
+ function getLog() {
19
+ return {
20
+ error(msg, ...args) {
21
+ log(console.error, { prefix: "error", color: "red" }, msg, args);
22
+ },
23
+ spinInfo(args) { },
24
+ info(msg, ...args) {
25
+ log(console.info, { prefix: "info ", color: "cyan" }, msg, args);
26
+ },
27
+ debug(msg, ...args) {
28
+ log(console.debug, { prefix: "debug", color: "gray" }, msg, args);
29
+ },
30
+ };
31
+ }
32
+ exports.default = getLog;
@@ -0,0 +1,5 @@
1
+ export declare type TemplateVars = Record<string, any>;
2
+ export declare type TemplateFunction<T> = (vars: T) => any;
3
+ export declare type FileTemplate<T> = TemplateFunction<T> | string | any;
4
+ export declare type ProjectTemplate<T extends TemplateVars = TemplateVars> = Record<string, FileTemplate<T>>;
5
+ export declare function write(dir: string, template: ProjectTemplate, vars: TemplateVars): void;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.write = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const posix_1 = (0, tslib_1.__importDefault)(require("path/posix"));
6
+ const fs = (0, tslib_1.__importStar)(require("fs"));
7
+ const indent_1 = require("./indent");
8
+ function toTemplateFunction(template) {
9
+ if (template === null || template === undefined) {
10
+ return () => undefined;
11
+ }
12
+ else if (typeof template === "function") {
13
+ return template;
14
+ }
15
+ else {
16
+ return () => template;
17
+ }
18
+ }
19
+ function write(dir, template, vars) {
20
+ Object.entries(template).forEach(([fileName, template]) => {
21
+ let filePath = posix_1.default.resolve(dir, fileName);
22
+ let fileDir = posix_1.default.dirname(filePath);
23
+ if (!fs.existsSync(fileDir)) {
24
+ fs.mkdirSync(fileDir, { recursive: true });
25
+ }
26
+ let content = toTemplateFunction(template)(vars);
27
+ if (typeof content === "object") {
28
+ content = JSON.stringify(content, null, 2);
29
+ }
30
+ if (content) {
31
+ let data = (0, indent_1.removeIndentation)(content);
32
+ fs.writeFileSync(filePath, data);
33
+ }
34
+ });
35
+ }
36
+ exports.write = write;
@@ -0,0 +1,5 @@
1
+ export declare const jitsuCliVersion: string;
2
+ export declare const jitsuPackageName: string;
3
+ export declare function getUpgradeMessage(newVersion: string): string;
4
+ export declare function box(msg: string): string;
5
+ export declare function hasNewerVersion(): Promise<string | undefined>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasNewerVersion = exports.box = exports.getUpgradeMessage = exports.jitsuPackageName = exports.jitsuCliVersion = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const package_json_1 = (0, tslib_1.__importDefault)(require("../../package.json"));
6
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
7
+ const log_1 = (0, tslib_1.__importDefault)(require("./log"));
8
+ const preload_1 = (0, tslib_1.__importDefault)(require("semver/preload"));
9
+ const fetch = require("cross-fetch");
10
+ exports.jitsuCliVersion = package_json_1.default.version;
11
+ exports.jitsuPackageName = package_json_1.default.name;
12
+ let newVersion = undefined;
13
+ function getUpgradeMessage(newVersion) {
14
+ return box(`🚀 New version of Jitsu CLI is available: ${newVersion}.\n Run ${chalk_1.default.bold("npm install -g " + exports.jitsuPackageName)} or ${chalk_1.default.bold("yarn global install " + exports.jitsuPackageName)}`);
15
+ }
16
+ exports.getUpgradeMessage = getUpgradeMessage;
17
+ function padRight(str, minLen, symbol = " ") {
18
+ return str.length >= minLen ? str : str + symbol.repeat(minLen - str.length);
19
+ }
20
+ function box(msg) {
21
+ let lines = msg.split("\n");
22
+ return ["──".repeat(80), ...lines.map(ln => ` ${ln}`), "──".repeat(80)].join("\n");
23
+ }
24
+ exports.box = box;
25
+ async function hasNewerVersion() {
26
+ try {
27
+ let json = (await (await fetch(`https://registry.npmjs.org/-/package/${exports.jitsuPackageName}/dist-tags`)).json());
28
+ let latestVersion = json.latest;
29
+ return preload_1.default.gt(latestVersion, exports.jitsuCliVersion) ? latestVersion : undefined;
30
+ }
31
+ catch (e) {
32
+ (0, log_1.default)().debug(`Failed to fetch latest version of ${exports.jitsuPackageName}: ${e?.message}`);
33
+ }
34
+ }
35
+ exports.hasNewerVersion = hasNewerVersion;
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "jitsu-cli",
3
+ "version": "0.6.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": " CLI interface of Jitsu (👉 https://jitsu.com),",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/jitsucom/jitsu-sdk",
11
+ "directory": "packages/jitsu-cli"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/jitsucom/jitsu/issues"
15
+ },
16
+ "license": "MIT",
17
+ "bin": {
18
+ "jitsu-cli": "./bin/jitsu-cli"
19
+ },
20
+ "files": [
21
+ "lib",
22
+ "bin"
23
+ ],
24
+ "scripts": {
25
+ "build": "yarn clean:some && tsc -p . && mv ./lib/src/* ./lib/ && rmdir ./lib/src/",
26
+ "global": "yarn install -g",
27
+ "clean:some": "rm -rf ./lib",
28
+ "start": "ts-node src/index.ts",
29
+ "test": "jest --verbose ./__tests__"
30
+ },
31
+ "devDependencies": {
32
+ "@babel/preset-env": "^7.16.4",
33
+ "@babel/preset-typescript": "^7.16.0",
34
+ "@types/commander": "^2.12.2",
35
+ "@types/inquirer": "^8.1.3",
36
+ "@types/jest": "^27.0.3",
37
+ "@types/jest-cli": "^24.3.0",
38
+ "@types/validate-npm-package-name": "^3.0.3",
39
+ "child_process": "^1.0.2",
40
+ "lerna": "^4.0.0",
41
+ "ts-node": "^10.4.0"
42
+ },
43
+ "dependencies": {
44
+ "@rollup/plugin-commonjs": "^21.0.1",
45
+ "@rollup/plugin-multi-entry": "^4.1.0",
46
+ "@rollup/plugin-node-resolve": "^13.0.6",
47
+ "@types/prismjs": "^1.16.6",
48
+ "chalk": "^4.1.2",
49
+ "commander": "^8.3.0",
50
+ "cross-fetch": "^3.1.4",
51
+ "inquirer": "^8.2.0",
52
+ "jest": "^27.3.1",
53
+ "jest-cli": "^27.3.1",
54
+ "json5": "^2.2.0",
55
+ "node-fetch": "^3.1.0",
56
+ "ora": "^6.0.1",
57
+ "prismjs": "^1.25.0",
58
+ "rollup": "^2.60.0",
59
+ "rollup-plugin-typescript2": "^0.31.0",
60
+ "semver": "^7.3.5",
61
+ "terminal-link": "^3.0.0",
62
+ "ts-jest": "^27.0.7",
63
+ "ts-node": "^10.4.0",
64
+ "tslib": "^2.3.1",
65
+ "typescript": "^4.5.2",
66
+ "validate-npm-package-name": "^3.0.0"
67
+ },
68
+ "gitHead": "4a5222ce49da3cb6be58648c78b1111b39764fe1"
69
+ }
package/lib/run.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function run(args: string[]): Promise<number>;
package/lib/run.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.run = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
6
+ const command_1 = require("./lib/command");
7
+ const extension_1 = require("./cli/extension");
8
+ const log_1 = (0, tslib_1.__importDefault)(require("./lib/log"));
9
+ const version_1 = require("./lib/version");
10
+ const commands = {
11
+ extension: (0, command_1.subcommands)(extension_1.extensionCommands, {
12
+ description: "Commands for building Jitsu extension",
13
+ binPrefix: "jitsu-cli extension",
14
+ customHelp: extension_1.help,
15
+ }),
16
+ };
17
+ function exitWithError(error, details) {
18
+ console.error(`${chalk_1.default.bold.red("Error!")} - ${error}`);
19
+ if (details) {
20
+ console.error(details);
21
+ }
22
+ return 1;
23
+ }
24
+ async function run(args) {
25
+ let result = await (0, command_1.executeCommand)(commands, args, {
26
+ description: "CLI interface of " + chalk_1.default.bold("Jitsu") + `(👉 https://jitsu.com), version ${version_1.jitsuCliVersion}`,
27
+ binPrefix: "jitsu-cli",
28
+ });
29
+ if (result.success) {
30
+ (0, log_1.default)().info("✨ Done");
31
+ return 0;
32
+ }
33
+ else {
34
+ return exitWithError(result.message, result.details);
35
+ }
36
+ }
37
+ exports.run = run;
package/lib/tests.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { DestinationTestParams } from "@jitsu/types/tests";
2
+ export declare function testDestination({ name, context, destination, event, expectedResult }: DestinationTestParams): void;
package/lib/tests.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testDestination = void 0;
4
+ function testDestination({ name, context, destination, event, expectedResult }) {
5
+ test(name, () => {
6
+ const result = destination(event, context);
7
+ expect(result).toEqual(expectedResult);
8
+ });
9
+ }
10
+ exports.testDestination = testDestination;
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "jitsu-cli",
3
+ "version": "0.6.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": " CLI interface of Jitsu (👉 https://jitsu.com),",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/jitsucom/jitsu-sdk",
11
+ "directory": "packages/jitsu-cli"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/jitsucom/jitsu/issues"
15
+ },
16
+ "license": "MIT",
17
+ "bin": {
18
+ "jitsu-cli": "./bin/jitsu-cli"
19
+ },
20
+ "files": [
21
+ "lib",
22
+ "bin"
23
+ ],
24
+ "scripts": {
25
+ "build": "yarn clean:some && tsc -p . && mv ./lib/src/* ./lib/ && rmdir ./lib/src/",
26
+ "global": "yarn install -g",
27
+ "clean:some": "rm -rf ./lib",
28
+ "start": "ts-node src/index.ts",
29
+ "test": "jest --verbose ./__tests__"
30
+ },
31
+ "devDependencies": {
32
+ "@babel/preset-env": "^7.16.4",
33
+ "@babel/preset-typescript": "^7.16.0",
34
+ "@types/commander": "^2.12.2",
35
+ "@types/inquirer": "^8.1.3",
36
+ "@types/jest": "^27.0.3",
37
+ "@types/jest-cli": "^24.3.0",
38
+ "@types/validate-npm-package-name": "^3.0.3",
39
+ "child_process": "^1.0.2",
40
+ "lerna": "^4.0.0",
41
+ "ts-node": "^10.4.0"
42
+ },
43
+ "dependencies": {
44
+ "@rollup/plugin-commonjs": "^21.0.1",
45
+ "@rollup/plugin-multi-entry": "^4.1.0",
46
+ "@rollup/plugin-node-resolve": "^13.0.6",
47
+ "@types/prismjs": "^1.16.6",
48
+ "chalk": "^4.1.2",
49
+ "commander": "^8.3.0",
50
+ "cross-fetch": "^3.1.4",
51
+ "inquirer": "^8.2.0",
52
+ "jest": "^27.3.1",
53
+ "jest-cli": "^27.3.1",
54
+ "json5": "^2.2.0",
55
+ "node-fetch": "^3.1.0",
56
+ "ora": "^6.0.1",
57
+ "prismjs": "^1.25.0",
58
+ "rollup": "^2.60.0",
59
+ "rollup-plugin-typescript2": "^0.31.0",
60
+ "semver": "^7.3.5",
61
+ "terminal-link": "^3.0.0",
62
+ "ts-jest": "^27.0.7",
63
+ "ts-node": "^10.4.0",
64
+ "tslib": "^2.3.1",
65
+ "typescript": "^4.5.2",
66
+ "validate-npm-package-name": "^3.0.0"
67
+ },
68
+ "gitHead": "82fbe5d15fbd1308e6c571961f9d4f8cb3644591"
69
+ }