Skip to content

Commit

Permalink
feat: add --exclude argument for ignore file patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
NLKNguyen committed Aug 22, 2023
1 parent 038c8dd commit 5d366d5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ git push origin {tag_name}

# 📝 Command Line Interface Usage

**code-formation** --scan *[file glob patterns]* --outdir *[base path for output files]*
**code-formation** --scan *[file glob patterns]* --exclude *[file glob patterns]* --outdir *[base path for output files]*


`--scan`: required list of file glob patterns separated by semicolon ";". It's possible to specify ignore and inverse ignore patterns just like .gitignore syntax.
`--scan`: required list of file glob patterns to include, separated by commas ","

`--exclude`: optional list of file glob patterns to exclude, separated by commas ","

`--outdir`: optional base output path for the output files, if any; some use cases only affect the input files and don't generate output files.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "code-formation",
"version": "0.7.2",
"version": "0.7.3",
"description": "context-free text manipulator using line-oriented DSL for easy embedding to existing source code",
"main": "./src/index.js",
"bin": "./src/index.js",
Expand Down
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ const logger = require("./logger.js")
// console.log('<xml>'.escapeXML('abc'))
;(async function () {
try {
let { outdir, scan, define } = Options.read([
let { outdir, scan, exclude, define } = Options.read([
Options.outdir,
Options.scan,
Options.exclude
// Options.define,
// TODO: --definitions <file> for dotenv file
])
Expand All @@ -72,11 +73,13 @@ const logger = require("./logger.js")
...scan.split(",").map((e) => e.trim()),
].filter(Boolean)

exclude = exclude.split(",").map((e) => e.trim()).filter(Boolean)

let sourceFiles = []
for (let p of glob.sync(scan)) {
for (let p of glob.sync(scan, { ignore: exclude })) {
if (fs.lstatSync(p).isDirectory()) {
glob
.sync([`${p}/.code-formation/**`])
.sync([`${p}/.code-formation/**`], { ignore: exclude })
.filter((e) => fs.lstatSync(e).isFile())
.forEach((e) => sourceFiles.push(e))
} else {
Expand Down
9 changes: 8 additions & 1 deletion src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ const outdir = {

const scan = {
pattern: "-s, --scan <file patterns>",
description: "glob file patterns to be scanned, separated by semi-colon ;",
description: "glob file patterns to be scanned, separated by commas ','",
default: ""
}

const exclude = {
pattern: "-e, --exclude <file patterns>",
description: "glob file patterns to be ignored, separated by commas ','",
default: ""
}

Expand All @@ -43,6 +49,7 @@ const define = {
module.exports = {
read,
scan,
exclude,
outdir,
define
}

0 comments on commit 5d366d5

Please sign in to comment.