wallapop-cli 0.1.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/LICENSE +21 -0
- package/cli.cjs +31 -0
- package/install.cjs +77 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Microck
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/cli.cjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { spawn } = require('node:child_process');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
|
|
7
|
+
const binary = process.platform === 'win32' ? 'wallapop.exe' : 'wallapop';
|
|
8
|
+
const child = spawn(path.join(__dirname, binary), process.argv.slice(2), { stdio: 'inherit' });
|
|
9
|
+
const handlers = new Map();
|
|
10
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
11
|
+
const handler = () => child.kill(signal);
|
|
12
|
+
handlers.set(signal, handler);
|
|
13
|
+
process.on(signal, handler);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
child.once('error', error => {
|
|
17
|
+
if (error.code === 'ENOENT') {
|
|
18
|
+
console.error('wallapop-cli: the release binary is missing. Enable install scripts and run npm rebuild wallapop-cli.');
|
|
19
|
+
} else {
|
|
20
|
+
console.error(`wallapop-cli: could not start the release binary: ${error.message}`);
|
|
21
|
+
}
|
|
22
|
+
process.exitCode = 1;
|
|
23
|
+
});
|
|
24
|
+
child.once('close', (code, signal) => {
|
|
25
|
+
for (const [name, handler] of handlers) process.removeListener(name, handler);
|
|
26
|
+
if (signal) {
|
|
27
|
+
process.kill(process.pid, signal);
|
|
28
|
+
} else {
|
|
29
|
+
process.exitCode = process.exitCode || code || 0;
|
|
30
|
+
}
|
|
31
|
+
});
|
package/install.cjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { createHash } = require('node:crypto');
|
|
4
|
+
const { createWriteStream } = require('node:fs');
|
|
5
|
+
const { chmod, lstat, mkdtemp, readFile, rename, rm } = require('node:fs/promises');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { Readable, Transform } = require('node:stream');
|
|
8
|
+
const { pipeline } = require('node:stream/promises');
|
|
9
|
+
const { version } = require('./package.json');
|
|
10
|
+
|
|
11
|
+
async function download(url, destination) {
|
|
12
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(120_000) });
|
|
13
|
+
if (!response.ok || !response.body) {
|
|
14
|
+
throw new Error(`Download failed (${response.status}): ${url}`);
|
|
15
|
+
}
|
|
16
|
+
const hash = createHash('sha256');
|
|
17
|
+
await pipeline(
|
|
18
|
+
Readable.fromWeb(response.body),
|
|
19
|
+
new Transform({
|
|
20
|
+
transform(chunk, encoding, callback) {
|
|
21
|
+
hash.update(chunk);
|
|
22
|
+
callback(null, chunk);
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
createWriteStream(destination, { flags: 'wx' }),
|
|
26
|
+
);
|
|
27
|
+
return hash.digest('hex');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function install() {
|
|
31
|
+
const os = { linux: 'linux', darwin: 'darwin', win32: 'windows' }[process.platform];
|
|
32
|
+
const arch = { x64: 'amd64', arm64: 'arm64' }[process.arch];
|
|
33
|
+
if (!os || !arch) {
|
|
34
|
+
throw new Error(`No Wallapop binary is available for ${process.platform}/${process.arch}. Supported platforms are Linux, macOS, and Windows on x64 and arm64.`);
|
|
35
|
+
}
|
|
36
|
+
const binary = process.platform === 'win32' ? 'wallapop.exe' : 'wallapop';
|
|
37
|
+
const archive = `wallapop_${version}_${os}_${arch}.${os === 'windows' ? 'zip' : 'tar.gz'}`;
|
|
38
|
+
const base = `https://github.com/Microck/wallapop-cli/releases/download/v${version}`;
|
|
39
|
+
// Use the package directory so the final rename stays on the same filesystem.
|
|
40
|
+
const temporary = await mkdtemp(path.join(__dirname, '.install-'));
|
|
41
|
+
try {
|
|
42
|
+
const checksumsPath = path.join(temporary, 'checksums.txt');
|
|
43
|
+
const archivePath = path.join(temporary, archive);
|
|
44
|
+
await download(`${base}/checksums.txt`, checksumsPath);
|
|
45
|
+
const checksums = await readFile(checksumsPath, 'utf8');
|
|
46
|
+
const matches = checksums.split(/\r?\n/).map(line => line.match(/^([a-fA-F0-9]{64})\s+\*?(.+)$/))
|
|
47
|
+
.filter(match => match && match[2] === archive);
|
|
48
|
+
if (matches.length !== 1) {
|
|
49
|
+
throw new Error(`Release v${version} must contain exactly one checksum for ${archive}.`);
|
|
50
|
+
}
|
|
51
|
+
const actual = await download(`${base}/${archive}`, archivePath);
|
|
52
|
+
if (actual !== matches[0][1].toLowerCase()) {
|
|
53
|
+
throw new Error(`SHA-256 checksum mismatch for ${archive}; the download will not be installed.`);
|
|
54
|
+
}
|
|
55
|
+
const extracted = path.join(temporary, 'extracted');
|
|
56
|
+
if (os === 'windows') {
|
|
57
|
+
await require('extract-zip')(archivePath, { dir: extracted });
|
|
58
|
+
} else {
|
|
59
|
+
const { mkdir } = require('node:fs/promises');
|
|
60
|
+
await mkdir(extracted);
|
|
61
|
+
await require('tar').x({ file: archivePath, cwd: extracted, strict: true });
|
|
62
|
+
}
|
|
63
|
+
const source = path.join(extracted, binary);
|
|
64
|
+
if (!(await lstat(source)).isFile()) {
|
|
65
|
+
throw new Error(`Release archive does not contain a regular ${binary} file.`);
|
|
66
|
+
}
|
|
67
|
+
await chmod(source, 0o755);
|
|
68
|
+
await rename(source, path.join(__dirname, binary));
|
|
69
|
+
} finally {
|
|
70
|
+
await rm(temporary, { recursive: true, force: true });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
install().catch(error => {
|
|
75
|
+
console.error(`wallapop-cli installation failed: ${error.message}`);
|
|
76
|
+
process.exitCode = 1;
|
|
77
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wallapop-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Terminal CLI for Wallapop",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Microck",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Microck/wallapop-cli.git",
|
|
10
|
+
"directory": "npm"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/Microck/wallapop-cli",
|
|
13
|
+
"bugs": "https://github.com/Microck/wallapop-cli/issues",
|
|
14
|
+
"bin": {
|
|
15
|
+
"wallapop": "cli.cjs",
|
|
16
|
+
"wallapop-cli": "cli.cjs"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"postinstall": "node install.cjs"
|
|
20
|
+
},
|
|
21
|
+
"files": ["cli.cjs", "install.cjs", "LICENSE"],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=22"
|
|
24
|
+
},
|
|
25
|
+
"os": ["linux", "darwin", "win32"],
|
|
26
|
+
"cpu": ["x64", "arm64"],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"extract-zip": "2.0.1",
|
|
32
|
+
"tar": "7.5.22"
|
|
33
|
+
}
|
|
34
|
+
}
|