11#!/usr/bin/env node
22
3- const fs = require ( "fs-extra" ) ;
4- const { resolve } = require ( "path" ) ;
5- const { Command } = require ( "commander" ) ;
3+ import fs from "fs-extra" ;
4+ import filenamify from "filenamify" ;
5+ import os from "os" ;
6+ import { resolve } from "path" ;
7+ import { Command } from "commander" ;
68const program = new Command ( ) ;
9+ const isWindows = os . platform ( ) == "win32" ;
710
811const opts = program
912 . name ( "unmap" )
10- . requiredOption ( "-p, --path <p>" , "input source map file" )
11- . option ( "-f, --filter <f>" , "filter out file names" )
12- . option ( "-o, --output <o>" , "output folder" , "./" )
13+ . requiredOption ( "-p, --path <p>" , "Input source map file" )
14+ . option ( "-f, --filter <f>" , "Filter out file names" )
15+ . option ( "-o, --output <o>" , "Output folder" , "./" )
1316 . parse ( process . argv )
1417 . opts ( ) ;
1518
1619fs . readFile ( opts . path )
1720 . catch ( async ( e ) => {
1821 if ( e . errno == - 13 ) {
19- console . log ( "Insufficient permissions to read the tnput file." ) ;
22+ console . log ( "Insufficient permissions to read the input file." ) ;
2023 }
2124 if ( e . errno == - 2 ) {
2225 console . log ( "Input file does not exists." ) ;
@@ -29,7 +32,10 @@ fs.readFile(opts.path)
2932 const files = js . sources
3033 . filter ( ( path ) => ( opts . filter ? path . includes ( opts . filter ) : true ) )
3134 . map ( ( path , idx ) => {
32- const outpath = resolve ( opts . output , path ) ;
35+ const outpath = resolve (
36+ opts . output ,
37+ isWindows ? filenamify ( path ) : path
38+ ) ;
3339 return fs . outputFile ( outpath , js . sourcesContent [ idx ] ) ;
3440 } ) ;
3541 return Promise . all ( files ) ;
0 commit comments