Skip to content

Commit 3f838a9

Browse files
committed
dirdo: πŸ—‚ Execute command in all nested directories
1 parent b1ca009 commit 3f838a9

File tree

6 files changed

+58
-9
lines changed

6 files changed

+58
-9
lines changed

β€Žpackage.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
"lint": "eslint '*.js' 'dists/*.js' '**/*.js' '**/*.mjs' -c .eslintrc",
2222
"dist": "./packages/run-all-the-things/bin/index.js webpack babel",
2323
"webpack": "webpack --config webpack.config.js",
24-
"babel": "./scripts/foreach.sh '[ \"null\" == \"$(cat package.json | jq '.scripts.dist')\" ] && echo \"no dist script\" || npm run dist'",
24+
"babel": "./packages/dirdo/bin.sh packages '[ \"null\" == \"$(cat package.json | jq '.scripts.dist')\" ] && echo \"no dist script\" || npm run dist'",
2525
"postdist": "mocha dists/test.js",
2626
"publish-packages": "./scripts/foreach.js \"published\"",
2727
"predoc": "./scripts/doc.sh",
2828
"doc": "node ./scripts/homepage.js",
2929
"postdoc": "cat ./src/styles.scss | node-sass --output-style compressed > ./docs/styles.css",
3030
"readme": "node ./scripts/readme.js",
31-
"update": "./scripts/foreach.sh '../../node_modules/.bin/npm-check -u'",
32-
"autoupdate": "./scripts/foreach.sh 'npm update'"
31+
"update": "./packages/dirdo/bin.sh packages '../../node_modules/.bin/npm-check -u'",
32+
"autoupdate": "./packages/dirdo/bin.sh packages 'npm update'"
3333
},
3434
"devDependencies": {
3535
"@babel/cli": "^7.4.4",

β€Žpackages/dirdo/.npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.*
2+
*.log
3+
spec.js

β€Žpackages/dirdo/.npmrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package-lock=false
2+
access=public

β€Žpackages/dirdo/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# dirdo [![](https://img.shields.io/npm/v/dirdo.svg)](https://www.npmjs.com/package/dirdo) [![](https://img.shields.io/badge/source--000000.svg?logo=github&style=social)](https://github.com/omrilotan/mono/tree/master/packages/dirdo)
2+
3+
## πŸ—‚ Execute command in all nested directories
4+
5+
Will iterate over all **directories** nested under the target directory and execute given command
6+
7+
![](https://user-images.githubusercontent.com/516342/59059060-b7233f80-88a6-11e9-93ff-9a8039950eca.gif)
8+
9+
Install
10+
```
11+
npm i -g dirdo
12+
```
13+
14+
Example
15+
```bash
16+
dirdo packages 'npm update'
17+
```
18+
19+
Or use straight out of NPM (good for CI tools)
20+
```
21+
npx dirdo packages 'npm i'
22+
```
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/bin/bash
22

3-
ACTION=$1
3+
DIRECTORY=$1
4+
shift
5+
ACTION=$@
46

5-
function search {
7+
function iterate {
68
for FILE in `ls -l ${1}`
79
do
810
if test -d "${1}/${FILE}"; then
@@ -12,12 +14,10 @@ function search {
1214
}
1315

1416
function execute {
15-
echo -e "\033[1mExecuting ${1}\033[0m"
17+
echo -e "\033[1mExecuting in ${1}\033[0m"
1618
cd $1
1719
eval $ACTION
1820
cd -
19-
echo -e "\n"
2021
}
2122

22-
23-
search "packages"
23+
iterate $DIRECTORY

β€Žpackages/dirdo/package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "dirdo",
3+
"version": "0.1.0",
4+
"description": "πŸ—‚ Execute command in all nested directories",
5+
"keywords": [
6+
"foreach",
7+
"dir",
8+
"exec",
9+
"cli",
10+
"directory",
11+
"do",
12+
"πŸ—‚"
13+
],
14+
"author": "omrilotan",
15+
"license": "MIT",
16+
"repository": {
17+
"type": "git",
18+
"url": "git+https://github.com/omrilotan/mono.git"
19+
},
20+
"homepage": "https://omrilotan.com/mono/dirdo/",
21+
"bin": "./bin.sh"
22+
}

0 commit comments

Comments
Β (0)