jitsu-cli 1.10.3 → 2.14.0-beta.4

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,18 +1,20 @@
1
1
  {
2
2
  "name": "jitsu-cli",
3
- "version": "0.0.0",
3
+ "version": "2.14.0-beta.4",
4
4
  "description": "",
5
5
  "author": "Jitsu Dev Team <dev@jitsu.com>",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
- "bin": "./bin/jitsu-cli",
9
+ "bin": {
10
+ "jitsu-cli": "./bin/jitsu-cli"
11
+ },
10
12
  "license": "MIT",
11
13
  "private": false,
12
14
  "scripts": {
13
15
  "clean": "rm -rf ./dist",
14
- "compile": "tsc -p . ",
15
- "build": "pnpm compile && webpack",
16
+ "typecheck": "tsc --noEmit",
17
+ "build": "tsc -p . && webpack",
16
18
  "run": "pnpm build && node dist/main.js",
17
19
  "login": "pnpm build && node dist/main.js login",
18
20
  "init child": "pnpm build && node dist/main.js init",
@@ -24,12 +26,14 @@
24
26
  "dependencies": {
25
27
  "figlet": "^1.6.0",
26
28
  "jest-cli": "^29.7.0",
27
- "tslib": "^2.6.3",
28
- "typescript": "^5.6.3"
29
+ "tslib": "catalog:",
30
+ "typescript": "catalog:"
29
31
  },
30
32
  "devDependencies": {
31
- "@babel/preset-env": "^7.23.2",
32
- "@babel/preset-typescript": "^7.23.2",
33
+ "@swc-node/register": "catalog:",
34
+ "swc-loader": "catalog:",
35
+ "@swc/core": "catalog:",
36
+ "@jitsu/common-config": "workspace:*",
33
37
  "@jitsu/functions-lib": "workspace:*",
34
38
  "@jitsu/protocols": "workspace:*",
35
39
  "@rollup/plugin-commonjs": "^28.0.2",
@@ -41,12 +45,11 @@
41
45
  "@types/commander": "^2.12.2",
42
46
  "@types/express": "^4.17.21",
43
47
  "@types/inquirer": "^9.0.3",
44
- "@types/jest": "^29.5.5",
45
- "@types/lodash": "^4.14.198",
46
- "@types/node": "^18.15.3",
48
+ "@types/lodash": "catalog:",
49
+ "@types/node": "catalog:",
50
+ "@vitest/ui": "catalog:",
47
51
  "@types/webpack": "^5.28.5",
48
52
  "@webpack-cli/generators": "^3.0.7",
49
- "babel-loader": "^9.1.3",
50
53
  "chalk": "^5.3.0",
51
54
  "commander": "^11.0.0",
52
55
  "cross-fetch": "^4.0.0",
@@ -56,16 +59,16 @@
56
59
  "jest": "^29.7.0",
57
60
  "json5": "^2.2.3",
58
61
  "juava": "workspace:*",
59
- "lodash": "^4.17.21",
62
+ "lodash": "catalog:",
60
63
  "node-fetch": "^3.3.2",
61
64
  "node-loader": "^2.0.0",
62
65
  "prismjs": "^1.30.0",
63
66
  "rollup": "^3.29.5",
64
67
  "semver": "^7.5.4",
65
- "ts-jest": "^29.1.1",
66
68
  "ts-loader": "^9.5.1",
67
- "ts-node": "^10.9.2",
68
- "webpack": "^5.99.5",
69
- "webpack-cli": "^6.0.1"
69
+ "ts-node": "catalog:",
70
+ "vitest": "catalog:",
71
+ "webpack": "catalog:",
72
+ "webpack-cli": "catalog:"
70
73
  }
71
74
  }
@@ -1,22 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.build = build;
4
- const tslib_1 = require("tslib");
5
- const path_1 = tslib_1.__importDefault(require("path"));
6
- const fs_1 = require("fs");
7
- const plugin_typescript_1 = tslib_1.__importDefault(require("@rollup/plugin-typescript"));
8
- const plugin_node_resolve_1 = tslib_1.__importDefault(require("@rollup/plugin-node-resolve"));
9
- const plugin_commonjs_1 = tslib_1.__importDefault(require("@rollup/plugin-commonjs"));
10
- const plugin_json_1 = tslib_1.__importDefault(require("@rollup/plugin-json"));
11
- const rollup_1 = require("rollup");
12
- const child_process_1 = require("child_process");
13
- const shared_1 = require("./shared");
14
- const chalk_code_highlight_1 = require("../lib/chalk-code-highlight");
15
- const compiled_function_1 = require("../lib/compiled-function");
16
- const ts = tslib_1.__importStar(require("typescript"));
17
- async function build({ dir }) {
18
- const { packageJson, projectDir } = await (0, shared_1.loadPackageJson)(dir || process.cwd());
19
- console.log(`Building ${(0, chalk_code_highlight_1.b)(packageJson.name)} project`);
1
+ import path from "path";
2
+ import { mkdirSync, readdirSync, writeFileSync, existsSync, lstatSync } from "fs";
3
+ import typescript from "@rollup/plugin-typescript";
4
+ import resolve from "@rollup/plugin-node-resolve";
5
+ import commonjs from "@rollup/plugin-commonjs";
6
+ import rollupJson from "@rollup/plugin-json";
7
+ import { rollup } from "rollup";
8
+ import { exec } from "child_process";
9
+ import { loadPackageJson } from "./shared";
10
+ import { b, green, red } from "../lib/chalk-code-highlight";
11
+ import { getFunctionFromFilePath } from "../lib/compiled-function";
12
+ import * as ts from "typescript";
13
+ export async function build({ dir }) {
14
+ const { packageJson, projectDir } = await loadPackageJson(dir || process.cwd());
15
+ console.log(`Building ${b(packageJson.name)} project`);
20
16
  const errors = checkTypescript(projectDir);
21
17
  if (errors) {
22
18
  console.error(`Found ${errors.length} errors in functions files. Exiting`);
@@ -29,10 +25,10 @@ async function build({ dir }) {
29
25
  catch (e) {
30
26
  throw new Error(`Some of the functions failed to compile. See details above. Last error: ${e.message || "unknown"}`);
31
27
  }
32
- console.log(`${(0, chalk_code_highlight_1.b)("Build finished.")}`);
28
+ console.log(`${b("Build finished.")}`);
33
29
  }
34
30
  const run = async (cmd) => {
35
- const child = (0, child_process_1.exec)(cmd, err => {
31
+ const child = exec(cmd, err => {
36
32
  if (err) {
37
33
  console.error(err);
38
34
  return;
@@ -44,20 +40,20 @@ const run = async (cmd) => {
44
40
  };
45
41
  async function buildFiles(projectDir, dir = "") {
46
42
  let lastError = undefined;
47
- const srcDir = path_1.default.resolve(projectDir, "src", dir);
48
- if (!(0, fs_1.existsSync)(srcDir)) {
49
- console.info(`${(0, chalk_code_highlight_1.b)(dir)} directory not found in ${(0, chalk_code_highlight_1.b)(path_1.default.resolve(projectDir, "src"))}`);
43
+ const srcDir = path.resolve(projectDir, "src", dir);
44
+ if (!existsSync(srcDir)) {
45
+ console.info(`${b(dir)} directory not found in ${b(path.resolve(projectDir, "src"))}`);
50
46
  return;
51
47
  }
52
- const files = (0, fs_1.readdirSync)(srcDir);
48
+ const files = readdirSync(srcDir);
53
49
  if (files.length === 0) {
54
- console.warn(`No functions found in ${(0, chalk_code_highlight_1.b)(srcDir)} directory`);
50
+ console.warn(`No functions found in ${b(srcDir)} directory`);
55
51
  return;
56
52
  }
57
53
  for (const file of files) {
58
- if ((0, fs_1.lstatSync)(path_1.default.resolve(srcDir, file)).isDirectory()) {
54
+ if (lstatSync(path.resolve(srcDir, file)).isDirectory()) {
59
55
  try {
60
- await buildFiles(projectDir, path_1.default.join(dir, file));
56
+ await buildFiles(projectDir, path.join(dir, file));
61
57
  }
62
58
  catch (e) {
63
59
  lastError = e;
@@ -69,7 +65,7 @@ async function buildFiles(projectDir, dir = "") {
69
65
  }
70
66
  catch (e) {
71
67
  console.error([
72
- `${(0, chalk_code_highlight_1.red)(`⚠`)} Function ${(0, chalk_code_highlight_1.b)(file)} failed to compile: ${(0, chalk_code_highlight_1.red)(e?.message)}. See details below`,
68
+ `${red(`⚠`)} Function ${b(file)} failed to compile: ${red(e?.message)}. See details below`,
73
69
  ...(e?.stack?.split("\n") || []).map(s => ` ${s}`),
74
70
  ]
75
71
  .filter(Boolean)
@@ -82,15 +78,15 @@ async function buildFiles(projectDir, dir = "") {
82
78
  }
83
79
  }
84
80
  async function buildFile(projectDir, dir, fileName) {
85
- const funcFile = path_1.default.resolve(projectDir, "src", path_1.default.join(dir, fileName));
81
+ const funcFile = path.resolve(projectDir, "src", path.join(dir, fileName));
86
82
  process.chdir(projectDir);
87
83
  const rollupPlugins = [
88
- (0, plugin_typescript_1.default)(),
89
- (0, plugin_node_resolve_1.default)({ preferBuiltins: false }),
90
- (0, plugin_commonjs_1.default)(),
91
- (0, plugin_json_1.default)(),
84
+ typescript(),
85
+ resolve({ preferBuiltins: false }),
86
+ commonjs(),
87
+ rollupJson(),
92
88
  ];
93
- const bundle = await (0, rollup_1.rollup)({
89
+ const bundle = await rollup({
94
90
  input: [funcFile],
95
91
  plugins: rollupPlugins,
96
92
  external: ["@jitsu/functions-lib"],
@@ -101,36 +97,36 @@ async function buildFile(projectDir, dir, fileName) {
101
97
  dir: projectDir,
102
98
  format: format,
103
99
  });
104
- (0, fs_1.mkdirSync)(path_1.default.resolve(projectDir, "dist/" + dir), { recursive: true });
100
+ mkdirSync(path.resolve(projectDir, "dist/" + dir), { recursive: true });
105
101
  const compiledFunctionPath = `dist/${dir}/${fileName.replace(".ts", ".js")}`;
106
- (0, fs_1.writeFileSync)(path_1.default.resolve(projectDir, compiledFunctionPath), output.output[0].code);
107
- const compiledFunction = await (0, compiled_function_1.getFunctionFromFilePath)(path_1.default.resolve(projectDir, compiledFunctionPath), "function");
108
- console.log([`${(0, chalk_code_highlight_1.green)(`✓`)} Function ${(0, chalk_code_highlight_1.b)(fileName)} compiled successfully`, ` slug = ${(0, chalk_code_highlight_1.b)(compiledFunction.meta.slug)}`]
102
+ writeFileSync(path.resolve(projectDir, compiledFunctionPath), output.output[0].code);
103
+ const compiledFunction = await getFunctionFromFilePath(path.resolve(projectDir, compiledFunctionPath), "function");
104
+ console.log([`${green(`✓`)} Function ${b(fileName)} compiled successfully`, ` slug = ${b(compiledFunction.meta.slug)}`]
109
105
  .filter(Boolean)
110
106
  .join("\n"));
111
107
  }
112
108
  function checkTypescript(projectDir) {
113
- const tsconfigPath = path_1.default.resolve(projectDir, "tsconfig.json");
114
- if (!(0, fs_1.existsSync)(tsconfigPath)) {
115
- console.info(`No ${(0, chalk_code_highlight_1.b)("tsconfig.json")} file found in ${(0, chalk_code_highlight_1.b)(projectDir)}. Assuming JavaScript project`);
109
+ const tsconfigPath = path.resolve(projectDir, "tsconfig.json");
110
+ if (!existsSync(tsconfigPath)) {
111
+ console.info(`No ${b("tsconfig.json")} file found in ${b(projectDir)}. Assuming JavaScript project`);
116
112
  return;
117
113
  }
118
- console.log(`Checking TypeScript files in ${(0, chalk_code_highlight_1.b)(projectDir)}`);
119
114
  let compilerOptions = {};
120
115
  let filenames = [];
121
116
  const tsconfig = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
122
117
  tsconfig.config.compilerOptions = {
123
118
  ...tsconfig.config.compilerOptions,
124
- typeRoots: [path_1.default.resolve(projectDir, "node_modules", "@types")],
119
+ typeRoots: [path.resolve(projectDir, "node_modules", "@types")],
125
120
  checkJs: true,
126
121
  allowJs: true,
122
+ skipLibCheck: true,
127
123
  noEmit: true,
128
124
  esModuleInterop: typeof compilerOptions.esModuleInterop !== "undefined" ? compilerOptions.esModuleInterop : true,
129
125
  moduleResolution: typeof compilerOptions.moduleResolution !== "undefined" ? compilerOptions.moduleResolution : "node",
130
126
  target: "esnext",
131
127
  module: "esnext",
132
128
  };
133
- const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path_1.default.dirname(tsconfigPath));
129
+ const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfigPath));
134
130
  filenames = parsed.fileNames;
135
131
  compilerOptions = parsed.options;
136
132
  let program = ts.createProgram(filenames, compilerOptions);
@@ -1,52 +1,48 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deploy = deploy;
4
- const tslib_1 = require("tslib");
5
- const path_1 = tslib_1.__importDefault(require("path"));
6
- const os_1 = require("os");
7
- const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
8
- const fs_1 = require("fs");
9
- const shared_1 = require("./shared");
10
- const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
11
- const cuid_1 = tslib_1.__importDefault(require("cuid"));
12
- const chalk_code_highlight_1 = require("../lib/chalk-code-highlight");
13
- const compiled_function_1 = require("../lib/compiled-function");
1
+ import path from "path";
2
+ import { homedir } from "os";
3
+ import inquirer from "inquirer";
4
+ import { existsSync, readdirSync, readFileSync } from "fs";
5
+ import { loadPackageJson } from "./shared";
6
+ import fetch from "node-fetch";
7
+ import cuid from "cuid";
8
+ import { b, green, red } from "../lib/chalk-code-highlight";
9
+ import { getFunctionFromFilePath } from "../lib/compiled-function";
14
10
  function readLoginFile() {
15
- const configFile = `${(0, os_1.homedir)()}/.jitsu/jitsu-cli.json`;
16
- if (!(0, fs_1.existsSync)(configFile)) {
17
- console.error((0, chalk_code_highlight_1.red)("Please login first with `jitsu-cli login` command or provide --apikey option"));
11
+ const configFile = `${homedir()}/.jitsu/jitsu-cli.json`;
12
+ if (!existsSync(configFile)) {
13
+ console.error(red("Please login first with `jitsu-cli login` command or provide --apikey option"));
18
14
  process.exit(1);
19
15
  }
20
- return JSON.parse((0, fs_1.readFileSync)(configFile, { encoding: "utf-8" }));
16
+ return JSON.parse(readFileSync(configFile, { encoding: "utf-8" }));
21
17
  }
22
- async function deploy({ dir, workspace, name: names, ...params }) {
23
- const { packageJson, projectDir } = await (0, shared_1.loadPackageJson)(dir || process.cwd());
18
+ export async function deploy({ dir, workspace, name: names, ...params }) {
19
+ const { packageJson, projectDir } = await loadPackageJson(dir || process.cwd());
24
20
  const { host, apikey } = params.apikey
25
21
  ? { apikey: params.apikey, host: params.host || "https://use.jitsu.com" }
26
22
  : readLoginFile();
27
- console.log(`Deploying ${(0, chalk_code_highlight_1.b)(packageJson.name)} project.${names && names.length > 0 ? ` (selected functions: ${names.join(",")})` : ""}`);
28
- const res = await (0, node_fetch_1.default)(`${host}/api/workspace`, {
23
+ console.log(`Deploying ${b(packageJson.name)} project.${names && names.length > 0 ? ` (selected functions: ${names.join(",")})` : ""}`);
24
+ const res = await fetch(`${host}/api/workspace`, {
29
25
  method: "GET",
30
26
  headers: {
31
27
  Authorization: `Bearer ${apikey}`,
32
28
  },
33
29
  });
34
30
  if (!res.ok) {
35
- console.error((0, chalk_code_highlight_1.red)(`Cannot get workspace list:\n${(0, chalk_code_highlight_1.b)(await res.text())}`));
31
+ console.error(red(`Cannot get workspace list:\n${b(await res.text())}`));
36
32
  process.exit(1);
37
33
  }
38
34
  const workspaces = (await res.json());
39
35
  let workspaceId = workspace;
40
36
  if (!workspace) {
41
37
  if (workspaces.length === 0) {
42
- console.error(`${(0, chalk_code_highlight_1.red)("No workspaces found")}`);
38
+ console.error(`${red("No workspaces found")}`);
43
39
  process.exit(1);
44
40
  }
45
41
  else if (workspaces.length === 1) {
46
42
  workspaceId = workspaces[0].id;
47
43
  }
48
44
  else {
49
- workspaceId = (await inquirer_1.default.prompt([
45
+ workspaceId = (await inquirer.prompt([
50
46
  {
51
47
  type: "list",
52
48
  name: "workspaceId",
@@ -62,7 +58,7 @@ async function deploy({ dir, workspace, name: names, ...params }) {
62
58
  const workspaceObj = workspaces.find(w => w.id === workspaceId);
63
59
  const workspaceName = workspaceObj?.name;
64
60
  if (!workspaceId || !workspaceName) {
65
- console.error((0, chalk_code_highlight_1.red)(`Workspace with id ${workspaceId} not found`));
61
+ console.error(red(`Workspace with id ${workspaceId} not found`));
66
62
  process.exit(1);
67
63
  }
68
64
  await deployFunctions({ ...params, host, apikey, name: names }, projectDir, packageJson, workspaceObj, "function");
@@ -71,10 +67,10 @@ async function deploy({ dir, workspace, name: names, ...params }) {
71
67
  async function deployFunctions({ host, apikey, name: names }, projectDir, packageJson, workspace, kind) {
72
68
  const selected = names ? names.flatMap(n => n.split(",")).map(n => n.trim()) : undefined;
73
69
  const dir = `dist/${kind}s`;
74
- const functionsDir = path_1.default.resolve(projectDir, dir);
75
- const functionsFiles = (0, fs_1.readdirSync)(functionsDir);
70
+ const functionsDir = path.resolve(projectDir, dir);
71
+ const functionsFiles = readdirSync(functionsDir);
76
72
  if (functionsFiles.length === 0) {
77
- console.warn((0, chalk_code_highlight_1.red)(`Can't find function files in ${(0, chalk_code_highlight_1.b)(dir)} directory. Please make sure that you have built the project.`));
73
+ console.warn(red(`Can't find function files in ${b(dir)} directory. Please make sure that you have built the project.`));
78
74
  process.exit(1);
79
75
  }
80
76
  const selectedFiles = [];
@@ -85,7 +81,7 @@ async function deployFunctions({ host, apikey, name: names }, projectDir, packag
85
81
  selectedFiles.push(file);
86
82
  }
87
83
  else {
88
- console.error((0, chalk_code_highlight_1.red)(`Can't find function file ${(0, chalk_code_highlight_1.b)(file)} in ${(0, chalk_code_highlight_1.b)(dir)} directory. Please make sure that you have built the project.`));
84
+ console.error(red(`Can't find function file ${b(file)} in ${b(dir)} directory. Please make sure that you have built the project.`));
89
85
  process.exit(1);
90
86
  }
91
87
  }
@@ -95,43 +91,43 @@ async function deployFunctions({ host, apikey, name: names }, projectDir, packag
95
91
  }
96
92
  let profileBuilders = [];
97
93
  if (kind == "profile") {
98
- const res = await (0, node_fetch_1.default)(`${host}/api/${workspace.id}/config/profile-builder`, {
94
+ const res = await fetch(`${host}/api/${workspace.id}/config/profile-builder`, {
99
95
  method: "GET",
100
96
  headers: {
101
97
  Authorization: `Bearer ${apikey}`,
102
98
  },
103
99
  });
104
100
  if (!res.ok) {
105
- console.error((0, chalk_code_highlight_1.red)(`Cannot get profile builders list:\n${(0, chalk_code_highlight_1.b)(await res.text())}`));
101
+ console.error(red(`Cannot get profile builders list:\n${b(await res.text())}`));
106
102
  process.exit(1);
107
103
  }
108
104
  profileBuilders = (await res.json()).profileBuilders;
109
105
  }
110
106
  for (const file of selectedFiles) {
111
- console.log(`${(0, chalk_code_highlight_1.b)(`𝑓`)} Deploying function ${(0, chalk_code_highlight_1.b)(path_1.default.basename(file))} to workspace ${workspace.name} (${host}/${workspace.slug || workspace.id})`);
112
- await deployFunction({ host, apikey }, packageJson, workspace, kind, path_1.default.resolve(functionsDir, file), profileBuilders);
107
+ console.log(`${b(`𝑓`)} Deploying function ${b(path.basename(file))} to workspace ${workspace.name} (${host}/${workspace.slug || workspace.id})`);
108
+ await deployFunction({ host, apikey }, packageJson, workspace, kind, path.resolve(functionsDir, file), profileBuilders);
113
109
  }
114
110
  }
115
111
  async function deployFunction({ host, apikey }, packageJson, workspace, kind, file, profileBuilders = []) {
116
- const code = (0, fs_1.readFileSync)(file, "utf-8");
117
- const wrapped = await (0, compiled_function_1.getFunctionFromFilePath)(file, kind, profileBuilders);
112
+ const code = readFileSync(file, "utf-8");
113
+ const wrapped = await getFunctionFromFilePath(file, kind, profileBuilders);
118
114
  const meta = wrapped.meta;
119
115
  if (meta) {
120
116
  console.log(` meta: slug=${meta.slug}, name=${meta.name || "not set"}`);
121
117
  }
122
118
  else {
123
- console.log(`File ${(0, chalk_code_highlight_1.b)(path_1.default.basename(file))} doesn't have function meta information. ${(0, chalk_code_highlight_1.red)("Skipping")}`);
119
+ console.log(`File ${b(path.basename(file))} doesn't have function meta information. ${red("Skipping")}`);
124
120
  return;
125
121
  }
126
122
  let existingFunctionId;
127
123
  if (meta.slug) {
128
- const res = await (0, node_fetch_1.default)(`${host}/api/${workspace.id}/config/function`, {
124
+ const res = await fetch(`${host}/api/${workspace.id}/config/function`, {
129
125
  headers: {
130
126
  Authorization: `Bearer ${apikey}`,
131
127
  },
132
128
  });
133
129
  if (!res.ok) {
134
- console.error((0, chalk_code_highlight_1.red)(`Cannot add function to workspace:\n${(0, chalk_code_highlight_1.b)(await res.text())}`));
130
+ console.error(red(`Cannot add function to workspace:\n${b(await res.text())}`));
135
131
  process.exit(1);
136
132
  }
137
133
  else {
@@ -152,8 +148,8 @@ async function deployFunction({ host, apikey }, packageJson, workspace, kind, fi
152
148
  };
153
149
  }
154
150
  if (!existingFunctionId) {
155
- const id = (0, cuid_1.default)();
156
- const res = await (0, node_fetch_1.default)(`${host}/api/${workspace.id}/config/function`, {
151
+ const id = cuid();
152
+ const res = await fetch(`${host}/api/${workspace.id}/config/function`, {
157
153
  method: "POST",
158
154
  headers: {
159
155
  Authorization: `Bearer ${apikey}`,
@@ -172,16 +168,16 @@ async function deployFunction({ host, apikey }, packageJson, workspace, kind, fi
172
168
  }),
173
169
  });
174
170
  if (!res.ok) {
175
- console.error((0, chalk_code_highlight_1.red)(`Cannot add function to workspace:\n${(0, chalk_code_highlight_1.b)(await res.text())}`));
171
+ console.error(red(`Cannot add function to workspace:\n${b(await res.text())}`));
176
172
  process.exit(1);
177
173
  }
178
174
  else {
179
- console.log(`Function ${(0, chalk_code_highlight_1.b)(meta.name)} was successfully added to workspace ${workspace.name} with id: ${(0, chalk_code_highlight_1.b)(id)}`);
175
+ console.log(`Function ${b(meta.name)} was successfully added to workspace ${workspace.name} with id: ${b(id)}`);
180
176
  }
181
177
  }
182
178
  else {
183
179
  const id = existingFunctionId;
184
- const res = await (0, node_fetch_1.default)(`${host}/api/${workspace.id}/config/function/${id}`, {
180
+ const res = await fetch(`${host}/api/${workspace.id}/config/function/${id}`, {
185
181
  method: "PUT",
186
182
  headers: {
187
183
  Authorization: `Bearer ${apikey}`,
@@ -199,11 +195,11 @@ async function deployFunction({ host, apikey }, packageJson, workspace, kind, fi
199
195
  }),
200
196
  });
201
197
  if (!res.ok) {
202
- console.error((0, chalk_code_highlight_1.red)(`⚠ Cannot deploy function ${(0, chalk_code_highlight_1.b)(meta.slug)}(${id}):\n${(0, chalk_code_highlight_1.b)(await res.text())}`));
198
+ console.error(red(`⚠ Cannot deploy function ${b(meta.slug)}(${id}):\n${b(await res.text())}`));
203
199
  process.exit(1);
204
200
  }
205
201
  else {
206
- console.log(`${(0, chalk_code_highlight_1.green)(`✓`)} ${(0, chalk_code_highlight_1.b)(meta.name)} deployed successfully!`);
202
+ console.log(`${green(`✓`)} ${b(meta.name)} deployed successfully!`);
207
203
  }
208
204
  }
209
205
  }
@@ -1,46 +1,42 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.init = init;
4
- const tslib_1 = require("tslib");
5
- const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
6
- const path_1 = tslib_1.__importDefault(require("path"));
7
- const chalk_code_highlight_1 = require("../lib/chalk-code-highlight");
8
- const fs = tslib_1.__importStar(require("fs"));
9
- const functions_1 = require("../templates/functions");
10
- const template_1 = require("../lib/template");
11
- const version_1 = require("../lib/version");
12
- async function init(dir, opts) {
1
+ import inquirer from "inquirer";
2
+ import path from "path";
3
+ import { b } from "../lib/chalk-code-highlight";
4
+ import * as fs from "fs";
5
+ import { functionProjectTemplate } from "../templates/functions";
6
+ import { write } from "../lib/template";
7
+ import { jitsuCliVersion } from "../lib/version";
8
+ export async function init(dir, opts) {
13
9
  let projectName;
14
10
  if (dir) {
15
- dir = path_1.default.resolve(dir);
11
+ dir = path.resolve(dir);
16
12
  if (!fs.existsSync(dir)) {
17
13
  fs.mkdirSync(dir);
18
14
  }
19
15
  else if (fs.readdirSync(dir).length > 0) {
20
- const msg = `Directory ${(0, chalk_code_highlight_1.b)(dir)} is not empty, can't create project there`;
16
+ const msg = `Directory ${b(dir)} is not empty, can't create project there`;
21
17
  if (opts?.allowNonEmptyDir) {
22
- console.warn(`Directory ${(0, chalk_code_highlight_1.b)(dir)} is not empty. Will create project there, files may be overwritten`);
18
+ console.warn(`Directory ${b(dir)} is not empty. Will create project there, files may be overwritten`);
23
19
  }
24
20
  else {
25
21
  console.error(msg);
26
22
  process.exit(1);
27
23
  }
28
24
  }
29
- projectName = path_1.default.basename(dir);
25
+ projectName = path.basename(dir);
30
26
  }
31
27
  else {
32
- projectName = (await inquirer_1.default.prompt([
28
+ projectName = (await inquirer.prompt([
33
29
  {
34
30
  type: "input",
35
31
  name: "project",
36
32
  message: `Enter project name. It will be used as a package name and directory name:`,
37
33
  },
38
34
  ])).project;
39
- dir = path_1.default.resolve(projectName);
35
+ dir = path.resolve(projectName);
40
36
  }
41
- (0, template_1.write)(dir, functions_1.functionProjectTemplate, {
37
+ write(dir, functionProjectTemplate, {
42
38
  packageName: projectName,
43
- jitsuVersion: opts?.jitsuVersion || version_1.jitsuCliVersion,
39
+ jitsuVersion: opts?.jitsuVersion || jitsuCliVersion,
44
40
  });
45
- console.log(`Project ${(0, chalk_code_highlight_1.b)(projectName)} created!`);
41
+ console.log(`Project ${b(projectName)} created!`);
46
42
  }
@@ -1,24 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logout = logout;
4
- exports.login = login;
5
- const tslib_1 = require("tslib");
6
- const juava_1 = require("juava");
7
- const fs = tslib_1.__importStar(require("fs"));
8
- const fs_1 = require("fs");
9
- const os_1 = require("os");
10
- const readline_1 = tslib_1.__importDefault(require("readline"));
11
- const chalk_code_highlight_1 = require("../lib/chalk-code-highlight");
12
- const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
1
+ import { decrypt, randomId } from "juava";
2
+ import * as fs from "fs";
3
+ import { mkdirSync, readFileSync, writeFileSync } from "fs";
4
+ import { homedir } from "os";
5
+ import readline from "readline";
6
+ import { b, red } from "../lib/chalk-code-highlight";
7
+ import inquirer from "inquirer";
13
8
  const origin = "jitsu-cli";
14
- async function logout({ force }) {
15
- const jitsuFile = `${(0, os_1.homedir)()}/.jitsu/jitsu-cli.json`;
9
+ export async function logout({ force }) {
10
+ const jitsuFile = `${homedir()}/.jitsu/jitsu-cli.json`;
16
11
  if (fs.existsSync(jitsuFile)) {
17
12
  if (force) {
18
13
  fs.unlinkSync(jitsuFile);
19
14
  }
20
15
  else {
21
- const { confirm } = await inquirer_1.default.prompt([
16
+ const { confirm } = await inquirer.prompt([
22
17
  {
23
18
  type: "confirm",
24
19
  name: "confirm",
@@ -40,15 +35,17 @@ async function logout({ force }) {
40
35
  console.log("You are not logged in");
41
36
  }
42
37
  }
43
- async function login({ host, apikey, force }) {
44
- const jitsuFile = `${(0, os_1.homedir)()}/.jitsu/jitsu-cli.json`;
38
+ export async function login({ host, apikey, force }) {
39
+ const jitsuDir = `${homedir()}/.jitsu`;
40
+ fs.mkdirSync(jitsuDir, { recursive: true });
41
+ const jitsuFile = `${jitsuDir}/jitsu-cli.json`;
45
42
  if (fs.existsSync(jitsuFile) && !force) {
46
- const loginInfo = JSON.parse((0, fs_1.readFileSync)(jitsuFile, { encoding: "utf-8" }));
47
- console.error((0, chalk_code_highlight_1.red)(`Error: seems like you already logged into jitsu at ${loginInfo.host}. If you want to re-login again, use --force flag, or logout first with \`jitsu-cli logout\` command`));
43
+ const loginInfo = JSON.parse(readFileSync(jitsuFile, { encoding: "utf-8" }));
44
+ console.error(red(`Error: seems like you already logged into jitsu at ${loginInfo.host}. If you want to re-login again, use --force flag, or logout first with \`jitsu-cli logout\` command`));
48
45
  process.exit(1);
49
46
  }
50
47
  if (apikey) {
51
- (0, fs_1.writeFileSync)(jitsuFile, JSON.stringify({ host, apikey }, null, 2));
48
+ writeFileSync(jitsuFile, JSON.stringify({ host, apikey }, null, 2));
52
49
  console.info(`\nSuccess!`);
53
50
  return;
54
51
  }
@@ -65,9 +62,9 @@ async function login({ host, apikey, force }) {
65
62
  url += "/";
66
63
  }
67
64
  try {
68
- const c = (0, juava_1.randomId)(32);
69
- console.log(`Please open this url in your browser and log in:\n\n${(0, chalk_code_highlight_1.b)(`${url}?origin=${origin}&c=${c}`)}`);
70
- const rl = readline_1.default.createInterface({
65
+ const c = randomId(32);
66
+ console.log(`Please open this url in your browser and log in:\n\n${b(`${url}?origin=${origin}&c=${c}`)}`);
67
+ const rl = readline.createInterface({
71
68
  input: process.stdin,
72
69
  output: process.stdout,
73
70
  });
@@ -86,14 +83,14 @@ function processCode(code, key, host) {
86
83
  try {
87
84
  const iv = `${origin}${code.substring(0, 16 - origin.length)}`;
88
85
  const enc = code.substring(16 - origin.length);
89
- const decoded = (0, juava_1.decrypt)(key, iv, enc);
86
+ const decoded = decrypt(key, iv, enc);
90
87
  const { plaintext, id } = JSON.parse(decoded);
91
- (0, fs_1.mkdirSync)(`${(0, os_1.homedir)()}/.jitsu`, { recursive: true });
92
- (0, fs_1.writeFileSync)(`${(0, os_1.homedir)()}/.jitsu/jitsu-cli.json`, JSON.stringify({ host, apikey: `${id}:${plaintext}` }, null, 2));
88
+ mkdirSync(`${homedir()}/.jitsu`, { recursive: true });
89
+ writeFileSync(`${homedir()}/.jitsu/jitsu-cli.json`, JSON.stringify({ host, apikey: `${id}:${plaintext}` }, null, 2));
93
90
  console.info(`\nSuccess!`);
94
91
  }
95
92
  catch (e) {
96
- console.error(`\n${(0, chalk_code_highlight_1.red)("Incorrect code value")}`);
93
+ console.error(`\n${red("Incorrect code value")}`);
97
94
  process.exit(1);
98
95
  }
99
96
  }