@ptkl/toolkit 0.6.0 → 0.6.2
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/dist/commands/apps.js +28 -1
- package/dist/playground.js +50 -24
- package/package.json +2 -2
package/dist/commands/apps.js
CHANGED
|
@@ -77,7 +77,34 @@ class AppsCommand {
|
|
|
77
77
|
const { apptype, directory, build } = options;
|
|
78
78
|
const profile = util.getCurrentProfile();
|
|
79
79
|
const client = new Api({ token: profile.token, host: profile.host }).app(apptype);
|
|
80
|
-
|
|
80
|
+
try {
|
|
81
|
+
let buffer = Buffer.alloc(0);
|
|
82
|
+
const bufferStream = new Writable({
|
|
83
|
+
write(chunk, encoding, callback) {
|
|
84
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
85
|
+
callback();
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
// Create tar.gz in memory
|
|
89
|
+
await new Promise((resolve, reject) => {
|
|
90
|
+
c({ gzip: true, cwd: directory }, ['.'])
|
|
91
|
+
.pipe(bufferStream)
|
|
92
|
+
.on('finish', resolve)
|
|
93
|
+
.on('error', reject);
|
|
94
|
+
});
|
|
95
|
+
console.log('Archive created successfully');
|
|
96
|
+
// Create FormData with buffer
|
|
97
|
+
const formData = new FormData();
|
|
98
|
+
const blob = new Blob([buffer], { type: 'application/gzip' });
|
|
99
|
+
formData.append('app', blob, 'app.tar.gz');
|
|
100
|
+
if (build) {
|
|
101
|
+
formData.append('build', 'true');
|
|
102
|
+
}
|
|
103
|
+
return await client.upload(formData);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
81
108
|
}
|
|
82
109
|
async deploy(options) {
|
|
83
110
|
const { apptype, dev_version, public_version, ref } = options;
|
package/dist/playground.js
CHANGED
|
@@ -23,7 +23,14 @@ export default class Playground {
|
|
|
23
23
|
console.log(`Starting playground at ${port}`);
|
|
24
24
|
console.log(`SDK Version: ${this.sdkVersion}`);
|
|
25
25
|
console.log(`Engine: ${this.engine}`);
|
|
26
|
-
|
|
26
|
+
// Initialize watcher with better options
|
|
27
|
+
this.watcher = chokidar.watch([], {
|
|
28
|
+
persistent: true,
|
|
29
|
+
ignoreInitial: true,
|
|
30
|
+
usePolling: false, // Set to true if still having issues on some systems
|
|
31
|
+
interval: 100,
|
|
32
|
+
binaryInterval: 300
|
|
33
|
+
});
|
|
27
34
|
this.srcPath = "";
|
|
28
35
|
}
|
|
29
36
|
async build(files) {
|
|
@@ -119,53 +126,72 @@ export default class Playground {
|
|
|
119
126
|
}
|
|
120
127
|
// Start watching and listen for events
|
|
121
128
|
start() {
|
|
129
|
+
console.log(`Adding watch path: ${this.srcPath}`);
|
|
122
130
|
this.watcher.add(this.srcPath);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.initalWsSend(this.connectedClient);
|
|
129
|
-
console.log("Playground connected");
|
|
130
|
-
});
|
|
131
|
-
const handleUpdate = async (filePath) => {
|
|
131
|
+
// Log watched paths for debugging
|
|
132
|
+
console.log(`Watched paths:`, this.watcher.getWatched());
|
|
133
|
+
// Define handlers outside and register them once
|
|
134
|
+
const handleUpdate = this.debounce(async (filePath) => {
|
|
135
|
+
console.log("handling update for:", filePath);
|
|
132
136
|
try {
|
|
133
137
|
const fileData = readFileSync(filePath, "utf-8");
|
|
134
138
|
const relativeFilePath = relative(this.srcPath, filePath);
|
|
135
139
|
let dist = await this.build({ [relativeFilePath]: fileData });
|
|
136
140
|
if (dist) {
|
|
137
|
-
this.connectedClient
|
|
141
|
+
if (this.connectedClient) {
|
|
142
|
+
this.connectedClient.send(JSON.stringify({ action: "update", dist }));
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
console.log("No connected client to send update.");
|
|
146
|
+
}
|
|
138
147
|
console.log(`Updating ${relativeFilePath}`);
|
|
139
148
|
}
|
|
140
|
-
this.watcher.on("add", this.debounce(handleUpdate, 300, false));
|
|
141
|
-
this.watcher.on("change", this.debounce(handleUpdate, 300, false));
|
|
142
|
-
this.watcher.on("unlink", this.debounce((filePath) => {
|
|
143
|
-
const relativeFilePath = relative(this.srcPath, filePath);
|
|
144
|
-
this.connectedClient.send(JSON.stringify({ action: "delete", files: [relativeFilePath] }));
|
|
145
|
-
console.log(`Deleting ${relativeFilePath}`);
|
|
146
|
-
}, 300, false));
|
|
147
149
|
}
|
|
148
150
|
catch (err) {
|
|
149
151
|
console.log(err.message);
|
|
150
152
|
}
|
|
151
|
-
};
|
|
153
|
+
}, 300, false);
|
|
154
|
+
const handleDelete = this.debounce((filePath) => {
|
|
155
|
+
const relativeFilePath = relative(this.srcPath, filePath);
|
|
156
|
+
this.connectedClient?.send(JSON.stringify({ action: "delete", files: [relativeFilePath] }));
|
|
157
|
+
console.log(`Deleting ${relativeFilePath}`);
|
|
158
|
+
}, 300, false);
|
|
159
|
+
// Register event listeners once
|
|
160
|
+
this.watcher.on("add", handleUpdate);
|
|
161
|
+
this.watcher.on("change", handleUpdate);
|
|
162
|
+
this.watcher.on("unlink", handleDelete);
|
|
163
|
+
// Add error handler for watcher
|
|
164
|
+
this.watcher.on("error", (error) => {
|
|
165
|
+
console.error("Watcher error:", error);
|
|
166
|
+
});
|
|
167
|
+
this.wss.on("connection", async (ws) => {
|
|
168
|
+
this.connectedClient = ws;
|
|
169
|
+
if (this.apptype == 'public-app') {
|
|
170
|
+
await this.auth(this.connectedClient);
|
|
171
|
+
}
|
|
172
|
+
this.initalWsSend(this.connectedClient);
|
|
173
|
+
console.log("Playground connected");
|
|
174
|
+
});
|
|
152
175
|
}
|
|
153
176
|
close() {
|
|
154
177
|
this.watcher.close();
|
|
155
|
-
|
|
178
|
+
this.wss.close();
|
|
179
|
+
console.log("Watcher and WebSocket server closed.");
|
|
156
180
|
}
|
|
157
181
|
debounce(func, wait, immediate) {
|
|
158
|
-
let timeout;
|
|
182
|
+
let timeout = null;
|
|
159
183
|
return function (...args) {
|
|
160
184
|
const callNow = immediate && !timeout;
|
|
161
|
-
|
|
185
|
+
if (timeout) {
|
|
186
|
+
clearTimeout(timeout);
|
|
187
|
+
}
|
|
162
188
|
timeout = setTimeout(() => {
|
|
163
189
|
timeout = null;
|
|
164
190
|
if (!immediate)
|
|
165
|
-
func.apply(
|
|
191
|
+
func.apply(this, args);
|
|
166
192
|
}, wait);
|
|
167
193
|
if (callNow)
|
|
168
|
-
func.apply(
|
|
194
|
+
func.apply(this, args);
|
|
169
195
|
};
|
|
170
196
|
}
|
|
171
197
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ptkl/toolkit",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
6
6
|
"build": "npx tsc",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@babel/standalone": "^7.26.10",
|
|
16
|
-
"@ptkl/sdk": "^0.9.
|
|
16
|
+
"@ptkl/sdk": "^0.9.5",
|
|
17
17
|
"@types/axios": "^0.14.0",
|
|
18
18
|
"@types/commander": "^2.12.2",
|
|
19
19
|
"@types/js-yaml": "^4.0.9",
|