source: trip-planner-front/node_modules/rimraf/bin.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#!/usr/bin/env node
2
3const rimraf = require('./')
4
5const path = require('path')
6
7const isRoot = arg => /^(\/|[a-zA-Z]:\\)$/.test(path.resolve(arg))
8const filterOutRoot = arg => {
9 const ok = preserveRoot === false || !isRoot(arg)
10 if (!ok) {
11 console.error(`refusing to remove ${arg}`)
12 console.error('Set --no-preserve-root to allow this')
13 }
14 return ok
15}
16
17let help = false
18let dashdash = false
19let noglob = false
20let preserveRoot = true
21const args = process.argv.slice(2).filter(arg => {
22 if (dashdash)
23 return !!arg
24 else if (arg === '--')
25 dashdash = true
26 else if (arg === '--no-glob' || arg === '-G')
27 noglob = true
28 else if (arg === '--glob' || arg === '-g')
29 noglob = false
30 else if (arg.match(/^(-+|\/)(h(elp)?|\?)$/))
31 help = true
32 else if (arg === '--preserve-root')
33 preserveRoot = true
34 else if (arg === '--no-preserve-root')
35 preserveRoot = false
36 else
37 return !!arg
38}).filter(arg => !preserveRoot || filterOutRoot(arg))
39
40const go = n => {
41 if (n >= args.length)
42 return
43 const options = noglob ? { glob: false } : {}
44 rimraf(args[n], options, er => {
45 if (er)
46 throw er
47 go(n+1)
48 })
49}
50
51if (help || args.length === 0) {
52 // If they didn't ask for help, then this is not a "success"
53 const log = help ? console.log : console.error
54 log('Usage: rimraf <path> [<path> ...]')
55 log('')
56 log(' Deletes all files and folders at "path" recursively.')
57 log('')
58 log('Options:')
59 log('')
60 log(' -h, --help Display this usage info')
61 log(' -G, --no-glob Do not expand glob patterns in arguments')
62 log(' -g, --glob Expand glob patterns in arguments (default)')
63 log(' --preserve-root Do not remove \'/\' (default)')
64 log(' --no-preserve-root Do not treat \'/\' specially')
65 log(' -- Stop parsing flags')
66 process.exit(help ? 0 : 1)
67} else
68 go(0)
Note: See TracBrowser for help on using the repository browser.