Comparing version 0.0.2 to 0.0.3
#! /usr/bin/env node | ||
const fs = require('fs/promises'); | ||
const path = require('path'); | ||
const fs = require('fs/promises') | ||
const path = require('path') | ||
const search = async (name, base, options) => { | ||
base = base ? path.normalize(base) : process.cwd(); | ||
let dir = await fs.readdir(base); | ||
let results = []; | ||
base = base ? path.normalize(base) : process.cwd() | ||
let dir = await fs.readdir(base) | ||
let results = [] | ||
for (let i = 0; i < dir.length; i++) { | ||
let currentPath = path.join(base, dir[i]); | ||
let currentPath = path.join(base, dir[i]) | ||
if ((await fs.stat(currentPath)).isDirectory()) { | ||
if (dir[i] === name) { | ||
results.push(currentPath); | ||
results.push(currentPath) | ||
} else { | ||
results.push(...(await search(name, currentPath, options))); | ||
results.push(...(await search(name, currentPath, options))) | ||
} | ||
@@ -21,28 +21,28 @@ } | ||
return results; | ||
}; | ||
return results | ||
} | ||
const clean = (dir) => { | ||
return fs.rmdir(dir, { recursive: true }); | ||
}; | ||
return fs.rm(dir, { recursive: true }) | ||
} | ||
const nmc = () => { | ||
let options = {}; | ||
let args = process.argv.slice(2); | ||
if (args.includes('-l') || args.includes('--log')) options.log = true; | ||
let options = {} | ||
let args = process.argv.slice(2) | ||
if (args.includes('-l') || args.includes('--log')) options.log = true | ||
if (options.log) console.log('\x1b[32m', 'Searching...', '\x1b[0m'); | ||
if (options.log) console.log('\x1b[32m', 'Searching...', '\x1b[0m') | ||
search('node_modules').then((results) => { | ||
if (results.length) { | ||
if (options.log) console.log('Directories found:', results); | ||
if (options.log) console.log('Directories found:', results) | ||
results.forEach((res) => { | ||
clean(res); | ||
}); | ||
clean(res) | ||
}) | ||
} else { | ||
console.error('\x1b[31m', 'No node_modules directories found', '\x1b[0m'); | ||
process.exit(1); | ||
console.error('\x1b[31m', 'No node_modules directories found', '\x1b[0m') | ||
process.exit(1) | ||
} | ||
console.log('\x1b[32m', 'nmc done!', '\x1b[0m'); | ||
}); | ||
}; | ||
console.log('\x1b[32m', 'nmc done!', '\x1b[0m') | ||
}) | ||
} | ||
nmc(); | ||
nmc() |
{ | ||
"name": "nmc", | ||
"version": "0.0.2", | ||
"description": "node modules cleaner", | ||
"main": "bin/nmc.js", | ||
"bin": { | ||
"nmc": "bin/nmc.js" | ||
}, | ||
"homepage": "https://github.com/origeva/nmc", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/origeva/nmc" | ||
}, | ||
"scripts": { | ||
"start": "node bin/nmc.js" | ||
}, | ||
"keywords": [ | ||
"node", | ||
"node_modules", | ||
"modules", | ||
"cli", | ||
"cleaner" | ||
], | ||
"author": "Ori Geva", | ||
"license": "MIT" | ||
"name": "nmc", | ||
"version": "0.0.3", | ||
"description": "node modules cleaner", | ||
"main": "bin/nmc.js", | ||
"bin": { | ||
"nmc": "bin/nmc.js" | ||
}, | ||
"homepage": "https://github.com/origeva/nmc", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/origeva/nmc" | ||
}, | ||
"scripts": { | ||
"start": "node bin/nmc.js" | ||
}, | ||
"keywords": [ | ||
"node", | ||
"node_modules", | ||
"modules", | ||
"cli", | ||
"cleaner" | ||
], | ||
"author": "Ori Geva", | ||
"license": "MIT" | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
3124