Skip to content

Commit

Permalink
feat(File Matching): Allows use of node-glob syntax for portable… (#38)
Browse files Browse the repository at this point in the history
feat(File Matching): Allows use of node-glob syntax for portable file matching
  • Loading branch information
zakhenry authored Aug 11, 2019
2 parents ea69e95 + 6b79dcf commit fa3b162
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,22 @@ Will result in the following output
If you want to run `embedme` over multiple files, you can use glob matching, i.e.

```bash
embedme src/**/*.md
embedme "src/**/*.md"
```

Note that this globbing is shell expansion, not internally handled so _don't_ quote the glob expression. You can test
you output with `ls`, i.e. `ls src/**/*.md`
Note embedme supports both quoted globbing and unquoted. Be careful using unquoted
globbing as this can lead to behaviour that is not portable between different
operating systems.

If you're using Windows, you must use forward slashes (`/`) to denote path separators.

You can also pass multiple separate glob patterns to match multiple sets of files

example:

```bash
embedme "src/**/*.md" "docs/**/*.markdown"
```

### CI Checks

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"dependencies": {
"chalk": "~2.4.2",
"commander": "~2.20.0",
"gitignore-parser": "~0.0.2"
"gitignore-parser": "~0.0.2",
"node-glob": "~1.2.0"
}
}
13 changes: 12 additions & 1 deletion src/embedme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { embedme, EmbedmeOptions, logBuilder } from './embedme.lib';
import { compile } from 'gitignore-parser';
import program from 'commander';
import chalk from 'chalk';
import glob from 'glob';
const pkg = require('../package.json');

program
Expand All @@ -22,12 +23,22 @@ program
.option('--strip-embed-comment', `Remove the comments from the code fence. *Must* be run with --stdout flag`)
.parse(process.argv);

let { args: sourceFiles } = program;
const { args: sourceFilesInput } = program;

const options: EmbedmeOptions = (program as unknown) as EmbedmeOptions;

const log = logBuilder(options);

let sourceFiles = sourceFilesInput.reduce<string[]>((files, file) => {
if (glob.hasMagic(file)) {
files.push(...glob.sync(file));
} else {
files.push(file);
}

return files;
}, []);

if (sourceFiles.length > 1) {
log(chalk.yellow(`More than one file matched your input, results will be concatenated in stdout`));
} else if (sourceFiles.length === 0) {
Expand Down
18 changes: 18 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ assign-symbols@^1.0.0:
resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367"
integrity sha1-WWZ/QfrdTyDMvCu5a41Pf3jsA2c=

async@^1.3.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
integrity sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
Expand Down Expand Up @@ -1605,6 +1610,11 @@ glob-parent@^3.1.0:
is-glob "^3.1.0"
path-dirname "^1.0.0"

glob-to-regexp@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.1.0.tgz#e0369d426578fd456d47dc23b09de05c1da9ea5d"
integrity sha1-4DadQmV4/UVtR9wjsJ3gXB2p6l0=

glob-to-regexp@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab"
Expand Down Expand Up @@ -2891,6 +2901,14 @@ node-fetch@^2.3.0:
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==

node-glob@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/node-glob/-/node-glob-1.2.0.tgz#5240ffedefc6d663ce8515e5796a4d47a750c0d5"
integrity sha1-UkD/7e/G1mPOhRXleWpNR6dQwNU=
dependencies:
async "^1.3.0"
glob-to-regexp "^0.1.0"

node-gyp@^3.8.0:
version "3.8.0"
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-3.8.0.tgz#540304261c330e80d0d5edce253a68cb3964218c"
Expand Down

0 comments on commit fa3b162

Please sign in to comment.