@sleekcms/cli 1.0.0 → 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/index.js +30 -10
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -11,11 +11,11 @@ const API_BASE_URLS = {
|
|
|
11
11
|
production: "https://app.sleekcms.com/api/template",
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const PORT = 8080;
|
|
15
14
|
const DEBOUNCE_DELAY = 1000; // 2 seconds delay
|
|
16
15
|
let isShuttingDown = false;
|
|
17
16
|
const pendingUpdates = {};
|
|
18
17
|
let fileMap = {};
|
|
18
|
+
let watcher;
|
|
19
19
|
|
|
20
20
|
// CLI Setup to take `--token=<token>`
|
|
21
21
|
program
|
|
@@ -107,21 +107,41 @@ function scheduleUpdate(filePath) {
|
|
|
107
107
|
|
|
108
108
|
async function createSchema(filePath) {
|
|
109
109
|
if (isShuttingDown) return;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
110
|
+
try {
|
|
111
|
+
const relativePath = filePath.replace(VIEWS_DIR, ""); // Extract relative file path
|
|
112
|
+
const resp = await apiClient.post("/cli", { file_path: relativePath});
|
|
113
|
+
const schema = resp.data;
|
|
114
|
+
const templateResp = await apiClient.get(`/${schema.tmpl_main_id}`);
|
|
115
|
+
const template = templateResp.data;
|
|
116
|
+
if (relativePath !== template.file_path) {
|
|
117
|
+
// rename the file
|
|
118
|
+
const oldPath = filePath;
|
|
119
|
+
const newPath = `./${VIEWS_DIR}${template.file_path}`;
|
|
120
|
+
watcher.unwatch(newPath);
|
|
121
|
+
await fs.move(oldPath, newPath);
|
|
122
|
+
watcher.add(newPath);
|
|
123
|
+
console.log(`✅ Renamed file from ${relativePath} to ${template.file_path}`);
|
|
124
|
+
}
|
|
125
|
+
fileMap[template.file_path] = schema.tmpl_main_id;
|
|
126
|
+
console.log("✅ Created model for:", template.file_path);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error("❌ Error creating model:", error.response?.data || error.message);
|
|
129
|
+
// delete the file locally
|
|
130
|
+
await fs.unlink(filePath);
|
|
131
|
+
}
|
|
116
132
|
}
|
|
117
133
|
|
|
118
134
|
// Function to monitor file changes
|
|
119
135
|
function monitorFiles() {
|
|
120
136
|
console.log("👀 Watching for file changes...");
|
|
121
137
|
|
|
122
|
-
chokidar.watch(`./${VIEWS_DIR}`, {
|
|
123
|
-
|
|
124
|
-
|
|
138
|
+
watcher = chokidar.watch(`./${VIEWS_DIR}`, {
|
|
139
|
+
persistent: true,
|
|
140
|
+
ignoreInitial: true,
|
|
141
|
+
ignored: /\.vscode\//
|
|
142
|
+
})
|
|
143
|
+
.on("change", scheduleUpdate)
|
|
144
|
+
.on("add", createSchema);
|
|
125
145
|
}
|
|
126
146
|
|
|
127
147
|
// Graceful shutdown handler
|