jitsu-cli 1.10.4 → 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.
- package/compiled/package.json +20 -17
- package/compiled/src/commands/build.js +41 -45
- package/compiled/src/commands/deploy.js +41 -45
- package/compiled/src/commands/init.js +17 -21
- package/compiled/src/commands/login.js +24 -27
- package/compiled/src/commands/shared.js +12 -17
- package/compiled/src/commands/test.js +7 -10
- package/compiled/src/commands/whoami.js +8 -12
- package/compiled/src/index.js +20 -23
- package/compiled/src/lib/chalk-code-highlight.js +15 -20
- package/compiled/src/lib/compiled-function.js +9 -13
- package/compiled/src/lib/indent.js +3 -8
- package/compiled/src/lib/template.js +7 -11
- package/compiled/src/lib/version.js +13 -20
- package/compiled/src/templates/functions.js +13 -18
- package/dist/140.js +3 -3
- package/dist/main.js +84596 -78688
- package/dist/main.js.map +1 -1
- package/package.json +34 -31
- package/src/commands/build.ts +1 -1
- package/src/commands/login.ts +3 -1
- package/tsconfig.json +2 -19
- package/{webpack.config.js → webpack.config.cjs} +5 -1
- package/.turbo/turbo-build.log +0 -28
- package/.turbo/turbo-clean.log +0 -5
- package/LICENSE +0 -21
- package/babel.config.cjs +0 -4
- package/dist/233.js +0 -4890
- package/dist/233.js.map +0 -1
- package/dist/445e7f36f8a19c2bf682.js +0 -900
package/compiled/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jitsu-cli",
|
|
3
|
-
"version": "
|
|
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":
|
|
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
|
-
"
|
|
15
|
-
"build": "
|
|
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": "
|
|
28
|
-
"typescript": "
|
|
29
|
+
"tslib": "catalog:",
|
|
30
|
+
"typescript": "catalog:"
|
|
29
31
|
},
|
|
30
32
|
"devDependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"
|
|
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/
|
|
45
|
-
"@types/
|
|
46
|
-
"@
|
|
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": "
|
|
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": "
|
|
68
|
-
"
|
|
69
|
-
"webpack
|
|
69
|
+
"ts-node": "catalog:",
|
|
70
|
+
"vitest": "catalog:",
|
|
71
|
+
"webpack": "catalog:",
|
|
72
|
+
"webpack-cli": "catalog:"
|
|
70
73
|
}
|
|
71
74
|
}
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
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(`${
|
|
28
|
+
console.log(`${b("Build finished.")}`);
|
|
33
29
|
}
|
|
34
30
|
const run = async (cmd) => {
|
|
35
|
-
const child =
|
|
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 =
|
|
48
|
-
if (!
|
|
49
|
-
console.info(`${
|
|
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 =
|
|
48
|
+
const files = readdirSync(srcDir);
|
|
53
49
|
if (files.length === 0) {
|
|
54
|
-
console.warn(`No functions found in ${
|
|
50
|
+
console.warn(`No functions found in ${b(srcDir)} directory`);
|
|
55
51
|
return;
|
|
56
52
|
}
|
|
57
53
|
for (const file of files) {
|
|
58
|
-
if (
|
|
54
|
+
if (lstatSync(path.resolve(srcDir, file)).isDirectory()) {
|
|
59
55
|
try {
|
|
60
|
-
await buildFiles(projectDir,
|
|
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
|
-
`${
|
|
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 =
|
|
81
|
+
const funcFile = path.resolve(projectDir, "src", path.join(dir, fileName));
|
|
86
82
|
process.chdir(projectDir);
|
|
87
83
|
const rollupPlugins = [
|
|
88
|
-
(
|
|
89
|
-
(
|
|
90
|
-
(
|
|
91
|
-
(
|
|
84
|
+
typescript(),
|
|
85
|
+
resolve({ preferBuiltins: false }),
|
|
86
|
+
commonjs(),
|
|
87
|
+
rollupJson(),
|
|
92
88
|
];
|
|
93
|
-
const bundle = await
|
|
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
|
-
|
|
100
|
+
mkdirSync(path.resolve(projectDir, "dist/" + dir), { recursive: true });
|
|
105
101
|
const compiledFunctionPath = `dist/${dir}/${fileName.replace(".ts", ".js")}`;
|
|
106
|
-
|
|
107
|
-
const compiledFunction = await
|
|
108
|
-
console.log([`${
|
|
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 =
|
|
114
|
-
if (!
|
|
115
|
-
console.info(`No ${
|
|
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: [
|
|
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,
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 = `${
|
|
16
|
-
if (!
|
|
17
|
-
console.error(
|
|
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(
|
|
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
|
|
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 ${
|
|
28
|
-
const res = await (
|
|
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(
|
|
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(`${
|
|
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
|
|
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(
|
|
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 =
|
|
75
|
-
const functionsFiles =
|
|
70
|
+
const functionsDir = path.resolve(projectDir, dir);
|
|
71
|
+
const functionsFiles = readdirSync(functionsDir);
|
|
76
72
|
if (functionsFiles.length === 0) {
|
|
77
|
-
console.warn(
|
|
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(
|
|
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 (
|
|
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(
|
|
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(`${
|
|
112
|
-
await deployFunction({ host, apikey }, packageJson, workspace, kind,
|
|
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 =
|
|
117
|
-
const wrapped = await
|
|
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 ${
|
|
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 (
|
|
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(
|
|
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 = (
|
|
156
|
-
const res = await (
|
|
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(
|
|
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 ${
|
|
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 (
|
|
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(
|
|
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(`${
|
|
202
|
+
console.log(`${green(`✓`)} ${b(meta.name)} deployed successfully!`);
|
|
207
203
|
}
|
|
208
204
|
}
|
|
209
205
|
}
|
|
@@ -1,46 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 =
|
|
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 ${
|
|
16
|
+
const msg = `Directory ${b(dir)} is not empty, can't create project there`;
|
|
21
17
|
if (opts?.allowNonEmptyDir) {
|
|
22
|
-
console.warn(`Directory ${
|
|
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 =
|
|
25
|
+
projectName = path.basename(dir);
|
|
30
26
|
}
|
|
31
27
|
else {
|
|
32
|
-
projectName = (await
|
|
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 =
|
|
35
|
+
dir = path.resolve(projectName);
|
|
40
36
|
}
|
|
41
|
-
|
|
37
|
+
write(dir, functionProjectTemplate, {
|
|
42
38
|
packageName: projectName,
|
|
43
|
-
jitsuVersion: opts?.jitsuVersion ||
|
|
39
|
+
jitsuVersion: opts?.jitsuVersion || jitsuCliVersion,
|
|
44
40
|
});
|
|
45
|
-
console.log(`Project ${
|
|
41
|
+
console.log(`Project ${b(projectName)} created!`);
|
|
46
42
|
}
|
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 = `${
|
|
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
|
|
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
|
|
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(
|
|
47
|
-
console.error(
|
|
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
|
-
|
|
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 =
|
|
69
|
-
console.log(`Please open this url in your browser and log in:\n\n${
|
|
70
|
-
const rl =
|
|
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 =
|
|
86
|
+
const decoded = decrypt(key, iv, enc);
|
|
90
87
|
const { plaintext, id } = JSON.parse(decoded);
|
|
91
|
-
|
|
92
|
-
|
|
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${
|
|
93
|
+
console.error(`\n${red("Incorrect code value")}`);
|
|
97
94
|
process.exit(1);
|
|
98
95
|
}
|
|
99
96
|
}
|