@procoderx/copy-file 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/README.md +183 -278
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,48 +1,48 @@
1
- # ProCoderX Copy CLI
1
+ # @procoderx/pcx-copy
2
2
 
3
- A lightweight Node.js CLI utility for copying files from one location to another.
3
+ > A lightweight Node.js CLI utility for copying files from one location to another.
4
4
 
5
- `pcx-copy` provides a simple command-line interface for copying files while demonstrating the fundamentals of building and publishing an npm-based Node.js CLI package.
5
+ [![npm version](https://img.shields.io/npm/v/@procoderx/pcx-copy.svg)](https://www.npmjs.com/package/@procoderx/pcx-copy)
6
+
7
+ [![npm downloads](https://img.shields.io/npm/dm/@procoderx/pcx-copy.svg)](https://www.npmjs.com/package/@procoderx/pcx-copy)
8
+
9
+ [![License](https://img.shields.io/npm/l/@procoderx/pcx-copy.svg)](https://www.npmjs.com/package/@procoderx/pcx-copy)
6
10
 
7
11
  ---
8
12
 
9
13
  ## Features
10
14
 
11
- - Copy files from the command line
12
- - Supports relative and absolute file paths
13
- - Uses Node.js `fs/promises`
14
- - Supports binary files through `Buffer`
15
- - Provides CLI argument validation
16
- - Displays clear usage and error messages
17
- - Returns appropriate process exit codes
18
- - Exposes a custom npm CLI command
19
- - Supports global npm installation
20
- - Can be executed through `npx`
21
- - Separates CLI handling from file-copy logic
15
+ - **File Copying** — Copy files directly from the terminal.
16
+ - **Relative & Absolute Paths** — Supports both relative and absolute source and destination paths.
17
+ - **Binary File Support** — Uses Node.js `Buffer` to handle binary file contents.
18
+ - **Node.js CLI** Provides a simple command-line interface through the `pcx-copy` command.
19
+ - **Modern ES Modules** — Built using JavaScript ES Modules.
20
+ - **CLI Validation** Validates required source and destination arguments.
21
+ - **Error Handling** Provides clear usage and file-system error messages.
22
+ - **Process Exit Codes** Returns appropriate exit codes when operations fail.
23
+ - **Global CLI Support** — Install the package globally and use the command from anywhere.
24
+ - **Zero-Install Execution** Run the package directly with `npx`.
22
25
 
23
26
  ---
24
27
 
25
- ## Tech Stack
28
+ ## Quick Start
26
29
 
27
- - **Node.js**
28
- - **JavaScript**
29
- - **ES Modules**
30
- - **npm**
31
- - **Node.js `fs/promises`**
32
- - **Node.js `path`**
30
+ Run the package directly with `npx`:
33
31
 
34
- ---
32
+ ```bash
33
+ npx @procoderx/pcx-copy ./source.txt ./destination.txt
34
+ ```
35
35
 
36
- ## Requirements
36
+ Or install it globally:
37
37
 
38
- - Node.js `18+`
39
- - npm `9+`
38
+ ```bash
39
+ npm install -g @procoderx/pcx-copy
40
+ ```
40
41
 
41
- Check your installed versions:
42
+ Then use:
42
43
 
43
44
  ```bash
44
- node -v
45
- npm -v
45
+ pcx-copy ./source.txt ./destination.txt
46
46
  ```
47
47
 
48
48
  ---
@@ -51,100 +51,79 @@ npm -v
51
51
 
52
52
  ### Global Installation
53
53
 
54
- Install the CLI globally with npm:
54
+ Install the package globally:
55
55
 
56
56
  ```bash
57
- npm install -g pcx-copy
57
+ npm install -g @procoderx/pcx-copy
58
58
  ```
59
59
 
60
60
  After installation, the `pcx-copy` command is available globally.
61
61
 
62
- Verify the installation:
62
+ Verify the command:
63
63
 
64
64
  ```bash
65
65
  pcx-copy
66
66
  ```
67
67
 
68
- If no arguments are provided, the CLI displays its usage information:
68
+ If the required arguments are missing, the CLI displays:
69
69
 
70
70
  ```text
71
71
  Usage: pcx-copy <source-file> <destination-file>
72
72
  ```
73
73
 
74
- ---
75
-
76
- ## Using with npx
74
+ ### Local Installation
77
75
 
78
- The package can also be executed with `npx` without manually installing it globally:
76
+ Install the package as a dependency in your project:
79
77
 
80
78
  ```bash
81
- npx pcx-copy <source-file> <destination-file>
79
+ npm install @procoderx/pcx-copy
82
80
  ```
83
81
 
84
- Example:
85
-
86
- ```bash
87
- npx pcx-copy ./money.png ./buffer.png
88
- ```
89
-
90
- This is useful when you want to run the CLI without adding it as a global command.
91
-
92
- ---
93
-
94
- ## Local Development
82
+ ### Using npx
95
83
 
96
- Clone the repository:
84
+ The package can also be executed without installing it globally:
97
85
 
98
86
  ```bash
99
- git clone https://github.com/theprocoderx/pcx-copy.git
87
+ npx @procoderx/pcx-copy ./source.txt ./destination.txt
100
88
  ```
101
89
 
102
- Navigate into the project:
90
+ ---
103
91
 
104
- ```bash
105
- cd pcx-copy
106
- ```
92
+ ## Usage
107
93
 
108
- Install the project dependencies:
94
+ ### Syntax
109
95
 
110
96
  ```bash
111
- npm install
97
+ pcx-copy <source-file> <destination-file>
112
98
  ```
113
99
 
114
- Link the package locally:
100
+ The command accepts:
115
101
 
116
- ```bash
117
- npm link
118
- ```
119
-
120
- After linking, the `pcx-copy` command becomes available in your terminal.
102
+ | Argument | Required | Description |
103
+ | -------------------- | -------- | -------------------------------------------- |
104
+ | `<source-file>` | Yes | Path to the file that should be copied |
105
+ | `<destination-file>` | Yes | Path where the copied file should be created |
121
106
 
122
107
  ---
123
108
 
124
- ## Usage
109
+ ## Examples
125
110
 
126
- ### Basic Syntax
127
-
128
- ```bash
129
- pcx-copy <source-file> <destination-file>
130
- ```
131
-
132
- ### Example
111
+ ### 1. Copy a File in the Same Directory
133
112
 
134
113
  ```bash
135
114
  pcx-copy ./money.png ./buffer.png
136
115
  ```
137
116
 
138
- The command copies:
117
+ This copies:
139
118
 
140
119
  ```text
141
- ./money.png
120
+ money.png
142
121
  ```
143
122
 
144
123
  to:
145
124
 
146
125
  ```text
147
- ./buffer.png
126
+ buffer.png
148
127
  ```
149
128
 
150
129
  Successful output:
@@ -155,131 +134,123 @@ Successfully copied "./money.png" to "./buffer.png"
155
134
 
156
135
  ---
157
136
 
158
- ## Copying to Another Location
159
-
160
- The CLI supports relative and absolute destination paths.
161
-
162
- ### Relative Path
137
+ ### 2. Copy to Another Directory
163
138
 
164
139
  ```bash
165
140
  pcx-copy ./money.png ./backup/money.png
166
141
  ```
167
142
 
168
- ### Absolute Path
143
+ The source file is copied to the `backup` directory.
144
+
145
+ ---
146
+
147
+ ### 3. Copy Using an Absolute Destination Path
169
148
 
170
149
  ```bash
171
150
  pcx-copy ./money.png /c/Users/user/Desktop/buffer.png
172
151
  ```
173
152
 
174
- The source and destination paths are resolved before the file operation is performed.
153
+ This copies the file to the specified absolute destination path.
175
154
 
176
155
  ---
177
156
 
178
- ## Supported Files
179
-
180
- The utility works with regular files, including binary files such as:
157
+ ### 4. Copy a Text File
181
158
 
182
- - Images
183
- - PDFs
184
- - ZIP files
185
- - Videos
186
- - Documents
187
- - Other binary files
159
+ ```bash
160
+ pcx-copy ./source.txt ./backup/source.txt
161
+ ```
188
162
 
189
- The file contents are handled as a Node.js `Buffer`.
163
+ The same command works with text files and other regular files.
190
164
 
191
165
  ---
192
166
 
193
167
  ## How It Works
194
168
 
195
- The CLI receives arguments from the terminal through `process.argv`.
196
-
197
- For example:
169
+ The application separates the command-line interface from the file-copy logic.
198
170
 
199
- ```bash
200
- pcx-copy ./money.png ./buffer.png
201
- ```
202
-
203
- The arguments are read using:
204
-
205
- ```js
206
- const [, , source, destination] = process.argv;
207
- ```
208
-
209
- The values become:
210
-
211
- ```text
212
- source → ./money.png
213
- destination → ./buffer.png
214
- ```
171
+ 1. The CLI receives the source and destination paths.
172
+ 2. The arguments are read using `process.argv`.
173
+ 3. The CLI validates the required arguments.
174
+ 4. The file-copy function resolves the paths.
175
+ 5. The source file is read asynchronously.
176
+ 6. The file contents are stored in a `Buffer`.
177
+ 7. The buffer is written to the destination file.
178
+ 8. The CLI reports the result to the terminal.
215
179
 
216
- The CLI then passes these values to the file-copy logic.
180
+ The overall flow is:
217
181
 
218
182
  ```text
219
- Terminal
220
-
221
- │ pcx-copy <source> <destination>
222
-
183
+ Terminal Command
184
+
223
185
  process.argv
224
-
225
- CLI Argument Validation
226
-
186
+
187
+ Argument Validation
188
+
227
189
  copyFile()
228
-
190
+
229
191
  readFile()
230
-
192
+
231
193
  Buffer
232
-
194
+
233
195
  writeFile()
234
-
196
+
235
197
  Destination File
236
198
  ```
237
199
 
238
200
  ---
239
201
 
240
- ## File Copy Implementation
202
+ ## Project Architecture
241
203
 
242
- The core file operation uses Node.js `fs/promises`:
204
+ ```text
205
+ pcx-copy/
243
206
 
244
- ```js
245
- const content = await readFile(sourcePath);
207
+ ├── bin/
208
+ │ └── pcx-copy.js # CLI entry point
246
209
 
247
- await writeFile(destinationPath, content);
248
- ```
210
+ ├── src/
211
+ │ └── copyFile.js # Core file-copy logic
249
212
 
250
- The process is asynchronous and uses promises, allowing the CLI to work with Node.js's asynchronous filesystem APIs.
213
+ ├── package.json # npm package configuration
214
+ ├── README.md
215
+ └── LICENSE
216
+ ```
251
217
 
252
- ---
218
+ ### `bin/pcx-copy.js`
253
219
 
254
- ## CLI Entry Point
220
+ Responsible for:
255
221
 
256
- The executable entry point is:
222
+ - Starting the CLI application
223
+ - Reading `process.argv`
224
+ - Validating CLI arguments
225
+ - Calling the file-copy function
226
+ - Displaying CLI messages
227
+ - Handling process exit codes
257
228
 
258
- ```text
259
- bin/pcx-copy.js
260
- ```
229
+ ### `src/copyFile.js`
261
230
 
262
- It starts with the Node.js shebang:
231
+ Contains the core file-copy logic responsible for:
263
232
 
264
- ```js
265
- #!/usr/bin/env node
266
- ```
233
+ - Resolving file paths
234
+ - Reading the source file
235
+ - Writing the destination file
236
+ - Performing the copy operation
267
237
 
268
- The shebang allows the file to be executed directly as a command when npm links the package's `bin` entry.
238
+ ### `package.json`
269
239
 
270
- The CLI entry point is responsible for:
240
+ Defines:
271
241
 
272
- - Reading command-line arguments
273
- - Validating arguments
274
- - Calling the copy operation
275
- - Displaying CLI messages
276
- - Handling process exit codes
242
+ - npm package metadata
243
+ - Package name
244
+ - Version
245
+ - ES Module configuration
246
+ - CLI binary mapping
247
+ - Package configuration
277
248
 
278
249
  ---
279
250
 
280
- ## npm `bin` Configuration
251
+ ## npm CLI Configuration
281
252
 
282
- The executable command is registered in `package.json`:
253
+ The package exposes the `pcx-copy` command through the `bin` field in `package.json`.
283
254
 
284
255
  ```json
285
256
  {
@@ -289,92 +260,44 @@ The executable command is registered in `package.json`:
289
260
  }
290
261
  ```
291
262
 
292
- This creates the relationship:
263
+ This creates the following relationship:
293
264
 
294
265
  ```text
295
266
  pcx-copy
296
-
267
+
297
268
  bin/pcx-copy.js
298
-
269
+
299
270
  Node.js
300
271
  ```
301
272
 
302
- Therefore, users can run:
273
+ The CLI entry file uses a Node.js shebang:
303
274
 
304
- ```bash
305
- pcx-copy ./source.txt ./destination.txt
275
+ ```js
276
+ #!/usr/bin/env node
306
277
  ```
307
278
 
308
- instead of:
309
-
310
- ```bash
311
- node bin/pcx-copy.js ./source.txt ./destination.txt
312
- ```
279
+ This allows npm to execute the file as a command.
313
280
 
314
281
  ---
315
282
 
316
- ## Project Structure
317
-
318
- ```text
319
- pcx-copy/
320
- ├── bin/
321
- │ └── pcx-copy.js ← CLI entry point (JavaScript)
322
- ├── src/
323
- │ └── copyFile.js ← file-copy logic (JavaScript)
324
- ├── package.json ← npm configuration
325
- ├── README.md ← documentation
326
- ├── LICENSE ← MIT license
327
- ├── .gitignore
328
- └── .npmignore
329
- ```
283
+ ## File Copy Implementation
330
284
 
331
- ---
285
+ The core operation uses Node.js `fs/promises`:
332
286
 
333
- ## Architecture
287
+ ```js
288
+ const content = await readFile(sourcePath);
334
289
 
335
- ```text
336
- Terminal
337
-
338
- │ CLI command
339
-
340
- bin/pcx-copy.js
341
-
342
- ├── process.argv
343
- ├── argument validation
344
- └── CLI output
345
-
346
-
347
- src/copyFile.js
348
-
349
- ├── path resolution
350
- ├── readFile()
351
- └── writeFile()
352
-
353
-
354
- Destination File
290
+ await writeFile(destinationPath, content);
355
291
  ```
356
292
 
357
- The CLI layer and application layer have separate responsibilities.
358
-
359
- ### `bin/pcx-copy.js`
360
-
361
- Responsible for:
362
-
363
- - CLI arguments
364
- - Input validation
365
- - CLI output
366
- - Process exit codes
367
-
368
- ### `src/copyFile.js`
369
-
370
- Responsible for:
293
+ The file contents are handled as a `Buffer`, allowing the utility to copy different types of files, including:
371
294
 
372
- - Resolving paths
373
- - Reading the source file
374
- - Writing the destination file
375
- - Performing the file-copy operation
376
-
377
- This separation keeps the package easier to maintain and test.
295
+ - Images
296
+ - PDFs
297
+ - ZIP files
298
+ - Videos
299
+ - Documents
300
+ - Other binary files
378
301
 
379
302
  ---
380
303
 
@@ -394,74 +317,62 @@ displays:
394
317
  Usage: pcx-copy <source-file> <destination-file>
395
318
  ```
396
319
 
397
- File-system errors are handled using `try...catch`:
320
+ File-system errors are handled and reported to the terminal.
398
321
 
399
- ```js
400
- try {
401
- // Copy operation
402
- } catch (error) {
403
- console.error(`Failed to copy file: ${error.message}`);
404
- process.exit(1);
405
- }
406
- ```
322
+ Example:
407
323
 
408
- A successful operation exits normally.
324
+ ```text
325
+ Failed to copy file: ENOENT: no such file or directory
326
+ ```
409
327
 
410
- A failed operation returns a non-zero process exit code.
328
+ The process returns a non-zero exit code when the operation fails.
411
329
 
412
330
  ---
413
331
 
414
- ## Development
332
+ ## Requirements
333
+
334
+ - Node.js 18+
335
+ - npm 9+
415
336
 
416
- Run the CLI directly during development:
337
+ Check your installed versions:
417
338
 
418
339
  ```bash
419
- node bin/pcx-copy.js ./source.txt ./destination.txt
340
+ node -v
341
+ npm -v
420
342
  ```
421
343
 
422
- Or link the package locally:
344
+ ---
345
+
346
+ ## Development
347
+
348
+ Clone the repository:
423
349
 
424
350
  ```bash
425
- npm link
351
+ git clone https://github.com/theprocoderx/pcx-copy.git
426
352
  ```
427
353
 
428
- Then use:
354
+ Navigate into the project:
429
355
 
430
356
  ```bash
431
- pcx-copy ./source.txt ./destination.txt
357
+ cd pcx-copy
432
358
  ```
433
359
 
434
- ---
360
+ Install dependencies:
435
361
 
436
- ## Package Configuration
437
-
438
- The npm package uses the `bin` field to expose the CLI command.
362
+ ```bash
363
+ npm install
364
+ ```
439
365
 
440
- Example:
366
+ For local CLI development, link the package:
441
367
 
442
- ```json
443
- {
444
- "name": "pcx-copy",
445
- "version": "1.0.0",
446
- "type": "module",
447
- "bin": {
448
- "pcx-copy": "./bin/pcx-copy.js"
449
- }
450
- }
368
+ ```bash
369
+ npm link
451
370
  ```
452
371
 
453
- The important relationship is:
372
+ The command can then be tested locally:
454
373
 
455
- ```text
456
- npm package
457
-
458
- package.json
459
-
460
- bin
461
-
462
- pcx-copy command
463
-
464
- bin/pcx-copy.js
374
+ ```bash
375
+ pcx-copy ./source.txt ./destination.txt
465
376
  ```
466
377
 
467
378
  ---
@@ -472,39 +383,33 @@ Possible future versions may include:
472
383
 
473
384
  - `--help` option
474
385
  - `--version` option
386
+ - `--update` option
475
387
  - Directory copying
476
388
  - Recursive directory copying
477
389
  - Multiple source files
478
390
  - File-existence checks
479
391
  - Overwrite confirmation
480
392
  - Progress indicators
481
- - Better cross-platform path handling
482
- - Improved error codes
393
+ - Improved cross-platform path handling
483
394
  - Automated tests
484
- - npm package versioning and release automation
395
+ - Improved CLI error codes
485
396
 
486
397
  ---
487
398
 
488
- ## Learning Objectives
489
-
490
- This project demonstrates the fundamentals of Node.js CLI development:
399
+ ## License
491
400
 
492
- - `process.argv`
493
- - Node.js `fs/promises`
494
- - `Buffer`
495
- - Node.js `path`
496
- - ES Modules
497
- - Shebangs
498
- - npm `bin` configuration
499
- - CLI argument validation
500
- - Process exit codes
501
- - npm package structure
502
- - Global CLI installation
503
- - `npx` execution
504
- - Separation of CLI and application logic
401
+ This project is licensed under the **MIT License**.
505
402
 
506
403
  ---
507
404
 
508
- ## License
405
+ ## Author
509
406
 
510
- This project is licensed under the **MIT License**.
407
+ **ProCoderX** (Magan Singh)
408
+
409
+ Building practical Node.js tools and developer-focused projects.
410
+
411
+ - **Website:** [procoderx.com](https://procoderx.com)
412
+ - **GitHub:** [@TheProCoderX](https://github.com/theprocoderx)
413
+ - **LinkedIn:** [ProCoderX](https://www.linkedin.com/in/procoderx)
414
+ - **npm:** [@procoderx](https://www.npmjs.com/~procoderx)
415
+ - **Email:** [procoderxs@gmail.com](mailto:procoderxs@gmail.com)
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@procoderx/copy-file",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A lightweight Node.js CLI tool for copying files from one location to another.",
5
5
  "type": "module",
6
6
  "bin": {
7
- "pcx-copy": "./bin/pcx-copy.js"
7
+ "pcx-copy-file": "./bin/pcx-copy.js"
8
8
  },
9
9
  "files": [
10
10
  "bin",