@dagu-org/dagu 1.17.4 → 1.23.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.
- package/README.md +2 -2
- package/bin/cli +44 -0
- package/index.js +35 -76
- package/install.js +97 -123
- package/lib/platform.js +65 -119
- package/package.json +14 -14
- package/lib/cache.js +0 -230
- package/lib/constants.js +0 -60
- package/lib/download.js +0 -404
- package/lib/validate.js +0 -65
package/lib/platform.js
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const fs = require('fs');
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const fs = require("fs");
|
|
4
3
|
|
|
5
4
|
// Platform mapping from Node.js to npm package names
|
|
6
5
|
const PLATFORM_MAP = {
|
|
7
6
|
// Tier 1 - Most common platforms
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
"linux-x64": "dagu-linux-x64",
|
|
8
|
+
"linux-arm64": "dagu-linux-arm64",
|
|
9
|
+
"darwin-x64": "dagu-darwin-x64",
|
|
10
|
+
"darwin-arm64": "dagu-darwin-arm64",
|
|
11
|
+
"win32-x64": "dagu-win32-x64",
|
|
12
|
+
|
|
14
13
|
// Tier 2 - Common but less frequent
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
"linux-ia32": "dagu-linux-ia32",
|
|
15
|
+
"win32-ia32": "dagu-win32-ia32",
|
|
16
|
+
"freebsd-x64": "dagu-freebsd-x64",
|
|
17
|
+
|
|
19
18
|
// Tier 3 - Rare platforms
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
"win32-arm64": "dagu-win32-arm64",
|
|
20
|
+
"linux-ppc64": "dagu-linux-ppc64",
|
|
21
|
+
"linux-s390x": "dagu-linux-s390x",
|
|
22
|
+
"freebsd-arm64": "dagu-freebsd-arm64",
|
|
23
|
+
"freebsd-ia32": "dagu-freebsd-ia32",
|
|
24
|
+
"freebsd-arm": "dagu-freebsd-arm",
|
|
25
|
+
"openbsd-x64": "dagu-openbsd-x64",
|
|
26
|
+
"openbsd-arm64": "dagu-openbsd-arm64",
|
|
28
27
|
};
|
|
29
28
|
|
|
30
29
|
// Cache for binary path
|
|
@@ -36,37 +35,45 @@ let cachedBinaryPath = null;
|
|
|
36
35
|
*/
|
|
37
36
|
function getArmVariant() {
|
|
38
37
|
// First try process.config
|
|
39
|
-
if (
|
|
38
|
+
if (
|
|
39
|
+
process.config &&
|
|
40
|
+
process.config.variables &&
|
|
41
|
+
process.config.variables.arm_version
|
|
42
|
+
) {
|
|
40
43
|
return String(process.config.variables.arm_version);
|
|
41
44
|
}
|
|
42
|
-
|
|
45
|
+
|
|
43
46
|
// On Linux, check /proc/cpuinfo
|
|
44
|
-
if (process.platform ===
|
|
47
|
+
if (process.platform === "linux") {
|
|
45
48
|
try {
|
|
46
|
-
const cpuinfo = fs.readFileSync(
|
|
47
|
-
|
|
49
|
+
const cpuinfo = fs.readFileSync("/proc/cpuinfo", "utf8");
|
|
50
|
+
|
|
48
51
|
// Check for specific ARM architecture indicators
|
|
49
|
-
if (
|
|
50
|
-
|
|
52
|
+
if (
|
|
53
|
+
cpuinfo.includes("ARMv6") ||
|
|
54
|
+
cpuinfo.includes("ARM926") ||
|
|
55
|
+
cpuinfo.includes("ARM1176")
|
|
56
|
+
) {
|
|
57
|
+
return "6";
|
|
51
58
|
}
|
|
52
|
-
if (cpuinfo.includes(
|
|
53
|
-
return
|
|
59
|
+
if (cpuinfo.includes("ARMv7") || cpuinfo.includes("Cortex-A")) {
|
|
60
|
+
return "7";
|
|
54
61
|
}
|
|
55
|
-
|
|
62
|
+
|
|
56
63
|
// Check CPU architecture field
|
|
57
64
|
const archMatch = cpuinfo.match(/^CPU architecture:\s*(\d+)/m);
|
|
58
65
|
if (archMatch && archMatch[1]) {
|
|
59
66
|
const arch = parseInt(archMatch[1], 10);
|
|
60
|
-
if (arch >= 7) return
|
|
61
|
-
if (arch === 6) return
|
|
67
|
+
if (arch >= 7) return "7";
|
|
68
|
+
if (arch === 6) return "6";
|
|
62
69
|
}
|
|
63
70
|
} catch (e) {
|
|
64
71
|
// Ignore errors, fall through to default
|
|
65
72
|
}
|
|
66
73
|
}
|
|
67
|
-
|
|
74
|
+
|
|
68
75
|
// Default to ARMv7 (more common)
|
|
69
|
-
return
|
|
76
|
+
return "7";
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
/**
|
|
@@ -76,32 +83,17 @@ function getArmVariant() {
|
|
|
76
83
|
function getPlatformPackage() {
|
|
77
84
|
let platform = process.platform;
|
|
78
85
|
let arch = process.arch;
|
|
79
|
-
|
|
86
|
+
|
|
80
87
|
// Special handling for ARM on Linux
|
|
81
|
-
if (platform ===
|
|
88
|
+
if (platform === "linux" && arch === "arm") {
|
|
82
89
|
const variant = getArmVariant();
|
|
83
|
-
return
|
|
90
|
+
return `dagu-linux-armv${variant}`;
|
|
84
91
|
}
|
|
85
|
-
|
|
92
|
+
|
|
86
93
|
const key = `${platform}-${arch}`;
|
|
87
94
|
return PLATFORM_MAP[key] || null;
|
|
88
95
|
}
|
|
89
96
|
|
|
90
|
-
/**
|
|
91
|
-
* Get supported platforms list for error messages
|
|
92
|
-
* @returns {string} Formatted list of supported platforms
|
|
93
|
-
*/
|
|
94
|
-
function getSupportedPlatforms() {
|
|
95
|
-
const platforms = [
|
|
96
|
-
'Linux: x64, arm64, arm (v6/v7), ia32, ppc64le, s390x',
|
|
97
|
-
'macOS: x64 (Intel), arm64 (Apple Silicon)',
|
|
98
|
-
'Windows: x64, ia32, arm64',
|
|
99
|
-
'FreeBSD: x64, arm64, ia32, arm',
|
|
100
|
-
'OpenBSD: x64, arm64'
|
|
101
|
-
];
|
|
102
|
-
return platforms.join('\n - ');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
97
|
/**
|
|
106
98
|
* Get the path to the Dagu binary
|
|
107
99
|
* @returns {string|null} Path to binary or null if not found
|
|
@@ -111,15 +103,17 @@ function getBinaryPath() {
|
|
|
111
103
|
if (cachedBinaryPath && fs.existsSync(cachedBinaryPath)) {
|
|
112
104
|
return cachedBinaryPath;
|
|
113
105
|
}
|
|
114
|
-
|
|
115
|
-
const binaryName = process.platform ===
|
|
116
|
-
|
|
106
|
+
|
|
107
|
+
const binaryName = process.platform === "win32" ? "dagu.exe" : "dagu";
|
|
108
|
+
|
|
117
109
|
// First, try platform-specific package
|
|
118
110
|
const platformPackage = getPlatformPackage();
|
|
119
111
|
if (platformPackage) {
|
|
120
112
|
try {
|
|
121
113
|
// Try to resolve the binary using require.resolve (Sentry approach)
|
|
122
|
-
const binaryPath = require.resolve(
|
|
114
|
+
const binaryPath = require.resolve(
|
|
115
|
+
`${platformPackage}/bin/${binaryName}`
|
|
116
|
+
);
|
|
123
117
|
if (fs.existsSync(binaryPath)) {
|
|
124
118
|
cachedBinaryPath = binaryPath;
|
|
125
119
|
return binaryPath;
|
|
@@ -128,14 +122,14 @@ function getBinaryPath() {
|
|
|
128
122
|
// Package not installed or binary not found
|
|
129
123
|
}
|
|
130
124
|
}
|
|
131
|
-
|
|
125
|
+
|
|
132
126
|
// Fallback to local binary in main package
|
|
133
|
-
const localBinary = path.join(__dirname,
|
|
127
|
+
const localBinary = path.join(__dirname, "..", "bin", binaryName);
|
|
134
128
|
if (fs.existsSync(localBinary)) {
|
|
135
129
|
cachedBinaryPath = localBinary;
|
|
136
130
|
return localBinary;
|
|
137
131
|
}
|
|
138
|
-
|
|
132
|
+
|
|
139
133
|
return null;
|
|
140
134
|
}
|
|
141
135
|
|
|
@@ -147,24 +141,6 @@ function setPlatformBinary(binaryPath) {
|
|
|
147
141
|
cachedBinaryPath = binaryPath;
|
|
148
142
|
}
|
|
149
143
|
|
|
150
|
-
/**
|
|
151
|
-
* Get platform details for debugging
|
|
152
|
-
* @returns {object} Platform information
|
|
153
|
-
*/
|
|
154
|
-
function getPlatformInfo() {
|
|
155
|
-
return {
|
|
156
|
-
platform: process.platform,
|
|
157
|
-
arch: process.arch,
|
|
158
|
-
nodeVersion: process.version,
|
|
159
|
-
v8Version: process.versions.v8,
|
|
160
|
-
systemPlatform: os.platform(),
|
|
161
|
-
systemArch: os.arch(),
|
|
162
|
-
systemRelease: os.release(),
|
|
163
|
-
armVariant: process.platform === 'linux' && process.arch === 'arm' ? getArmVariant() : null,
|
|
164
|
-
detectedPackage: getPlatformPackage()
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
144
|
/**
|
|
169
145
|
* Check if platform-specific package is installed
|
|
170
146
|
* @returns {boolean} True if installed, false otherwise
|
|
@@ -174,9 +150,9 @@ function isPlatformSpecificPackageInstalled() {
|
|
|
174
150
|
if (!platformPackage) {
|
|
175
151
|
return false;
|
|
176
152
|
}
|
|
177
|
-
|
|
178
|
-
const binaryName = process.platform ===
|
|
179
|
-
|
|
153
|
+
|
|
154
|
+
const binaryName = process.platform === "win32" ? "dagu.exe" : "dagu";
|
|
155
|
+
|
|
180
156
|
try {
|
|
181
157
|
// Resolving will fail if the optionalDependency was not installed
|
|
182
158
|
require.resolve(`${platformPackage}/bin/${binaryName}`);
|
|
@@ -186,45 +162,15 @@ function isPlatformSpecificPackageInstalled() {
|
|
|
186
162
|
}
|
|
187
163
|
}
|
|
188
164
|
|
|
189
|
-
/**
|
|
190
|
-
* Check if we're in a cross-platform scenario (node_modules moved between architectures)
|
|
191
|
-
* @returns {object|null} Warning info if cross-platform detected
|
|
192
|
-
*/
|
|
193
|
-
function checkCrossPlatformScenario() {
|
|
194
|
-
const pkg = require('../package.json');
|
|
195
|
-
const optionalDeps = Object.keys(pkg.optionalDependencies || {});
|
|
196
|
-
const currentPlatformPackage = getPlatformPackage();
|
|
197
|
-
|
|
198
|
-
// Check if any platform package is installed but it's not the right one
|
|
199
|
-
for (const dep of optionalDeps) {
|
|
200
|
-
try {
|
|
201
|
-
require.resolve(`${dep}/package.json`);
|
|
202
|
-
// Package is installed
|
|
203
|
-
if (dep !== currentPlatformPackage) {
|
|
204
|
-
// Wrong platform package is installed
|
|
205
|
-
const installedPlatform = dep.replace('@dagu-org/dagu-', '');
|
|
206
|
-
const currentPlatform = `${process.platform}-${process.arch}`;
|
|
207
|
-
return {
|
|
208
|
-
installed: installedPlatform,
|
|
209
|
-
current: currentPlatform,
|
|
210
|
-
message: `WARNING: Found binary for ${installedPlatform} but current platform is ${currentPlatform}.\nThis usually happens when node_modules are copied between different systems.\nPlease reinstall @dagu-org/dagu to get the correct binary.`
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
} catch (e) {
|
|
214
|
-
// Package not installed, continue checking
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return null;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
165
|
module.exports = {
|
|
222
166
|
getPlatformPackage,
|
|
223
167
|
getBinaryPath,
|
|
224
168
|
setPlatformBinary,
|
|
225
|
-
getSupportedPlatforms,
|
|
226
|
-
getPlatformInfo,
|
|
227
|
-
getArmVariant,
|
|
228
169
|
isPlatformSpecificPackageInstalled,
|
|
229
|
-
|
|
230
|
-
|
|
170
|
+
getPlatformInfo: () => ({
|
|
171
|
+
platform: process.platform,
|
|
172
|
+
arch: process.arch,
|
|
173
|
+
nodeVersion: process.version,
|
|
174
|
+
detectedPackage: getPlatformPackage(),
|
|
175
|
+
}),
|
|
176
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dagu-org/dagu",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"description": "A powerful Workflow Orchestration Engine with simple declarative YAML API. Zero-dependency, single binary for Linux, macOS, and Windows.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"workflow",
|
|
@@ -25,25 +25,25 @@
|
|
|
25
25
|
"license": "GPL-3.0",
|
|
26
26
|
"author": "Dagu Contributors",
|
|
27
27
|
"bin": {
|
|
28
|
-
"dagu": "
|
|
28
|
+
"dagu": "bin/cli"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
|
-
"postinstall": "node install.js"
|
|
31
|
+
"postinstall": "node ./install.js"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"tar": "^
|
|
34
|
+
"tar": "^7.4.3"
|
|
35
35
|
},
|
|
36
36
|
"optionalDependencies": {
|
|
37
|
-
"@dagu-org/dagu-linux-x64": "1.
|
|
38
|
-
"@dagu-org/dagu-linux-arm64": "1.
|
|
39
|
-
"@dagu-org/dagu-darwin-x64": "1.
|
|
40
|
-
"@dagu-org/dagu-darwin-arm64": "1.
|
|
41
|
-
"@dagu-org/dagu-win32-x64": "1.
|
|
42
|
-
"@dagu-org/dagu-linux-ia32": "1.
|
|
43
|
-
"@dagu-org/dagu-linux-armv7": "1.
|
|
44
|
-
"@dagu-org/dagu-linux-armv6": "1.
|
|
45
|
-
"@dagu-org/dagu-win32-ia32": "1.
|
|
46
|
-
"@dagu-org/dagu-freebsd-x64": "1.
|
|
37
|
+
"@dagu-org/dagu-linux-x64": "1.23.0",
|
|
38
|
+
"@dagu-org/dagu-linux-arm64": "1.23.0",
|
|
39
|
+
"@dagu-org/dagu-darwin-x64": "1.23.0",
|
|
40
|
+
"@dagu-org/dagu-darwin-arm64": "1.23.0",
|
|
41
|
+
"@dagu-org/dagu-win32-x64": "1.23.0",
|
|
42
|
+
"@dagu-org/dagu-linux-ia32": "1.23.0",
|
|
43
|
+
"@dagu-org/dagu-linux-armv7": "1.23.0",
|
|
44
|
+
"@dagu-org/dagu-linux-armv6": "1.23.0",
|
|
45
|
+
"@dagu-org/dagu-win32-ia32": "1.23.0",
|
|
46
|
+
"@dagu-org/dagu-freebsd-x64": "1.23.0"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": ">=14.0.0"
|
package/lib/cache.js
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const crypto = require('crypto');
|
|
4
|
-
const os = require('os');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Get cache directory for binaries
|
|
8
|
-
* @returns {string} Cache directory path
|
|
9
|
-
*/
|
|
10
|
-
function getCacheDir() {
|
|
11
|
-
// Use standard cache locations based on platform
|
|
12
|
-
const homeDir = os.homedir();
|
|
13
|
-
let cacheDir;
|
|
14
|
-
|
|
15
|
-
if (process.platform === 'win32') {
|
|
16
|
-
// Windows: %LOCALAPPDATA%\dagu-cache
|
|
17
|
-
cacheDir = path.join(process.env.LOCALAPPDATA || path.join(homeDir, 'AppData', 'Local'), 'dagu-cache');
|
|
18
|
-
} else if (process.platform === 'darwin') {
|
|
19
|
-
// macOS: ~/Library/Caches/dagu
|
|
20
|
-
cacheDir = path.join(homeDir, 'Library', 'Caches', 'dagu');
|
|
21
|
-
} else {
|
|
22
|
-
// Linux/BSD: ~/.cache/dagu
|
|
23
|
-
cacheDir = path.join(process.env.XDG_CACHE_HOME || path.join(homeDir, '.cache'), 'dagu');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Allow override via environment variable
|
|
27
|
-
if (process.env.DAGU_CACHE_DIR) {
|
|
28
|
-
cacheDir = process.env.DAGU_CACHE_DIR;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return cacheDir;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Get cached binary path
|
|
36
|
-
* @param {string} version Version of the binary
|
|
37
|
-
* @param {string} platform Platform identifier
|
|
38
|
-
* @returns {string} Path to cached binary
|
|
39
|
-
*/
|
|
40
|
-
function getCachedBinaryPath(version, platform) {
|
|
41
|
-
const cacheDir = getCacheDir();
|
|
42
|
-
const binaryName = process.platform === 'win32' ? 'dagu.exe' : 'dagu';
|
|
43
|
-
return path.join(cacheDir, `${version}-${platform}`, binaryName);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Check if binary exists in cache
|
|
48
|
-
* @param {string} version Version of the binary
|
|
49
|
-
* @param {string} platform Platform identifier
|
|
50
|
-
* @returns {boolean} True if cached, false otherwise
|
|
51
|
-
*/
|
|
52
|
-
function isCached(version, platform) {
|
|
53
|
-
const cachedPath = getCachedBinaryPath(version, platform);
|
|
54
|
-
return fs.existsSync(cachedPath);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Save binary to cache
|
|
59
|
-
* @param {string} sourcePath Path to the binary to cache
|
|
60
|
-
* @param {string} version Version of the binary
|
|
61
|
-
* @param {string} platform Platform identifier
|
|
62
|
-
* @returns {string} Path to cached binary
|
|
63
|
-
*/
|
|
64
|
-
function cacheBinary(sourcePath, version, platform) {
|
|
65
|
-
const cachedPath = getCachedBinaryPath(version, platform);
|
|
66
|
-
const cacheDir = path.dirname(cachedPath);
|
|
67
|
-
|
|
68
|
-
// Create cache directory if it doesn't exist
|
|
69
|
-
if (!fs.existsSync(cacheDir)) {
|
|
70
|
-
fs.mkdirSync(cacheDir, { recursive: true });
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Copy binary to cache
|
|
74
|
-
fs.copyFileSync(sourcePath, cachedPath);
|
|
75
|
-
|
|
76
|
-
// Preserve executable permissions
|
|
77
|
-
if (process.platform !== 'win32') {
|
|
78
|
-
fs.chmodSync(cachedPath, 0o755);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Create a metadata file with cache info
|
|
82
|
-
const metadataPath = path.join(cacheDir, 'metadata.json');
|
|
83
|
-
const metadata = {
|
|
84
|
-
version,
|
|
85
|
-
platform,
|
|
86
|
-
cachedAt: new Date().toISOString(),
|
|
87
|
-
checksum: calculateChecksum(cachedPath)
|
|
88
|
-
};
|
|
89
|
-
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
|
|
90
|
-
|
|
91
|
-
return cachedPath;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Get binary from cache
|
|
96
|
-
* @param {string} version Version of the binary
|
|
97
|
-
* @param {string} platform Platform identifier
|
|
98
|
-
* @returns {string|null} Path to cached binary or null if not found
|
|
99
|
-
*/
|
|
100
|
-
function getCachedBinary(version, platform) {
|
|
101
|
-
if (!isCached(version, platform)) {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const cachedPath = getCachedBinaryPath(version, platform);
|
|
106
|
-
|
|
107
|
-
// Verify the cached binary still works
|
|
108
|
-
try {
|
|
109
|
-
fs.accessSync(cachedPath, fs.constants.X_OK);
|
|
110
|
-
return cachedPath;
|
|
111
|
-
} catch (e) {
|
|
112
|
-
// Cached binary is corrupted or not executable
|
|
113
|
-
// Remove it from cache
|
|
114
|
-
cleanCacheEntry(version, platform);
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Calculate checksum of a file
|
|
121
|
-
* @param {string} filePath Path to the file
|
|
122
|
-
* @returns {string} SHA256 checksum
|
|
123
|
-
*/
|
|
124
|
-
function calculateChecksum(filePath) {
|
|
125
|
-
const hash = crypto.createHash('sha256');
|
|
126
|
-
const data = fs.readFileSync(filePath);
|
|
127
|
-
hash.update(data);
|
|
128
|
-
return hash.digest('hex');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Clean specific cache entry
|
|
133
|
-
* @param {string} version Version of the binary
|
|
134
|
-
* @param {string} platform Platform identifier
|
|
135
|
-
*/
|
|
136
|
-
function cleanCacheEntry(version, platform) {
|
|
137
|
-
const cacheDir = path.dirname(getCachedBinaryPath(version, platform));
|
|
138
|
-
|
|
139
|
-
if (fs.existsSync(cacheDir)) {
|
|
140
|
-
fs.rmSync(cacheDir, { recursive: true, force: true });
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Clean old cache entries (older than specified days)
|
|
146
|
-
* @param {number} maxAgeDays Maximum age in days (default 30)
|
|
147
|
-
*/
|
|
148
|
-
function cleanOldCache(maxAgeDays = 30) {
|
|
149
|
-
const cacheDir = getCacheDir();
|
|
150
|
-
|
|
151
|
-
if (!fs.existsSync(cacheDir)) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const maxAgeMs = maxAgeDays * 24 * 60 * 60 * 1000;
|
|
156
|
-
const now = Date.now();
|
|
157
|
-
|
|
158
|
-
try {
|
|
159
|
-
const entries = fs.readdirSync(cacheDir);
|
|
160
|
-
|
|
161
|
-
for (const entry of entries) {
|
|
162
|
-
const entryPath = path.join(cacheDir, entry);
|
|
163
|
-
const metadataPath = path.join(entryPath, 'metadata.json');
|
|
164
|
-
|
|
165
|
-
if (fs.existsSync(metadataPath)) {
|
|
166
|
-
try {
|
|
167
|
-
const metadata = JSON.parse(fs.readFileSync(metadataPath, 'utf8'));
|
|
168
|
-
const cachedAt = new Date(metadata.cachedAt).getTime();
|
|
169
|
-
|
|
170
|
-
if (now - cachedAt > maxAgeMs) {
|
|
171
|
-
fs.rmSync(entryPath, { recursive: true, force: true });
|
|
172
|
-
}
|
|
173
|
-
} catch (e) {
|
|
174
|
-
// Invalid metadata, remove entry
|
|
175
|
-
fs.rmSync(entryPath, { recursive: true, force: true });
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
} catch (e) {
|
|
180
|
-
// Ignore errors during cleanup
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Get cache size
|
|
186
|
-
* @returns {number} Total size in bytes
|
|
187
|
-
*/
|
|
188
|
-
function getCacheSize() {
|
|
189
|
-
const cacheDir = getCacheDir();
|
|
190
|
-
|
|
191
|
-
if (!fs.existsSync(cacheDir)) {
|
|
192
|
-
return 0;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
let totalSize = 0;
|
|
196
|
-
|
|
197
|
-
function calculateDirSize(dirPath) {
|
|
198
|
-
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
199
|
-
|
|
200
|
-
for (const entry of entries) {
|
|
201
|
-
const fullPath = path.join(dirPath, entry.name);
|
|
202
|
-
|
|
203
|
-
if (entry.isDirectory()) {
|
|
204
|
-
calculateDirSize(fullPath);
|
|
205
|
-
} else {
|
|
206
|
-
const stats = fs.statSync(fullPath);
|
|
207
|
-
totalSize += stats.size;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
try {
|
|
213
|
-
calculateDirSize(cacheDir);
|
|
214
|
-
} catch (e) {
|
|
215
|
-
// Ignore errors
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return totalSize;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
module.exports = {
|
|
222
|
-
getCacheDir,
|
|
223
|
-
getCachedBinaryPath,
|
|
224
|
-
isCached,
|
|
225
|
-
cacheBinary,
|
|
226
|
-
getCachedBinary,
|
|
227
|
-
cleanCacheEntry,
|
|
228
|
-
cleanOldCache,
|
|
229
|
-
getCacheSize
|
|
230
|
-
};
|
package/lib/constants.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Constants for Dagu npm distribution
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const GITHUB_ORG = 'dagu-org';
|
|
6
|
-
const GITHUB_REPO = 'dagu';
|
|
7
|
-
const NPM_ORG = '@dagu-org';
|
|
8
|
-
|
|
9
|
-
// Tier classification for platform support
|
|
10
|
-
const PLATFORM_TIERS = {
|
|
11
|
-
TIER_1: [
|
|
12
|
-
'linux-x64',
|
|
13
|
-
'linux-arm64',
|
|
14
|
-
'darwin-x64',
|
|
15
|
-
'darwin-arm64',
|
|
16
|
-
'win32-x64'
|
|
17
|
-
],
|
|
18
|
-
TIER_2: [
|
|
19
|
-
'linux-ia32',
|
|
20
|
-
'linux-armv7',
|
|
21
|
-
'win32-ia32',
|
|
22
|
-
'freebsd-x64'
|
|
23
|
-
],
|
|
24
|
-
TIER_3: [
|
|
25
|
-
'linux-armv6',
|
|
26
|
-
'linux-ppc64',
|
|
27
|
-
'linux-s390x',
|
|
28
|
-
'win32-arm64',
|
|
29
|
-
'freebsd-arm64',
|
|
30
|
-
'freebsd-ia32',
|
|
31
|
-
'freebsd-arm',
|
|
32
|
-
'openbsd-x64',
|
|
33
|
-
'openbsd-arm64'
|
|
34
|
-
]
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// Error messages
|
|
38
|
-
const ERRORS = {
|
|
39
|
-
UNSUPPORTED_PLATFORM: 'Unsupported platform',
|
|
40
|
-
DOWNLOAD_FAILED: 'Failed to download binary',
|
|
41
|
-
VALIDATION_FAILED: 'Binary validation failed',
|
|
42
|
-
CHECKSUM_MISMATCH: 'Checksum verification failed',
|
|
43
|
-
EXTRACTION_FAILED: 'Failed to extract archive'
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// URLs
|
|
47
|
-
const URLS = {
|
|
48
|
-
RELEASES: `https://github.com/${GITHUB_ORG}/${GITHUB_REPO}/releases`,
|
|
49
|
-
ISSUES: `https://github.com/${GITHUB_ORG}/${GITHUB_REPO}/issues`,
|
|
50
|
-
BUILD_DOCS: `https://github.com/${GITHUB_ORG}/${GITHUB_REPO}#building-from-source`
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
module.exports = {
|
|
54
|
-
GITHUB_ORG,
|
|
55
|
-
GITHUB_REPO,
|
|
56
|
-
NPM_ORG,
|
|
57
|
-
PLATFORM_TIERS,
|
|
58
|
-
ERRORS,
|
|
59
|
-
URLS
|
|
60
|
-
};
|