Comparing version 0.2.0 to 0.2.1
@@ -5,3 +5,2 @@ const kleur = require('kleur') | ||
const path = require('path') | ||
const shell = require('shelljs') | ||
@@ -30,10 +29,17 @@ function warn (text) { | ||
async function makeDir (dirPath, options = {}) { | ||
if (!options.silentFail && (await pathExists(dirPath))) { | ||
warn(`already exists: ${path.relative(process.cwd(), dirPath)}`) | ||
} else { | ||
shell.mkdir('-p', dirPath) | ||
/* | ||
* Used with Array.filter; Filters out directories that have | ||
* files in them (i.e. only includes directories in array if | ||
* there's not also files from that dir in the array) | ||
*/ | ||
function removeNonEmptyDirs (filepath, i, filepaths) { | ||
let dirAlreadyRepresented = false | ||
if (isDirectory(filepath)) { | ||
dirAlreadyRepresented = filepaths.some(otherFilepath => { | ||
return filepath === path.dirname(otherFilepath) | ||
}) | ||
} | ||
return dirPath | ||
return !dirAlreadyRepresented | ||
} | ||
@@ -48,3 +54,4 @@ | ||
cwd, | ||
dot: true | ||
dot: true, | ||
onlyFiles: false | ||
}) | ||
@@ -55,3 +62,5 @@ | ||
return result.sort() | ||
return result | ||
.filter(removeNonEmptyDirs) | ||
.sort() | ||
} | ||
@@ -64,6 +73,6 @@ | ||
isString, | ||
makeDir, | ||
pathExists, | ||
removeNonEmptyDirs, | ||
resolveGlobs, | ||
warn | ||
} |
@@ -1,43 +0,30 @@ | ||
const shell = require('shelljs') | ||
const { normalize, parse, relative, resolve } = require('path') | ||
const { isDirectory, makeDir, pathExists, warn } = require('../_utils.js') | ||
const fse = require('fs-extra') | ||
const path = require('path') | ||
const { isDirectory, pathExists, warn } = require('../_utils.js') | ||
async function createPath (path) { | ||
const cwd = process.cwd() | ||
if (isDirectory(path)) { | ||
await makeDir(path) | ||
async function createPath (filepath) { | ||
if (await pathExists(filepath)) { | ||
warn(`already exists: ${path.relative(process.cwd(), filepath)}`) | ||
} else { | ||
const { base, dir } = parse(path) | ||
if (isDirectory(filepath)) { | ||
await fse.ensureDir(filepath) | ||
} else { | ||
const { dir } = path.parse(filepath) | ||
await makeDir(dir, { silentFail: true }) | ||
shell.cd(dir) | ||
shell.touch(base) | ||
shell.cd(cwd) | ||
await fse.ensureDir(dir) | ||
await fse.writeFile(filepath, '', 'utf-8') | ||
} | ||
} | ||
return path | ||
return filepath | ||
} | ||
async function resolvePaths (command) { | ||
function resolvePaths (command) { | ||
const { args, mods } = command | ||
const cwd = process.cwd() | ||
const from = normalize(mods.in || '') | ||
const paths = await Promise.all( | ||
args.map(async (arg) => { | ||
const resolvedPath = resolve(cwd, from, normalize(arg)) | ||
let result | ||
const from = path.normalize(mods.in || '') | ||
if (await pathExists(resolvedPath)) { | ||
warn(`${command.type}: already exists: ${relative(cwd, resolvedPath)}`) | ||
result = false | ||
} else { | ||
result = resolvedPath | ||
} | ||
return result | ||
}) | ||
) | ||
return paths.filter(Boolean) | ||
return args.map(arg => { | ||
return path.resolve(cwd, from, path.normalize(arg)) | ||
}) | ||
} | ||
@@ -52,5 +39,5 @@ | ||
module.exports = async function (command) { | ||
const paths = await resolvePaths(command) | ||
const paths = resolvePaths(command) | ||
return Promise.all(paths.map(createPath)) | ||
} |
const commands = require('./commands/index.js') | ||
const parseCommand = require('./parse-command.js') | ||
const shell = require('shelljs') | ||
const { isArray, isString } = require('./_utils.js') | ||
@@ -10,3 +9,3 @@ | ||
if (options.cwd) { | ||
shell.cd(options.cwd) | ||
process.chdir(options.cwd) | ||
} | ||
@@ -31,3 +30,3 @@ | ||
} finally { | ||
shell.cd(origCwd) | ||
process.chdir(origCwd) | ||
} | ||
@@ -34,0 +33,0 @@ } |
{ | ||
"name": "heycli", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "A human-readable interface for terminal commands", | ||
@@ -54,3 +54,2 @@ "keywords": [ | ||
"kleur": "^2.0.2", | ||
"shelljs": "^0.8.1", | ||
"trash": "^4.3.0" | ||
@@ -57,0 +56,0 @@ }, |
4
9193
208
4
- Removedshelljs@^0.8.1
- Removedinterpret@1.4.0(transitive)
- Removedis-core-module@2.16.1(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedrechoir@0.6.2(transitive)
- Removedresolve@1.22.10(transitive)
- Removedshelljs@0.8.5(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)