@mikrojs/esptool 0.0.7

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Bjørge Næss
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/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @mikrojs/esptool
2
+
3
+ Downloads and caches standalone [esptool](https://github.com/espressif/esptool) binaries from Espressif. Eliminates the Python dependency for flashing ESP32 devices.
4
+
5
+ Binaries are cached locally after the first download.
@@ -0,0 +1,7 @@
1
+ declare const ESPTOOL_VERSION = "v5.2.0";
2
+ /**
3
+ * Get the path to the esptool binary, downloading it if necessary.
4
+ */
5
+ export declare function getEsptoolPath(): Promise<string>;
6
+ export { ESPTOOL_VERSION };
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,QAAA,MAAM,eAAe,WAAW,CAAA;AA8DhC;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAoCtD;AAED,OAAO,EAAC,eAAe,EAAC,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,95 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { createWriteStream } from 'node:fs';
3
+ import * as fs from 'node:fs/promises';
4
+ import * as os from 'node:os';
5
+ import * as path from 'node:path';
6
+ import { pipeline } from 'node:stream/promises';
7
+ import { promisify } from 'node:util';
8
+ const execFileAsync = promisify(execFile);
9
+ const ESPTOOL_VERSION = 'v5.2.0';
10
+ const GITHUB_REPO = 'espressif/esptool';
11
+ const CACHE_DIR = path.join(os.homedir(), '.cache', 'mikrojs', 'esptool');
12
+ function getPlatform() {
13
+ switch (os.platform()) {
14
+ case 'linux':
15
+ return 'linux';
16
+ case 'darwin':
17
+ return 'macos';
18
+ case 'win32':
19
+ return 'windows';
20
+ default:
21
+ throw new Error(`Unsupported platform: ${os.platform()}`);
22
+ }
23
+ }
24
+ function getArch() {
25
+ switch (os.arch()) {
26
+ case 'x64':
27
+ return 'amd64';
28
+ case 'arm64':
29
+ return getPlatform() === 'linux' ? 'aarch64' : 'arm64';
30
+ default:
31
+ throw new Error(`Unsupported architecture: ${os.arch()}`);
32
+ }
33
+ }
34
+ function getAssetName(platform, arch) {
35
+ const ext = platform === 'windows' ? 'zip' : 'tar.gz';
36
+ return `esptool-${ESPTOOL_VERSION}-${platform}-${arch}.${ext}`;
37
+ }
38
+ function getExtractedDirName(platform, arch) {
39
+ return `esptool-${platform}-${arch}`;
40
+ }
41
+ function getBinaryName(platform) {
42
+ return platform === 'windows' ? 'esptool.exe' : 'esptool';
43
+ }
44
+ function getDownloadUrl(assetName) {
45
+ return `https://github.com/${GITHUB_REPO}/releases/download/${ESPTOOL_VERSION}/${assetName}`;
46
+ }
47
+ async function download(url, destPath) {
48
+ const response = await fetch(url, { redirect: 'follow' });
49
+ if (!response.ok) {
50
+ throw new Error(`Failed to download ${url}: ${response.status} ${response.statusText}`);
51
+ }
52
+ if (!response.body) {
53
+ throw new Error(`No response body from ${url}`);
54
+ }
55
+ await fs.mkdir(path.dirname(destPath), { recursive: true });
56
+ const fileStream = createWriteStream(destPath);
57
+ await pipeline(response.body, fileStream);
58
+ }
59
+ /**
60
+ * Get the path to the esptool binary, downloading it if necessary.
61
+ */
62
+ export async function getEsptoolPath() {
63
+ const platform = getPlatform();
64
+ const arch = getArch();
65
+ const binaryName = getBinaryName(platform);
66
+ const extractedDir = getExtractedDirName(platform, arch);
67
+ const binaryPath = path.join(CACHE_DIR, ESPTOOL_VERSION, extractedDir, binaryName);
68
+ // Check if already cached
69
+ try {
70
+ await fs.access(binaryPath, fs.constants.X_OK);
71
+ return binaryPath;
72
+ }
73
+ catch {
74
+ // Not cached, proceed with download
75
+ }
76
+ const assetName = getAssetName(platform, arch);
77
+ const downloadUrl = getDownloadUrl(assetName);
78
+ const versionDir = path.join(CACHE_DIR, ESPTOOL_VERSION);
79
+ const archivePath = path.join(versionDir, assetName);
80
+ await fs.mkdir(versionDir, { recursive: true });
81
+ await download(downloadUrl, archivePath);
82
+ if (platform === 'windows') {
83
+ await execFileAsync('unzip', ['-o', archivePath, '-d', versionDir]);
84
+ }
85
+ else {
86
+ await execFileAsync('tar', ['xzf', archivePath, '-C', versionDir]);
87
+ }
88
+ // Clean up the archive
89
+ await fs.rm(archivePath);
90
+ // Ensure the binary is executable
91
+ await fs.chmod(binaryPath, 0o755);
92
+ return binaryPath;
93
+ }
94
+ export { ESPTOOL_VERSION };
95
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAC,iBAAiB,EAAC,MAAM,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B,MAAM,EAAE,CAAC,EAAE,CAAC,WAAW,CAAC,CAAA;IAExB,kCAAkC;IAClC,MAAM,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,CAAA;IAEjC,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,OAAO,EAAC,eAAe,EAAC,CAAA"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@mikrojs/esptool",
3
+ "version": "0.0.7",
4
+ "description": "Download and cache standalone esptool binaries from Espressif",
5
+ "keywords": [
6
+ "esp32",
7
+ "esptool",
8
+ "mikrojs"
9
+ ],
10
+ "homepage": "https://github.com/mikrojs/mikrojs#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/mikrojs/mikrojs/issues"
13
+ },
14
+ "license": "MIT",
15
+ "author": "Bjørge Næss <bjoerge@gmail.com>",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/mikrojs/mikrojs.git"
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "exports": {
26
+ ".": "./dist/index.js",
27
+ "./package.json": "./package.json"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^25.6.0"
31
+ },
32
+ "engines": {
33
+ "node": ">=24.0.0"
34
+ },
35
+ "scripts": {
36
+ "build:ts": "tsc -p tsconfig.build.json",
37
+ "publint": "publint",
38
+ "typecheck": "tsc --noEmit",
39
+ "watch": "tsc -p tsconfig.build.json --watch --preserveWatchOutput"
40
+ }
41
+ }