@intuned/runtime-dev 0.1.0-test.10 → 0.1.0-test.12

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.
Files changed (103) hide show
  1. package/.babelrc +1 -2
  2. package/dist/commands/api/run.js +170 -105
  3. package/dist/commands/api/run.ts +105 -0
  4. package/dist/commands/auth-sessions/load.js +26 -28
  5. package/dist/commands/auth-sessions/load.ts +30 -0
  6. package/dist/commands/auth-sessions/run-check.js +53 -52
  7. package/dist/commands/auth-sessions/run-check.ts +51 -0
  8. package/dist/commands/auth-sessions/run-create.js +96 -91
  9. package/dist/commands/auth-sessions/run-create.ts +91 -0
  10. package/dist/commands/browser/save-state.js +16 -14
  11. package/dist/commands/browser/save-state.ts +14 -0
  12. package/dist/commands/browser/start-browser.js +11 -11
  13. package/dist/commands/browser/start-browser.ts +11 -0
  14. package/dist/commands/build.js +108 -75
  15. package/dist/commands/build.ts +78 -0
  16. package/dist/commands/common/browserUtils.js +51 -53
  17. package/dist/commands/common/browserUtils.ts +45 -0
  18. package/dist/commands/common/getDefaultExportFromFile.js +12 -17
  19. package/dist/commands/common/getDefaultExportFromFile.ts +11 -0
  20. package/dist/commands/common/getFirstLineNumber.js +93 -93
  21. package/dist/commands/common/{getFirstLineNumber.test.js → getFirstLineNumber.test.ts} +46 -51
  22. package/dist/commands/common/getFirstLineNumber.ts +96 -0
  23. package/dist/commands/common/sendMessageToClient.js +4 -9
  24. package/dist/commands/common/sendMessageToClient.ts +3 -0
  25. package/dist/commands/common/utils/fileUtils.js +22 -32
  26. package/dist/commands/common/utils/fileUtils.ts +23 -0
  27. package/dist/commands/common/utils/settings.js +19 -27
  28. package/dist/commands/common/utils/settings.ts +22 -0
  29. package/dist/commands/common/utils/unixSocket.js +43 -43
  30. package/dist/commands/common/utils/unixSocket.ts +38 -0
  31. package/dist/commands/common/utils/webTemplate.js +27 -29
  32. package/dist/commands/common/utils/webTemplate.ts +22 -0
  33. package/dist/commands/interface/run.js +151 -150
  34. package/dist/commands/interface/run.ts +156 -0
  35. package/dist/commands/ts-check.js +49 -49
  36. package/dist/commands/ts-check.ts +50 -0
  37. package/dist/common/Logger/Logger/index.d.ts +1 -1
  38. package/dist/common/Logger/Logger/index.js +42 -55
  39. package/dist/common/Logger/Logger/index.ts +53 -0
  40. package/dist/common/Logger/Logger/types.js +1 -5
  41. package/dist/common/Logger/Logger/types.ts +1 -0
  42. package/dist/common/Logger/index.d.ts +1 -1
  43. package/dist/common/Logger/index.js +42 -55
  44. package/dist/common/Logger/index.ts +53 -0
  45. package/dist/common/Logger/types.js +1 -5
  46. package/dist/common/Logger/types.ts +1 -0
  47. package/dist/common/asyncLocalStorage/index.js +8 -16
  48. package/dist/common/asyncLocalStorage/index.ts +9 -0
  49. package/dist/common/cleanEnvironmentVariables.js +12 -16
  50. package/dist/common/cleanEnvironmentVariables.ts +10 -0
  51. package/dist/common/constants.js +1 -7
  52. package/dist/common/constants.ts +1 -0
  53. package/dist/common/contextStorageStateHelpers.js +38 -47
  54. package/dist/common/contextStorageStateHelpers.ts +43 -0
  55. package/dist/common/getPlaywrightConstructs.d.ts +1 -1
  56. package/dist/common/getPlaywrightConstructs.js +196 -177
  57. package/dist/common/getPlaywrightConstructs.ts +181 -0
  58. package/dist/common/jwtTokenManager.js +79 -76
  59. package/dist/common/jwtTokenManager.ts +71 -0
  60. package/dist/common/runApi/errors.d.ts +1 -1
  61. package/dist/common/runApi/errors.js +150 -159
  62. package/dist/common/runApi/errors.ts +154 -0
  63. package/dist/common/runApi/index.d.ts +4 -4
  64. package/dist/common/runApi/index.js +220 -269
  65. package/dist/common/runApi/index.ts +253 -0
  66. package/dist/common/runApi/types.d.ts +1 -1
  67. package/dist/common/runApi/types.js +56 -49
  68. package/dist/common/runApi/types.ts +43 -0
  69. package/dist/common/settingsSchema.js +10 -15
  70. package/dist/common/settingsSchema.ts +9 -0
  71. package/dist/common/telemetry.js +30 -28
  72. package/dist/common/telemetry.ts +23 -0
  73. package/dist/index.d.ts +4 -4
  74. package/dist/index.js +4 -69
  75. package/dist/index.ts +4 -0
  76. package/dist/runtime/RunError.d.ts +1 -1
  77. package/dist/runtime/RunError.js +11 -18
  78. package/dist/runtime/RunError.ts +12 -0
  79. package/dist/runtime/downloadDirectory.js +13 -19
  80. package/dist/runtime/downloadDirectory.ts +13 -0
  81. package/dist/runtime/enums.d.ts +1 -11
  82. package/dist/runtime/enums.js +12 -18
  83. package/dist/runtime/enums.ts +12 -0
  84. package/dist/runtime/executionHelpers.test.ts +51 -0
  85. package/dist/runtime/export.d.ts +1 -202
  86. package/dist/runtime/extendPayload.d.ts +1 -1
  87. package/dist/runtime/extendPayload.js +15 -21
  88. package/dist/runtime/extendPayload.ts +15 -0
  89. package/dist/runtime/extendTimeout.js +21 -28
  90. package/dist/runtime/extendTimeout.ts +24 -0
  91. package/dist/runtime/index.d.ts +7 -7
  92. package/dist/runtime/index.js +6 -53
  93. package/dist/runtime/index.ts +6 -0
  94. package/dist/runtime/requestMoreInfo.js +16 -23
  95. package/dist/runtime/requestMoreInfo.ts +18 -0
  96. package/dist/runtime/runInfo.d.ts +1 -1
  97. package/dist/runtime/runInfo.js +14 -21
  98. package/dist/runtime/runInfo.ts +15 -0
  99. package/package.json +3 -2
  100. package/tsconfig.json +1 -1
  101. package/dist/runtime/enums.d.js +0 -5
  102. package/dist/runtime/executionHelpers.test.js +0 -53
  103. package/dist/runtime/export.d.js +0 -5
@@ -1,29 +1,24 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _getFirstLineNumber = _interopRequireDefault(require("./getFirstLineNumber"));
5
- var fs = _interopRequireWildcard(require("fs"));
6
- var path = _interopRequireWildcard(require("path"));
7
- 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); }
8
- 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 && Object.prototype.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; }
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- (0, _vitest.describe)("getFirstLineNumber", () => {
1
+ import { expect, describe, it, beforeAll, afterAll } from "vitest";
2
+ import getFirstLineNumber from "./getFirstLineNumber.js";
3
+ import * as fs from "fs";
4
+ import * as path from "path";
5
+ describe("getFirstLineNumber", () => {
11
6
  const testFilesDir = path.join(__dirname, "testFiles");
12
7
  const createTestFile = (fileName, content) => {
13
8
  const filePath = path.join(testFilesDir, fileName);
14
9
  fs.writeFileSync(filePath, content);
15
10
  return filePath;
16
11
  };
17
- (0, _vitest.beforeAll)(() => {
12
+ beforeAll(() => {
18
13
  if (!fs.existsSync(testFilesDir)) {
19
14
  fs.mkdirSync(testFilesDir);
20
15
  }
21
16
  });
22
- (0, _vitest.afterAll)(() => {
17
+ afterAll(() => {
23
18
  fs.readdirSync(testFilesDir).forEach(file => fs.unlinkSync(path.join(testFilesDir, file)));
24
19
  fs.rmdirSync(testFilesDir);
25
20
  });
26
- (0, _vitest.it)("correctly identifies first line in a default exported named function", async () => {
21
+ it("correctly identifies first line in a default exported named function", async () => {
27
22
  const filePath = createTestFile("defaultFunction.ts", `import {
28
23
  EnhancedPlaywrightPage,
29
24
  EnhancedPlaywrightBrowserContext,
@@ -46,10 +41,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
46
41
  return { done: "true", name: "custom name from api1" };
47
42
  }
48
43
  `);
49
- const result = await (0, _getFirstLineNumber.default)(filePath);
50
- (0, _vitest.expect)(result.lineNumber).toBe(4);
44
+ const result = await getFirstLineNumber(filePath);
45
+ expect(result.lineNumber).toBe(4);
51
46
  });
52
- (0, _vitest.it)("correctly identifies first line in a default exported anonymous function", async () => {
47
+ it("correctly identifies first line in a default exported anonymous function", async () => {
53
48
  const filePath = createTestFile("defaultFunction.ts", `import {
54
49
  EnhancedPlaywrightPage,
55
50
  EnhancedPlaywrightBrowserContext,
@@ -72,10 +67,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
72
67
  return { done: "true", name: "custom name from api1" };
73
68
  }
74
69
  `);
75
- const result = await (0, _getFirstLineNumber.default)(filePath);
76
- (0, _vitest.expect)(result.lineNumber).toBe(4);
70
+ const result = await getFirstLineNumber(filePath);
71
+ expect(result.lineNumber).toBe(4);
77
72
  });
78
- (0, _vitest.it)("correctly identifies first line in a default exported function identifier", async () => {
73
+ it("correctly identifies first line in a default exported function identifier", async () => {
79
74
  const filePath = createTestFile("defaultFunction.ts", `import {
80
75
  EnhancedPlaywrightPage,
81
76
  EnhancedPlaywrightBrowserContext,
@@ -99,10 +94,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
99
94
  }
100
95
  export default runApi;
101
96
  `);
102
- const result = await (0, _getFirstLineNumber.default)(filePath);
103
- (0, _vitest.expect)(result.lineNumber).toBe(4);
97
+ const result = await getFirstLineNumber(filePath);
98
+ expect(result.lineNumber).toBe(4);
104
99
  });
105
- (0, _vitest.it)("correctly identifies first line in a file with multiple exports including a default function", async () => {
100
+ it("correctly identifies first line in a file with multiple exports including a default function", async () => {
106
101
  const filePath = createTestFile("multipleExports.ts", `import {
107
102
  EnhancedPlaywrightPage,
108
103
  EnhancedPlaywrightBrowserContext,
@@ -126,10 +121,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
126
121
  return { done: "true", name: "custom name from api1" };
127
122
  }
128
123
  export default runApi;`);
129
- const result = await (0, _getFirstLineNumber.default)(filePath);
130
- (0, _vitest.expect)(result.lineNumber).toBe(7);
124
+ const result = await getFirstLineNumber(filePath);
125
+ expect(result.lineNumber).toBe(7);
131
126
  });
132
- (0, _vitest.it)("correctly identifies first line in a default exported arrow function identifier", async () => {
127
+ it("correctly identifies first line in a default exported arrow function identifier", async () => {
133
128
  const filePath = createTestFile("multipleExports.ts", `import {
134
129
  EnhancedPlaywrightPage,
135
130
  EnhancedPlaywrightBrowserContext,
@@ -152,10 +147,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
152
147
  return { done: "true", name: "custom name from api1" };
153
148
  }
154
149
  export default runApi;`);
155
- const result = await (0, _getFirstLineNumber.default)(filePath);
156
- (0, _vitest.expect)(result.lineNumber).toBe(4);
150
+ const result = await getFirstLineNumber(filePath);
151
+ expect(result.lineNumber).toBe(4);
157
152
  });
158
- (0, _vitest.it)("correctly identifies first line in a default exported anonymous arrow function", async () => {
153
+ it("correctly identifies first line in a default exported anonymous arrow function", async () => {
159
154
  const filePath = createTestFile("multipleExports.ts", `import {
160
155
  EnhancedPlaywrightPage,
161
156
  EnhancedPlaywrightBrowserContext,
@@ -177,52 +172,52 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
177
172
  await page.getByLabel("Search Wikipedia").press("Enter");
178
173
  return { done: "true", name: "custom name from api1" };
179
174
  };`);
180
- const result = await (0, _getFirstLineNumber.default)(filePath);
181
- (0, _vitest.expect)(result.lineNumber).toBe(4);
175
+ const result = await getFirstLineNumber(filePath);
176
+ expect(result.lineNumber).toBe(4);
182
177
  });
183
- (0, _vitest.it)("identifies first executable line in a default exported arrow function", async () => {
178
+ it("identifies first executable line in a default exported arrow function", async () => {
184
179
  const filePath = createTestFile("defaultArrowFunction.ts", `export default () => {
185
180
  console.log("Hello, Arrow World!");
186
181
  };`);
187
- const result = await (0, _getFirstLineNumber.default)(filePath);
188
- (0, _vitest.expect)(result.lineNumber).toBe(4);
182
+ const result = await getFirstLineNumber(filePath);
183
+ expect(result.lineNumber).toBe(4);
189
184
  });
190
- (0, _vitest.it)("identifies first executable line within nested functions of a default export", async () => {
185
+ it("identifies first executable line within nested functions of a default export", async () => {
191
186
  const filePath = createTestFile("nestedFunctions.ts", `const x = 4;
192
187
  export default function() {
193
188
  const nested = (x) => console.log("Nested function call");
194
189
  nested(x);
195
190
  }`);
196
- const result = await (0, _getFirstLineNumber.default)(filePath);
197
- (0, _vitest.expect)(result.lineNumber).toBe(5);
191
+ const result = await getFirstLineNumber(filePath);
192
+ expect(result.lineNumber).toBe(5);
198
193
  });
199
- (0, _vitest.it)("handles async default exported function correctly", async () => {
194
+ it("handles async default exported function correctly", async () => {
200
195
  const filePath = createTestFile("asyncDefaultFunction.ts", `export default async function() {
201
196
  await Promise.resolve(console.log("Async Hello, World!"));
202
197
  }`);
203
- const result = await (0, _getFirstLineNumber.default)(filePath);
204
- (0, _vitest.expect)(result.lineNumber).toBe(4);
198
+ const result = await getFirstLineNumber(filePath);
199
+ expect(result.lineNumber).toBe(4);
205
200
  });
206
- (0, _vitest.it)("returns -1 for a default exported class", async () => {
201
+ it("returns -1 for a default exported class", async () => {
207
202
  const filePath = createTestFile("defaultClass.ts", `export default class MyClass {
208
203
  constructor() {}
209
204
  }`);
210
- const result = await (0, _getFirstLineNumber.default)(filePath);
211
- (0, _vitest.expect)(result.lineNumber).toBe(-1);
205
+ const result = await getFirstLineNumber(filePath);
206
+ expect(result.lineNumber).toBe(-1);
212
207
  });
213
- (0, _vitest.it)("returns -1 for a default exported variable", async () => {
208
+ it("returns -1 for a default exported variable", async () => {
214
209
  const filePath = createTestFile("defaultVariable.ts", `export default 42;`);
215
- const result = await (0, _getFirstLineNumber.default)(filePath);
216
- (0, _vitest.expect)(result.lineNumber).toBe(-1);
210
+ const result = await getFirstLineNumber(filePath);
211
+ expect(result.lineNumber).toBe(-1);
217
212
  });
218
- (0, _vitest.it)("returns -1 when there is no default export", async () => {
213
+ it("returns -1 when there is no default export", async () => {
219
214
  const filePath = createTestFile("noDefaultExport.ts", `export const foo = () => console.log("bar");`);
220
- const result = await (0, _getFirstLineNumber.default)(filePath);
221
- (0, _vitest.expect)(result.lineNumber).toBe(-1);
215
+ const result = await getFirstLineNumber(filePath);
216
+ expect(result.lineNumber).toBe(-1);
222
217
  });
223
- (0, _vitest.it)("returns -1 for an empty file", async () => {
218
+ it("returns -1 for an empty file", async () => {
224
219
  const filePath = createTestFile("emptyFile.ts", ``);
225
- const result = await (0, _getFirstLineNumber.default)(filePath);
226
- (0, _vitest.expect)(result.lineNumber).toBe(-1);
220
+ const result = await getFirstLineNumber(filePath);
221
+ expect(result.lineNumber).toBe(-1);
227
222
  });
228
223
  });
@@ -0,0 +1,96 @@
1
+ import { ts, Project, ModuleKind, ScriptTarget, Node } from "ts-morph";
2
+ import { SourceMapConsumer } from "source-map";
3
+ function compileTypeScript(apiFilePath) {
4
+ const compilerOptions = {
5
+ lib: ["dom", "es2020"],
6
+ sourceMap: true,
7
+ inlineSourceMap: true,
8
+ inlineSources: true,
9
+ declaration: false,
10
+ noEmit: false,
11
+ module: ModuleKind.CommonJS,
12
+ target: ScriptTarget.ES2020
13
+ };
14
+ const project = new Project({
15
+ compilerOptions
16
+ });
17
+ const sourceFile = project.addSourceFileAtPath(apiFilePath);
18
+ const outputJS = project.emitToMemory({
19
+ targetSourceFile: sourceFile
20
+ });
21
+ const outputJSText = outputJS.getFiles()[0].text;
22
+ return {
23
+ sourceFile,
24
+ outputJSText
25
+ };
26
+ }
27
+ export function findFirstExecutableLine(sourceFile) {
28
+ var _defaultExportSymbol$;
29
+ let functionBody;
30
+ const defaultExportSymbol = sourceFile.getDefaultExportSymbol();
31
+ const defaultExportDeclaration = defaultExportSymbol === null || defaultExportSymbol === void 0 || (_defaultExportSymbol$ = defaultExportSymbol.getDeclarations()) === null || _defaultExportSymbol$ === void 0 ? void 0 : _defaultExportSymbol$[0];
32
+ if (defaultExportDeclaration) {
33
+ if (defaultExportDeclaration.getKind() === ts.SyntaxKind.FunctionDeclaration) {
34
+ functionBody = defaultExportDeclaration.getBody();
35
+ } else {
36
+ const exportAssignments = sourceFile.getExportAssignments();
37
+ for (const exportAssignment of exportAssignments) {
38
+ const expression = exportAssignment.getExpression();
39
+ if (!expression) continue;
40
+ if (expression.getKind() === ts.SyntaxKind.Identifier || expression.getKind() === ts.SyntaxKind.FunctionExpression || expression.getKind() === ts.SyntaxKind.ArrowFunction) {
41
+ var _sourceFile$getVariab;
42
+ const identifier = expression.getText();
43
+ const possiblyExportedFunction = sourceFile.getFunction(identifier) || ((_sourceFile$getVariab = sourceFile.getVariableStatement(identifier)) === null || _sourceFile$getVariab === void 0 ? void 0 : _sourceFile$getVariab.getDescendants().find(node => node.getKind() === ts.SyntaxKind.FunctionExpression || node.getKind() === ts.SyntaxKind.ArrowFunction));
44
+ if (possiblyExportedFunction) {
45
+ functionBody = possiblyExportedFunction.getBody();
46
+ break;
47
+ }
48
+ }
49
+ if (Node.hasBody(expression) && (expression.getKind() === ts.SyntaxKind.FunctionExpression || expression.getKind() === ts.SyntaxKind.ArrowFunction)) {
50
+ functionBody = expression.getBody();
51
+ break;
52
+ }
53
+ }
54
+ }
55
+ }
56
+ if (!functionBody || !Node.isStatemented(functionBody)) {
57
+ return -1;
58
+ }
59
+ if (functionBody.getStatements().length === 0) {
60
+ return -1;
61
+ }
62
+ const position = functionBody.getStatements()[0].getStart();
63
+ return sourceFile.getLineAndColumnAtPos(position);
64
+ }
65
+ async function getSourceMap(jsCode) {
66
+ const sourceMapBase64 = jsCode.substring(jsCode.lastIndexOf("//# sourceMappingURL=data:application/json;base64,") + "//# sourceMappingURL=data:application/json;base64,".length);
67
+ const sourceMapText = Buffer.from(sourceMapBase64, "base64").toString("utf-8");
68
+ const sourceMap = JSON.parse(sourceMapText);
69
+ return new SourceMapConsumer(sourceMap);
70
+ }
71
+ async function mapFirstLineNumberBySourceMap(sourceFileName, jsCode, line, column) {
72
+ const sourceMap = await getSourceMap(jsCode);
73
+ const generatedLineNumber = sourceMap.generatedPositionFor({
74
+ source: sourceFileName,
75
+ line,
76
+ column
77
+ }).line;
78
+ if (!generatedLineNumber) return -1;
79
+ return generatedLineNumber;
80
+ }
81
+ export default async function getFirstLineNumber(apiFilePath) {
82
+ const sourceFileName = apiFilePath.split("/").pop() ?? apiFilePath;
83
+ const {
84
+ sourceFile,
85
+ outputJSText
86
+ } = compileTypeScript(apiFilePath);
87
+ const result = findFirstExecutableLine(sourceFile);
88
+ if (result === -1) return {
89
+ sourceFileName,
90
+ lineNumber: -1
91
+ };
92
+ return {
93
+ sourceFileName,
94
+ lineNumber: await mapFirstLineNumberBySourceMap(sourceFileName, outputJSText, result.line, result.column)
95
+ };
96
+ }
@@ -1,10 +1,5 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.sendBreakPointOnToClient = void 0;
7
- const sendBreakPointOnToClient = (sourceFileName, lineNumber) => {
8
- console.log(`breakpoint on ${sourceFileName}:${lineNumber}`);
1
+ // Send information to the parent process where it should continue the debugger
2
+ // This is handled by DebuggingProcessManager
3
+ export const sendBreakPointOnToClient = (sourceFileName, lineNumber) => {
4
+ console.log(`breakpoint on ${sourceFileName}:${lineNumber}`);
9
5
  };
10
- exports.sendBreakPointOnToClient = sendBreakPointOnToClient;
@@ -0,0 +1,3 @@
1
+ export const sendBreakPointOnToClient = (sourceFileName, lineNumber) => {
2
+ console.log(`breakpoint on ${sourceFileName}:${lineNumber}`);
3
+ };
@@ -1,33 +1,23 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getFullPathInProject = getFullPathInProject;
7
- exports.listProjectFilesAndFolders = listProjectFilesAndFolders;
8
- var path = _interopRequireWildcard(require("path"));
9
- var fs = _interopRequireWildcard(require("fs-extra"));
10
- var _dotenv = _interopRequireDefault(require("dotenv"));
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- 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); }
13
- 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 && Object.prototype.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; }
14
- _dotenv.default.config();
15
- function getFullPathInProject(...paths) {
16
- return path.resolve(process.cwd(), process.env.ROOT || "./", ...paths);
1
+ import * as path from "path";
2
+ import * as fs from "fs-extra";
3
+ import dotenv from "dotenv";
4
+ dotenv.config();
5
+ // TODO: todo-identity handle identity instances
6
+ export function getFullPathInProject(...paths) {
7
+ return path.resolve(process.cwd(), process.env.ROOT || "./", ...paths);
8
+ }
9
+ export async function listProjectFilesAndFolders() {
10
+ const projectPath = path.resolve(process.cwd(), process.env.ROOT || "./");
11
+ try {
12
+ const files = await fs.readdir(projectPath, { withFileTypes: true });
13
+ return files.map((file) => ({
14
+ type: file.isDirectory() ? "Folder" : "File",
15
+ fullPath: path.join(projectPath, file.name),
16
+ name: file.name,
17
+ }));
18
+ }
19
+ catch (err) {
20
+ console.error("Error reading the directory:", err);
21
+ throw err;
22
+ }
17
23
  }
18
- async function listProjectFilesAndFolders() {
19
- const projectPath = path.resolve(process.cwd(), process.env.ROOT || "./");
20
- try {
21
- const files = await fs.readdir(projectPath, {
22
- withFileTypes: true
23
- });
24
- return files.map(file => ({
25
- type: file.isDirectory() ? "Folder" : "File",
26
- fullPath: path.join(projectPath, file.name),
27
- name: file.name
28
- }));
29
- } catch (err) {
30
- console.error("Error reading the directory:", err);
31
- throw err;
32
- }
33
- }
@@ -0,0 +1,23 @@
1
+ import * as path from "path";
2
+ import * as fs from "fs-extra";
3
+ import dotenv from "dotenv";
4
+ dotenv.config();
5
+ export function getFullPathInProject(...paths) {
6
+ return path.resolve(process.cwd(), process.env.ROOT || "./", ...paths);
7
+ }
8
+ export async function listProjectFilesAndFolders() {
9
+ const projectPath = path.resolve(process.cwd(), process.env.ROOT || "./");
10
+ try {
11
+ const files = await fs.readdir(projectPath, {
12
+ withFileTypes: true
13
+ });
14
+ return files.map(file => ({
15
+ type: file.isDirectory() ? "Folder" : "File",
16
+ fullPath: path.join(projectPath, file.name),
17
+ name: file.name
18
+ }));
19
+ } catch (err) {
20
+ console.error("Error reading the directory:", err);
21
+ throw err;
22
+ }
23
+ }
@@ -1,28 +1,20 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getSettings = getSettings;
7
- var _fileUtils = require("./fileUtils");
8
- var _settingsSchema = require("../../../common/settingsSchema");
9
- var _fsExtra = require("fs-extra");
10
- async function getSettings() {
11
- const settingsFilePath = (0, _fileUtils.getFullPathInProject)("Intuned.json");
12
- console.log("loading settings");
13
- const settings = await (0, _fsExtra.readJSON)(settingsFilePath);
14
- if (settings) {
15
- const parsed = _settingsSchema.settingsSchema.safeParse(settings);
16
- console.log(parsed);
17
- if (parsed.success) {
18
- return parsed.data;
19
- } else {
20
- throw new Error(parsed.error.message);
1
+ import { getFullPathInProject } from "./fileUtils.js";
2
+ import { settingsSchema, } from "../../../common/settingsSchema";
3
+ import { readJSON } from "fs-extra";
4
+ export async function getSettings() {
5
+ const settingsFilePath = getFullPathInProject("Intuned.json");
6
+ console.log("loading settings");
7
+ const settings = await readJSON(settingsFilePath);
8
+ if (settings) {
9
+ const parsed = settingsSchema.safeParse(settings);
10
+ console.log(parsed);
11
+ if (parsed.success) {
12
+ return parsed.data;
13
+ }
14
+ else {
15
+ // ToDo: why does the type not work here?
16
+ throw new Error(parsed.error.message);
17
+ }
21
18
  }
22
- }
23
- return {
24
- authSessions: {
25
- enabled: false
26
- }
27
- };
28
- }
19
+ return { authSessions: { enabled: false } };
20
+ }
@@ -0,0 +1,22 @@
1
+ import { getFullPathInProject } from "./fileUtils.js";
2
+ import { settingsSchema } from "../../../common/settingsSchema";
3
+ import { readJSON } from "fs-extra";
4
+ export async function getSettings() {
5
+ const settingsFilePath = getFullPathInProject("Intuned.json");
6
+ console.log("loading settings");
7
+ const settings = await readJSON(settingsFilePath);
8
+ if (settings) {
9
+ const parsed = settingsSchema.safeParse(settings);
10
+ console.log(parsed);
11
+ if (parsed.success) {
12
+ return parsed.data;
13
+ } else {
14
+ throw new Error(parsed.error.message);
15
+ }
16
+ }
17
+ return {
18
+ authSessions: {
19
+ enabled: false
20
+ }
21
+ };
22
+ }
@@ -1,45 +1,45 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.JSONUnixSocket = void 0;
7
- class JSONUnixSocket {
8
- static LENGTH_HEADER_LENGTH = 4;
9
- constructor(socket) {
10
- this.socket = socket;
11
- }
12
- sendJSON(data) {
13
- const dataToSend = JSON.stringify(data);
14
- const length = Buffer.byteLength(dataToSend);
15
- const buffer = Buffer.alloc(JSONUnixSocket.LENGTH_HEADER_LENGTH + length);
16
- buffer.writeUInt32BE(length, 0);
17
- buffer.write(dataToSend, JSONUnixSocket.LENGTH_HEADER_LENGTH);
18
- this.socket.write(buffer);
19
- }
20
- async *receiveJSON() {
21
- let buffer = Buffer.alloc(0);
22
- const endPromise = new Promise((resolve, reject) => {
23
- this.socket.once("end", () => {
24
- console.log("end");
25
- resolve();
26
- });
27
- this.socket.once("error", reject);
28
- });
29
- while (true) {
30
- const chunk = await Promise.race([new Promise(resolve => this.socket.once("data", data => resolve(data))), endPromise]);
31
- if (!(chunk instanceof Buffer)) {
32
- break;
33
- }
34
- buffer = Buffer.concat([buffer, chunk]);
35
- const length = buffer.readUInt32BE(0);
36
- if (buffer.length < length + JSONUnixSocket.LENGTH_HEADER_LENGTH) {
37
- continue;
38
- }
39
- const data = buffer.subarray(JSONUnixSocket.LENGTH_HEADER_LENGTH, length + JSONUnixSocket.LENGTH_HEADER_LENGTH);
40
- buffer = buffer.subarray(length + JSONUnixSocket.LENGTH_HEADER_LENGTH);
41
- yield JSON.parse(data.toString());
1
+ export class JSONUnixSocket {
2
+ constructor(socket) {
3
+ this.socket = socket;
4
+ }
5
+ sendJSON(data) {
6
+ const dataToSend = JSON.stringify(data);
7
+ // calculate length
8
+ const length = Buffer.byteLength(dataToSend);
9
+ // create buffer
10
+ const buffer = Buffer.alloc(JSONUnixSocket.LENGTH_HEADER_LENGTH + length);
11
+ // write length in big endian
12
+ buffer.writeUInt32BE(length, 0);
13
+ // write data
14
+ buffer.write(dataToSend, JSONUnixSocket.LENGTH_HEADER_LENGTH);
15
+ this.socket.write(buffer);
16
+ }
17
+ async *receiveJSON() {
18
+ let buffer = Buffer.alloc(0);
19
+ const endPromise = new Promise((resolve, reject) => {
20
+ this.socket.once("end", () => {
21
+ console.log("end");
22
+ resolve();
23
+ });
24
+ this.socket.once("error", reject);
25
+ });
26
+ while (true) {
27
+ const chunk = await Promise.race([
28
+ new Promise((resolve) => this.socket.once("data", (data) => resolve(data))),
29
+ endPromise,
30
+ ]);
31
+ if (!(chunk instanceof Buffer)) {
32
+ break;
33
+ }
34
+ buffer = Buffer.concat([buffer, chunk]);
35
+ const length = buffer.readUInt32BE(0);
36
+ if (buffer.length < length + JSONUnixSocket.LENGTH_HEADER_LENGTH) {
37
+ continue;
38
+ }
39
+ const data = buffer.subarray(JSONUnixSocket.LENGTH_HEADER_LENGTH, length + JSONUnixSocket.LENGTH_HEADER_LENGTH);
40
+ buffer = buffer.subarray(length + JSONUnixSocket.LENGTH_HEADER_LENGTH);
41
+ yield JSON.parse(data.toString());
42
+ }
42
43
  }
43
- }
44
44
  }
45
- exports.JSONUnixSocket = JSONUnixSocket;
45
+ JSONUnixSocket.LENGTH_HEADER_LENGTH = 4;
@@ -0,0 +1,38 @@
1
+ export class JSONUnixSocket {
2
+ static LENGTH_HEADER_LENGTH = 4;
3
+ constructor(socket) {
4
+ this.socket = socket;
5
+ }
6
+ sendJSON(data) {
7
+ const dataToSend = JSON.stringify(data);
8
+ const length = Buffer.byteLength(dataToSend);
9
+ const buffer = Buffer.alloc(JSONUnixSocket.LENGTH_HEADER_LENGTH + length);
10
+ buffer.writeUInt32BE(length, 0);
11
+ buffer.write(dataToSend, JSONUnixSocket.LENGTH_HEADER_LENGTH);
12
+ this.socket.write(buffer);
13
+ }
14
+ async *receiveJSON() {
15
+ let buffer = Buffer.alloc(0);
16
+ const endPromise = new Promise((resolve, reject) => {
17
+ this.socket.once("end", () => {
18
+ console.log("end");
19
+ resolve();
20
+ });
21
+ this.socket.once("error", reject);
22
+ });
23
+ while (true) {
24
+ const chunk = await Promise.race([new Promise(resolve => this.socket.once("data", data => resolve(data))), endPromise]);
25
+ if (!(chunk instanceof Buffer)) {
26
+ break;
27
+ }
28
+ buffer = Buffer.concat([buffer, chunk]);
29
+ const length = buffer.readUInt32BE(0);
30
+ if (buffer.length < length + JSONUnixSocket.LENGTH_HEADER_LENGTH) {
31
+ continue;
32
+ }
33
+ const data = buffer.subarray(JSONUnixSocket.LENGTH_HEADER_LENGTH, length + JSONUnixSocket.LENGTH_HEADER_LENGTH);
34
+ buffer = buffer.subarray(length + JSONUnixSocket.LENGTH_HEADER_LENGTH);
35
+ yield JSON.parse(data.toString());
36
+ }
37
+ }
38
+ }
@@ -1,31 +1,29 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.moveWebTemplateFiles = void 0;
7
- var fs = _interopRequireWildcard(require("fs-extra"));
8
- var path = _interopRequireWildcard(require("path"));
9
- var _fileUtils = require("./fileUtils");
10
- 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); }
11
- 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 && Object.prototype.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; }
12
- const moveWebTemplateFiles = async () => {
13
- await fs.remove("./intuned");
14
- await fs.ensureDir("./intuned");
15
- const currentFileLocation = path.resolve(__dirname, "..", "..", "..", "..", "WebTemplate");
16
- await fs.copy(`${currentFileLocation}`, "./intuned/WebTemplate", {
17
- filter: (src, dest) => {
18
- if (src.includes(".d.ts")) {
19
- return false;
20
- }
21
- return true;
1
+ import * as fs from "fs-extra";
2
+ import * as path from "path";
3
+ import { getFullPathInProject, listProjectFilesAndFolders, } from "./fileUtils.js";
4
+ export const moveWebTemplateFiles = async () => {
5
+ await fs.remove("./intuned");
6
+ await fs.ensureDir("./intuned");
7
+ const currentFileLocation = path.resolve(__dirname, "..", "..", "..", "..", "WebTemplate");
8
+ // copy WebTemplate to ./intuned
9
+ await fs.copy(`${currentFileLocation}`, "./intuned/WebTemplate", {
10
+ filter: (src, dest) => {
11
+ if (src.includes(".d.ts")) {
12
+ return false;
13
+ }
14
+ return true;
15
+ },
16
+ });
17
+ const filesAndFolders = await listProjectFilesAndFolders();
18
+ const pathsIgnoreList = [
19
+ getFullPathInProject("intuned"),
20
+ getFullPathInProject("node_modules"),
21
+ getFullPathInProject("package.json"),
22
+ getFullPathInProject("yarn.lock"),
23
+ getFullPathInProject(".env"),
24
+ ];
25
+ const filesToCopy = filesAndFolders.filter((file) => !pathsIgnoreList.includes(file.fullPath));
26
+ for (const file of filesToCopy) {
27
+ await fs.copy(file.fullPath, `./intuned/WebTemplate/${file.name}`);
22
28
  }
23
- });
24
- const filesAndFolders = await (0, _fileUtils.listProjectFilesAndFolders)();
25
- const pathsIgnoreList = [(0, _fileUtils.getFullPathInProject)("intuned"), (0, _fileUtils.getFullPathInProject)("node_modules"), (0, _fileUtils.getFullPathInProject)("package.json"), (0, _fileUtils.getFullPathInProject)("yarn.lock"), (0, _fileUtils.getFullPathInProject)(".env")];
26
- const filesToCopy = filesAndFolders.filter(file => !pathsIgnoreList.includes(file.fullPath));
27
- for (const file of filesToCopy) {
28
- await fs.copy(file.fullPath, `./intuned/WebTemplate/${file.name}`);
29
- }
30
29
  };
31
- exports.moveWebTemplateFiles = moveWebTemplateFiles;