@khangal.j/fireside-cli 0.0.1 → 0.0.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.
Files changed (3) hide show
  1. package/README.md +1 -2
  2. package/dist/index.js +54 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -22,8 +22,7 @@ fireside projects list
22
22
 
23
23
  The CLI stores local files under the `fireside` config directory.
24
24
 
25
- - macOS: `~/Library/Application Support/fireside/{config,auth}.json`
26
- - Linux: `$XDG_CONFIG_HOME/fireside/{config,auth}.json` or `~/.config/fireside/{config,auth}.json`
25
+ - macOS/Linux: `$XDG_CONFIG_HOME/fireside/{config,auth}.json` or `~/.config/fireside/{config,auth}.json`
27
26
  - Windows: `%APPDATA%\\fireside\\{config,auth}.json`
28
27
 
29
28
  `config.json` stores settings like `baseUrl`. `auth.json` stores the local session token.
package/dist/index.js CHANGED
@@ -139,22 +139,23 @@ var legacyMigrationPromise = null;
139
139
  function normalizeBaseUrl(baseUrl) {
140
140
  return baseUrl.trim().replace(/\/+$/, "");
141
141
  }
142
+ function getUnixConfigHomeDirectory() {
143
+ return process.env.XDG_CONFIG_HOME || (0, import_node_path.join)((0, import_node_os.homedir)(), ".config");
144
+ }
142
145
  function getConfigDirectory(appName = "fireside") {
143
146
  switch (process.platform) {
144
- case "darwin":
145
- return (0, import_node_path.join)((0, import_node_os.homedir)(), "Library", "Application Support", appName);
146
147
  case "win32":
147
148
  return (0, import_node_path.join)(
148
149
  process.env.APPDATA || (0, import_node_path.join)((0, import_node_os.homedir)(), "AppData", "Roaming"),
149
150
  appName
150
151
  );
151
152
  default:
152
- return (0, import_node_path.join)(
153
- process.env.XDG_CONFIG_HOME || (0, import_node_path.join)((0, import_node_os.homedir)(), ".config"),
154
- appName
155
- );
153
+ return (0, import_node_path.join)(getUnixConfigHomeDirectory(), appName);
156
154
  }
157
155
  }
156
+ function getLegacyMacOsConfigDirectory(appName) {
157
+ return (0, import_node_path.join)((0, import_node_os.homedir)(), "Library", "Application Support", appName);
158
+ }
158
159
  function getAuthStateFilePath() {
159
160
  return (0, import_node_path.join)(getConfigDirectory(), "auth.json");
160
161
  }
@@ -162,8 +163,17 @@ function getConfigStateFilePath() {
162
163
  return (0, import_node_path.join)(getConfigDirectory(), "config.json");
163
164
  }
164
165
  function getLegacyAuthStateFilePath() {
166
+ if (process.platform === "darwin") {
167
+ return (0, import_node_path.join)(getLegacyMacOsConfigDirectory("fireside-cli"), "auth.json");
168
+ }
165
169
  return (0, import_node_path.join)(getConfigDirectory("fireside-cli"), "auth.json");
166
170
  }
171
+ function getLegacyMacOsAuthStateFilePath() {
172
+ return (0, import_node_path.join)(getLegacyMacOsConfigDirectory("fireside"), "auth.json");
173
+ }
174
+ function getLegacyMacOsConfigStateFilePath() {
175
+ return (0, import_node_path.join)(getLegacyMacOsConfigDirectory("fireside"), "config.json");
176
+ }
167
177
  async function fileExists(filePath) {
168
178
  try {
169
179
  await (0, import_promises.access)(filePath);
@@ -215,6 +225,40 @@ function isLegacyAuthState(value) {
215
225
  return isAuthState(value) && isConfigState(value);
216
226
  }
217
227
  async function migrateLegacyState() {
228
+ const authStateFilePath = getAuthStateFilePath();
229
+ const configStateFilePath = getConfigStateFilePath();
230
+ let hasAuthState = await fileExists(authStateFilePath);
231
+ let hasConfigState = await fileExists(configStateFilePath);
232
+ if (process.platform === "darwin") {
233
+ const legacyMacOsAuthState = await readStateFile(
234
+ getLegacyMacOsAuthStateFilePath()
235
+ );
236
+ const legacyMacOsConfigState = await readStateFile(
237
+ getLegacyMacOsConfigStateFilePath()
238
+ );
239
+ if (legacyMacOsAuthState !== null) {
240
+ if (!isAuthState(legacyMacOsAuthState)) {
241
+ throw new Error("Invalid legacy auth state file format.");
242
+ }
243
+ if (!hasAuthState) {
244
+ await writeStateFile(authStateFilePath, legacyMacOsAuthState);
245
+ hasAuthState = true;
246
+ }
247
+ await (0, import_promises.rm)(getLegacyMacOsAuthStateFilePath(), { force: true });
248
+ }
249
+ if (legacyMacOsConfigState !== null) {
250
+ if (!isConfigState(legacyMacOsConfigState)) {
251
+ throw new Error("Invalid legacy config state file format.");
252
+ }
253
+ if (!hasConfigState) {
254
+ await writeStateFile(configStateFilePath, {
255
+ baseUrl: normalizeBaseUrl(legacyMacOsConfigState.baseUrl)
256
+ });
257
+ hasConfigState = true;
258
+ }
259
+ await (0, import_promises.rm)(getLegacyMacOsConfigStateFilePath(), { force: true });
260
+ }
261
+ }
218
262
  const legacyState = await readStateFile(getLegacyAuthStateFilePath());
219
263
  if (legacyState === null) {
220
264
  return;
@@ -222,18 +266,18 @@ async function migrateLegacyState() {
222
266
  if (!isLegacyAuthState(legacyState)) {
223
267
  throw new Error("Invalid legacy auth state file format.");
224
268
  }
225
- const authStateFilePath = getAuthStateFilePath();
226
- const configStateFilePath = getConfigStateFilePath();
227
- if (!await fileExists(authStateFilePath)) {
269
+ if (!hasAuthState) {
228
270
  await writeStateFile(authStateFilePath, {
229
271
  accessToken: legacyState.accessToken,
230
272
  createdAt: legacyState.createdAt
231
273
  });
274
+ hasAuthState = true;
232
275
  }
233
- if (!await fileExists(configStateFilePath)) {
276
+ if (!hasConfigState) {
234
277
  await writeStateFile(configStateFilePath, {
235
278
  baseUrl: normalizeBaseUrl(legacyState.baseUrl)
236
279
  });
280
+ hasConfigState = true;
237
281
  }
238
282
  await (0, import_promises.rm)(getLegacyAuthStateFilePath(), { force: true });
239
283
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khangal.j/fireside-cli",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Fireside CLI",
5
5
  "license": "MIT",
6
6
  "private": false,