@sleekcms/cli 1.0.0 → 1.2.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.
Files changed (2) hide show
  1. package/index.js +34 -13
  2. 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
@@ -40,6 +40,8 @@ const VIEWS_DIR = AUTH_TOKEN.split('-')[0] + "-views/";
40
40
  const apiClient = axios.create({
41
41
  baseURL: API_BASE_URL,
42
42
  headers: { Authorization: `Bearer ${AUTH_TOKEN}` },
43
+ maxContentLength: Infinity,
44
+ maxBodyLength: Infinity,
43
45
  });
44
46
 
45
47
 
@@ -94,9 +96,8 @@ function scheduleUpdate(filePath) {
94
96
  pendingUpdates[fileId] = setTimeout(async () => {
95
97
  try {
96
98
  const code = await fs.readFile(filePath, "utf-8");
97
-
98
- await apiClient.patch(`/${fileId}`, { code });
99
- console.log("✅ Updated template for:", relativePath);
99
+ let template = await apiClient.patch(`/${fileId}`, { code: code || "foo bar" });
100
+ console.log("✅ Updated template for: ", relativePath, `In: ${code.length}, Out: ${template.data.code.length}`);
100
101
 
101
102
  delete pendingUpdates[fileId]; // Cleanup
102
103
  } catch (error) {
@@ -107,21 +108,41 @@ function scheduleUpdate(filePath) {
107
108
 
108
109
  async function createSchema(filePath) {
109
110
  if (isShuttingDown) return;
110
-
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
- fileMap[relativePath] = schema.tmpl_main_id;
115
- console.log("✅ Created model for:", relativePath);
111
+ try {
112
+ const relativePath = filePath.replace(VIEWS_DIR, ""); // Extract relative file path
113
+ const resp = await apiClient.post("/cli", { file_path: relativePath});
114
+ const schema = resp.data;
115
+ const templateResp = await apiClient.get(`/${schema.tmpl_main_id}`);
116
+ const template = templateResp.data;
117
+ if (relativePath !== template.file_path) {
118
+ // rename the file
119
+ const oldPath = filePath;
120
+ const newPath = `./${VIEWS_DIR}${template.file_path}`;
121
+ watcher.unwatch(newPath);
122
+ await fs.move(oldPath, newPath);
123
+ watcher.add(newPath);
124
+ console.log(`✅ Renamed file from ${relativePath} to ${template.file_path}`);
125
+ }
126
+ fileMap[template.file_path] = schema.tmpl_main_id;
127
+ console.log("✅ Created model for:", template.file_path);
128
+ } catch (error) {
129
+ console.error("❌ Error creating model:", error.response?.data || error.message);
130
+ // delete the file locally
131
+ await fs.unlink(filePath);
132
+ }
116
133
  }
117
134
 
118
135
  // Function to monitor file changes
119
136
  function monitorFiles() {
120
137
  console.log("👀 Watching for file changes...");
121
138
 
122
- chokidar.watch(`./${VIEWS_DIR}`, { persistent: true, ignoreInitial: true })
123
- .on("change", scheduleUpdate)
124
- .on("add", createSchema);
139
+ watcher = chokidar.watch(`./${VIEWS_DIR}`, {
140
+ persistent: true,
141
+ ignoreInitial: true,
142
+ ignored: /\.vscode\//
143
+ })
144
+ .on("change", scheduleUpdate)
145
+ .on("add", createSchema);
125
146
  }
126
147
 
127
148
  // Graceful shutdown handler
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleekcms/cli",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "SleekCMS CLI for locally editing SleekCMS site template code",
5
5
  "main": "index.js",
6
6
  "bin": {