@caleb-collar/steamcmd 1.0.0-alpha.1 → 1.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.
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @module steamcmd
3
+ * @description ESM wrapper for steamcmd module
4
+ */
5
+
6
+ import { createRequire } from 'module'
7
+ const require = createRequire(import.meta.url)
8
+
9
+ const steamcmd = require('./steamcmd.js')
10
+
11
+ // Named exports
12
+ export const install = steamcmd.install
13
+ export const isInstalled = steamcmd.isInstalled
14
+ export const ensureInstalled = steamcmd.ensureInstalled
15
+ export const getInfo = steamcmd.getInfo
16
+ export const SteamCmdError = steamcmd.SteamCmdError
17
+ export const DownloadError = steamcmd.DownloadError
18
+ export const InstallError = steamcmd.InstallError
19
+ export const downloadWithProgress = steamcmd.downloadWithProgress
20
+ export const installWithProgress = steamcmd.installWithProgress
21
+ export const getInstalledApps = steamcmd.getInstalledApps
22
+ export const update = steamcmd.update
23
+ export const validate = steamcmd.validate
24
+ export const getInstalledVersion = steamcmd.getInstalledVersion
25
+ export const createProgressEmitter = steamcmd.createProgressEmitter
26
+
27
+ // Default export
28
+ export default steamcmd
package/package.json CHANGED
@@ -1,35 +1,41 @@
1
1
  {
2
2
  "name": "@caleb-collar/steamcmd",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.1.0",
4
4
  "description": "Node.js wrapper for SteamCMD - download, install, and manage Steam applications programmatically",
5
- "main": "src/steamcmd.js",
6
- "module": "src/steamcmd.mjs",
7
- "types": "types/steamcmd.d.ts",
5
+ "main": "dist/steamcmd.js",
6
+ "module": "dist/steamcmd.mjs",
7
+ "types": "dist/steamcmd.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
10
  "import": {
11
- "types": "./types/steamcmd.d.ts",
12
- "default": "./src/steamcmd.mjs"
11
+ "types": "./dist/steamcmd.d.ts",
12
+ "default": "./dist/steamcmd.mjs"
13
13
  },
14
14
  "require": {
15
- "types": "./types/steamcmd.d.ts",
16
- "default": "./src/steamcmd.js"
15
+ "types": "./dist/steamcmd.d.ts",
16
+ "default": "./dist/steamcmd.js"
17
17
  }
18
18
  }
19
19
  },
20
20
  "scripts": {
21
- "lint": "standard --verbose **/*.js bin/*",
21
+ "build": "tsc && npm run build:esm-wrapper",
22
+ "build:esm-wrapper": "node -e \"const fs=require('fs');fs.writeFileSync('dist/steamcmd.mjs',fs.readFileSync('src/steamcmd.mjs.template','utf8'))\"",
23
+ "clean": "rimraf dist docs",
24
+ "docs": "typedoc --out docs src/steamcmd.ts",
25
+ "prepublishOnly": "npm run clean && npm run build",
26
+ "lint": "biome check .",
27
+ "lint:fix": "biome check --write .",
28
+ "format": "biome format --write .",
22
29
  "test": "vitest run",
23
30
  "test:watch": "vitest",
24
31
  "test:coverage": "vitest run --coverage"
25
32
  },
26
33
  "bin": {
27
- "steamcmd": "./bin/steamcmd"
34
+ "steamcmd": "bin/steamcmd"
28
35
  },
29
36
  "files": [
30
- "src/",
37
+ "dist/",
31
38
  "bin/",
32
- "types/",
33
39
  "README.md",
34
40
  "LICENSE",
35
41
  "CHANGELOG.md"
@@ -64,8 +70,13 @@
64
70
  "unzipper": "^0.12.3"
65
71
  },
66
72
  "devDependencies": {
73
+ "@biomejs/biome": "^2.3.13",
74
+ "@types/node": "^25.1.0",
75
+ "@types/unzipper": "^0.10.11",
67
76
  "@vitest/coverage-v8": "^4.0.18",
68
- "standard": "^17.1.2",
77
+ "rimraf": "^6.1.2",
78
+ "typedoc": "^0.28.16",
79
+ "typescript": "^5.9.3",
69
80
  "vitest": "^4.0.18"
70
81
  }
71
82
  }
package/src/download.js DELETED
@@ -1,220 +0,0 @@
1
- /**
2
- * @module steamcmd/download
3
- * @description Downloads and extracts SteamCMD for the current platform
4
- * @private
5
- */
6
-
7
- const https = require('https')
8
- const fs = require('fs')
9
- const tar = require('tar')
10
- const unzip = require('unzipper')
11
- const { EventEmitter } = require('events')
12
-
13
- const env = require('./env')
14
-
15
- /**
16
- * SteamCMD download URLs by platform
17
- */
18
- const DOWNLOAD_URLS = {
19
- darwin:
20
- 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd_osx.tar.gz',
21
- linux:
22
- 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz',
23
- win32: 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip'
24
- }
25
-
26
- /**
27
- * Custom error class for download failures
28
- */
29
- class DownloadError extends Error {
30
- constructor (message, code) {
31
- super(message)
32
- this.name = 'DownloadError'
33
- this.code = code
34
- }
35
- }
36
-
37
- /**
38
- * Download and extract SteamCMD for the current platform
39
- * @param {Object} [options] - Download options
40
- * @param {Function} [options.onProgress] - Progress callback(progress) with { phase, percent, bytesDownloaded, totalBytes }
41
- * @param {Function} [callback] - Optional callback(err). If omitted, returns a Promise.
42
- * @returns {Promise<void>|undefined} Promise if no callback provided
43
- *
44
- * @example
45
- * // With progress callback
46
- * await download({
47
- * onProgress: (progress) => {
48
- * console.log(`${progress.phase}: ${progress.percent}%`);
49
- * }
50
- * });
51
- */
52
- function download (options, callback) {
53
- // Handle legacy signature: download(callback)
54
- if (typeof options === 'function') {
55
- callback = options
56
- options = {}
57
- }
58
- options = options || {}
59
-
60
- // Support Promise-based usage
61
- if (typeof callback !== 'function') {
62
- return new Promise((resolve, reject) => {
63
- download(options, (err) => {
64
- if (err) reject(err)
65
- else resolve()
66
- })
67
- })
68
- }
69
-
70
- const onProgress =
71
- typeof options.onProgress === 'function' ? options.onProgress : () => {}
72
-
73
- const platform = env.platform()
74
- const url = DOWNLOAD_URLS[platform]
75
- const destDir = env.directory()
76
-
77
- if (!url) {
78
- callback(
79
- new DownloadError(
80
- `Unsupported platform: ${platform}`,
81
- 'UNSUPPORTED_PLATFORM'
82
- )
83
- )
84
- return
85
- }
86
-
87
- // Ensure destination directory exists
88
- try {
89
- fs.mkdirSync(destDir, { recursive: true })
90
- } catch (err) {
91
- callback(
92
- new DownloadError(
93
- `Failed to create directory ${destDir}: ${err.message}`,
94
- 'DIRECTORY_ERROR'
95
- )
96
- )
97
- return
98
- }
99
-
100
- onProgress({
101
- phase: 'starting',
102
- percent: 0,
103
- bytesDownloaded: 0,
104
- totalBytes: 0
105
- })
106
-
107
- https
108
- .get(url, (res) => {
109
- if (res.statusCode !== 200) {
110
- callback(
111
- new DownloadError(
112
- `Failed to download SteamCMD: HTTP ${res.statusCode}`,
113
- 'HTTP_ERROR'
114
- )
115
- )
116
- return
117
- }
118
-
119
- const totalBytes = parseInt(res.headers['content-length'], 10) || 0
120
- let bytesDownloaded = 0
121
-
122
- res.on('data', (chunk) => {
123
- bytesDownloaded += chunk.length
124
- const percent =
125
- totalBytes > 0 ? Math.round((bytesDownloaded / totalBytes) * 100) : 0
126
- onProgress({
127
- phase: 'downloading',
128
- percent,
129
- bytesDownloaded,
130
- totalBytes
131
- })
132
- })
133
-
134
- if (platform === 'darwin' || platform === 'linux') {
135
- res
136
- .pipe(tar.x({ cwd: destDir }))
137
- .on('error', (err) => {
138
- callback(
139
- new DownloadError(
140
- `Failed to extract tar archive: ${err.message}`,
141
- 'EXTRACT_ERROR'
142
- )
143
- )
144
- })
145
- .on('finish', () => {
146
- onProgress({
147
- phase: 'complete',
148
- percent: 100,
149
- bytesDownloaded,
150
- totalBytes
151
- })
152
- callback(null)
153
- })
154
- } else if (platform === 'win32') {
155
- res
156
- .pipe(unzip.Extract({ path: destDir }))
157
- .on('error', (err) => {
158
- callback(
159
- new DownloadError(
160
- `Failed to extract zip archive: ${err.message}`,
161
- 'EXTRACT_ERROR'
162
- )
163
- )
164
- })
165
- .on('close', () => {
166
- onProgress({
167
- phase: 'complete',
168
- percent: 100,
169
- bytesDownloaded,
170
- totalBytes
171
- })
172
- callback(null)
173
- })
174
- }
175
- })
176
- .on('error', (err) => {
177
- callback(
178
- new DownloadError(`Network error: ${err.message}`, 'NETWORK_ERROR')
179
- )
180
- })
181
- }
182
-
183
- /**
184
- * Download SteamCMD with EventEmitter-based progress
185
- * @param {Object} [options] - Download options
186
- * @returns {EventEmitter} Emitter that fires 'progress', 'error', and 'complete' events
187
- *
188
- * @example
189
- * const emitter = downloadWithProgress();
190
- * emitter.on('progress', (p) => console.log(`${p.percent}%`));
191
- * emitter.on('complete', () => console.log('Done!'));
192
- * emitter.on('error', (err) => console.error(err));
193
- */
194
- function downloadWithProgress (options) {
195
- const emitter = new EventEmitter()
196
-
197
- // Run download in next tick to allow event binding
198
- process.nextTick(() => {
199
- download(
200
- {
201
- ...options,
202
- onProgress: (progress) => emitter.emit('progress', progress)
203
- },
204
- (err) => {
205
- if (err) {
206
- emitter.emit('error', err)
207
- } else {
208
- emitter.emit('complete')
209
- }
210
- }
211
- )
212
- })
213
-
214
- return emitter
215
- }
216
-
217
- module.exports = download
218
- module.exports.downloadWithProgress = downloadWithProgress
219
- module.exports.DownloadError = DownloadError
220
- module.exports.DOWNLOAD_URLS = DOWNLOAD_URLS
package/src/env.js DELETED
@@ -1,66 +0,0 @@
1
- /**
2
- * @module steamcmd/env
3
- * @description Platform detection and path resolution for SteamCMD
4
- * @private
5
- */
6
-
7
- const os = require('os')
8
- const path = require('path')
9
- const envPaths = require('env-paths')
10
-
11
- const paths = envPaths('steamcmd', { suffix: '' })
12
-
13
- /**
14
- * Supported platforms for SteamCMD
15
- */
16
- const SUPPORTED_PLATFORMS = ['linux', 'darwin', 'win32']
17
-
18
- /**
19
- * Get the SteamCMD installation directory
20
- * @returns {string} Path to the SteamCMD directory
21
- */
22
- function directory () {
23
- return paths.data
24
- }
25
-
26
- /**
27
- * Get the current platform
28
- * @returns {string} The current OS platform
29
- */
30
- function platform () {
31
- return os.platform()
32
- }
33
-
34
- /**
35
- * Check if the current platform is supported
36
- * @returns {boolean} True if platform is supported
37
- */
38
- function isPlatformSupported () {
39
- return SUPPORTED_PLATFORMS.includes(platform())
40
- }
41
-
42
- /**
43
- * Get the path to the SteamCMD executable
44
- * @returns {string|null} Path to executable or null if unsupported platform
45
- */
46
- function executable () {
47
- const plat = platform()
48
-
49
- if (plat === 'linux' || plat === 'darwin') {
50
- return path.resolve(directory(), 'steamcmd.sh')
51
- }
52
-
53
- if (plat === 'win32') {
54
- return path.resolve(directory(), 'steamcmd.exe')
55
- }
56
-
57
- return null
58
- }
59
-
60
- module.exports = {
61
- directory,
62
- executable,
63
- platform,
64
- isPlatformSupported,
65
- SUPPORTED_PLATFORMS
66
- }