@punkcode/cli 0.1.4 → 0.1.5
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/cli.js +23 -5
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -180,11 +180,14 @@ function getOrCreateDeviceId() {
|
|
|
180
180
|
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
181
181
|
return id;
|
|
182
182
|
}
|
|
183
|
-
function collectDeviceInfo(deviceId) {
|
|
183
|
+
function collectDeviceInfo(deviceId, customName) {
|
|
184
|
+
if (customName) {
|
|
185
|
+
saveConfigField("deviceName", customName);
|
|
186
|
+
}
|
|
184
187
|
const cpus = os.cpus();
|
|
185
188
|
return {
|
|
186
189
|
deviceId,
|
|
187
|
-
name: getDeviceName(),
|
|
190
|
+
name: customName || getDeviceName(),
|
|
188
191
|
platform: process.platform,
|
|
189
192
|
arch: process.arch,
|
|
190
193
|
username: os.userInfo().username,
|
|
@@ -198,6 +201,11 @@ function collectDeviceInfo(deviceId) {
|
|
|
198
201
|
};
|
|
199
202
|
}
|
|
200
203
|
function getDeviceName() {
|
|
204
|
+
try {
|
|
205
|
+
const config = JSON.parse(fs.readFileSync(CONFIG_FILE, "utf-8"));
|
|
206
|
+
if (config.deviceName) return config.deviceName;
|
|
207
|
+
} catch {
|
|
208
|
+
}
|
|
201
209
|
if (process.platform === "darwin") {
|
|
202
210
|
try {
|
|
203
211
|
const { stdout } = execaSync("scutil", ["--get", "ComputerName"], { timeout: 3e3 });
|
|
@@ -208,6 +216,16 @@ function getDeviceName() {
|
|
|
208
216
|
}
|
|
209
217
|
return os.hostname();
|
|
210
218
|
}
|
|
219
|
+
function saveConfigField(key, value) {
|
|
220
|
+
fs.mkdirSync(PUNK_DIR, { recursive: true });
|
|
221
|
+
let config = {};
|
|
222
|
+
try {
|
|
223
|
+
config = JSON.parse(fs.readFileSync(CONFIG_FILE, "utf-8"));
|
|
224
|
+
} catch {
|
|
225
|
+
}
|
|
226
|
+
config[key] = value;
|
|
227
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
228
|
+
}
|
|
211
229
|
function parseBattery() {
|
|
212
230
|
try {
|
|
213
231
|
if (process.platform === "darwin") {
|
|
@@ -778,7 +796,7 @@ async function connect(server, options) {
|
|
|
778
796
|
const activeSessions = /* @__PURE__ */ new Map();
|
|
779
797
|
socket.on("connect", () => {
|
|
780
798
|
logger.info("Connected");
|
|
781
|
-
const deviceInfo = collectDeviceInfo(deviceId);
|
|
799
|
+
const deviceInfo = collectDeviceInfo(deviceId, options.name);
|
|
782
800
|
socket.emit("register", deviceInfo, (response) => {
|
|
783
801
|
if (response.success) {
|
|
784
802
|
logger.info({ deviceId }, "Registered");
|
|
@@ -826,7 +844,7 @@ async function connect(server, options) {
|
|
|
826
844
|
});
|
|
827
845
|
socket.on("reconnect", (attemptNumber) => {
|
|
828
846
|
logger.info({ attemptNumber }, "Reconnected");
|
|
829
|
-
socket.emit("register", collectDeviceInfo(deviceId));
|
|
847
|
+
socket.emit("register", collectDeviceInfo(deviceId, options.name));
|
|
830
848
|
});
|
|
831
849
|
socket.on("connect_error", (err) => {
|
|
832
850
|
logger.error({ err }, "Connection error");
|
|
@@ -1022,7 +1040,7 @@ function logout() {
|
|
|
1022
1040
|
|
|
1023
1041
|
// src/commands/index.ts
|
|
1024
1042
|
function registerCommands(program2) {
|
|
1025
|
-
program2.command("connect").argument("[server]", "Backend server URL", "https://api.punkcode.dev").description("Connect to backend server").option("-t, --token <token>", "Authentication token").option("-d, --device-id <deviceId>", "Device identifier (defaults to hostname)").action(connect);
|
|
1043
|
+
program2.command("connect").argument("[server]", "Backend server URL", "https://api.punkcode.dev").description("Connect to backend server").option("-t, --token <token>", "Authentication token").option("-d, --device-id <deviceId>", "Device identifier (defaults to hostname)").option("-n, --name <name>", "Custom device display name").action(connect);
|
|
1026
1044
|
program2.command("login").description("Log in with your email and password").action(login);
|
|
1027
1045
|
program2.command("logout").description("Log out and clear stored credentials").action(logout);
|
|
1028
1046
|
}
|