fabrica-e-commerce 0.1.13 → 0.1.15
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/package.json +4 -1
- package/src/store.js +50 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fabrica-e-commerce",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "Orange themed CMD launcher for deploying Fabrica e-commerce stores with Supabase and Vercel.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -39,5 +39,8 @@
|
|
|
39
39
|
"homepage": "https://github.com/trucount/fabrica-e-c#readme",
|
|
40
40
|
"bugs": {
|
|
41
41
|
"url": "https://github.com/trucount/fabrica-e-c/issues"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"boxen": "^8.0.1"
|
|
42
45
|
}
|
|
43
46
|
}
|
package/src/store.js
CHANGED
|
@@ -1,12 +1,60 @@
|
|
|
1
|
-
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { access, cp, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// Use the same "app data" convention native desktop apps use, so the data
|
|
6
|
+
// survives even when Fabrica is run via `npx` and never actually installed
|
|
7
|
+
// (npx's own package cache can be cleared at any time — this folder can't be,
|
|
8
|
+
// since it isn't part of the npx cache at all).
|
|
9
|
+
// Windows: %APPDATA%\FABRICA\E-COMMERCE (...\AppData\Roaming\...)
|
|
10
|
+
// macOS: ~/Library/Application Support/FABRICA/E-COMMERCE
|
|
11
|
+
// Linux: $XDG_DATA_HOME/FABRICA/E-COMMERCE or ~/.local/share/FABRICA/E-COMMERCE
|
|
12
|
+
function platformAppDataRoot() {
|
|
13
|
+
if (process.platform === 'win32') {
|
|
14
|
+
return process.env.APPDATA || path.join(homedir(), 'AppData', 'Roaming');
|
|
15
|
+
}
|
|
16
|
+
if (process.platform === 'darwin') {
|
|
17
|
+
return path.join(homedir(), 'Library', 'Application Support');
|
|
18
|
+
}
|
|
19
|
+
return process.env.XDG_DATA_HOME || path.join(homedir(), '.local', 'share');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const dataDir = path.join(platformAppDataRoot(), 'FABRICA', 'E-COMMERCE');
|
|
6
23
|
export const projectsFile = path.join(dataDir, 'projects.json');
|
|
7
24
|
export const buildsDir = path.join(dataDir, 'builds');
|
|
8
25
|
|
|
26
|
+
// Versions before this change stored everything under ~/.fabrica-ecommerce.
|
|
27
|
+
// Migrate that data once, automatically, so upgrading never loses existing
|
|
28
|
+
// projects/builds — it just moves them to the new standard location.
|
|
29
|
+
const legacyDataDir = path.join(homedir(), '.fabrica-ecommerce');
|
|
30
|
+
|
|
31
|
+
async function exists(target) {
|
|
32
|
+
try {
|
|
33
|
+
await access(target);
|
|
34
|
+
return true;
|
|
35
|
+
} catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function migrateLegacyDataIfNeeded() {
|
|
41
|
+
if (legacyDataDir === dataDir) return;
|
|
42
|
+
if (!(await exists(legacyDataDir))) return;
|
|
43
|
+
if (await exists(dataDir)) return; // new location already has data, don't touch it
|
|
44
|
+
|
|
45
|
+
await mkdir(path.dirname(dataDir), { recursive: true });
|
|
46
|
+
try {
|
|
47
|
+
await rename(legacyDataDir, dataDir);
|
|
48
|
+
} catch {
|
|
49
|
+
// rename() can fail across drives/filesystems (e.g. EXDEV on some Windows
|
|
50
|
+
// setups) — fall back to a recursive copy, then remove the old folder.
|
|
51
|
+
await cp(legacyDataDir, dataDir, { recursive: true });
|
|
52
|
+
await rm(legacyDataDir, { recursive: true, force: true });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
9
56
|
export async function ensureStore() {
|
|
57
|
+
await migrateLegacyDataIfNeeded();
|
|
10
58
|
await mkdir(buildsDir, { recursive: true });
|
|
11
59
|
}
|
|
12
60
|
|