@intuned/runtime-dev 1.0.6-cli.8.3.4 → 1.0.6-dev-1
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/bin/intuned-run +3 -0
- package/dist/commands/deploy/deploy.js +10 -23
- package/dist/commands/deploy/utils.d.ts +2 -11
- package/dist/commands/deploy/utils.js +58 -211
- package/dist/commands/init/init.js +4 -3
- package/dist/{common/cli → commands/init}/types.js +1 -1
- package/dist/commands/init/utils.d.ts +3 -3
- package/dist/commands/init/utils.js +24 -57
- package/dist/commands/intuned-run/intuned-run.d.ts +4 -0
- package/dist/commands/intuned-run/intuned-run.js +84 -0
- package/dist/commands/intuned-run/utils.d.ts +1 -0
- package/dist/{common/cli → commands/intuned-run}/utils.js +21 -18
- package/dist/common/asyncLocalStorage/index.d.ts +1 -1
- package/dist/common/asyncLocalStorage/index.js +2 -2
- package/my-intuned-project/Intuned.json +15 -0
- package/my-intuned-project/api/book-details.ts +46 -0
- package/my-intuned-project/api/books-all.ts +68 -0
- package/my-intuned-project/package.json +36 -0
- package/my-intuned-project/params/bookInput.json +3 -0
- package/my-intuned-project/yarn.lock +4539 -0
- package/package.json +5 -11
- package/bin/cli-build +0 -3
- package/bin/run-api +0 -3
- package/dist/commands/cli-build/cli-build.d.ts +0 -2
- package/dist/commands/cli-build/cli-build.js +0 -20
- package/dist/commands/common/projectExclusions.d.ts +0 -2
- package/dist/commands/common/projectExclusions.js +0 -8
- package/dist/commands/run-api-cli/run-api.d.ts +0 -2
- package/dist/commands/run-api-cli/run-api.js +0 -48
- package/dist/commands/run-api-cli/utils.d.ts +0 -7
- package/dist/commands/run-api-cli/utils.js +0 -94
- package/dist/common/cli/cliReadme.d.ts +0 -1
- package/dist/common/cli/cliReadme.js +0 -65
- package/dist/common/cli/constants.d.ts +0 -24
- package/dist/common/cli/constants.js +0 -30
- package/dist/common/cli/utils.d.ts +0 -5
- /package/bin/{deploy → intuned-deploy} +0 -0
- /package/bin/{init → intuned-init} +0 -0
- /package/dist/{common/cli → commands/init}/types.d.ts +0 -0
package/bin/intuned-run
ADDED
|
@@ -4,41 +4,28 @@
|
|
|
4
4
|
var _commander = require("commander");
|
|
5
5
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
6
6
|
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
7
|
-
var _utils = require("
|
|
8
|
-
var _utils2 = require("
|
|
7
|
+
var _utils = require("../init/utils");
|
|
8
|
+
var _utils2 = require("./utils");
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
_dotenv.default.config({
|
|
11
11
|
path: `.env`
|
|
12
12
|
});
|
|
13
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
14
|
try {
|
|
15
|
-
|
|
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) {
|
|
15
|
+
if (!projectName) {
|
|
25
16
|
throw new Error("Project name is required");
|
|
26
17
|
}
|
|
27
|
-
const projectNameValidation = (0,
|
|
18
|
+
const projectNameValidation = (0, _utils2.validateProjectName)(projectName);
|
|
28
19
|
if (!projectNameValidation.isValid) {
|
|
29
20
|
throw new Error(projectNameValidation.errorMessage);
|
|
30
21
|
}
|
|
31
|
-
const auth =
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
deployErrorMessage
|
|
36
|
-
} = await (0, _utils.deployProject)(_projectName, auth);
|
|
37
|
-
if (!deployDone) {
|
|
38
|
-
throw new Error(`Project not deployed: ${deployErrorMessage}`);
|
|
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");
|
|
39
26
|
}
|
|
40
|
-
const url =
|
|
41
|
-
console.log(_chalk.default.green(`\n
|
|
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`));
|
|
42
29
|
} catch (error) {
|
|
43
30
|
console.error(_chalk.default.red(`\n${error.message}`));
|
|
44
31
|
process.exit(1);
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import { AuthCredentials, FileSystemTree } from "
|
|
1
|
+
import { AuthCredentials, FileSystemTree } from "../init/types";
|
|
2
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
|
-
}>;
|
|
3
|
+
export declare function deployProject(projectName: string, auth: AuthCredentials): Promise<boolean>;
|
|
8
4
|
export declare const validateProjectName: (projectName: string) => {
|
|
9
5
|
isValid: boolean;
|
|
10
6
|
errorMessage?: string;
|
|
11
7
|
};
|
|
12
|
-
export declare const validateIntunedProject: () => Promise<{
|
|
13
|
-
isValid: boolean;
|
|
14
|
-
errorMessage?: string;
|
|
15
|
-
}>;
|
|
16
|
-
export declare const runBuild: () => Promise<boolean>;
|
|
@@ -5,21 +5,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.convertProjectToCodeTree = convertProjectToCodeTree;
|
|
7
7
|
exports.deployProject = deployProject;
|
|
8
|
-
exports.validateProjectName =
|
|
9
|
-
var fs = _interopRequireWildcard(require("fs
|
|
8
|
+
exports.validateProjectName = void 0;
|
|
9
|
+
var fs = _interopRequireWildcard(require("fs"));
|
|
10
10
|
var path = _interopRequireWildcard(require("path"));
|
|
11
11
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
12
|
-
var _minimatch = require("minimatch");
|
|
12
|
+
var _minimatch = _interopRequireDefault(require("minimatch"));
|
|
13
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
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
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); }
|
|
20
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; }
|
|
21
|
-
|
|
22
|
-
|
|
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) {
|
|
23
25
|
const relativePath = path.relative(projectPath, filePath);
|
|
24
26
|
if (relativePath.startsWith("node_modules")) {
|
|
25
27
|
return true;
|
|
@@ -27,10 +29,10 @@ function ignoreFilesByPattern(filePath, patterns, projectPath) {
|
|
|
27
29
|
for (const pattern of patterns) {
|
|
28
30
|
if (!pattern || pattern.startsWith("#")) continue;
|
|
29
31
|
if (pattern.startsWith("!")) {
|
|
30
|
-
if ((0, _minimatch.
|
|
32
|
+
if ((0, _minimatch.default)(relativePath, pattern.substring(1))) {
|
|
31
33
|
return false;
|
|
32
34
|
}
|
|
33
|
-
} else if ((0, _minimatch.
|
|
35
|
+
} else if ((0, _minimatch.default)(relativePath, pattern)) {
|
|
34
36
|
return true;
|
|
35
37
|
}
|
|
36
38
|
}
|
|
@@ -43,7 +45,7 @@ function listFilesNotIgnored(projectPath, ignorePatterns) {
|
|
|
43
45
|
const entries = fs.readdirSync(dirPath);
|
|
44
46
|
for (const entry of entries) {
|
|
45
47
|
const fullPath = path.join(dirPath, entry);
|
|
46
|
-
if (
|
|
48
|
+
if (matchesGitignorePatterns(fullPath, ignorePatterns, projectPath)) {
|
|
47
49
|
continue;
|
|
48
50
|
}
|
|
49
51
|
try {
|
|
@@ -65,17 +67,45 @@ function listFilesNotIgnored(projectPath, ignorePatterns) {
|
|
|
65
67
|
return results;
|
|
66
68
|
}
|
|
67
69
|
async function convertProjectToCodeTree(projectPath) {
|
|
68
|
-
const
|
|
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
|
+
}
|
|
69
94
|
console.log(_chalk.default.cyan("\nFiles to be deployed:"));
|
|
70
|
-
|
|
71
|
-
|
|
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)}`));
|
|
72
102
|
function readDirectory(dirPath) {
|
|
73
103
|
const tree = {};
|
|
74
104
|
try {
|
|
75
105
|
const entries = fs.readdirSync(dirPath);
|
|
76
106
|
for (const entry of entries) {
|
|
77
107
|
const entryPath = path.join(dirPath, entry);
|
|
78
|
-
if (
|
|
108
|
+
if (matchesGitignorePatterns(entryPath, ignorePatterns, projectPath)) {
|
|
79
109
|
continue;
|
|
80
110
|
}
|
|
81
111
|
try {
|
|
@@ -108,7 +138,7 @@ async function convertProjectToCodeTree(projectPath) {
|
|
|
108
138
|
}
|
|
109
139
|
return tree;
|
|
110
140
|
}
|
|
111
|
-
console.log(_chalk.default.cyan("\
|
|
141
|
+
console.log(_chalk.default.cyan("\nBuilding project..."));
|
|
112
142
|
const tree = readDirectory(projectPath);
|
|
113
143
|
return tree;
|
|
114
144
|
}
|
|
@@ -117,7 +147,7 @@ async function deployProject(projectName, auth) {
|
|
|
117
147
|
workspaceId,
|
|
118
148
|
apiKey
|
|
119
149
|
} = auth;
|
|
120
|
-
const baseUrl =
|
|
150
|
+
const baseUrl = "https://rauf-2.intuned-team-local.com";
|
|
121
151
|
const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create`;
|
|
122
152
|
const headers = {
|
|
123
153
|
"x-api-key": apiKey,
|
|
@@ -125,14 +155,9 @@ async function deployProject(projectName, auth) {
|
|
|
125
155
|
};
|
|
126
156
|
const projectPath = process.cwd();
|
|
127
157
|
const codeTree = await convertProjectToCodeTree(projectPath);
|
|
128
|
-
codeTree["tsconfig.json"] = {
|
|
129
|
-
file: {
|
|
130
|
-
contents: JSON.stringify(_constants.tsConfigCli, null, 2)
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
158
|
const deployProjectPayload = {
|
|
134
159
|
name: projectName,
|
|
135
|
-
codeTree,
|
|
160
|
+
codeTree: codeTree,
|
|
136
161
|
isCli: true,
|
|
137
162
|
language: "typescript"
|
|
138
163
|
};
|
|
@@ -142,43 +167,16 @@ async function deployProject(projectName, auth) {
|
|
|
142
167
|
body: JSON.stringify(deployProjectPayload)
|
|
143
168
|
});
|
|
144
169
|
if (!response.ok) {
|
|
145
|
-
if (response.status === 401) {
|
|
146
|
-
throw new Error(`Invalid API key. Please check your API key and try again.`);
|
|
147
|
-
}
|
|
148
170
|
throw new Error(`Error deploying project`);
|
|
149
171
|
}
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
projectId
|
|
159
|
-
} = await checkIntunedProjectDeployStatus(workspaceId, projectName, apiKey);
|
|
160
|
-
if (status === "completed" || status === "failed" || status === "not_found") {
|
|
161
|
-
clearInterval(checkInterval);
|
|
162
|
-
resolve(status === "completed" ? {
|
|
163
|
-
deployDone: true,
|
|
164
|
-
projectId
|
|
165
|
-
} : {
|
|
166
|
-
deployDone: false,
|
|
167
|
-
projectId: "",
|
|
168
|
-
deployErrorMessage: message
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
const elapsedTime = Date.now() - startTime;
|
|
172
|
-
if (elapsedTime > _constants.PROJECT_DEPLOY_TIMEOUT) {
|
|
173
|
-
clearInterval(checkInterval);
|
|
174
|
-
reject(new Error(`Deployment timed out after ${Math.floor(_constants.PROJECT_DEPLOY_TIMEOUT / 1000 / 60)} minutes`));
|
|
175
|
-
}
|
|
176
|
-
} catch (error) {
|
|
177
|
-
clearInterval(checkInterval);
|
|
178
|
-
reject(error);
|
|
179
|
-
}
|
|
180
|
-
}, 5000);
|
|
181
|
-
});
|
|
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;
|
|
182
180
|
}
|
|
183
181
|
const validateProjectName = projectName => {
|
|
184
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, {
|
|
@@ -195,155 +193,4 @@ const validateProjectName = projectName => {
|
|
|
195
193
|
isValid: true
|
|
196
194
|
};
|
|
197
195
|
};
|
|
198
|
-
exports.validateProjectName = validateProjectName;
|
|
199
|
-
const validateIntunedProject = async () => {
|
|
200
|
-
const currentDirectoryToDeploy = process.cwd();
|
|
201
|
-
const validationSteps = [{
|
|
202
|
-
name: "build",
|
|
203
|
-
check: async () => {
|
|
204
|
-
try {
|
|
205
|
-
const buildResult = await runBuild();
|
|
206
|
-
if (!buildResult) {
|
|
207
|
-
return {
|
|
208
|
-
isValid: false,
|
|
209
|
-
errorMessage: "Build failed"
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
return {
|
|
213
|
-
isValid: true
|
|
214
|
-
};
|
|
215
|
-
} catch (error) {
|
|
216
|
-
return {
|
|
217
|
-
isValid: false,
|
|
218
|
-
errorMessage: "Build failed"
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}, {
|
|
223
|
-
name: "package.json",
|
|
224
|
-
check: async () => {
|
|
225
|
-
try {
|
|
226
|
-
var _packageJson$dependen;
|
|
227
|
-
const packageJsonPath = path.join(currentDirectoryToDeploy, "package.json");
|
|
228
|
-
await fs.exists(packageJsonPath);
|
|
229
|
-
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, {
|
|
230
|
-
encoding: "utf-8"
|
|
231
|
-
}));
|
|
232
|
-
const userCodePlaywrightVersion = (_packageJson$dependen = packageJson.dependencies) === null || _packageJson$dependen === void 0 ? void 0 : _packageJson$dependen.playwright;
|
|
233
|
-
if (userCodePlaywrightVersion !== _constants.CURRENT_PLAYWRIGHT_VERSION) {
|
|
234
|
-
return {
|
|
235
|
-
isValid: false,
|
|
236
|
-
errorMessage: `Playwright version mismatch: expected ${_constants.CURRENT_PLAYWRIGHT_VERSION}, found ${userCodePlaywrightVersion || "none"}`
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
isValid: true
|
|
241
|
-
};
|
|
242
|
-
} catch (error) {
|
|
243
|
-
return {
|
|
244
|
-
isValid: false,
|
|
245
|
-
errorMessage: "Package.json file not found or cannot be read"
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}, {
|
|
250
|
-
name: "Intuned.json",
|
|
251
|
-
check: async () => {
|
|
252
|
-
try {
|
|
253
|
-
const intunedJsonPath = path.join(currentDirectoryToDeploy, "Intuned.json");
|
|
254
|
-
await fs.exists(intunedJsonPath);
|
|
255
|
-
return {
|
|
256
|
-
isValid: true
|
|
257
|
-
};
|
|
258
|
-
} catch (error) {
|
|
259
|
-
return {
|
|
260
|
-
isValid: false,
|
|
261
|
-
errorMessage: "Intuned.json file not found"
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}, {
|
|
266
|
-
name: "api folder",
|
|
267
|
-
check: async () => {
|
|
268
|
-
try {
|
|
269
|
-
const apiFolderPath = path.join(currentDirectoryToDeploy, "api");
|
|
270
|
-
await fs.access(apiFolderPath);
|
|
271
|
-
return {
|
|
272
|
-
isValid: true
|
|
273
|
-
};
|
|
274
|
-
} catch (error) {
|
|
275
|
-
return {
|
|
276
|
-
isValid: false,
|
|
277
|
-
errorMessage: "API folder not found"
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}];
|
|
282
|
-
for (const step of validationSteps) {
|
|
283
|
-
const result = await step.check();
|
|
284
|
-
if (!result.isValid) {
|
|
285
|
-
return result;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return {
|
|
289
|
-
isValid: true
|
|
290
|
-
};
|
|
291
|
-
};
|
|
292
|
-
exports.validateIntunedProject = validateIntunedProject;
|
|
293
|
-
const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey) => {
|
|
294
|
-
try {
|
|
295
|
-
const baseUrl = process.env.INTUNED_API_DEV_DOMAIN || `https://app.intuned.io`;
|
|
296
|
-
const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create/${projectName}/result`;
|
|
297
|
-
const headers = {
|
|
298
|
-
"x-api-key": apiKey,
|
|
299
|
-
"Content-Type": "application/json"
|
|
300
|
-
};
|
|
301
|
-
const response = await fetch(url, {
|
|
302
|
-
headers,
|
|
303
|
-
method: "GET"
|
|
304
|
-
});
|
|
305
|
-
if (response.status === 404) {
|
|
306
|
-
return {
|
|
307
|
-
status: "not_found",
|
|
308
|
-
message: "Project not found"
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
if (!response.ok) {
|
|
312
|
-
throw new Error("Error querying deployment status");
|
|
313
|
-
}
|
|
314
|
-
const data = await response.json();
|
|
315
|
-
if (data.status) {
|
|
316
|
-
return {
|
|
317
|
-
status: data.status,
|
|
318
|
-
message: data.message,
|
|
319
|
-
projectId: data.projectId
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
return {
|
|
323
|
-
status: "failed",
|
|
324
|
-
message: `Deployment failed, please try again: ${data.message}`
|
|
325
|
-
};
|
|
326
|
-
} catch (e) {
|
|
327
|
-
throw new Error(`Error during deployment`);
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
const runBuild = async () => {
|
|
331
|
-
const currentProjectDirectory = process.cwd();
|
|
332
|
-
console.log(_chalk.default.yellow("Running build..."));
|
|
333
|
-
const distPath = path.join(currentProjectDirectory, "dist");
|
|
334
|
-
if (await fs.exists(distPath)) {
|
|
335
|
-
await fs.remove(distPath);
|
|
336
|
-
}
|
|
337
|
-
const buildCommand = "tsc";
|
|
338
|
-
try {
|
|
339
|
-
await execPromise(buildCommand, {
|
|
340
|
-
cwd: currentProjectDirectory
|
|
341
|
-
});
|
|
342
|
-
console.log(_chalk.default.green("🏗️ Build completed successfully"));
|
|
343
|
-
return true;
|
|
344
|
-
} catch (error) {
|
|
345
|
-
console.error(_chalk.default.red(`Build failed: ${error.message}`));
|
|
346
|
-
return false;
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
exports.runBuild = runBuild;
|
|
196
|
+
exports.validateProjectName = validateProjectName;
|
|
@@ -9,11 +9,12 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
9
9
|
_dotenv.default.config({
|
|
10
10
|
path: `.env`
|
|
11
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 => {
|
|
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
13
|
try {
|
|
14
|
+
const auth = (0, _utils.getAuthCredentials)(options);
|
|
14
15
|
const template = await (0, _utils.selectTemplate)(templateName);
|
|
15
|
-
|
|
16
|
-
await (0, _utils.scaffoldProject)(template,
|
|
16
|
+
await (0, _utils.checkEmptyDirectory)();
|
|
17
|
+
await (0, _utils.scaffoldProject)(template, auth);
|
|
17
18
|
} catch (error) {
|
|
18
19
|
console.error(_chalk.default.red(`\n${error.message}`));
|
|
19
20
|
process.exit(1);
|
|
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.templateIds = void 0;
|
|
7
|
-
const templateIds = exports.templateIds = ["default", "empty", "linkedin-recorder", "api-auth-sessions", "nested-scheduling", "ai-extractors", "npm-auth-sessions"];
|
|
7
|
+
const templateIds = exports.templateIds = ["default", "empty", "linkedin-recorder", "api-auth-sessions", "nested-scheduling", "ai-extractors", "npm-auth-sessions", "python-empty"];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { FileSystemTree } from "
|
|
1
|
+
import { AuthCredentials, FileSystemTree } from "./types";
|
|
2
2
|
export declare function mountFiles(cwd: string, tree: FileSystemTree): Promise<void>;
|
|
3
|
-
export declare function checkEmptyDirectory(): Promise<
|
|
3
|
+
export declare function checkEmptyDirectory(): Promise<void>;
|
|
4
4
|
export declare function getAuthCredentials(options: any): {
|
|
5
5
|
workspaceId: any;
|
|
6
6
|
apiKey: any;
|
|
7
7
|
};
|
|
8
8
|
export declare function selectTemplate(templateName: any): Promise<any>;
|
|
9
|
-
export declare function scaffoldProject(templateId: string,
|
|
9
|
+
export declare function scaffoldProject(templateId: string, authCredentials: AuthCredentials): Promise<void>;
|
|
@@ -9,14 +9,11 @@ exports.mountFiles = mountFiles;
|
|
|
9
9
|
exports.scaffoldProject = scaffoldProject;
|
|
10
10
|
exports.selectTemplate = selectTemplate;
|
|
11
11
|
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
12
|
-
var _types = require("
|
|
12
|
+
var _types = require("./types");
|
|
13
13
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
14
14
|
var _inquirer = _interopRequireDefault(require("inquirer"));
|
|
15
15
|
var _path = _interopRequireDefault(require("path"));
|
|
16
16
|
var _boxen = _interopRequireDefault(require("boxen"));
|
|
17
|
-
var _projectExclusions = _interopRequireDefault(require("../common/projectExclusions"));
|
|
18
|
-
var _constants = require("../../common/cli/constants");
|
|
19
|
-
var _cliReadme = require("../../common/cli/cliReadme");
|
|
20
17
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
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); }
|
|
22
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; }
|
|
@@ -46,8 +43,10 @@ async function checkEmptyDirectory() {
|
|
|
46
43
|
throw new Error("The current path is not a directory.");
|
|
47
44
|
}
|
|
48
45
|
const files = await fs.readdir(currentDir);
|
|
49
|
-
const significantFiles = files.filter(file => !
|
|
50
|
-
|
|
46
|
+
const significantFiles = files.filter(file => ![".git", ".DS_Store", "Thumbs.db", ".gitkeep"].includes(file));
|
|
47
|
+
if (significantFiles.length) {
|
|
48
|
+
throw new Error("The current directory is not empty.");
|
|
49
|
+
}
|
|
51
50
|
} catch (error) {
|
|
52
51
|
if (error.code === "ENOENT") {
|
|
53
52
|
throw new Error("The specified directory does not exist.");
|
|
@@ -77,7 +76,7 @@ function getAuthCredentials(options) {
|
|
|
77
76
|
});
|
|
78
77
|
}
|
|
79
78
|
if (missingAuth.length) {
|
|
80
|
-
throw new Error(
|
|
79
|
+
throw new Error("Authentication details are required. Please provide them via command line options or environment variables.");
|
|
81
80
|
}
|
|
82
81
|
return {
|
|
83
82
|
workspaceId,
|
|
@@ -105,48 +104,36 @@ async function selectTemplate(templateName) {
|
|
|
105
104
|
}]);
|
|
106
105
|
return template;
|
|
107
106
|
}
|
|
108
|
-
async function scaffoldProject(templateId,
|
|
109
|
-
if (!isTargetDirectoryEmpty) {
|
|
110
|
-
const {
|
|
111
|
-
confirm
|
|
112
|
-
} = await _inquirer.default.prompt([{
|
|
113
|
-
type: "confirm",
|
|
114
|
-
name: "confirm",
|
|
115
|
-
message: `The current directory is not empty. Do you want to proceed and override files?`,
|
|
116
|
-
default: false,
|
|
117
|
-
choices: [{
|
|
118
|
-
name: "Yes,",
|
|
119
|
-
value: true
|
|
120
|
-
}, {
|
|
121
|
-
name: "No",
|
|
122
|
-
value: false
|
|
123
|
-
}]
|
|
124
|
-
}]);
|
|
125
|
-
if (!confirm) {
|
|
126
|
-
throw new Error("Project initialization cancelled");
|
|
127
|
-
}
|
|
128
|
-
}
|
|
107
|
+
async function scaffoldProject(templateId, authCredentials) {
|
|
129
108
|
const cwd = process.cwd();
|
|
130
109
|
console.log(_chalk.default.cyan(`\n🚀 Initializing ${_chalk.default.bold(templateId)} project...\n`));
|
|
131
110
|
console.log(_chalk.default.cyan("📦 Fetching template..."));
|
|
132
|
-
const template = await fetchProjectTemplate(templateId);
|
|
133
|
-
console.log(_chalk.default.green(`✓ Template "${
|
|
111
|
+
const template = await fetchProjectTemplate(templateId, authCredentials);
|
|
112
|
+
console.log(_chalk.default.green(`✓ Template "${template}" fetched successfully!`));
|
|
134
113
|
console.log(_chalk.default.cyan("🔨 Creating project files..."));
|
|
135
114
|
const codeTree = template;
|
|
136
|
-
await prepareCLITemplate(codeTree);
|
|
137
115
|
await mountFiles(cwd, codeTree);
|
|
138
|
-
console.log(_chalk.default.green("✓ Project files created"));
|
|
139
|
-
console.log((0, _boxen.default)(_chalk.default.green(`✅ Project initialized successfully
|
|
116
|
+
console.log(_chalk.default.green("✓ Project files created!"));
|
|
117
|
+
console.log((0, _boxen.default)(_chalk.default.green(`✅ Project initialized successfully!`) + `\n\n${_chalk.default.cyan("Project details:")}` + `\n• Template: ${_chalk.default.bold(template)}` + `\n• Directory: ${_chalk.default.bold(process.cwd())}` + `\n• Workspace ID: ${_chalk.default.bold(authCredentials.workspaceId.substring(0, 5) + "...")}` + `\n\n${_chalk.default.cyan("Next steps:")}` + `\n1. ${_chalk.default.bold("cd")} into your project directory (if not already there)` + `\n2. Run ${_chalk.default.bold("npm install")} to install dependencies` + `\n3. Run ${_chalk.default.bold("npm start")} to start the development server`, {
|
|
140
118
|
padding: 1,
|
|
141
119
|
margin: 1,
|
|
142
120
|
borderStyle: "round",
|
|
143
121
|
borderColor: "green"
|
|
144
122
|
}));
|
|
145
123
|
}
|
|
146
|
-
async function fetchProjectTemplate(templateId) {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
124
|
+
async function fetchProjectTemplate(templateId, authCredentials) {
|
|
125
|
+
const {
|
|
126
|
+
workspaceId,
|
|
127
|
+
apiKey
|
|
128
|
+
} = authCredentials;
|
|
129
|
+
const baseUrl = "https://rauf-2.intuned-team-local.com";
|
|
130
|
+
const url = `${baseUrl}/api/v1/workspace/${workspaceId}/templates/${templateId}`;
|
|
131
|
+
const headers = {
|
|
132
|
+
"x-api-key": apiKey
|
|
133
|
+
};
|
|
134
|
+
const response = await fetch(url, {
|
|
135
|
+
headers
|
|
136
|
+
});
|
|
150
137
|
if (!response.ok) {
|
|
151
138
|
throw new Error(`Error fetching template: ${response.statusText} (${response.status})`);
|
|
152
139
|
}
|
|
@@ -155,24 +142,4 @@ async function fetchProjectTemplate(templateId) {
|
|
|
155
142
|
throw new Error("Template not found");
|
|
156
143
|
}
|
|
157
144
|
return data.template;
|
|
158
|
-
}
|
|
159
|
-
async function prepareCLITemplate(codeTree) {
|
|
160
|
-
codeTree["parameters"] = {
|
|
161
|
-
directory: {}
|
|
162
|
-
};
|
|
163
|
-
codeTree["tsconfig.json"] = {
|
|
164
|
-
file: {
|
|
165
|
-
contents: JSON.stringify(_constants.tsConfigCli, null, 2)
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
if (_isFileNode(codeTree["package.json"]) && codeTree["package.json"].file) {
|
|
169
|
-
const packageJson = JSON.parse(codeTree["package.json"].file.contents);
|
|
170
|
-
packageJson.scripts = _constants.userCLIScripts;
|
|
171
|
-
codeTree["package.json"].file.contents = JSON.stringify(packageJson, null, 2);
|
|
172
|
-
}
|
|
173
|
-
codeTree["README.md"] = {
|
|
174
|
-
file: {
|
|
175
|
-
contents: _cliReadme.cliReadme
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
145
|
}
|