scaffoldrite 2.0.7 → 2.0.8
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.
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateStructure = generateStructure;
|
|
7
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
|
+
async function generateStructure(params) {
|
|
9
|
+
try {
|
|
10
|
+
const response = await (0, node_fetch_1.default)("http://localhost:3000/generate-structure", {
|
|
11
|
+
method: "POST",
|
|
12
|
+
headers: { "Content-Type": "application/json" },
|
|
13
|
+
body: JSON.stringify(params),
|
|
14
|
+
});
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
const text = await response.text();
|
|
17
|
+
throw new Error(`Backend error: ${text}`);
|
|
18
|
+
}
|
|
19
|
+
const data = await response.json();
|
|
20
|
+
if (typeof data?.result !== "string") {
|
|
21
|
+
throw new Error("Invalid backend response: result missing");
|
|
22
|
+
}
|
|
23
|
+
return data.result;
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
throw new Error(`Failed to generate structure: ${err.message}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ai = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const data_1 = require("../../data");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const generateStructure_1 = require("./generateStructure");
|
|
12
|
+
// ─────────────────────────────────────────────
|
|
13
|
+
// HELPER: readline wrapper
|
|
14
|
+
// ─────────────────────────────────────────────
|
|
15
|
+
function createAsk() {
|
|
16
|
+
const rl = require("readline").createInterface({
|
|
17
|
+
input: process.stdin,
|
|
18
|
+
output: process.stdout,
|
|
19
|
+
});
|
|
20
|
+
const ask = (q) => new Promise((res) => rl.question(q, res));
|
|
21
|
+
return { ask, close: () => rl.close() };
|
|
22
|
+
}
|
|
23
|
+
// ─────────────────────────────────────────────
|
|
24
|
+
// HELPER: sanitize AI output for ScaffoldRite
|
|
25
|
+
// ─────────────────────────────────────────────
|
|
26
|
+
function sanitizeStructureSR(input) {
|
|
27
|
+
return input
|
|
28
|
+
.split("\n")
|
|
29
|
+
.filter((line) => !line.match(/^\s*(STRUCTURE|FORMAT|SYNTAX|RULES)/i))
|
|
30
|
+
.join("\n")
|
|
31
|
+
.trim();
|
|
32
|
+
}
|
|
33
|
+
// ─────────────────────────────────────────────
|
|
34
|
+
// MAIN AI FUNCTION
|
|
35
|
+
// ─────────────────────────────────────────────
|
|
36
|
+
const ai = async () => {
|
|
37
|
+
try {
|
|
38
|
+
// ─────────────────────────────────────────────
|
|
39
|
+
// 1️⃣ INITIAL QUESTIONS
|
|
40
|
+
// ─────────────────────────────────────────────
|
|
41
|
+
let { ask, close } = createAsk();
|
|
42
|
+
const projectName = await ask("Project name: ");
|
|
43
|
+
const framework = await ask("Framework (react, vue, vanilla): ");
|
|
44
|
+
const language = await ask("Language (js, ts): ");
|
|
45
|
+
close(); // ❗ CLOSE BEFORE execSync
|
|
46
|
+
// ─────────────────────────────────────────────
|
|
47
|
+
// 2️⃣ CREATE VITE PROJECT
|
|
48
|
+
// ─────────────────────────────────────────────
|
|
49
|
+
let template = framework.toLowerCase();
|
|
50
|
+
if (framework === "react" && language === "ts")
|
|
51
|
+
template = "react-ts";
|
|
52
|
+
if (framework === "vue" && language === "ts")
|
|
53
|
+
template = "vue-ts";
|
|
54
|
+
if (framework === "vanilla" && language === "ts")
|
|
55
|
+
template = "vanilla-ts";
|
|
56
|
+
(0, child_process_1.execSync)(`npx create-vite@latest "${projectName}" --template ${template} --no-rolldown --no-immediate`, {
|
|
57
|
+
stdio: "inherit",
|
|
58
|
+
shell: process.platform === "win32" ? "cmd.exe" : "/bin/sh",
|
|
59
|
+
});
|
|
60
|
+
const projectPath = path_1.default.resolve(process.cwd(), projectName);
|
|
61
|
+
// ─────────────────────────────────────────────
|
|
62
|
+
// 3️⃣ INIT SCAFFOLDRITE
|
|
63
|
+
// ─────────────────────────────────────────────
|
|
64
|
+
(0, child_process_1.execSync)("sr init --from-fs .", {
|
|
65
|
+
cwd: projectPath,
|
|
66
|
+
stdio: "inherit",
|
|
67
|
+
shell: process.platform === "win32" ? "cmd.exe" : "/bin/sh",
|
|
68
|
+
});
|
|
69
|
+
// ─────────────────────────────────────────────
|
|
70
|
+
// 4️⃣ ASK FOR AI ASSISTANCE
|
|
71
|
+
// ─────────────────────────────────────────────
|
|
72
|
+
({ ask, close } = createAsk());
|
|
73
|
+
const wantAI = await ask("\n🤖 Do you want AI assistance in scaffolding the structure of your app? (yes/no): ");
|
|
74
|
+
if (wantAI.toLowerCase() === "yes") {
|
|
75
|
+
while (true) {
|
|
76
|
+
const description = await ask("\n📝 Describe your project or what you want to add/change:\n");
|
|
77
|
+
const structurePath = path_1.default.join(projectPath, ".scaffoldrite", "structure.sr");
|
|
78
|
+
const existingStructure = fs_1.default.readFileSync(structurePath, "utf-8");
|
|
79
|
+
const result = await (0, generateStructure_1.generateStructure)({
|
|
80
|
+
existingStructure,
|
|
81
|
+
description,
|
|
82
|
+
});
|
|
83
|
+
// 🧠 CLARIFICATION MODE
|
|
84
|
+
if (result.startsWith("CLARIFICATION_REQUIRED")) {
|
|
85
|
+
console.log("\n🤖 I need clarification:\n");
|
|
86
|
+
console.log(result);
|
|
87
|
+
const confirm = await ask("\nIs this what you meant? (yes/no): ");
|
|
88
|
+
if (confirm.toLowerCase() === "yes") {
|
|
89
|
+
await ask("\n✏️ Please rephrase clearly what you want:\n");
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
console.log("\n🔁 Okay, please describe what you want again.\n");
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// ✅ STRUCTURE MODE
|
|
98
|
+
const clean = sanitizeStructureSR(result);
|
|
99
|
+
fs_1.default.writeFileSync(structurePath, clean);
|
|
100
|
+
// SAFETY STEP — NON-NEGOTIABLE
|
|
101
|
+
(0, child_process_1.execSync)("sr merge --from-fs .", {
|
|
102
|
+
cwd: projectPath,
|
|
103
|
+
stdio: "inherit",
|
|
104
|
+
});
|
|
105
|
+
// NOW it's safe
|
|
106
|
+
(0, child_process_1.execSync)("sr generate .", {
|
|
107
|
+
cwd: projectPath,
|
|
108
|
+
stdio: "inherit",
|
|
109
|
+
});
|
|
110
|
+
(0, child_process_1.execSync)("sr list --sr --with-icon", {
|
|
111
|
+
cwd: projectPath,
|
|
112
|
+
stdio: "inherit",
|
|
113
|
+
});
|
|
114
|
+
// Ask if satisfied
|
|
115
|
+
({ ask, close } = createAsk());
|
|
116
|
+
const satisfied = await ask("\n✅ Are you satisfied with the structure? (yes/no): ");
|
|
117
|
+
if (satisfied.toLowerCase() === "yes")
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
close();
|
|
122
|
+
// ─────────────────────────────────────────────
|
|
123
|
+
// 5️⃣ FINISH
|
|
124
|
+
// ─────────────────────────────────────────────
|
|
125
|
+
console.log(data_1.theme.success(`\n🎉 Project ${projectName} is ready!\n`));
|
|
126
|
+
console.log(data_1.theme.muted(` cd ${projectName}`));
|
|
127
|
+
console.log(data_1.theme.muted(" npm install"));
|
|
128
|
+
console.log(data_1.theme.muted(" npm run dev"));
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
console.error(data_1.theme.error(`❌ Failed: ${err.message}`));
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
exports.ai = ai;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scaffoldrite",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "A project structure validator and generator CLI tool.",
|
|
5
5
|
"author": "Isaac Anasonye",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"validate": "npm run type-check && npm run build",
|
|
39
39
|
"test": "jest",
|
|
40
40
|
"prepublishOnly": "npm run build && node dist/cli.js --help npm pack --dry-run",
|
|
41
|
-
"release:test": "npm run build && node -e \"const { execSync } = require('child_process'); const name=require('./package.json').name; const version=require('./package.json').version; const file=`${name}-${version}.tgz`; execSync('npm pack', { stdio: 'inherit' }); execSync(`npm install -g ${file}`, { stdio: 'inherit' }); execSync('sr --help', { stdio: 'inherit' }); execSync('npm uninstall -g
|
|
41
|
+
"release:test": "npm run build && node -e \"const { execSync } = require('child_process'); const name=require('./package.json').name; const version=require('./package.json').version; const file=`${name}-${version}.tgz`; execSync('npm pack', { stdio: 'inherit' }); execSync(`npm install -g ${file}`, { stdio: 'inherit' }); execSync('sr --help', { stdio: 'inherit' }); execSync('npm uninstall -g ${name}-${version}', { stdio: 'inherit' });\""
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/cli-progress": "^3.11.6",
|