@intuned/runtime-dev 1.0.6-dev-2 → 1.0.6-playwright-1.46.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/InterfaceTemplate/utils.ts +31 -53
- package/dist/commands/common/tsNodeImport.d.ts +1 -2
- package/dist/commands/common/tsNodeImport.js +5 -19
- package/dist/commands/common/utils/unixSocket.d.ts +0 -1
- package/dist/commands/interface/run.js +3 -30
- package/dist/common/asyncLocalStorage/index.d.ts +0 -1
- package/dist/common/runApi/index.d.ts +0 -1
- package/dist/common/runApi/index.js +2 -9
- package/dist/common/runApi/types.d.ts +3 -9
- package/package.json +4 -11
- package/bin/intuned-deploy +0 -3
- package/bin/intuned-init +0 -3
- package/bin/intuned-run +0 -3
- package/dist/commands/deploy/deploy.d.ts +0 -2
- package/dist/commands/deploy/deploy.js +0 -34
- package/dist/commands/deploy/utils.d.ts +0 -7
- package/dist/commands/deploy/utils.js +0 -196
- package/dist/commands/init/init.d.ts +0 -2
- package/dist/commands/init/init.js +0 -23
- package/dist/commands/init/types.d.ts +0 -52
- package/dist/commands/init/types.js +0 -7
- package/dist/commands/init/utils.d.ts +0 -9
- package/dist/commands/init/utils.js +0 -145
- package/dist/commands/intuned-run/intuned-run.d.ts +0 -4
- package/dist/commands/intuned-run/intuned-run.js +0 -84
- package/dist/commands/intuned-run/utils.d.ts +0 -1
- package/dist/commands/intuned-run/utils.js +0 -34
- package/my-intuned-project/Intuned.json +0 -15
- package/my-intuned-project/api/book-details.ts +0 -46
- package/my-intuned-project/api/books-all.ts +0 -68
- package/my-intuned-project/package.json +0 -36
- package/my-intuned-project/params/bookInput.json +0 -3
- package/my-intuned-project/yarn.lock +0 -4539
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { err, ok } from "neverthrow";
|
|
3
|
-
|
|
4
|
-
export const importModule: ImportFunction = async (path: string) => {
|
|
1
|
+
export async function importModule(path: string) {
|
|
5
2
|
const [folderName, ...functionNameParts] = path.split("/");
|
|
6
3
|
const functionNameDepth = functionNameParts.length;
|
|
7
4
|
|
|
@@ -9,53 +6,34 @@ export const importModule: ImportFunction = async (path: string) => {
|
|
|
9
6
|
// currently we support only 5 levels of depth
|
|
10
7
|
// rollup dynamic import does not support multiple levels of dynamic imports so we need to specify the possible paths explicitly
|
|
11
8
|
let imported: any = undefined;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
error: new Error(
|
|
41
|
-
`intuned supports maximum 5 levels of depth in the api folder`
|
|
42
|
-
),
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return ok(imported);
|
|
46
|
-
} catch (e: any) {
|
|
47
|
-
if (
|
|
48
|
-
"message" in e &&
|
|
49
|
-
typeof e.message === "string" &&
|
|
50
|
-
e.message.includes("Unknown variable dynamic import")
|
|
51
|
-
) {
|
|
52
|
-
return err({
|
|
53
|
-
type: "not_found",
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return err({
|
|
57
|
-
type: "other",
|
|
58
|
-
error: e,
|
|
59
|
-
});
|
|
9
|
+
switch (functionNameDepth) {
|
|
10
|
+
case 1:
|
|
11
|
+
imported = await import(`./${folderName}/${functionNameParts[0]}.ts`);
|
|
12
|
+
break;
|
|
13
|
+
case 2:
|
|
14
|
+
imported = await import(
|
|
15
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}.ts`
|
|
16
|
+
);
|
|
17
|
+
break;
|
|
18
|
+
case 3:
|
|
19
|
+
imported = await import(
|
|
20
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`
|
|
21
|
+
);
|
|
22
|
+
break;
|
|
23
|
+
case 4:
|
|
24
|
+
imported = await import(
|
|
25
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`
|
|
26
|
+
);
|
|
27
|
+
break;
|
|
28
|
+
case 5:
|
|
29
|
+
imported = await import(
|
|
30
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`
|
|
31
|
+
);
|
|
32
|
+
break;
|
|
33
|
+
default:
|
|
34
|
+
throw new Error(
|
|
35
|
+
"intuned supports maximum 5 levels of depth in the api folder"
|
|
36
|
+
);
|
|
60
37
|
}
|
|
61
|
-
|
|
38
|
+
return imported;
|
|
39
|
+
}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const tsNodeImport: ExtendedRunApiParameters["importFunction"];
|
|
1
|
+
export declare function tsNodeImport(apiName: string): Promise<any>;
|
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.tsNodeImport =
|
|
7
|
-
var _neverthrow = require("neverthrow");
|
|
6
|
+
exports.tsNodeImport = tsNodeImport;
|
|
8
7
|
var _fileUtils = require("./utils/fileUtils");
|
|
9
8
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
9
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
-
|
|
10
|
+
async function tsNodeImport(apiName) {
|
|
12
11
|
require("ts-node").register({
|
|
13
12
|
transpileOnly: true,
|
|
14
13
|
compilerOptions: {
|
|
@@ -16,19 +15,6 @@ const tsNodeImport = async apiName => {
|
|
|
16
15
|
}
|
|
17
16
|
});
|
|
18
17
|
const path = (0, _fileUtils.getFullPathInProject)(...apiName.split("/"));
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} catch (e) {
|
|
23
|
-
if ("code" in e && e.code === "MODULE_NOT_FOUND") {
|
|
24
|
-
return (0, _neverthrow.err)({
|
|
25
|
-
type: "not_found"
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return (0, _neverthrow.err)({
|
|
29
|
-
type: "other",
|
|
30
|
-
error: e
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
exports.tsNodeImport = tsNodeImport;
|
|
18
|
+
const imported = await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(path);
|
|
19
|
+
return imported;
|
|
20
|
+
}
|
|
@@ -15,10 +15,9 @@ var _unixSocket = require("../common/utils/unixSocket");
|
|
|
15
15
|
var _promises = require("timers/promises");
|
|
16
16
|
var _jwtTokenManager = require("../../common/jwtTokenManager");
|
|
17
17
|
var _formatZodError = require("../../common/formatZodError");
|
|
18
|
-
var _neverthrow = require("neverthrow");
|
|
19
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
18
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
19
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
21
|
const startRunApiSchema = _zod.default.object({
|
|
23
22
|
type: _zod.default.literal("start"),
|
|
24
23
|
parameters: _runApi.runApiParametersSchema.extend({
|
|
@@ -48,11 +47,7 @@ const tokenUpdateSchema = _zod.default.object({
|
|
|
48
47
|
functionsToken: _zod.default.string()
|
|
49
48
|
})
|
|
50
49
|
});
|
|
51
|
-
const
|
|
52
|
-
type: _zod.default.literal("ping"),
|
|
53
|
-
parameters: _zod.default.object({}).optional()
|
|
54
|
-
});
|
|
55
|
-
const inputSchema = _zod.default.union([startRunApiSchema, nextRunApiSchema, abortRunApiSchema, tokenUpdateSchema, pingSchema]);
|
|
50
|
+
const inputSchema = _zod.default.union([startRunApiSchema, nextRunApiSchema, abortRunApiSchema, tokenUpdateSchema]);
|
|
56
51
|
_dotenv.default.config({
|
|
57
52
|
path: `.env`
|
|
58
53
|
});
|
|
@@ -110,7 +105,7 @@ function runAutomationCLI(importFunction) {
|
|
|
110
105
|
generator = (0, _runApi.runApiGenerator)({
|
|
111
106
|
...message.parameters,
|
|
112
107
|
abortSignal: abortController.signal,
|
|
113
|
-
importFunction
|
|
108
|
+
importFunction
|
|
114
109
|
});
|
|
115
110
|
context = {
|
|
116
111
|
extendedPayloads: [],
|
|
@@ -185,12 +180,6 @@ function runAutomationCLI(importFunction) {
|
|
|
185
180
|
});
|
|
186
181
|
break;
|
|
187
182
|
}
|
|
188
|
-
if (message.type === "ping") {
|
|
189
|
-
jsonUnixSocket.sendJSON({
|
|
190
|
-
type: "pong"
|
|
191
|
-
});
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
183
|
await handleMessage(message);
|
|
195
184
|
receiveMessagesPromise = receiveMessages();
|
|
196
185
|
continue;
|
|
@@ -220,22 +209,6 @@ function getProxyUrlFromRunOptions(runOptions) {
|
|
|
220
209
|
url.password = proxy.password;
|
|
221
210
|
return url.toString();
|
|
222
211
|
}
|
|
223
|
-
const _defaultImport = async path => {
|
|
224
|
-
try {
|
|
225
|
-
const imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`../../../${path}.ts`);
|
|
226
|
-
return (0, _neverthrow.ok)(imported);
|
|
227
|
-
} catch (e) {
|
|
228
|
-
if ("code" in e && e.code === "MODULE_NOT_FOUND") {
|
|
229
|
-
return (0, _neverthrow.err)({
|
|
230
|
-
type: "not_found"
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
return (0, _neverthrow.err)({
|
|
234
|
-
type: "other",
|
|
235
|
-
error: e
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
212
|
if (require.main === module) {
|
|
240
213
|
runAutomationCLI();
|
|
241
214
|
}
|
|
@@ -10,4 +10,3 @@ export declare function runApiGenerator<ResultType = any, _YieldType = any, _Nex
|
|
|
10
10
|
export declare function runApiGenerator<ResultType = any, _YieldType = any, _NextType = any>(params: ExtendedRunApiParameters): AsyncGenerator<_YieldType, RunApiResult<ResultType>, _NextType>;
|
|
11
11
|
export declare function runApi<ResultType = any>(params: ExtendedRunApiParameters): Promise<RunApiResult<ResultType>>;
|
|
12
12
|
export declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, checkFn: (..._: any) => Promise<boolean>, retries?: number): Promise<Result<boolean, RunAutomationError>>;
|
|
13
|
-
export type ImportFunction = ExtendedRunApiParameters["importFunction"];
|
|
@@ -242,14 +242,7 @@ async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3)
|
|
|
242
242
|
}
|
|
243
243
|
async function importUsingImportFunction(path, importFunction) {
|
|
244
244
|
try {
|
|
245
|
-
const
|
|
246
|
-
if (importedResult.isErr()) {
|
|
247
|
-
if (importedResult.error.type === "not_found") {
|
|
248
|
-
return (0, _neverthrow.err)(new _errors.ApiNotFoundError(path));
|
|
249
|
-
}
|
|
250
|
-
return (0, _neverthrow.err)(new _errors.AutomationError(importedResult.error.error));
|
|
251
|
-
}
|
|
252
|
-
const imported = importedResult.value;
|
|
245
|
+
const imported = importFunction ? await importFunction(path) : await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`../../../${path}.ts`);
|
|
253
246
|
if (!imported || !imported.default || !imported.default.constructor) {
|
|
254
247
|
return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default export"));
|
|
255
248
|
}
|
|
@@ -267,6 +260,6 @@ async function importUsingImportFunction(path, importFunction) {
|
|
|
267
260
|
}
|
|
268
261
|
return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default async function/generator export"));
|
|
269
262
|
} catch (error) {
|
|
270
|
-
return (0, _neverthrow.err)(new _errors.
|
|
263
|
+
return (0, _neverthrow.err)(new _errors.ApiNotFoundError(path));
|
|
271
264
|
}
|
|
272
265
|
}
|
|
@@ -545,12 +545,12 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
545
545
|
} | undefined;
|
|
546
546
|
}, {
|
|
547
547
|
environment: "standalone";
|
|
548
|
-
headless?: boolean | undefined;
|
|
549
548
|
proxy?: {
|
|
550
549
|
server: string;
|
|
551
550
|
username: string;
|
|
552
551
|
password: string;
|
|
553
552
|
} | undefined;
|
|
553
|
+
headless?: boolean | undefined;
|
|
554
554
|
}>, z.ZodObject<{
|
|
555
555
|
environment: z.ZodLiteral<"cdp">;
|
|
556
556
|
cdpAddress: z.ZodString;
|
|
@@ -673,12 +673,12 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
673
673
|
} | undefined;
|
|
674
674
|
runOptions?: {
|
|
675
675
|
environment: "standalone";
|
|
676
|
-
headless?: boolean | undefined;
|
|
677
676
|
proxy?: {
|
|
678
677
|
server: string;
|
|
679
678
|
username: string;
|
|
680
679
|
password: string;
|
|
681
680
|
} | undefined;
|
|
681
|
+
headless?: boolean | undefined;
|
|
682
682
|
} | {
|
|
683
683
|
mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
|
|
684
684
|
environment: "cdp";
|
|
@@ -688,15 +688,9 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
688
688
|
}>;
|
|
689
689
|
export type RunApiSession = z.infer<typeof runApiSessionSchema>;
|
|
690
690
|
export type RunApiParameters = z.input<typeof runApiParametersSchema>;
|
|
691
|
-
export type ImportFunctionError = {
|
|
692
|
-
type: "not_found";
|
|
693
|
-
} | {
|
|
694
|
-
type: "other";
|
|
695
|
-
error: any;
|
|
696
|
-
};
|
|
697
691
|
export type ExtendedRunApiParameters = RunApiParameters & {
|
|
698
692
|
abortSignal?: AbortSignal;
|
|
699
|
-
importFunction
|
|
693
|
+
importFunction?: (name: string) => Promise<any> | undefined;
|
|
700
694
|
};
|
|
701
695
|
export type RunApiResultOk<R = any> = {
|
|
702
696
|
result: R;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intuned/runtime-dev",
|
|
3
|
-
"version": "1.0.6-
|
|
3
|
+
"version": "1.0.6-playwright-1.46.0",
|
|
4
4
|
"description": "Intuned runtime",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -48,10 +48,7 @@
|
|
|
48
48
|
"intuned-build": "./bin/intuned-build",
|
|
49
49
|
"intuned-browser-start": "./bin/intuned-browser-start",
|
|
50
50
|
"intuned-browser-save-state": "./bin/intuned-browser-save-state",
|
|
51
|
-
"intuned-ts-check": "./bin/intuned-ts-check"
|
|
52
|
-
"intuned-init": "./bin/intuned-init",
|
|
53
|
-
"intuned-run": "./bin/intuned-run",
|
|
54
|
-
"intuned-deploy": "./bin/intuned-deploy"
|
|
51
|
+
"intuned-ts-check": "./bin/intuned-ts-check"
|
|
55
52
|
},
|
|
56
53
|
"dependencies": {
|
|
57
54
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
@@ -68,8 +65,6 @@
|
|
|
68
65
|
"applicationinsights": "^2.9.2",
|
|
69
66
|
"async-retry": "^1.3.3",
|
|
70
67
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
71
|
-
"box": "^0.0.4",
|
|
72
|
-
"boxen": "^8.0.1",
|
|
73
68
|
"chalk": "^4.1.2",
|
|
74
69
|
"commander": "^11.0.0",
|
|
75
70
|
"cross-fetch": "^4.0.0",
|
|
@@ -80,15 +75,13 @@
|
|
|
80
75
|
"fs-extra": "^11.3.0",
|
|
81
76
|
"https-proxy-agent": "^7.0.5",
|
|
82
77
|
"image-size": "^1.1.1",
|
|
83
|
-
"inquirer": "^12.6.0",
|
|
84
78
|
"jsonwebtoken": "^9.0.2",
|
|
85
79
|
"lodash": "^4.17.21",
|
|
86
80
|
"milliparsec": "^2.3.0",
|
|
87
|
-
"minimatch": "^10.0.1",
|
|
88
81
|
"ms": "^2.1.3",
|
|
89
82
|
"nanoid": "3",
|
|
90
83
|
"neverthrow": "^6.1.0",
|
|
91
|
-
"playwright": "1.
|
|
84
|
+
"playwright": "1.46.0",
|
|
92
85
|
"playwright-extra": "^4.3.6",
|
|
93
86
|
"prettier": "^2.8.0",
|
|
94
87
|
"promptly": "^3.2.0",
|
|
@@ -140,4 +133,4 @@
|
|
|
140
133
|
"peerDependencies": {
|
|
141
134
|
"@intuned/runtime": "*"
|
|
142
135
|
}
|
|
143
|
-
}
|
|
136
|
+
}
|
package/bin/intuned-deploy
DELETED
package/bin/intuned-init
DELETED
package/bin/intuned-run
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
var _commander = require("commander");
|
|
5
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
6
|
-
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
7
|
-
var _utils = require("../init/utils");
|
|
8
|
-
var _utils2 = require("./utils");
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
_dotenv.default.config({
|
|
11
|
-
path: `.env`
|
|
12
|
-
});
|
|
13
|
-
_commander.program.description("Deploy an Intuned project to be public").argument("[project-name]", "Name of the project to deploy").option("-w, --workspace-id <id>", "Your Intuned workspace ID").option("-k, --api-key <key>", "Your Intuned API key").action(async (projectName, options) => {
|
|
14
|
-
try {
|
|
15
|
-
if (!projectName) {
|
|
16
|
-
throw new Error("Project name is required");
|
|
17
|
-
}
|
|
18
|
-
const projectNameValidation = (0, _utils2.validateProjectName)(projectName);
|
|
19
|
-
if (!projectNameValidation.isValid) {
|
|
20
|
-
throw new Error(projectNameValidation.errorMessage);
|
|
21
|
-
}
|
|
22
|
-
const auth = (0, _utils.getAuthCredentials)(options);
|
|
23
|
-
const deployStarted = await (0, _utils2.deployProject)(projectName, auth);
|
|
24
|
-
if (!deployStarted) {
|
|
25
|
-
throw new Error("Project not deployed");
|
|
26
|
-
}
|
|
27
|
-
const url = `https://rauf-2.intuned-team-local.com/projects`;
|
|
28
|
-
console.log(_chalk.default.green(`\n🚀 Project "${projectName}" started deployment successfully!` + `\n\nYou can check your project on the platform: ${_chalk.default.bold(url)}\n`));
|
|
29
|
-
} catch (error) {
|
|
30
|
-
console.error(_chalk.default.red(`\n${error.message}`));
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
_commander.program.parse(process.argv);
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AuthCredentials, FileSystemTree } from "../init/types";
|
|
2
|
-
export declare function convertProjectToCodeTree(projectPath: string): Promise<FileSystemTree>;
|
|
3
|
-
export declare function deployProject(projectName: string, auth: AuthCredentials): Promise<boolean>;
|
|
4
|
-
export declare const validateProjectName: (projectName: string) => {
|
|
5
|
-
isValid: boolean;
|
|
6
|
-
errorMessage?: string;
|
|
7
|
-
};
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.convertProjectToCodeTree = convertProjectToCodeTree;
|
|
7
|
-
exports.deployProject = deployProject;
|
|
8
|
-
exports.validateProjectName = void 0;
|
|
9
|
-
var fs = _interopRequireWildcard(require("fs"));
|
|
10
|
-
var path = _interopRequireWildcard(require("path"));
|
|
11
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
12
|
-
var _minimatch = require("minimatch");
|
|
13
|
-
var _zod = require("zod");
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
-
function formatBytes(bytes) {
|
|
18
|
-
if (bytes === 0) return "0 Bytes";
|
|
19
|
-
const k = 1024;
|
|
20
|
-
const sizes = ["Bytes", "KB", "MB", "GB"];
|
|
21
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
22
|
-
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
|
23
|
-
}
|
|
24
|
-
function matchesGitignorePatterns(filePath, patterns, projectPath) {
|
|
25
|
-
const relativePath = path.relative(projectPath, filePath);
|
|
26
|
-
if (relativePath.startsWith("node_modules")) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
for (const pattern of patterns) {
|
|
30
|
-
if (!pattern || pattern.startsWith("#")) continue;
|
|
31
|
-
if (pattern.startsWith("!")) {
|
|
32
|
-
if ((0, _minimatch.minimatch)(relativePath, pattern.substring(1))) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
} else if ((0, _minimatch.minimatch)(relativePath, pattern)) {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
function listFilesNotIgnored(projectPath, ignorePatterns) {
|
|
42
|
-
const results = [];
|
|
43
|
-
function traverseDirectory(dirPath) {
|
|
44
|
-
try {
|
|
45
|
-
const entries = fs.readdirSync(dirPath);
|
|
46
|
-
for (const entry of entries) {
|
|
47
|
-
const fullPath = path.join(dirPath, entry);
|
|
48
|
-
if (matchesGitignorePatterns(fullPath, ignorePatterns, projectPath)) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
const stats = fs.statSync(fullPath);
|
|
53
|
-
if (stats.isDirectory()) {
|
|
54
|
-
traverseDirectory(fullPath);
|
|
55
|
-
} else if (stats.isFile()) {
|
|
56
|
-
results.push(path.relative(projectPath, fullPath));
|
|
57
|
-
}
|
|
58
|
-
} catch (error) {
|
|
59
|
-
console.log(_chalk.default.yellow(`Warning: Could not access ${fullPath}`));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
} catch (error) {
|
|
63
|
-
console.log(_chalk.default.yellow(`Warning: Could not read directory ${dirPath}`));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
traverseDirectory(projectPath);
|
|
67
|
-
return results;
|
|
68
|
-
}
|
|
69
|
-
async function convertProjectToCodeTree(projectPath) {
|
|
70
|
-
const defaultExcludes = ["node_modules/**", ".git/**", "dist/**", "build/**", "coverage/**", ".next/**", ".cache/**", "out/**", "tmp/**", ".DS_Store", "npm-debug.log*", "yarn-debug.log*", "yarn-error.log*", ".env", ".env.*", "**/*.map", "**/*.tsbuildinfo"];
|
|
71
|
-
let ignorePatterns = [...defaultExcludes];
|
|
72
|
-
let currentDir = path.normalize(projectPath);
|
|
73
|
-
let gitignoreFound = false;
|
|
74
|
-
while (currentDir !== path.parse(currentDir).root) {
|
|
75
|
-
const gitignorePath = path.join(currentDir, ".gitignore");
|
|
76
|
-
if (fs.existsSync(gitignorePath)) {
|
|
77
|
-
const gitignoreContent = fs.readFileSync(gitignorePath, "utf-8").split("\n");
|
|
78
|
-
ignorePatterns = [...ignorePatterns, ...gitignoreContent];
|
|
79
|
-
console.log(`Found .gitignore file: ${_chalk.default.cyan.bold(gitignorePath)}`);
|
|
80
|
-
gitignoreFound = true;
|
|
81
|
-
break;
|
|
82
|
-
} else {
|
|
83
|
-
currentDir = path.dirname(currentDir);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
const filesToDeploy = listFilesNotIgnored(projectPath, ignorePatterns);
|
|
87
|
-
let totalSize = 0;
|
|
88
|
-
for (const file of filesToDeploy) {
|
|
89
|
-
try {
|
|
90
|
-
const stats = fs.statSync(path.join(projectPath, file));
|
|
91
|
-
totalSize += stats.size;
|
|
92
|
-
} catch (error) {}
|
|
93
|
-
}
|
|
94
|
-
console.log(_chalk.default.cyan("\nFiles to be deployed:"));
|
|
95
|
-
if (filesToDeploy.length > 100) {
|
|
96
|
-
console.log(_chalk.default.yellow(` ${filesToDeploy.length} files (too many to display)`));
|
|
97
|
-
} else {
|
|
98
|
-
const filesToDeployText = "\n " + filesToDeploy.join("\n ");
|
|
99
|
-
console.log(filesToDeployText);
|
|
100
|
-
}
|
|
101
|
-
console.log(_chalk.default.cyan(`\nSummary: ${filesToDeploy.length} files, ${formatBytes(totalSize)}`));
|
|
102
|
-
function readDirectory(dirPath) {
|
|
103
|
-
const tree = {};
|
|
104
|
-
try {
|
|
105
|
-
const entries = fs.readdirSync(dirPath);
|
|
106
|
-
for (const entry of entries) {
|
|
107
|
-
const entryPath = path.join(dirPath, entry);
|
|
108
|
-
if (matchesGitignorePatterns(entryPath, ignorePatterns, projectPath)) {
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
try {
|
|
112
|
-
const stats = fs.statSync(entryPath);
|
|
113
|
-
if (stats.isFile()) {
|
|
114
|
-
try {
|
|
115
|
-
const content = fs.readFileSync(entryPath, "utf-8");
|
|
116
|
-
tree[entry] = {
|
|
117
|
-
file: {
|
|
118
|
-
contents: content
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
} catch (error) {
|
|
122
|
-
console.log(_chalk.default.yellow(`Warning: Could not read file ${entryPath}`));
|
|
123
|
-
}
|
|
124
|
-
} else if (stats.isDirectory()) {
|
|
125
|
-
const subTree = readDirectory(entryPath);
|
|
126
|
-
if (Object.keys(subTree).length > 0) {
|
|
127
|
-
tree[entry] = {
|
|
128
|
-
directory: subTree
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
} catch (error) {
|
|
133
|
-
console.log(_chalk.default.yellow(`Warning: Could not access ${entryPath}`));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
} catch (error) {
|
|
137
|
-
console.log(_chalk.default.yellow(`Warning: Could not read directory ${dirPath}`));
|
|
138
|
-
}
|
|
139
|
-
return tree;
|
|
140
|
-
}
|
|
141
|
-
console.log(_chalk.default.cyan("\nBuilding project..."));
|
|
142
|
-
const tree = readDirectory(projectPath);
|
|
143
|
-
return tree;
|
|
144
|
-
}
|
|
145
|
-
async function deployProject(projectName, auth) {
|
|
146
|
-
const {
|
|
147
|
-
workspaceId,
|
|
148
|
-
apiKey
|
|
149
|
-
} = auth;
|
|
150
|
-
const baseUrl = "https://rauf-2.intuned-team-local.com";
|
|
151
|
-
const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create`;
|
|
152
|
-
const headers = {
|
|
153
|
-
"x-api-key": apiKey,
|
|
154
|
-
"Content-Type": "application/json"
|
|
155
|
-
};
|
|
156
|
-
const projectPath = process.cwd();
|
|
157
|
-
const codeTree = await convertProjectToCodeTree(projectPath);
|
|
158
|
-
const deployProjectPayload = {
|
|
159
|
-
name: projectName,
|
|
160
|
-
codeTree: codeTree,
|
|
161
|
-
isCli: true,
|
|
162
|
-
language: "typescript"
|
|
163
|
-
};
|
|
164
|
-
const response = await fetch(url, {
|
|
165
|
-
headers,
|
|
166
|
-
method: "POST",
|
|
167
|
-
body: JSON.stringify(deployProjectPayload)
|
|
168
|
-
});
|
|
169
|
-
if (!response.ok) {
|
|
170
|
-
throw new Error(`Error deploying project`);
|
|
171
|
-
}
|
|
172
|
-
const data = await response.json();
|
|
173
|
-
if (response.status === 202) {
|
|
174
|
-
return true;
|
|
175
|
-
}
|
|
176
|
-
if (!data) {
|
|
177
|
-
throw new Error("Project not deployed");
|
|
178
|
-
}
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
const validateProjectName = projectName => {
|
|
182
|
-
const nameSchema = _zod.z.string().min(1, "Project Name is required").max(50, "Name must be 50 characters or less").regex(/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/, "Name can only contain lowercase letters, numbers, hyphens, and underscores in between").refine(value => !_zod.z.string().uuid().safeParse(value).success, {
|
|
183
|
-
message: "Name cannot be a UUID"
|
|
184
|
-
});
|
|
185
|
-
const validation = nameSchema.safeParse(projectName);
|
|
186
|
-
if (!validation.success) {
|
|
187
|
-
return {
|
|
188
|
-
isValid: false,
|
|
189
|
-
errorMessage: validation.error.errors[0].message
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
return {
|
|
193
|
-
isValid: true
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
exports.validateProjectName = validateProjectName;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
var _commander = require("commander");
|
|
5
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
6
|
-
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
7
|
-
var _utils = require("./utils");
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
_dotenv.default.config({
|
|
10
|
-
path: `.env`
|
|
11
|
-
});
|
|
12
|
-
_commander.program.description("Initialize a new Intuned project from a template").argument("[template-name]", "Name of the template to use").option("-w, --workspace-id <id>", "Your Intuned workspace ID").option("-k, --api-key <key>", "Your Intuned API key").action(async (templateName, options) => {
|
|
13
|
-
try {
|
|
14
|
-
const auth = (0, _utils.getAuthCredentials)(options);
|
|
15
|
-
const template = await (0, _utils.selectTemplate)(templateName);
|
|
16
|
-
await (0, _utils.checkEmptyDirectory)();
|
|
17
|
-
await (0, _utils.scaffoldProject)(template, auth);
|
|
18
|
-
} catch (error) {
|
|
19
|
-
console.error(_chalk.default.red(`\n${error.message}`));
|
|
20
|
-
process.exit(1);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
_commander.program.parse(process.argv);
|