Skip to content

Commit

Permalink
fix: fix match files issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 31, 2023
1 parent 95862fb commit 6449b02
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
15 changes: 13 additions & 2 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $ ejsc "template/*.ejs" "template/about/*.ejs" --watch

## Command Help

Below is a help of commands you might find useful.
Below is a help of commands you might find useful. You can use the `ejsc` and `ejs-cli` commands:

```shell
Usage: ejs-cli <source...> [options]
Expand All @@ -41,12 +41,23 @@ Examples:

$ ejsc "template/*.ejs" "template/about/*.ejs"
$ ejsc "template/*.ejs" "template/about/*.ejs" --watch
$ ejsc "template/*.ejs" --watch
# The above command: matches all `.ejs` files in the template folder
$ ejsc "template/**/*" --watch
$ ejs-cli "template/*.ejs" --watch

Copyright 2023
```

## Match files

Folders and `.ejs` files starting with an _underscore_ (`_`) will be ignored.

```shell
$ ejsc "template/**/*"
```

The above command: matches all `.ejs` files in the template folder, excluding files starting with **`_`** and `.ejs` files in folders starting with **`_`**.

## Inject data

Inject data by default
Expand Down
8 changes: 7 additions & 1 deletion core/src/cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ import { helpStr } from "./help.mjs";
const output = path.resolve(process.cwd(), cli.flags.out);
let entry = [...cli.input];

entry = await glob(entry, { ignore: "node_modules/**" });
entry = await glob(entry, {
ignore: {
ignored: (p) => !/\.ejs$/i.test(p.name) || p.name.startsWith("_"),
childrenIgnored: (p) => p.name.startsWith("_"),
},
});
console.log("entry:2", entry);
const isWatch = cli.flags.watch;

const defaultOption: Options = {
Expand Down
5 changes: 1 addition & 4 deletions core/src/watch.mts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ export async function watch(
fs.removeSync(outputPath);
console.log("🗑️ Delete folder \x1b[32;1m%s\x1b[0m !!!", filepath);
}
const isPartial = !!filepath
.split(path.sep)
.find((m) => m.startsWith("_"));

if (!/(add|change)$/i.test(eventName) || isPartial) return;
if (!/(add|change)$/i.test(eventName)) return;

if (/(.ejs)$/.test(filepath)) {
try {
Expand Down
4 changes: 2 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"build": "ejs-cli 'template/*.ejs' 'template/about/*.ejs' -f data.json",
"start": "ejs-cli 'template/*.ejs' 'template/about/*.ejs' -f data.json --watch"
"build": "ejs-cli 'template/**/*' -f data.json",
"start": "ejs-cli 'template/**/*' -f data.json --watch"
},
"devDependencies": {
"@wcj/ejs-cli": "1.1.0"
Expand Down

0 comments on commit 6449b02

Please sign in to comment.