muagqa 1.4.5 → 1.5.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/package.json +1 -1
- package/src/generateTemplate.js +32 -0
- package/src/index.js +8 -0
- package/src/templateMode.js +1 -1
- package/src/generate-template.js +0 -50
package/package.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import fetch from "node-fetch";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
|
|
4
|
+
export async function generateTemplateFromDashboard(token) {
|
|
5
|
+
console.log("🔍 Fetching template test cases…");
|
|
6
|
+
|
|
7
|
+
const response = await fetch("https://muagqa.com/api/template/generate", {
|
|
8
|
+
method: "POST",
|
|
9
|
+
headers: { "Content-Type": "application/json" },
|
|
10
|
+
body: JSON.stringify({
|
|
11
|
+
token
|
|
12
|
+
})
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const data = await response.json();
|
|
16
|
+
|
|
17
|
+
if (!data.success) {
|
|
18
|
+
console.error("❌ ERROR:", data.error);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const output = data.testCode;
|
|
23
|
+
|
|
24
|
+
// Save file locally
|
|
25
|
+
fs.writeFileSync("generated-template.spec.js", output);
|
|
26
|
+
|
|
27
|
+
console.log("✅ Smart test template generated:");
|
|
28
|
+
console.log("==============================");
|
|
29
|
+
console.log(output);
|
|
30
|
+
console.log("==============================");
|
|
31
|
+
console.log("File saved as: generated-template.spec.js");
|
|
32
|
+
}
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { promisify } from "util";
|
|
|
5
5
|
import chalk from "chalk";
|
|
6
6
|
import { startRecording } from "./recordMode.js";
|
|
7
7
|
import { generateTemplateTests } from "./templateMode.js";
|
|
8
|
+
import fetch from "node-fetch";
|
|
8
9
|
|
|
9
10
|
const execAsync = promisify(exec);
|
|
10
11
|
const require = createRequire(import.meta.url);
|
|
@@ -12,6 +13,13 @@ const pkg = require("../package.json");
|
|
|
12
13
|
|
|
13
14
|
console.log(chalk.cyan.bold("\nMuagQA CLI - One-Time Test Case Recorder\n"));
|
|
14
15
|
|
|
16
|
+
const args = process.argv.slice(2);
|
|
17
|
+
|
|
18
|
+
if (args[0] === "--template") {
|
|
19
|
+
const token = args[1];
|
|
20
|
+
generateTemplateFromDashboard(token);
|
|
21
|
+
}
|
|
22
|
+
|
|
15
23
|
async function checkForUpdate({ force = false } = {}) {
|
|
16
24
|
try {
|
|
17
25
|
const { stdout } = await execAsync("npm view muagqa version", {
|
package/src/templateMode.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import inquirer from "inquirer";
|
|
2
|
-
import { runTemplateGeneration } from "./
|
|
2
|
+
import { runTemplateGeneration } from "./generateTemplate.js";
|
|
3
3
|
|
|
4
4
|
export async function generateTemplateTests(sessionToken) {
|
|
5
5
|
let token = sessionToken || process.env.MUAGQA_SESSION;
|
package/src/generate-template.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import fetch from "node-fetch";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import chalk from "chalk";
|
|
5
|
-
|
|
6
|
-
export async function runTemplateGeneration(token) {
|
|
7
|
-
console.log(chalk.cyan("\n▶ Starting smart template generation…"));
|
|
8
|
-
console.log(chalk.gray("Using token:"), chalk.yellow(token));
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
const res = await fetch(
|
|
12
|
-
"https://muagqa.vercel.app/api/cli/generate-templates",
|
|
13
|
-
{
|
|
14
|
-
method: "POST",
|
|
15
|
-
headers: { "Content-Type": "application/json" },
|
|
16
|
-
body: JSON.stringify({ token })
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
const data = await res.json();
|
|
21
|
-
|
|
22
|
-
if (!res.ok || data.error) {
|
|
23
|
-
console.log(chalk.red("❌ Template generation failed:"), data.error);
|
|
24
|
-
process.exit(1);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Create output folder
|
|
28
|
-
const saveDir = path.join(process.cwd(), "generated-tests", "templates");
|
|
29
|
-
fs.mkdirSync(saveDir, { recursive: true });
|
|
30
|
-
|
|
31
|
-
console.log(chalk.green("\n✔ Templates received — writing files...\n"));
|
|
32
|
-
|
|
33
|
-
// Write each generated template
|
|
34
|
-
for (const [fileName, content] of Object.entries(data.templates)) {
|
|
35
|
-
const filePath = path.join(saveDir, fileName);
|
|
36
|
-
fs.writeFileSync(filePath, content, "utf8");
|
|
37
|
-
|
|
38
|
-
console.log(chalk.blue("➤ Created"), chalk.yellow(fileName));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
console.log(
|
|
42
|
-
chalk.green(
|
|
43
|
-
`\n✔ Template generation complete! Files saved in generated-tests/templates/\n`
|
|
44
|
-
)
|
|
45
|
-
);
|
|
46
|
-
} catch (err) {
|
|
47
|
-
console.error(chalk.red("💥 Template Engine Crash:"), err);
|
|
48
|
-
process.exit(1);
|
|
49
|
-
}
|
|
50
|
-
}
|