File tree Expand file tree Collapse file tree 3 files changed +74
-1
lines changed
Expand file tree Collapse file tree 3 files changed +74
-1
lines changed Original file line number Diff line number Diff line change @@ -26,3 +26,12 @@ The diff format is the streaming compressed format; use `patchStream` to apply i
2626
2727Apply diff file to old file and write new file by streaming. In sync mode
2828returns ` outNewPath ` . In async mode, callback signature is ` (err, outNewPath) ` .
29+
30+ ## CLI
31+
32+ After install, you can run:
33+
34+ ``` bash
35+ hdp diff < oldFile> < newFile> < outDiff>
36+ hdp patch < oldFile> < diffFile> < outNew>
37+ ```
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+ 'use strict' ;
3+
4+ const hdiffpatch = require ( '..' ) ;
5+
6+ function usage ( ) {
7+ console . log (
8+ [
9+ 'Usage:' ,
10+ ' hdp diff <oldFile> <newFile> <outDiff>' ,
11+ ' hdp patch <oldFile> <diffFile> <outNew>' ,
12+ '' ,
13+ 'Notes:' ,
14+ ' - Uses streaming diff/patch for low memory usage.' ,
15+ ' - Outputs are files specified by <outDiff>/<outNew>.' ,
16+ ] . join ( '\n' )
17+ ) ;
18+ }
19+
20+ function fail ( msg ) {
21+ if ( msg ) console . error ( `Error: ${ msg } ` ) ;
22+ usage ( ) ;
23+ process . exit ( 1 ) ;
24+ }
25+
26+ const args = process . argv . slice ( 2 ) ;
27+ if ( args . length === 0 || args [ 0 ] === '-h' || args [ 0 ] === '--help' ) {
28+ usage ( ) ;
29+ process . exit ( 0 ) ;
30+ }
31+
32+ const cmd = args [ 0 ] ;
33+ if ( cmd === 'diff' ) {
34+ if ( args . length !== 4 ) fail ( 'diff expects 3 arguments.' ) ;
35+ const oldFile = args [ 1 ] ;
36+ const newFile = args [ 2 ] ;
37+ const outDiff = args [ 3 ] ;
38+ try {
39+ hdiffpatch . diffStream ( oldFile , newFile , outDiff ) ;
40+ console . log ( outDiff ) ;
41+ } catch ( err ) {
42+ fail ( err && err . message ? err . message : String ( err ) ) ;
43+ }
44+ process . exit ( 0 ) ;
45+ }
46+
47+ if ( cmd === 'patch' ) {
48+ if ( args . length !== 4 ) fail ( 'patch expects 3 arguments.' ) ;
49+ const oldFile = args [ 1 ] ;
50+ const diffFile = args [ 2 ] ;
51+ const outNew = args [ 3 ] ;
52+ try {
53+ hdiffpatch . patchStream ( oldFile , diffFile , outNew ) ;
54+ console . log ( outNew ) ;
55+ } catch ( err ) {
56+ fail ( err && err . message ? err . message : String ( err ) ) ;
57+ }
58+ process . exit ( 0 ) ;
59+ }
60+
61+ fail ( `unknown command: ${ cmd } ` ) ;
Original file line number Diff line number Diff line change 11{
22 "name" : " node-hdiffpatch" ,
3- "version" : " 1.1.0 " ,
3+ "version" : " 1.1.1 " ,
44 "description" : " hdiffpatch port to node.js" ,
55 "main" : " index.js" ,
6+ "bin" : {
7+ "hdp" : " bin/hdiffpatch.js"
8+ },
69 "scripts" : {
710 "test" : " node test/test.js" ,
811 "benchmark" : " node --expose-gc test/benchmark.js" ,
You can’t perform that action at this time.
0 commit comments