Skip to content

Commit

Permalink
refactoring and better naming for some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
goerwin committed Feb 26, 2022
1 parent c91e07f commit d035aea
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .directoryvalidator.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"package-lock.json",
".DS_Store"
],
"ignoreDirs": ["node_modules", "lib", ".git", ".github"],
"ignoreDirs": ["node_modules", "dist", ".git", ".github"],
"commonRules": {
"rule_indexfile": {
"type": "file",
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.DS_Store
node_modules
.nyc_output
coverage
lib
dist
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/_tests
dist
13 changes: 13 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"jsxSingleQuote": false,
"embeddedLanguageFormatting": "off",
"arrowParens": "always",
"printWidth": 80,
"endOfLine": "lf",
"bracketSpacing": true
}
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ $ npm install directory-validator
## Usage

Generate a configuration file `.directoryvalidator.json` to start with:

```
$ directory-validator --init
```

Run the validator on the current directory:

```
$ directory-validator .
```
Expand Down Expand Up @@ -67,6 +69,7 @@ The tool will evaluate the rules provided by the configuration file against the
```

In this example:

- We ignore the file `.gitignore` and both `.node_modules` and `.git` directories from being analized
- We want to have one file name `package.json` and one file named `index.js`
- We want one directory `src` to have one file named `index.js`. Since it's optional,
Expand All @@ -81,7 +84,7 @@ A string or glob pattern. For example:
[
"package.json",
"**/*.test.js",
".*" // files starting with "."
".*", // files starting with "."
]
```

Expand All @@ -93,7 +96,7 @@ A string or glob pattern. For example:
[
"node_modules",
"src/**/tests",
".*" // dirs starting with "."
".*", // dirs starting with "."
]
```

Expand Down Expand Up @@ -214,7 +217,7 @@ Can contain File, Directory and Common Rules

## Notes

* When you run `$ directory-validator ./` it will look for a `.directoryvalidator.json` file in the current directory, if it doesn't find one, it will try to look for one in the upper directory and so on until the home directory is reached. If no file is found then no rules are applied.
- When you run `$ directory-validator ./` it will look for a `.directoryvalidator.json` file in the current directory, if it doesn't find one, it will try to look for one in the upper directory and so on until the home directory is reached. If no file is found then no rules are applied.

* Rules are inclusive, meaning that if multiple rules match the same files/dirs, they pass.
* For example, the rules `{ "name": "index.js", "type": "file" }` and `{ "name": "[camelCase].js", "type": "file" }`, will match a file `index.js` so they both pass.
- Rules are inclusive, meaning that if multiple rules match the same files/dirs, they pass.
- For example, the rules `{ "name": "index.js", "type": "file" }` and `{ "name": "[camelCase].js", "type": "file" }`, will match a file `index.js` so they both pass.
25 changes: 22 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "directory-validator",
"version": "1.5.1",
"version": "1.5.2",
"description": "CLI Tool to validate directory structures.",
"main": "lib/index.js",
"main": "dist/index.js",
"bin": {
"directory-validator": "lib/index.js"
"directory-validator": "dist/index.js"
},
"scripts": {
"build": "npm run clean && tsc && cp src/supportFiles/* lib/supportFiles",
"clean": "rm -rf lib",
"test": "jest"
"build": "npm run clean && tsc && cp src/resources/* dist/resources",
"clean": "rm -rf dist",
"prettier": "prettier -c .",
"test": "npm run prettier && jest"
},
"author": "Erwin Gaitan O <[email protected]>",
"license": "MIT",
Expand All @@ -19,6 +20,7 @@
"@types/lodash": "^4.14.168",
"@types/node": "^14.14.37",
"jest": "^26.6.3",
"prettier": "^2.5.1",
"ts-jest": "^26.5.4",
"typescript": "^4.5.5"
},
Expand All @@ -31,7 +33,7 @@
"lodash": "^4.17.21"
},
"files": [
"lib",
"dist",
"LICENSE",
"README.md"
],
Expand Down
4 changes: 1 addition & 3 deletions src/_tests/program/examples/project2/conf2.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"ignoreFiles": [
"file1.jpg"
],
"ignoreFiles": ["file1.jpg"],
"rules": [
{
"type": "file",
Expand Down
4 changes: 1 addition & 3 deletions src/_tests/program/examples/project3/conf2.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"ignoreDirs": [
"dir1"
],
"ignoreDirs": ["dir1"],
"rules": [
{
"type": "file",
Expand Down
4 changes: 1 addition & 3 deletions src/_tests/program/examples/project3/conf4.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
"rule_dir": {
"type": "directory",
"name": "dir1",
"rules": [
{ "type": "file", "name": "lul" }
]
"rules": [{ "type": "file", "name": "lul" }]
}
}
}
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function getDefaultConfigFilePath(dirPath: string) {

export function writeDefaultConfigFile(parentPath: string) {
fs.copyFileSync(
path.join(__dirname, './supportFiles/defaultConfig.json'),
path.join(__dirname, './resources/defaultConfig.json'),
parentPath
);
}
Expand Down Expand Up @@ -59,7 +59,7 @@ const selectedOptions = commanderProgram.opts();

if (selectedOptions.init) {
fs.copyFileSync(
path.join(__dirname, './supportFiles/defaultConfig.json'),
path.join(__dirname, './resources/defaultConfig.json'),
path.join(process.cwd(), initConfigFilename)
);
console.log('\n\t', initConfigFilename.red, 'created', '\n');
Expand All @@ -82,6 +82,7 @@ if (selectedOptions.init) {

if (selectedOptions.print && results.asciiTree) {
console.log(
'\n',
results.asciiTree
.replace(/\/fileIgnored/g, '[File Ignored]'.dim)
.replace(/\/directoryIgnored/g, '[Directory Ignored]'.dim)
Expand Down
2 changes: 1 addition & 1 deletion src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'goerwin-helpers/node/file';
import * as _ from 'lodash';
import * as errors from './errors';
import schema from './supportFiles/schema.json';
import schema from './resources/schema.json';
import * as types from './types';
import * as validator from './validator';

Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 6 additions & 5 deletions todo.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@

# TODO

- more error info (path) in validatorRuleError
- better ubication of a rule when displaying errors (rules[3].rules[1]) like
ajv when validating json schemas
- Examples
- Provide some folder examples:
* examples/basic
* examples/recursive-directories
* examples/multimatching-rules
- examples/basic
- examples/recursive-directories
- examples/multimatching-rules
- allow rules to be exclusive

# DONE

- common dir rules can have other common rules inside
- common rules can be optional
- option to print the directory structure printed
Expand All @@ -26,7 +27,7 @@
- allow RegExp in names/extensions
- create bin file
- what if you want 2 dirs in a directory and the rest can be whatever?
- { name: * } should validate all the files/dirs recursively
- { name: \* } should validate all the files/dirs recursively
- better errors in console
- rename it to directory-validator
- read config from passed file
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"exclude": ["src/**/_tests/*", "src/**/*/*.test.ts"],
"exclude": ["src/**/_tests/*", "src/**/*/*.test.ts", "dist"],
"compilerOptions": {
/* Basic Options */
"target": "es2016" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */,
Expand All @@ -13,7 +13,7 @@
"declaration": true /* Generates corresponding '.d.ts' file. */,
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib" /* Redirect output structure to the directory. */,
"outDir": "./dist" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
Expand Down

0 comments on commit d035aea

Please sign in to comment.