comment-variables 0.3.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +155 -1
- package/comments.config.js +37 -37
- package/library/_commons/constants/bases.js +1 -1
- package/library/_commons/utilities/resolve-config.js +2 -2
- package/library/index.js +23 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1 +1,155 @@
|
|
|
1
|
-
|
|
1
|
+
A CLI tool for configuring, managing and maintaining JavaScript comments as JavaScript variables, via a `comments.config.js` file at the root of your project.
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
npm install -g comment-variables
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
## Commands
|
|
8
|
+
|
|
9
|
+
**`comment-variables` comes with three commands in this initial release:**
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
comment-variables
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Interacts with your `comments.config.js` default exported object to print all the parameters you need to be aware of before running `compress` or `resolve`. Also acts as a dry run validation check. If no error is printed, it means you can run `compress` or `resolve` safely, as long the printed parameters correspond to what you've expected from your defined config.
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
comment-variables compress
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Scans your line and block comments for string values defined in your `comments.config.js` (like `"This is a comment"`) to turn them into their corresponding `$COMMENT#*` tokens defined in your `comments.config.js`. (`This is a comment.` => `$COMMENT#COMMENT`)
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
comment-variables resolve
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Scans your line and block comments for `$COMMENT#*` tokens (like `$COMMENT#COMMENT`) to turn them into their corresponding string values defined in your `comments.config.js`. (`$COMMENT#COMMENT` => `This is a comment.`)
|
|
28
|
+
|
|
29
|
+
_The `compress` and `resolve` commands make each other entirely reversible._
|
|
30
|
+
|
|
31
|
+
## Flags
|
|
32
|
+
|
|
33
|
+
**The CLI tool also comes with three flags initially:**
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
comment-variables --config <your-config.js>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Pass a different file as your config instead of the default `comments.config.js` (like `comment-variables --config your-config.js`).
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
comment-variables --lint-config-imports
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
By default, `comment-variables` excludes your config file and all the (JavaScript/TypeScript) files it recursively imports. This flag cancels this mechanism, linting config imports. (The config file however still remains excluded from linting.)
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
comment-variables --my-ignores-only
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
By default, `comment-variables` includes a preset list of ignored folders (`"node_modules"`, `".next"`, `".react-router"`...). This flag cancels this mechanism so that you can have full control over your ignored files and folders.
|
|
52
|
+
|
|
53
|
+
_All three flags can be composed together, and with any of the three commands:_
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
comment-variables --config your-config.js
|
|
57
|
+
comment-variables compress --config your-config.js --lint-config-imports
|
|
58
|
+
comment-variables resolve --config your-config.js --lint-config-imports --my-ignores-only
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## **`comments.config.js`**
|
|
62
|
+
|
|
63
|
+
A `comments.config.js` file looks like this. (This is the config file I'm using to manage my JavaScript comments in this library.)
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
const data = {
|
|
67
|
+
jsDoc: Object.freeze({
|
|
68
|
+
definitions: Object.freeze({
|
|
69
|
+
exitDueToFailure:
|
|
70
|
+
"Terminates the whole process with a 'failure' code (1).", // $COMMENT#JSDOC#DEFINITIONS#EXITDUETOFAILURE
|
|
71
|
+
escapeRegex:
|
|
72
|
+
'Escapes all regex characters with a `"\\"` in a string to prepare it for use in a regex.', // $COMMENT#JSDOC#DEFINITIONS#ESCAPEREGEX
|
|
73
|
+
makeRuleResolve:
|
|
74
|
+
"The utility that creates the resolve rule based on the flattened config data, used to transform $COMMENT#* placeholders into actual comments.", // $COMMENT#JSDOC#DEFINITIONS#MAKERULERESOLVE
|
|
75
|
+
makeRuleCompress:
|
|
76
|
+
"The utility that creates the compress rule based on the reversed flattened config data, used to transform actual comments into $COMMENT#* placeholders.", // $COMMENT#JSDOC#DEFINITIONS#MAKERULECOMPRESS
|
|
77
|
+
coreCommentsFlow:
|
|
78
|
+
"The core flow at the heart of resolving and compressing comments.", // $COMMENT#JSDOC#DEFINITIONS#CORECOMMENTSFLOW
|
|
79
|
+
resolveCommentsFlow:
|
|
80
|
+
"The flow that resolves $COMMENT#* placeholders intro actual comments.", // $COMMENT#JSDOC#DEFINITIONS#RESOLVECOMMENTSFLOW
|
|
81
|
+
compressCommentsFlow:
|
|
82
|
+
"The flow that compresses actual comments into $COMMENT#* placeholders.", // $COMMENT#JSDOC#DEFINITIONS#COMPRESSCOMMENTSFLOW
|
|
83
|
+
findAllImports:
|
|
84
|
+
"Finds all import paths recursively related to a given file path.", // $COMMENT#JSDOC#DEFINITIONS#FINDALLIMPORTS
|
|
85
|
+
processImport: "Processes recursively and resolves a single import path.", // $COMMENT#JSDOC#DEFINITIONS#PROCESSIMPORT
|
|
86
|
+
flattenConfigData:
|
|
87
|
+
"Flattens the config's data property into a one-dimensional object of $COMMENT-*-like keys and string values.", // $COMMENT#JSDOC#DEFINITIONS#FLATTENCONFIGDATA
|
|
88
|
+
resolveConfig:
|
|
89
|
+
"Verifies, validates and resolves the config path to retrieve the config's data and ignores.", // $COMMENT#JSDOC#DEFINITIONS#RESOLVECONFIG
|
|
90
|
+
}),
|
|
91
|
+
params: Object.freeze({
|
|
92
|
+
string: "The string.", // $COMMENT#JSDOC#PARAMS#STRING
|
|
93
|
+
flattenedConfigData:
|
|
94
|
+
"The flattened config data, with $COMMENT#* placeholders as keys and actual comments as values.", // $COMMENT#JSDOC#PARAMS#FLATTENEDCONFIGDATA
|
|
95
|
+
reversedFlattenedConfigData:
|
|
96
|
+
"The reversed flattened config data, with actual comments as keys and $COMMENT#* placeholders as values.", // $COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA
|
|
97
|
+
ruleName:
|
|
98
|
+
'The name of the rule currently used. (Either `"resolve"` or `"compress"`.)', // $COMMENT#JSDOC#PARAMS#RULENAME
|
|
99
|
+
ignores:
|
|
100
|
+
"The array of paths and globs for the flow's ESLint instance to ignore.", // $COMMENT#JSDOC#PARAMS#IGNORES
|
|
101
|
+
eitherFlattenedConfigData:
|
|
102
|
+
"Either the flattened config data or the reversed flattened config data, since they share the same structure.", // $COMMENT#JSDOC#PARAMS#EITHERFLATTENEDCONFIGDATA
|
|
103
|
+
filePath:
|
|
104
|
+
"The absolute path of the file whose imports are being recursively found, such as that of a project's `comments.config.js` file.", // $COMMENT#JSDOC#PARAMS#FILEPATH
|
|
105
|
+
cwd: "The current working directory, set as `process.cwd()` by default.", // $COMMENT#JSDOC#PARAMS#CWD
|
|
106
|
+
visitedSet:
|
|
107
|
+
"The set of strings tracking the import paths that have already been visited, instantiated as a `new Set()` by default.", // $COMMENT#JSDOC#PARAMS#VISITEDSET
|
|
108
|
+
depth:
|
|
109
|
+
"The current depth of the recursion, instantiated at `0` by default.", // $COMMENT#JSDOC#PARAMS#DEPTH
|
|
110
|
+
maxDepth:
|
|
111
|
+
"The maximum depth allowed for the recursion, instantiated at `100` by default.", // $COMMENT#JSDOC#PARAMS#MAXDEPTH
|
|
112
|
+
importPath: "The import path currently being addressed.", // $COMMENT#JSDOC#PARAMS#IMPORTPATH
|
|
113
|
+
currentDir:
|
|
114
|
+
"The directory containing the import path currently being addressed.", // $COMMENT#JSDOC#PARAMS#CURRENTDIR
|
|
115
|
+
configData:
|
|
116
|
+
"The config's data property. (Values are typed `any` given the limitations in typing recursive values in JSDoc.)", // $COMMENT#JSDOC#PARAMS#CONFIGDATA
|
|
117
|
+
configDataMap:
|
|
118
|
+
"The map housing the flattened keys with their values and sources through recursion, instantiated as a `new Map()`.", // $COMMENT#JSDOC#PARAMS#CONFIGDATAMAP
|
|
119
|
+
parentKeys:
|
|
120
|
+
"The list of keys that are parent to the key at hand given the recursive nature of the config's data's data structure, instantiated as an empty array of strings.", // $COMMENT#JSDOC#PARAMS#PARENTKEYS
|
|
121
|
+
configPath:
|
|
122
|
+
"The path of the config, either from `comments.config.js` or from a config passed via the `--config` flag.", // $COMMENT#JSDOC#PARAMS#CONFIGPATH
|
|
123
|
+
}),
|
|
124
|
+
returns: Object.freeze({
|
|
125
|
+
exitDueToFailure:
|
|
126
|
+
"Never. (Somehow typing needs to be explicit for unreachable code inference.)", // $COMMENT#JSDOC#RETURNS#EXITDUETOFAILURE
|
|
127
|
+
escapeRegex: `The string with regex characters escaped.`, // $COMMENT#JSDOC#RETURNS#ESCAPEREGEX
|
|
128
|
+
makeRuleResolve: "The resolve rule based on the flattened config data.", // $COMMENT#JSDOC#RETURNS#MAKERULERESOLVE
|
|
129
|
+
makeRuleCompress:
|
|
130
|
+
"The compress rule based on the reversed flattened config data.", // $COMMENT#JSDOC#RETURNS#MAKERULECOMPRESS
|
|
131
|
+
findAllImports:
|
|
132
|
+
"The complete set of strings of import paths recursively related to the given file path, or `null` if an issue has arisen.", // $COMMENT#JSDOC#RETURNS#FINDALLIMPORTS
|
|
133
|
+
processImport:
|
|
134
|
+
"`true` to skip unresolved paths, `false` if resolution fails at any level.", // $COMMENT#JSDOC#RETURNS#PROCESSIMPORT
|
|
135
|
+
flattenConfigData:
|
|
136
|
+
"Both the flattened config data and its reversed version to ensure the strict reversibility of the `resolve` and `compress` commands.", // $COMMENT#JSDOC#RETURNS#FLATTENCONFIGDATA
|
|
137
|
+
resolveConfig:
|
|
138
|
+
"The flattened config data, the reverse flattened config data, the verified config path, the raw passed ignores, and the original config.", // $COMMENT#JSDOC#RETURNS#RESOLVECONFIG
|
|
139
|
+
}),
|
|
140
|
+
}),
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const ignores = ["README.md"];
|
|
144
|
+
|
|
145
|
+
const config = {
|
|
146
|
+
data,
|
|
147
|
+
ignores,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export default config;
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
And yes, even comments within JavaScript and TypeScript blocks in Markdown files are addressed.
|
|
154
|
+
|
|
155
|
+
_Leverage the full power of JavaScript to programmatically design your JavaScript comments._
|
package/comments.config.js
CHANGED
|
@@ -16,80 +16,80 @@ const data = {
|
|
|
16
16
|
jsDoc: Object.freeze({
|
|
17
17
|
definitions: Object.freeze({
|
|
18
18
|
exitDueToFailure:
|
|
19
|
-
"Terminates the whole process with a 'failure' code (1).",
|
|
19
|
+
"Terminates the whole process with a 'failure' code (1).", // $COMMENT#JSDOC#DEFINITIONS#EXITDUETOFAILURE
|
|
20
20
|
escapeRegex:
|
|
21
|
-
'Escapes all regex characters with a `"\\"` in a string to prepare it for use in a regex.',
|
|
21
|
+
'Escapes all regex characters with a `"\\"` in a string to prepare it for use in a regex.', // $COMMENT#JSDOC#DEFINITIONS#ESCAPEREGEX
|
|
22
22
|
makeRuleResolve:
|
|
23
|
-
"The utility that creates the resolve rule based on the flattened config data, used to transform $COMMENT#* placeholders into actual comments.",
|
|
23
|
+
"The utility that creates the resolve rule based on the flattened config data, used to transform $COMMENT#* placeholders into actual comments.", // $COMMENT#JSDOC#DEFINITIONS#MAKERULERESOLVE
|
|
24
24
|
makeRuleCompress:
|
|
25
|
-
"The utility that creates the compress rule based on the reversed flattened config data, used to transform actual comments into $COMMENT#* placeholders.",
|
|
25
|
+
"The utility that creates the compress rule based on the reversed flattened config data, used to transform actual comments into $COMMENT#* placeholders.", // $COMMENT#JSDOC#DEFINITIONS#MAKERULECOMPRESS
|
|
26
26
|
coreCommentsFlow:
|
|
27
|
-
"The core flow at the heart of resolving and compressing comments.",
|
|
27
|
+
"The core flow at the heart of resolving and compressing comments.", // $COMMENT#JSDOC#DEFINITIONS#CORECOMMENTSFLOW
|
|
28
28
|
resolveCommentsFlow:
|
|
29
|
-
"The flow that resolves $COMMENT#* placeholders intro actual comments.",
|
|
29
|
+
"The flow that resolves $COMMENT#* placeholders intro actual comments.", // $COMMENT#JSDOC#DEFINITIONS#RESOLVECOMMENTSFLOW
|
|
30
30
|
compressCommentsFlow:
|
|
31
|
-
"The flow that compresses actual comments into $COMMENT#* placeholders.",
|
|
31
|
+
"The flow that compresses actual comments into $COMMENT#* placeholders.", // $COMMENT#JSDOC#DEFINITIONS#COMPRESSCOMMENTSFLOW
|
|
32
32
|
findAllImports:
|
|
33
|
-
"Finds all import paths recursively related to a given file path.",
|
|
34
|
-
processImport: "Processes recursively and resolves a single import path.",
|
|
33
|
+
"Finds all import paths recursively related to a given file path.", // $COMMENT#JSDOC#DEFINITIONS#FINDALLIMPORTS
|
|
34
|
+
processImport: "Processes recursively and resolves a single import path.", // $COMMENT#JSDOC#DEFINITIONS#PROCESSIMPORT
|
|
35
35
|
flattenConfigData:
|
|
36
|
-
"Flattens the config's data property into a one-dimensional object of $COMMENT-*-like keys and string values.",
|
|
36
|
+
"Flattens the config's data property into a one-dimensional object of $COMMENT-*-like keys and string values.", // $COMMENT#JSDOC#DEFINITIONS#FLATTENCONFIGDATA
|
|
37
37
|
resolveConfig:
|
|
38
|
-
"Verifies, validates and resolves the config path to retrieve the config's data and ignores.",
|
|
38
|
+
"Verifies, validates and resolves the config path to retrieve the config's data and ignores.", // $COMMENT#JSDOC#DEFINITIONS#RESOLVECONFIG
|
|
39
39
|
}),
|
|
40
40
|
params: Object.freeze({
|
|
41
|
-
string: "The string.",
|
|
41
|
+
string: "The string.", // $COMMENT#JSDOC#PARAMS#STRING
|
|
42
42
|
flattenedConfigData:
|
|
43
|
-
"The flattened config data, with $COMMENT#* placeholders as keys and actual comments as values.",
|
|
43
|
+
"The flattened config data, with $COMMENT#* placeholders as keys and actual comments as values.", // $COMMENT#JSDOC#PARAMS#FLATTENEDCONFIGDATA
|
|
44
44
|
reversedFlattenedConfigData:
|
|
45
|
-
"The reversed flattened config data, with actual comments as keys and $COMMENT#* placeholders as values.",
|
|
45
|
+
"The reversed flattened config data, with actual comments as keys and $COMMENT#* placeholders as values.", // $COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA
|
|
46
46
|
ruleName:
|
|
47
|
-
'The name of the rule currently used. (Either `"resolve"` or `"compress"`.)',
|
|
47
|
+
'The name of the rule currently used. (Either `"resolve"` or `"compress"`.)', // $COMMENT#JSDOC#PARAMS#RULENAME
|
|
48
48
|
ignores:
|
|
49
|
-
"The array of paths and globs for the flow's ESLint instance to ignore.",
|
|
49
|
+
"The array of paths and globs for the flow's ESLint instance to ignore.", // $COMMENT#JSDOC#PARAMS#IGNORES
|
|
50
50
|
eitherFlattenedConfigData:
|
|
51
|
-
"Either the flattened config data or the reversed flattened config data, since they share the same structure.",
|
|
51
|
+
"Either the flattened config data or the reversed flattened config data, since they share the same structure.", // $COMMENT#JSDOC#PARAMS#EITHERFLATTENEDCONFIGDATA
|
|
52
52
|
filePath:
|
|
53
|
-
"The absolute path of the file whose imports are being recursively found, such as that of a project's `comments.config.js` file.",
|
|
54
|
-
cwd: "The current working directory, set as `process.cwd()` by default.",
|
|
53
|
+
"The absolute path of the file whose imports are being recursively found, such as that of a project's `comments.config.js` file.", // $COMMENT#JSDOC#PARAMS#FILEPATH
|
|
54
|
+
cwd: "The current working directory, set as `process.cwd()` by default.", // $COMMENT#JSDOC#PARAMS#CWD
|
|
55
55
|
visitedSet:
|
|
56
|
-
"The set of strings tracking the import paths that have already been visited, instantiated as a `new Set()` by default.",
|
|
56
|
+
"The set of strings tracking the import paths that have already been visited, instantiated as a `new Set()` by default.", // $COMMENT#JSDOC#PARAMS#VISITEDSET
|
|
57
57
|
depth:
|
|
58
|
-
"The current depth of the recursion, instantiated at `0` by default.",
|
|
58
|
+
"The current depth of the recursion, instantiated at `0` by default.", // $COMMENT#JSDOC#PARAMS#DEPTH
|
|
59
59
|
maxDepth:
|
|
60
|
-
"The maximum depth allowed for the recursion, instantiated at `100` by default.",
|
|
61
|
-
importPath: "The import path currently being addressed.",
|
|
60
|
+
"The maximum depth allowed for the recursion, instantiated at `100` by default.", // $COMMENT#JSDOC#PARAMS#MAXDEPTH
|
|
61
|
+
importPath: "The import path currently being addressed.", // $COMMENT#JSDOC#PARAMS#IMPORTPATH
|
|
62
62
|
currentDir:
|
|
63
|
-
"The directory containing the import path currently being addressed.",
|
|
63
|
+
"The directory containing the import path currently being addressed.", // $COMMENT#JSDOC#PARAMS#CURRENTDIR
|
|
64
64
|
configData:
|
|
65
|
-
"The config's data property. (Values are typed `any` given the limitations in typing recursive values in JSDoc.)",
|
|
65
|
+
"The config's data property. (Values are typed `any` given the limitations in typing recursive values in JSDoc.)", // $COMMENT#JSDOC#PARAMS#CONFIGDATA
|
|
66
66
|
configDataMap:
|
|
67
|
-
"The map housing the flattened keys with their values and sources through recursion, instantiated as a `new Map()`.",
|
|
67
|
+
"The map housing the flattened keys with their values and sources through recursion, instantiated as a `new Map()`.", // $COMMENT#JSDOC#PARAMS#CONFIGDATAMAP
|
|
68
68
|
parentKeys:
|
|
69
|
-
"The list of keys that are parent to the key at hand given the recursive nature of the config's data's data structure, instantiated as an empty array of strings.",
|
|
69
|
+
"The list of keys that are parent to the key at hand given the recursive nature of the config's data's data structure, instantiated as an empty array of strings.", // $COMMENT#JSDOC#PARAMS#PARENTKEYS
|
|
70
70
|
configPath:
|
|
71
|
-
"The path of the config, either from `comments.config.js` or from a config passed via the `--config` flag.",
|
|
71
|
+
"The path of the config, either from `comments.config.js` or from a config passed via the `--config` flag.", // $COMMENT#JSDOC#PARAMS#CONFIGPATH
|
|
72
72
|
}),
|
|
73
73
|
returns: Object.freeze({
|
|
74
74
|
exitDueToFailure:
|
|
75
|
-
"Never. (Somehow typing needs to be explicit for unreachable code inference.)",
|
|
76
|
-
escapeRegex: `The string with regex characters escaped.`,
|
|
77
|
-
makeRuleResolve: "The resolve rule based on the flattened config data.",
|
|
75
|
+
"Never. (Somehow typing needs to be explicit for unreachable code inference.)", // $COMMENT#JSDOC#RETURNS#EXITDUETOFAILURE
|
|
76
|
+
escapeRegex: `The string with regex characters escaped.`, // $COMMENT#JSDOC#RETURNS#ESCAPEREGEX
|
|
77
|
+
makeRuleResolve: "The resolve rule based on the flattened config data.", // $COMMENT#JSDOC#RETURNS#MAKERULERESOLVE
|
|
78
78
|
makeRuleCompress:
|
|
79
|
-
"The compress rule based on the reversed flattened config data.",
|
|
79
|
+
"The compress rule based on the reversed flattened config data.", // $COMMENT#JSDOC#RETURNS#MAKERULECOMPRESS
|
|
80
80
|
findAllImports:
|
|
81
|
-
"The complete set of strings of import paths recursively related to the given file path, or `null` if an issue has arisen.",
|
|
81
|
+
"The complete set of strings of import paths recursively related to the given file path, or `null` if an issue has arisen.", // $COMMENT#JSDOC#RETURNS#FINDALLIMPORTS
|
|
82
82
|
processImport:
|
|
83
|
-
"`true` to skip unresolved paths, `false` if resolution fails at any level.",
|
|
83
|
+
"`true` to skip unresolved paths, `false` if resolution fails at any level.", // $COMMENT#JSDOC#RETURNS#PROCESSIMPORT
|
|
84
84
|
flattenConfigData:
|
|
85
|
-
"Both the flattened config data and its reversed version to ensure the strict reversibility of the `resolve` and `compress` commands.",
|
|
85
|
+
"Both the flattened config data and its reversed version to ensure the strict reversibility of the `resolve` and `compress` commands.", // $COMMENT#JSDOC#RETURNS#FLATTENCONFIGDATA
|
|
86
86
|
resolveConfig:
|
|
87
|
-
"The flattened config data, the reverse flattened config data, the verified config path
|
|
87
|
+
"The flattened config data, the reverse flattened config data, the verified config path, the raw passed ignores, and the original config.", // $COMMENT#JSDOC#RETURNS#RESOLVECONFIG
|
|
88
88
|
}),
|
|
89
89
|
}),
|
|
90
90
|
};
|
|
91
91
|
|
|
92
|
-
const ignores = ["
|
|
92
|
+
const ignores = ["README.md"];
|
|
93
93
|
|
|
94
94
|
const config = {
|
|
95
95
|
data,
|
|
@@ -8,7 +8,7 @@ import { ConfigDataSchema, ConfigIgnoresSchema } from "../schemas/config.js";
|
|
|
8
8
|
/**
|
|
9
9
|
* Verifies, validates and resolves the config path to retrieve the config's data and ignores.
|
|
10
10
|
* @param {string} configPath The path of the config, either from `comments.config.js` or from a config passed via the `--config` flag.
|
|
11
|
-
* @returns The flattened config data, the reverse flattened config data, the verified config path
|
|
11
|
+
* @returns The flattened config data, the reverse flattened config data, the verified config path, the raw passed ignores, and the original config.
|
|
12
12
|
*/
|
|
13
13
|
export async function resolveConfig(configPath) {
|
|
14
14
|
// Step 1: Checks if config file exists
|
|
@@ -58,10 +58,10 @@ export async function resolveConfig(configPath) {
|
|
|
58
58
|
// - the reverse flattened config data,
|
|
59
59
|
// - the verified config path
|
|
60
60
|
// - and the raw passed ignores
|
|
61
|
-
console.log("Running with config:", config);
|
|
62
61
|
return {
|
|
63
62
|
...flattenConfigData(configDataResult.data), // finalized
|
|
64
63
|
configPath, // finalized
|
|
65
64
|
passedIgnores: configIgnoresSchemaResult.data, // addressed with --lint-config-imports and --my-ignores-only to be finalized
|
|
65
|
+
config, // and the config itself too
|
|
66
66
|
};
|
|
67
67
|
}
|
package/library/index.js
CHANGED
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
lintConfigImportsFlag,
|
|
13
13
|
myIgnoresOnlyFlag,
|
|
14
14
|
knownIgnores,
|
|
15
|
+
resolveRuleName,
|
|
16
|
+
compressRuleName,
|
|
15
17
|
} from "./_commons/constants/bases.js";
|
|
16
18
|
|
|
17
19
|
import { exitDueToFailure } from "./_commons/utilities/helpers.js";
|
|
@@ -40,6 +42,10 @@ if (!hasGitFolder) {
|
|
|
40
42
|
// GATHERS COMMANDS.
|
|
41
43
|
|
|
42
44
|
const commands = process.argv;
|
|
45
|
+
const coreCommand = commands[2];
|
|
46
|
+
|
|
47
|
+
const skipDetails =
|
|
48
|
+
coreCommand === resolveRuleName || coreCommand === compressRuleName;
|
|
43
49
|
|
|
44
50
|
// OBTAINS THE VALIDATED FLATTENED CONFIG, REVERSE FLATTENED CONFIG, CONFIG PATH, AND PASSED IGNORES.
|
|
45
51
|
|
|
@@ -61,16 +67,19 @@ if (!results) {
|
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
const {
|
|
70
|
+
config,
|
|
64
71
|
flattenedConfigData,
|
|
65
72
|
reversedFlattenedConfigData,
|
|
66
73
|
configPath,
|
|
67
74
|
passedIgnores,
|
|
68
75
|
} = results;
|
|
69
76
|
|
|
70
|
-
console.log("
|
|
71
|
-
console.log("
|
|
72
|
-
|
|
73
|
-
console.log("
|
|
77
|
+
skipDetails || console.log("Running with config:", config);
|
|
78
|
+
skipDetails || console.log("Flattened config is:", flattenedConfigData);
|
|
79
|
+
skipDetails ||
|
|
80
|
+
console.log("Reversed flattened config is:", reversedFlattenedConfigData);
|
|
81
|
+
skipDetails || console.log("Config path is:", configPath);
|
|
82
|
+
skipDetails || console.log("Passed ignores are:", passedIgnores);
|
|
74
83
|
|
|
75
84
|
// ADDRESSES THE --lint-config-imports FLAG, GIVEN THAT THE FILES IMPORTED BY THE CONFIG ARE IGNORED BY DEFAULT.
|
|
76
85
|
|
|
@@ -84,10 +93,11 @@ const configPathIgnores = rawConfigPathIgnores.map((e) =>
|
|
|
84
93
|
path.relative(cwd, e)
|
|
85
94
|
);
|
|
86
95
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
skipDetails ||
|
|
97
|
+
console.log(
|
|
98
|
+
lintConfigImports ? "Config path ignore is:" : "Config path ignores are:",
|
|
99
|
+
configPathIgnores
|
|
100
|
+
);
|
|
91
101
|
|
|
92
102
|
// ADDRESSES THE --my-ignores-only FLAG, GIVEN THAT KNOWN IGNORES ARE IGNORED BY DEFAULT
|
|
93
103
|
|
|
@@ -95,17 +105,17 @@ const myIgnoresOnly = commands.indexOf(myIgnoresOnlyFlag) >= 2;
|
|
|
95
105
|
const rawIgnores = [...configPathIgnores, ...passedIgnores];
|
|
96
106
|
const ignores = myIgnoresOnly ? rawIgnores : [...rawIgnores, ...knownIgnores];
|
|
97
107
|
|
|
98
|
-
console.log("Ignores are:", ignores);
|
|
108
|
+
skipDetails || console.log("Ignores are:", ignores);
|
|
99
109
|
|
|
100
110
|
// ADDRESSES THE CORE COMMANDS "resolve" AND "compress".
|
|
101
111
|
|
|
102
|
-
const coreCommand = commands[2];
|
|
103
|
-
|
|
104
112
|
switch (coreCommand) {
|
|
105
|
-
case
|
|
113
|
+
case resolveRuleName:
|
|
114
|
+
console.log(`Running ${resolveRuleName}...`);
|
|
106
115
|
await resolveCommentsFlow(ignores, flattenedConfigData);
|
|
107
116
|
break;
|
|
108
|
-
case
|
|
117
|
+
case compressRuleName:
|
|
118
|
+
console.log(`Running ${compressRuleName}...`);
|
|
109
119
|
await compressCommentsFlow(ignores, reversedFlattenedConfigData);
|
|
110
120
|
break;
|
|
111
121
|
default:
|
package/package.json
CHANGED