@intuned/runtime 1.0.5 → 1.1.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 +53 -31
- package/LICENSE +43 -0
- package/bin/check-auth-session +3 -0
- package/bin/cli-build +3 -0
- package/bin/create-auth-session +3 -0
- package/bin/deploy +3 -0
- package/bin/init +3 -0
- package/bin/run-api +3 -0
- package/dist/commands/cli-auth-sessions/check.d.ts +2 -0
- package/dist/commands/cli-auth-sessions/check.js +40 -0
- package/dist/commands/cli-auth-sessions/create.d.ts +2 -0
- package/dist/commands/cli-auth-sessions/create.js +53 -0
- package/dist/commands/cli-auth-sessions/utils.d.ts +28 -0
- package/dist/commands/cli-auth-sessions/utils.js +285 -0
- package/dist/commands/cli-build/cli-build.d.ts +2 -0
- package/dist/commands/cli-build/cli-build.js +20 -0
- package/dist/commands/common/projectExclusions.d.ts +2 -0
- package/dist/commands/common/projectExclusions.js +8 -0
- package/dist/commands/common/tsNodeImport.d.ts +2 -1
- package/dist/commands/common/tsNodeImport.js +19 -5
- package/dist/commands/deploy/deploy.d.ts +2 -0
- package/dist/commands/deploy/deploy.js +47 -0
- package/dist/commands/deploy/utils.d.ts +16 -0
- package/dist/commands/deploy/utils.js +408 -0
- package/dist/commands/init/init.d.ts +2 -0
- package/dist/commands/init/init.js +22 -0
- package/dist/commands/init/utils.d.ts +11 -0
- package/dist/commands/init/utils.js +181 -0
- package/dist/commands/interface/run.js +30 -3
- package/dist/commands/run-api-cli/run-api.d.ts +2 -0
- package/dist/commands/run-api-cli/run-api.js +57 -0
- package/dist/commands/run-api-cli/utils.d.ts +9 -0
- package/dist/commands/run-api-cli/utils.js +144 -0
- package/dist/common/asyncLocalStorage/index.d.ts +1 -1
- package/dist/common/asyncLocalStorage/index.js +2 -2
- package/dist/common/cli/cliReadme.d.ts +1 -0
- package/dist/common/cli/cliReadme.js +92 -0
- package/dist/common/cli/constants.d.ts +33 -0
- package/dist/common/cli/constants.js +39 -0
- package/dist/common/cli/types.d.ts +74 -0
- package/dist/common/cli/types.js +13 -0
- package/dist/common/cli/utils.d.ts +6 -0
- package/dist/common/cli/utils.js +35 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +3 -2
- package/dist/common/runApi/index.d.ts +1 -0
- package/dist/common/runApi/index.js +9 -2
- package/dist/common/runApi/types.d.ts +7 -1
- package/package.json +15 -4
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.tsNodeImport =
|
|
6
|
+
exports.tsNodeImport = void 0;
|
|
7
|
+
var _neverthrow = require("neverthrow");
|
|
7
8
|
var _fileUtils = require("./utils/fileUtils");
|
|
8
9
|
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); }
|
|
9
10
|
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; }
|
|
10
|
-
async
|
|
11
|
+
const tsNodeImport = async apiName => {
|
|
11
12
|
require("ts-node").register({
|
|
12
13
|
transpileOnly: true,
|
|
13
14
|
compilerOptions: {
|
|
@@ -15,6 +16,19 @@ async function tsNodeImport(apiName) {
|
|
|
15
16
|
}
|
|
16
17
|
});
|
|
17
18
|
const path = (0, _fileUtils.getFullPathInProject)(...apiName.split("/"));
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
try {
|
|
20
|
+
const imported = await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(path);
|
|
21
|
+
return (0, _neverthrow.ok)(imported);
|
|
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;
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
var _utils2 = require("../../common/cli/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
|
+
const {
|
|
16
|
+
isValid,
|
|
17
|
+
errorMessage
|
|
18
|
+
} = await (0, _utils.validateIntunedProject)();
|
|
19
|
+
if (!isValid) {
|
|
20
|
+
const userErrorMesage = `Project to be deployed is not a valid Intuned project: ${errorMessage}, modify and check again`;
|
|
21
|
+
throw new Error(userErrorMesage);
|
|
22
|
+
}
|
|
23
|
+
const _projectName = projectName || (await (0, _utils2.getSettingIntunedJSON)("projectName"));
|
|
24
|
+
if (!_projectName) {
|
|
25
|
+
throw new Error("Project name is required");
|
|
26
|
+
}
|
|
27
|
+
const projectNameValidation = (0, _utils.validateProjectName)(_projectName);
|
|
28
|
+
if (!projectNameValidation.isValid) {
|
|
29
|
+
throw new Error(projectNameValidation.errorMessage);
|
|
30
|
+
}
|
|
31
|
+
const auth = await (0, _utils2.getAuthCredentials)(options);
|
|
32
|
+
const {
|
|
33
|
+
deployDone,
|
|
34
|
+
projectId,
|
|
35
|
+
deployErrorMessage
|
|
36
|
+
} = await (0, _utils.deployProject)(_projectName, auth);
|
|
37
|
+
if (!deployDone) {
|
|
38
|
+
throw new Error(`Project not deployed: ${deployErrorMessage}`);
|
|
39
|
+
}
|
|
40
|
+
const url = (0, _utils2.getBaseUrl)();
|
|
41
|
+
console.log(_chalk.default.green(`\n✅ Project "${_projectName}" deployed successfully!` + `\n\nYou can check your project on the platform: ${_chalk.default.bold(`${url}/projects/${projectId}/details`)}\n`));
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error(_chalk.default.red(`\n${error.message}`));
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
_commander.program.parse(process.argv);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AuthCredentials, FileSystemTree } from "../../common/cli/types";
|
|
2
|
+
export declare function convertProjectToCodeTree(projectPath: string): Promise<FileSystemTree>;
|
|
3
|
+
export declare function deployProject(projectName: string, auth: AuthCredentials): Promise<{
|
|
4
|
+
deployDone: boolean;
|
|
5
|
+
projectId?: string;
|
|
6
|
+
deployErrorMessage?: string;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const validateProjectName: (projectName: string) => {
|
|
9
|
+
isValid: boolean;
|
|
10
|
+
errorMessage?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const validateIntunedProject: () => Promise<{
|
|
13
|
+
isValid: boolean;
|
|
14
|
+
errorMessage?: string;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const runBuild: () => Promise<boolean>;
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.convertProjectToCodeTree = convertProjectToCodeTree;
|
|
7
|
+
exports.deployProject = deployProject;
|
|
8
|
+
exports.validateProjectName = exports.validateIntunedProject = exports.runBuild = void 0;
|
|
9
|
+
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
10
|
+
var path = _interopRequireWildcard(require("path"));
|
|
11
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
12
|
+
var _minimatch = require("minimatch");
|
|
13
|
+
var _zod = require("zod");
|
|
14
|
+
var _child_process = require("child_process");
|
|
15
|
+
var _util = require("util");
|
|
16
|
+
var _projectExclusions = _interopRequireDefault(require("../common/projectExclusions"));
|
|
17
|
+
var _constants = require("../../common/cli/constants");
|
|
18
|
+
var _utils = require("../../common/cli/utils");
|
|
19
|
+
var _utils2 = require("../init/utils");
|
|
20
|
+
var _lodash = require("lodash");
|
|
21
|
+
var _uuid = require("uuid");
|
|
22
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
23
|
+
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); }
|
|
24
|
+
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; }
|
|
25
|
+
const execPromise = (0, _util.promisify)(_child_process.exec);
|
|
26
|
+
function ignoreFilesByPattern(filePath, patterns, projectPath) {
|
|
27
|
+
const relativePath = path.relative(projectPath, filePath);
|
|
28
|
+
if (relativePath.startsWith("node_modules")) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
for (const pattern of patterns) {
|
|
32
|
+
if (!pattern || pattern.startsWith("#")) continue;
|
|
33
|
+
if (pattern.startsWith("!")) {
|
|
34
|
+
if ((0, _minimatch.minimatch)(relativePath, pattern.substring(1))) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
} else if ((0, _minimatch.minimatch)(relativePath, pattern)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
function listFilesNotIgnored(projectPath, ignorePatterns) {
|
|
44
|
+
const results = [];
|
|
45
|
+
function traverseDirectory(dirPath) {
|
|
46
|
+
try {
|
|
47
|
+
const entries = fs.readdirSync(dirPath);
|
|
48
|
+
for (const entry of entries) {
|
|
49
|
+
const fullPath = path.join(dirPath, entry);
|
|
50
|
+
if (ignoreFilesByPattern(fullPath, ignorePatterns, projectPath)) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const stats = fs.statSync(fullPath);
|
|
55
|
+
if (stats.isDirectory()) {
|
|
56
|
+
traverseDirectory(fullPath);
|
|
57
|
+
} else if (stats.isFile()) {
|
|
58
|
+
results.push(path.relative(projectPath, fullPath));
|
|
59
|
+
}
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.log(_chalk.default.yellow(`Warning: Could not access ${fullPath}`));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.log(_chalk.default.yellow(`Warning: Could not read directory ${dirPath}`));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
traverseDirectory(projectPath);
|
|
69
|
+
return results;
|
|
70
|
+
}
|
|
71
|
+
async function convertProjectToCodeTree(projectPath) {
|
|
72
|
+
const filesToDeploy = listFilesNotIgnored(projectPath, _projectExclusions.default);
|
|
73
|
+
console.log(_chalk.default.cyan("\nFiles to be deployed:"));
|
|
74
|
+
const filesToDeployText = "\n " + filesToDeploy.join("\n ");
|
|
75
|
+
console.log(filesToDeployText);
|
|
76
|
+
function readDirectory(dirPath) {
|
|
77
|
+
const tree = {};
|
|
78
|
+
try {
|
|
79
|
+
const entries = fs.readdirSync(dirPath);
|
|
80
|
+
for (const entry of entries) {
|
|
81
|
+
const entryPath = path.join(dirPath, entry);
|
|
82
|
+
if (ignoreFilesByPattern(entryPath, _projectExclusions.default, projectPath)) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const stats = fs.statSync(entryPath);
|
|
87
|
+
if (stats.isFile()) {
|
|
88
|
+
try {
|
|
89
|
+
const content = fs.readFileSync(entryPath, "utf-8");
|
|
90
|
+
tree[entry] = {
|
|
91
|
+
file: {
|
|
92
|
+
contents: content
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.log(_chalk.default.yellow(`Warning: Could not read file ${entryPath}`));
|
|
97
|
+
}
|
|
98
|
+
} else if (stats.isDirectory()) {
|
|
99
|
+
const subTree = readDirectory(entryPath);
|
|
100
|
+
if (Object.keys(subTree).length > 0) {
|
|
101
|
+
tree[entry] = {
|
|
102
|
+
directory: subTree
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.log(_chalk.default.yellow(`Warning: Could not access ${entryPath}`));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.log(_chalk.default.yellow(`Warning: Could not read directory ${dirPath}`));
|
|
112
|
+
}
|
|
113
|
+
return tree;
|
|
114
|
+
}
|
|
115
|
+
console.log(_chalk.default.cyan("\n📦 Building project..."));
|
|
116
|
+
const tree = readDirectory(projectPath);
|
|
117
|
+
await mapToIDEParams(tree);
|
|
118
|
+
return tree;
|
|
119
|
+
}
|
|
120
|
+
async function deployProject(projectName, auth) {
|
|
121
|
+
const {
|
|
122
|
+
workspaceId,
|
|
123
|
+
apiKey
|
|
124
|
+
} = auth;
|
|
125
|
+
const baseUrl = (0, _utils.getBaseUrl)();
|
|
126
|
+
const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create`;
|
|
127
|
+
const headers = {
|
|
128
|
+
"x-api-key": apiKey,
|
|
129
|
+
"Content-Type": "application/json"
|
|
130
|
+
};
|
|
131
|
+
const projectPath = process.cwd();
|
|
132
|
+
const codeTree = await convertProjectToCodeTree(projectPath);
|
|
133
|
+
codeTree["tsconfig.json"] = {
|
|
134
|
+
file: {
|
|
135
|
+
contents: JSON.stringify(_constants.tsConfigCli, null, 2)
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const deployProjectPayload = {
|
|
139
|
+
name: projectName,
|
|
140
|
+
codeTree,
|
|
141
|
+
isCli: true,
|
|
142
|
+
language: "typescript"
|
|
143
|
+
};
|
|
144
|
+
const response = await fetch(url, {
|
|
145
|
+
headers,
|
|
146
|
+
method: "POST",
|
|
147
|
+
body: JSON.stringify(deployProjectPayload)
|
|
148
|
+
});
|
|
149
|
+
if (!response.ok) {
|
|
150
|
+
if (response.status === 401) {
|
|
151
|
+
throw new Error(`Invalid API key. Please check your API key and try again.`);
|
|
152
|
+
}
|
|
153
|
+
throw new Error(`Error deploying project`);
|
|
154
|
+
}
|
|
155
|
+
const startTime = Date.now();
|
|
156
|
+
console.log(_chalk.default.greenBright(`\n🚀 Deploying project...`));
|
|
157
|
+
return new Promise((resolve, reject) => {
|
|
158
|
+
const checkInterval = setInterval(async () => {
|
|
159
|
+
try {
|
|
160
|
+
const {
|
|
161
|
+
status,
|
|
162
|
+
message,
|
|
163
|
+
projectId
|
|
164
|
+
} = await checkIntunedProjectDeployStatus(workspaceId, projectName, apiKey);
|
|
165
|
+
if (status === "completed" || status === "failed" || status === "not_found") {
|
|
166
|
+
clearInterval(checkInterval);
|
|
167
|
+
resolve(status === "completed" ? {
|
|
168
|
+
deployDone: true,
|
|
169
|
+
projectId
|
|
170
|
+
} : {
|
|
171
|
+
deployDone: false,
|
|
172
|
+
projectId: "",
|
|
173
|
+
deployErrorMessage: message
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
const elapsedTime = Date.now() - startTime;
|
|
177
|
+
if (elapsedTime > _constants.PROJECT_DEPLOY_TIMEOUT) {
|
|
178
|
+
clearInterval(checkInterval);
|
|
179
|
+
reject(new Error(`Deployment timed out after ${Math.floor(_constants.PROJECT_DEPLOY_TIMEOUT / 1000 / 60)} minutes`));
|
|
180
|
+
}
|
|
181
|
+
} catch (error) {
|
|
182
|
+
clearInterval(checkInterval);
|
|
183
|
+
reject(error);
|
|
184
|
+
}
|
|
185
|
+
}, 5000);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
const validateProjectName = projectName => {
|
|
189
|
+
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, {
|
|
190
|
+
message: "Name cannot be a UUID"
|
|
191
|
+
});
|
|
192
|
+
const validation = nameSchema.safeParse(projectName);
|
|
193
|
+
if (!validation.success) {
|
|
194
|
+
return {
|
|
195
|
+
isValid: false,
|
|
196
|
+
errorMessage: validation.error.errors[0].message
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
isValid: true
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
exports.validateProjectName = validateProjectName;
|
|
204
|
+
const validateIntunedProject = async () => {
|
|
205
|
+
const currentDirectoryToDeploy = process.cwd();
|
|
206
|
+
const validationSteps = [{
|
|
207
|
+
name: "build",
|
|
208
|
+
check: async () => {
|
|
209
|
+
try {
|
|
210
|
+
const buildResult = await runBuild();
|
|
211
|
+
if (!buildResult) {
|
|
212
|
+
return {
|
|
213
|
+
isValid: false,
|
|
214
|
+
errorMessage: "Build failed"
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
isValid: true
|
|
219
|
+
};
|
|
220
|
+
} catch (error) {
|
|
221
|
+
return {
|
|
222
|
+
isValid: false,
|
|
223
|
+
errorMessage: "Build failed"
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}, {
|
|
228
|
+
name: "package.json",
|
|
229
|
+
check: async () => {
|
|
230
|
+
try {
|
|
231
|
+
var _packageJson$dependen;
|
|
232
|
+
const packageJsonPath = path.join(currentDirectoryToDeploy, "package.json");
|
|
233
|
+
await fs.exists(packageJsonPath);
|
|
234
|
+
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, {
|
|
235
|
+
encoding: "utf-8"
|
|
236
|
+
}));
|
|
237
|
+
const userCodePlaywrightVersion = (_packageJson$dependen = packageJson.dependencies) === null || _packageJson$dependen === void 0 ? void 0 : _packageJson$dependen.playwright;
|
|
238
|
+
if (userCodePlaywrightVersion !== _constants.CURRENT_PLAYWRIGHT_VERSION) {
|
|
239
|
+
return {
|
|
240
|
+
isValid: false,
|
|
241
|
+
errorMessage: `Playwright version mismatch: expected ${_constants.CURRENT_PLAYWRIGHT_VERSION}, found ${userCodePlaywrightVersion || "none"}`
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
isValid: true
|
|
246
|
+
};
|
|
247
|
+
} catch (error) {
|
|
248
|
+
return {
|
|
249
|
+
isValid: false,
|
|
250
|
+
errorMessage: "Package.json file not found or cannot be read"
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}, {
|
|
255
|
+
name: "Intuned.json",
|
|
256
|
+
check: async () => {
|
|
257
|
+
try {
|
|
258
|
+
const intunedJsonPath = path.join(currentDirectoryToDeploy, "Intuned.json");
|
|
259
|
+
await fs.exists(intunedJsonPath);
|
|
260
|
+
return {
|
|
261
|
+
isValid: true
|
|
262
|
+
};
|
|
263
|
+
} catch (error) {
|
|
264
|
+
return {
|
|
265
|
+
isValid: false,
|
|
266
|
+
errorMessage: "Intuned.json file not found"
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}, {
|
|
271
|
+
name: "api folder",
|
|
272
|
+
check: async () => {
|
|
273
|
+
try {
|
|
274
|
+
const apiFolderPath = path.join(currentDirectoryToDeploy, "api");
|
|
275
|
+
await fs.access(apiFolderPath);
|
|
276
|
+
return {
|
|
277
|
+
isValid: true
|
|
278
|
+
};
|
|
279
|
+
} catch (error) {
|
|
280
|
+
return {
|
|
281
|
+
isValid: false,
|
|
282
|
+
errorMessage: "API folder not found"
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}];
|
|
287
|
+
for (const step of validationSteps) {
|
|
288
|
+
const result = await step.check();
|
|
289
|
+
if (!result.isValid) {
|
|
290
|
+
return result;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
isValid: true
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
exports.validateIntunedProject = validateIntunedProject;
|
|
298
|
+
const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey) => {
|
|
299
|
+
try {
|
|
300
|
+
const baseUrl = (0, _utils.getBaseUrl)();
|
|
301
|
+
const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create/${projectName}/result`;
|
|
302
|
+
const headers = {
|
|
303
|
+
"x-api-key": apiKey,
|
|
304
|
+
"Content-Type": "application/json"
|
|
305
|
+
};
|
|
306
|
+
const response = await fetch(url, {
|
|
307
|
+
headers,
|
|
308
|
+
method: "GET"
|
|
309
|
+
});
|
|
310
|
+
if (response.status === 404) {
|
|
311
|
+
return {
|
|
312
|
+
status: "not_found",
|
|
313
|
+
message: "Project not found"
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
if (!response.ok) {
|
|
317
|
+
throw new Error("Error querying deployment status");
|
|
318
|
+
}
|
|
319
|
+
const data = await response.json();
|
|
320
|
+
if (data.status) {
|
|
321
|
+
return {
|
|
322
|
+
status: data.status,
|
|
323
|
+
message: data.message,
|
|
324
|
+
projectId: data.projectId
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
status: "failed",
|
|
329
|
+
message: `Deployment failed, please try again: ${data.message}`
|
|
330
|
+
};
|
|
331
|
+
} catch (e) {
|
|
332
|
+
throw new Error(`Error during deployment`);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
const runBuild = async () => {
|
|
336
|
+
const currentProjectDirectory = process.cwd();
|
|
337
|
+
console.log(_chalk.default.yellow("Running build..."));
|
|
338
|
+
const distPath = path.join(currentProjectDirectory, "dist");
|
|
339
|
+
if (await fs.exists(distPath)) {
|
|
340
|
+
await fs.remove(distPath);
|
|
341
|
+
}
|
|
342
|
+
const buildCommand = "tsc";
|
|
343
|
+
try {
|
|
344
|
+
await execPromise(buildCommand, {
|
|
345
|
+
cwd: currentProjectDirectory
|
|
346
|
+
});
|
|
347
|
+
console.log(_chalk.default.green("🏗️ Build completed successfully"));
|
|
348
|
+
return true;
|
|
349
|
+
} catch (error) {
|
|
350
|
+
console.error(_chalk.default.red(`Build failed: ${error.message}`));
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
exports.runBuild = runBuild;
|
|
355
|
+
async function mapToIDEParams(tree) {
|
|
356
|
+
if (!tree) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (!tree["parameters"] || (0, _utils2._isFileNode)(tree["parameters"])) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const apiParametersMap = {};
|
|
363
|
+
const cliParameters = Object.keys(tree["parameters"].directory);
|
|
364
|
+
const ____testParameters = {
|
|
365
|
+
directory: {}
|
|
366
|
+
};
|
|
367
|
+
for (const parameterKey of cliParameters) {
|
|
368
|
+
const parameter = tree["parameters"].directory[parameterKey];
|
|
369
|
+
if ((0, _utils2._isDirectoryNode)(parameter)) {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
if ((0, _lodash.isEmpty)(parameter.file.contents)) {
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
const parameterPayload = JSON.parse(parameter.file.contents);
|
|
376
|
+
if (!parameterPayload["__api-name"]) {
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
const api = parameterPayload["__api-name"];
|
|
380
|
+
const {
|
|
381
|
+
"__api-name": _,
|
|
382
|
+
...parameterValue
|
|
383
|
+
} = parameterPayload;
|
|
384
|
+
const testParameter = {
|
|
385
|
+
name: parameterKey.replace(".json", ""),
|
|
386
|
+
lastUsed: false,
|
|
387
|
+
id: (0, _uuid.v4)(),
|
|
388
|
+
value: JSON.stringify(parameterValue)
|
|
389
|
+
};
|
|
390
|
+
if (!apiParametersMap[api]) {
|
|
391
|
+
apiParametersMap[api] = [];
|
|
392
|
+
}
|
|
393
|
+
apiParametersMap[api].push(testParameter);
|
|
394
|
+
}
|
|
395
|
+
for (const api in apiParametersMap) {
|
|
396
|
+
if (apiParametersMap[api].length > 0) {
|
|
397
|
+
apiParametersMap[api][apiParametersMap[api].length - 1].lastUsed = true;
|
|
398
|
+
}
|
|
399
|
+
____testParameters.directory[`${api}.json`] = {
|
|
400
|
+
file: {
|
|
401
|
+
contents: JSON.stringify(apiParametersMap[api], null, 2)
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
delete tree["parameters"];
|
|
406
|
+
tree["____testParameters"] = ____testParameters;
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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").action(async templateName => {
|
|
13
|
+
try {
|
|
14
|
+
const template = await (0, _utils.selectTemplate)(templateName);
|
|
15
|
+
const isTargetDirectoryEmpty = await (0, _utils.checkEmptyDirectory)();
|
|
16
|
+
await (0, _utils.scaffoldProject)(template, isTargetDirectoryEmpty);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error(_chalk.default.red(`\n${error.message}`));
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
_commander.program.parse(process.argv);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DirectoryNode, FileNode, FileSystemTree } from "../../common/cli/types";
|
|
2
|
+
export declare function _isDirectoryNode(node: DirectoryNode | FileNode): node is DirectoryNode;
|
|
3
|
+
export declare function _isFileNode(node: DirectoryNode | FileNode): node is FileNode;
|
|
4
|
+
export declare function mountFiles(cwd: string, tree: FileSystemTree): Promise<void>;
|
|
5
|
+
export declare function checkEmptyDirectory(): Promise<boolean>;
|
|
6
|
+
export declare function getAuthCredentials(options: any): {
|
|
7
|
+
workspaceId: any;
|
|
8
|
+
apiKey: any;
|
|
9
|
+
};
|
|
10
|
+
export declare function selectTemplate(templateName: any): Promise<any>;
|
|
11
|
+
export declare function scaffoldProject(templateId: string, isTargetDirectoryEmpty: boolean): Promise<void>;
|