@@ -3,6 +3,7 @@ const getStdin = require('get-stdin');
33const fg = require ( 'fast-glob' ) ;
44const mm = require ( 'micromatch' ) ;
55const parser = require ( 'js2xmlparser' ) ;
6+ const fs = require ( 'fs' ) ;
67
78class StaticSitemapCliCommand extends Command {
89
@@ -94,7 +95,11 @@ class StaticSitemapCliCommand extends Command {
9495 doubleQuotes : true
9596 }
9697 } ) ;
97- this . log ( sitemap ) ;
98+ if ( flags . save ) {
99+ fs . writeFileSync ( `${ addSlash ( flags . root ) } sitemap.xml` , `${ sitemap } \n` , 'utf-8' ) ;
100+ } else {
101+ this . log ( sitemap ) ;
102+ }
98103
99104 }
100105}
@@ -118,8 +123,8 @@ StaticSitemapCliCommand.flags = {
118123 help : flags . help ( { char : 'h' } ) ,
119124 root : flags . string ( {
120125 char : 'r' ,
121- description : '[default: current] root working directory' ,
122- default : '' ,
126+ description : 'root working directory' ,
127+ default : '. ' ,
123128 } ) ,
124129 match : flags . string ( {
125130 char : 'm' ,
@@ -143,7 +148,7 @@ StaticSitemapCliCommand.flags = {
143148 default : false ,
144149 } ) ,
145150 slash : flags . boolean ( {
146- char : 's ' ,
151+ char : 'l ' ,
147152 description : 'add trailing slash to all URLs' ,
148153 default : false ,
149154 exclusive : [ 'no-clean' ] ,
@@ -154,6 +159,12 @@ StaticSitemapCliCommand.flags = {
154159 default : false ,
155160 exclusive : [ 'priority' , 'changefreq' ] ,
156161 } ) ,
162+ save : flags . boolean ( {
163+ char : 's' ,
164+ description : 'save output directly to file <root>/sitemap.xml' ,
165+ default : false ,
166+ exclusive : [ 'text' ] ,
167+ } ) ,
157168 verbose : flags . boolean ( {
158169 char : 'v' ,
159170 description : 'be more verbose' ,
0 commit comments