@procoderx/pcx-copy 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ProCoderX
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,374 @@
1
+ # @procoderx/pcx-copy
2
+
3
+ > A lightweight Node.js CLI utility for copying files from one location to another.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@procoderx/pcx-copy.svg)](https://www.npmjs.com/package/@procoderx/pcx-copy)
6
+ [![npm downloads](https://img.shields.io/npm/dm/@procoderx/pcx-copy.svg)](https://www.npmjs.com/package/@procoderx/pcx-copy)
7
+ [![License](https://img.shields.io/npm/l/@procoderx/pcx-copy.svg)](https://www.npmjs.com/package/@procoderx/pcx-copy)
8
+
9
+ ---
10
+
11
+ ## Features
12
+
13
+ - Copy files directly from the terminal
14
+ - Supports relative and absolute file paths
15
+ - Handles binary files using Node.js `Buffer`
16
+ - Built with modern ES Modules
17
+ - Provides CLI argument validation
18
+ - Displays clear usage and error messages
19
+ - Returns appropriate process exit codes
20
+ - Supports global installation
21
+ - Supports `npx` execution
22
+ - Separates CLI handling from core file-copy logic
23
+
24
+ ---
25
+
26
+ ## Requirements
27
+
28
+ - Node.js `18+`
29
+ - npm `9+`
30
+
31
+ Check installed versions:
32
+
33
+ ```bash
34
+ node -v
35
+ npm -v
36
+ ```
37
+
38
+ ---
39
+
40
+ ## Quick Start
41
+
42
+ Run directly with `npx`:
43
+
44
+ ```bash
45
+ npx @procoderx/pcx-copy ./source.txt ./destination.txt
46
+ ```
47
+
48
+ Or install globally:
49
+
50
+ ```bash
51
+ npm install -g @procoderx/pcx-copy
52
+ ```
53
+
54
+ Then use:
55
+
56
+ ```bash
57
+ pcx-copy ./source.txt ./destination.txt
58
+ ```
59
+
60
+ ---
61
+
62
+ ## Installation
63
+
64
+ ### Global Installation
65
+
66
+ ```bash
67
+ npm install -g @procoderx/pcx-copy
68
+ ```
69
+
70
+ The `pcx-copy` command is then available globally.
71
+
72
+ Verify the installation:
73
+
74
+ ```bash
75
+ pcx-copy
76
+ ```
77
+
78
+ Output:
79
+
80
+ ```text
81
+ Usage: pcx-copy <source-file> <destination-file>
82
+ ```
83
+
84
+ ### Local Installation
85
+
86
+ ```bash
87
+ npm install @procoderx/pcx-copy
88
+ ```
89
+
90
+ ### Using npx
91
+
92
+ ```bash
93
+ npx @procoderx/pcx-copy ./source.txt ./destination.txt
94
+ ```
95
+
96
+ ---
97
+
98
+ ## Usage
99
+
100
+ ### Syntax
101
+
102
+ ```bash
103
+ pcx-copy <source-file> <destination-file>
104
+ ```
105
+
106
+ | Argument | Required | Description |
107
+ | -------------------- | -------- | -------------------------------------------- |
108
+ | `<source-file>` | Yes | Path to the source file |
109
+ | `<destination-file>` | Yes | Path where the copied file should be created |
110
+
111
+ ---
112
+
113
+ ## Examples
114
+
115
+ ### Copy a File
116
+
117
+ ```bash
118
+ pcx-copy ./money.png ./buffer.png
119
+ ```
120
+
121
+ Output:
122
+
123
+ ```text
124
+ Successfully copied "./money.png" to "./buffer.png"
125
+ ```
126
+
127
+ ### Copy to Another Directory
128
+
129
+ ```bash
130
+ pcx-copy ./money.png ./backup/money.png
131
+ ```
132
+
133
+ ### Copy Using an Absolute Path
134
+
135
+ ```bash
136
+ pcx-copy ./money.png /c/Users/user/Desktop/buffer.png
137
+ ```
138
+
139
+ ### Run with npx
140
+
141
+ ```bash
142
+ npx @procoderx/pcx-copy ./money.png ./buffer.png
143
+ ```
144
+
145
+ ---
146
+
147
+ ## Supported Files
148
+
149
+ The utility can copy regular files including:
150
+
151
+ - Images
152
+ - PDFs
153
+ - ZIP files
154
+ - Documents
155
+ - Videos
156
+ - Executables
157
+ - Other binary files
158
+
159
+ File contents are handled as raw data, so the utility is not limited to text files.
160
+
161
+ ---
162
+
163
+ ## How It Works
164
+
165
+ The CLI separates command-line handling from the core file-copy operation.
166
+
167
+ ```text
168
+ Terminal Command
169
+
170
+ process.argv
171
+
172
+ Argument Validation
173
+
174
+ copyFile()
175
+
176
+ readFile()
177
+
178
+ Buffer
179
+
180
+ writeFile()
181
+
182
+ Destination File
183
+ ```
184
+
185
+ The CLI:
186
+
187
+ - Reads arguments using `process.argv`
188
+ - Validates the source and destination paths
189
+ - Reads the source file asynchronously
190
+ - Handles the file contents as a `Buffer`
191
+ - Writes the contents to the destination
192
+ - Reports the result to the terminal
193
+
194
+ ---
195
+
196
+ ## Project Structure
197
+
198
+ ```text
199
+ pcx-copy/
200
+
201
+ ├── bin/
202
+ │ └── pcx-copy.js
203
+
204
+ ├── src/
205
+ │ └── copyFile.js
206
+
207
+ ├── package.json
208
+ ├── README.md
209
+ └── LICENSE
210
+ ```
211
+
212
+ ### `bin/pcx-copy.js`
213
+
214
+ The CLI entry point responsible for:
215
+
216
+ - Reading command-line arguments
217
+ - Validating input
218
+ - Calling the copy function
219
+ - Displaying CLI messages
220
+ - Handling process exit codes
221
+
222
+ ### `src/copyFile.js`
223
+
224
+ Contains the core file-copy logic responsible for:
225
+
226
+ - Resolving paths
227
+ - Reading the source file
228
+ - Writing the destination file
229
+ - Performing the copy operation
230
+
231
+ ---
232
+
233
+ ## npm CLI Configuration
234
+
235
+ The package exposes the `pcx-copy` command through the `bin` field in `package.json`.
236
+
237
+ ```json
238
+ {
239
+ "name": "@procoderx/pcx-copy",
240
+ "type": "module",
241
+ "bin": {
242
+ "pcx-copy": "./bin/pcx-copy.js"
243
+ }
244
+ }
245
+ ```
246
+
247
+ This creates the following relationship:
248
+
249
+ ```text
250
+ pcx-copy
251
+
252
+ bin/pcx-copy.js
253
+
254
+ Node.js
255
+ ```
256
+
257
+ The CLI entry file uses the Node.js shebang:
258
+
259
+ ```js
260
+ #!/usr/bin/env node
261
+ ```
262
+
263
+ This allows npm to execute the file directly as a terminal command.
264
+
265
+ ---
266
+
267
+ ## Core Implementation
268
+
269
+ The file-copy operation uses Node.js `fs/promises`:
270
+
271
+ ```js
272
+ const content = await readFile(sourcePath);
273
+
274
+ await writeFile(destinationPath, content);
275
+ ```
276
+
277
+ The file contents are handled as a `Buffer`, allowing the utility to copy both text and binary files.
278
+
279
+ ---
280
+
281
+ ## Error Handling
282
+
283
+ If required arguments are missing:
284
+
285
+ ```bash
286
+ pcx-copy
287
+ ```
288
+
289
+ The CLI displays:
290
+
291
+ ```text
292
+ Usage: pcx-copy <source-file> <destination-file>
293
+ ```
294
+
295
+ File-system errors are reported to the terminal.
296
+
297
+ Example:
298
+
299
+ ```text
300
+ Failed to copy file: ENOENT: no such file or directory
301
+ ```
302
+
303
+ Failed operations return a non-zero process exit code.
304
+
305
+ ---
306
+
307
+ ## Development
308
+
309
+ Clone the repository:
310
+
311
+ ```bash
312
+ git clone https://github.com/theprocoderx/pcx-copy.git
313
+ ```
314
+
315
+ Navigate into the project:
316
+
317
+ ```bash
318
+ cd pcx-copy
319
+ ```
320
+
321
+ Install dependencies:
322
+
323
+ ```bash
324
+ npm install
325
+ ```
326
+
327
+ Link the package locally:
328
+
329
+ ```bash
330
+ npm link
331
+ ```
332
+
333
+ Test the CLI:
334
+
335
+ ```bash
336
+ pcx-copy ./source.txt ./destination.txt
337
+ ```
338
+
339
+ ---
340
+
341
+ ## Future Improvements
342
+
343
+ Possible future versions may include:
344
+
345
+ - `--help`
346
+ - `--version`
347
+ - Overwrite confirmation
348
+ - File-existence checks
349
+ - Directory copying
350
+ - Recursive copying
351
+ - Multiple source files
352
+ - Progress indicators
353
+ - Improved error codes
354
+ - Automated tests
355
+
356
+ ---
357
+
358
+ ## License
359
+
360
+ This project is licensed under the **MIT License**.
361
+
362
+ ---
363
+
364
+ ## Author
365
+
366
+ **ProCoderX (Magan Singh)**
367
+
368
+ Building practical Node.js tools and developer-focused projects.
369
+
370
+ - **Website:** https://procoderx.com
371
+ - **GitHub:** https://github.com/theprocoderx
372
+ - **LinkedIn:** https://www.linkedin.com/in/procoderx
373
+ - **npm:** https://www.npmjs.com/~procoderx
374
+ - **Email:** procoderxs@gmail.com
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { copyFile } from '../src/copyFile.js';
4
+
5
+ const [, , source, destination] = process.argv;
6
+
7
+ if (!source || !destination) {
8
+ console.error(
9
+ 'Usage: pcx-copy <source-file> <destination-file>'
10
+ );
11
+ process.exit(1);
12
+ }
13
+
14
+ await copyFile(source, destination);
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@procoderx/pcx-copy",
3
+ "version": "1.0.0",
4
+ "description": "A lightweight Node.js CLI utility for copying files from one location to another.",
5
+ "type": "module",
6
+ "bin": {
7
+ "pcx-copy": "./bin/pcx-copy.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "keywords": [
16
+ "copy",
17
+ "copy-file",
18
+ "file-copy",
19
+ "copy-cli",
20
+ "nodejs-cli",
21
+ "cli-tool"
22
+ ],
23
+ "author": {
24
+ "name": "ProCoderX (Magan Singh)",
25
+ "url": "https://procoderx.com"
26
+ },
27
+ "license": "MIT",
28
+ "engines": {
29
+ "node": ">=18"
30
+ }
31
+ }
@@ -0,0 +1,20 @@
1
+ import { readFile, writeFile } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+
4
+ export async function copyFile(source, destination) {
5
+ try {
6
+ const sourcePath = resolve(source);
7
+ const destinationPath = resolve(destination);
8
+
9
+ const content = await readFile(sourcePath);
10
+
11
+ await writeFile(destinationPath, content);
12
+
13
+ console.log(
14
+ `Successfully copied "${source}" to "${destination}"`
15
+ );
16
+ } catch (error) {
17
+ console.error(`Failed to copy file: ${error.message}`);
18
+ process.exit(1);
19
+ }
20
+ }