comment-variables 0.15.4 → 0.16.0

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 CHANGED
@@ -18,19 +18,19 @@ npm install -g comment-variables
18
18
  comment-variables
19
19
  ```
20
20
 
21
- 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 as the printed parameters correspond to what you've expected from your defined config. (Additionally creates a resolved version of your config data as a JSON file.)
21
+ Interacts with your root `comments.config.js` file's 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 as the printed parameters correspond to what you've expected from your defined config. (Additionally creates a resolved version of your config data as a JSON file.)
22
22
 
23
23
  ```
24
24
  comment-variables compress
25
25
  ```
26
26
 
27
- 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#*` placeholders defined in your `comments.config.js`. (`This is a comment.` => `$COMMENT#COMMENT`)
27
+ Scans your line and block comments for string values defined in your root `comments.config.js` file (like `"This is a comment"`) to turn them into their corresponding `$COMMENT#*` placeholders defined in your `comments.config.js`. (`This is a comment.` => `$COMMENT#COMMENT`)
28
28
 
29
29
  ```
30
30
  comment-variables resolve
31
31
  ```
32
32
 
33
- Scans your line and block comments for `$COMMENT#*` placeholders (like `$COMMENT#COMMENT`) to turn them into their corresponding string values defined in your `comments.config.js`. (`$COMMENT#COMMENT` => `This is a comment.`)
33
+ Scans your line and block comments for `$COMMENT#*` placeholders (like `$COMMENT#COMMENT`) to turn them into their corresponding string values defined in your root `comments.config.js` file. (`$COMMENT#COMMENT` => `This is a comment.`)
34
34
 
35
35
  _The `compress` and `resolve` commands make each other entirely reversible._
36
36
 
@@ -50,19 +50,19 @@ Creates Comment Variables placeholders right next to the single sources of truth
50
50
  comment-variables --config <your-config.js>
51
51
  ```
52
52
 
53
- Passes a different file as your config instead of the default `comments.config.js` (like `comment-variables --config your-config.js`), through a path relative to the root of your project.
53
+ Passes a different file as your config instead of the default root `comments.config.js` file (like `comment-variables --config your-config.js`), through a path relative to the root of your project.
54
54
 
55
55
  ```
56
56
  --lint-config-imports is now part of the config at the `lintConfigImports` key
57
57
  ```
58
58
 
59
- 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.)
59
+ By default, `comment-variables` excludes your config file and all the (JavaScript/TypeScript) files it recursively imports. This config option cancels this mechanism, linting config imports. (The config file however still remains excluded from linting.)
60
60
 
61
61
  ```
62
62
  --my-ignores-only is now part of the config at the `myIgnoresOnly` key
63
63
  ```
64
64
 
65
- 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.
65
+ By default, `comment-variables` includes a preset list of ignored folders (`"node_modules"`, `".next"`, `".react-router"`...). This config option cancels this mechanism so that you can have full control over your ignored files and folders.
66
66
 
67
67
  _The --config flag can be composed with any of the commands:_
68
68
 
@@ -75,7 +75,7 @@ comment-variables placeholders --config your-config.js
75
75
 
76
76
  ## **`comments.config.js`**
77
77
 
78
- A `comments.config.js` file looks like this. (This is the config file I'm using to manage my JavaScript comments in this library.)
78
+ A root `comments.config.js` file looks like this. (This is the config file I'm using to manage my JavaScript comments in this library.)
79
79
 
80
80
  ```js
81
81
  const data = {
@@ -120,7 +120,7 @@ const data = {
120
120
  configPathIgnores:
121
121
  'The array of paths linked to the config file, (named "ignores" given it is ignored by the "compress" and "resolve" commands).' /* $COMMENT#JSDOC#PARAMS#CONFIGPATHIGNORES */,
122
122
  originalFlattenedConfigData:
123
- "The original flattened config data, before changes to Aliases Variables and Composed Variables are applied." /* $COMMENT#JSDOC#PARAMS#ORIGINALFLATTENEDCONFIGDATA */,
123
+ "The original flattened config data, before changes to aliases variables and composed variables are applied." /* $COMMENT#JSDOC#PARAMS#ORIGINALFLATTENEDCONFIGDATA */,
124
124
  }),
125
125
  returns: Object.freeze({
126
126
  exitDueToFailure:
@@ -130,13 +130,17 @@ const data = {
130
130
  makeRuleCompress:
131
131
  "The compress rule based on the reversed flattened config data." /* $COMMENT#JSDOC#RETURNS#MAKERULECOMPRESS */,
132
132
  }),
133
+ constants: Object.freeze({
134
+ sortedReversedFlattenedConfigData:
135
+ "The whole `reversedFlattenedConfigData` turned from an object to an array of key-value arrays sorted by the descending length of each key to prevent partial replacements." /* $COMMENT#JSDOC#CONSTANTS#SORTEDREVERSEDFLATTENEDCONFIGDATA */,
136
+ }),
133
137
  }),
134
138
  };
135
139
 
136
- const ignores = ["README.md"];
140
+ const ignores = ["README.md", "generate.template.js", "generate.example.js"];
137
141
 
138
- const lintConfigImports = false; // can be ommitted
139
- const myIgnoresOnly = false; // can be ommitted
142
+ const lintConfigImports = false; // can be omitted
143
+ const myIgnoresOnly = false; // can be omitted
140
144
 
141
145
  const config = {
142
146
  data,
@@ -91,7 +91,7 @@ const data = {
91
91
  configPathIgnores:
92
92
  'The array of paths linked to the config file, (named "ignores" given it is ignored by the "compress" and "resolve" commands).' /* $COMMENT#JSDOC#PARAMS#CONFIGPATHIGNORES */,
93
93
  originalFlattenedConfigData:
94
- "The original flattened config data, before changes to Aliases Variables and Composed Variables are applied." /* $COMMENT#JSDOC#PARAMS#ORIGINALFLATTENEDCONFIGDATA */,
94
+ "The original flattened config data, before changes to aliases variables and composed variables are applied." /* $COMMENT#JSDOC#PARAMS#ORIGINALFLATTENEDCONFIGDATA */,
95
95
  }),
96
96
  returns: Object.freeze({
97
97
  exitDueToFailure:
@@ -101,15 +101,19 @@ const data = {
101
101
  makeRuleCompress:
102
102
  "The compress rule based on the reversed flattened config data." /* $COMMENT#JSDOC#RETURNS#MAKERULECOMPRESS */,
103
103
  }),
104
+ constants: Object.freeze({
105
+ sortedReversedFlattenedConfigData:
106
+ "The whole `reversedFlattenedConfigData` turned from an object to an array of key-value arrays sorted by the descending length of each key to prevent partial replacements." /* $COMMENT#JSDOC#CONSTANTS#SORTEDREVERSEDFLATTENEDCONFIGDATA */,
107
+ }),
104
108
  }),
105
109
  };
106
110
 
107
- const ignores = ["README.md"];
111
+ const ignores = ["README.md", "generate.template.js", "generate.example.js"];
108
112
 
109
113
  // FORMER CLI FLAGS NOW TO BE INCLUDED INSIDE THE CONFIG ITSELF
110
114
 
111
- const lintConfigImports = false; // can be ommitted
112
- const myIgnoresOnly = false; // can be ommitted
115
+ const lintConfigImports = false; // can be omitted
116
+ const myIgnoresOnly = false; // can be omitted
113
117
 
114
118
  const config = {
115
119
  data,
@@ -123,7 +123,7 @@
123
123
  "placeholder": "$COMMENT#JSDOC#PARAMS#CONFIGPATHIGNORES"
124
124
  },
125
125
  "originalFlattenedConfigData": {
126
- "value": "The original flattened config data, before changes to Aliases Variables and Composed Variables are applied.",
126
+ "value": "The original flattened config data, before changes to aliases variables and composed variables are applied.",
127
127
  "key": "JSDOC#PARAMS#ORIGINALFLATTENEDCONFIGDATA",
128
128
  "placeholder": "$COMMENT#JSDOC#PARAMS#ORIGINALFLATTENEDCONFIGDATA"
129
129
  }
@@ -144,6 +144,13 @@
144
144
  "key": "JSDOC#RETURNS#MAKERULECOMPRESS",
145
145
  "placeholder": "$COMMENT#JSDOC#RETURNS#MAKERULECOMPRESS"
146
146
  }
147
+ },
148
+ "constants": {
149
+ "sortedReversedFlattenedConfigData": {
150
+ "value": "The whole `reversedFlattenedConfigData` turned from an object to an array of key-value arrays sorted by the descending length of each key to prevent partial replacements.",
151
+ "key": "JSDOC#CONSTANTS#SORTEDREVERSEDFLATTENEDCONFIGDATA",
152
+ "placeholder": "$COMMENT#JSDOC#CONSTANTS#SORTEDREVERSEDFLATTENEDCONFIGDATA"
153
+ }
147
154
  }
148
155
  }
149
156
  }
@@ -1,7 +1,8 @@
1
1
  // A Comment Variables config template generated in case no config file has been found. Feel free to use it as a stepping stone to learn how to use Comment Variables.
2
2
 
3
- // As a first step, go ahead and run the command `comment-variables placeholders`.
4
- // Then rename the `$COMMENT#COMMENT` placeholder next to `alias` to `$COMMENT#ALIAS` and run again `comment-variables placeholders` to see what happens.
3
+ // As a first step, go ahead and run the command `comment-variables placeholders`. (This generates the Comment Variables placeholders right next to where their values are defined.)
4
+ // Then rename the `$COMMENT#COMMENT` placeholder next to the `alias` key's value in the `data` object to `$COMMENT#ALIAS`, and run again `comment-variables placeholders` to see what happens. (...Which is nothing, and I let you figure out why.)
5
+
5
6
  // You can now use and explore Comment Variables on the accompanying `comments.example.js` file that has also been generated.
6
7
 
7
8
  const data = Object.freeze({
@@ -16,8 +17,8 @@ const data = Object.freeze({
16
17
 
17
18
  const ignores = [];
18
19
 
19
- const lintConfigImports = false; // can be ommitted
20
- const myIgnoresOnly = false; // can be ommitted
20
+ const lintConfigImports = false; // can be omitted
21
+ const myIgnoresOnly = false; // can be omitted
21
22
 
22
23
  const config = {
23
24
  data,
@@ -36,9 +36,9 @@ const coreCommentsFlow = async (
36
36
  ) => {
37
37
  const eslint = new ESLint({
38
38
  fix: true,
39
+ ignorePatterns: ignores,
39
40
  errorOnUnmatchedPattern: false,
40
41
  overrideConfigFile: true,
41
- ignorePatterns: ignores,
42
42
  overrideConfig: [
43
43
  {
44
44
  files: allJSTSFileGlobs,
@@ -138,7 +138,7 @@ export const compressCommentsFlow = async (
138
138
  /**
139
139
  * The flow that creates `$COMMENT` placeholders right next to where they're defined.
140
140
  * @param {string[]} configPathIgnores The array of paths linked to the config file, (named "ignores" given it is ignored by the "compress" and "resolve" commands).
141
- * @param {{[k: string]: string;}} originalFlattenedConfigData The original flattened config data, before changes to Aliases Variables and Composed Variables are applied.
141
+ * @param {{[k: string]: string;}} originalFlattenedConfigData The original flattened config data, before changes to aliases variables and composed variables are applied.
142
142
  * @param {Record<string, string>} aliases_flattenedKeys The dictionary that connects aliases to their original flattened keys in case an encountered placeholder is actually an alias.
143
143
  * @returns
144
144
  */
package/library/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // The shebang (#!) is necessary to communicate with Unix-based systems, like Linux and macOS. On Windows, it is ignored, but npm tooling bridges the gap by generating wrappers that make the CLI work anyway.
2
+ // The shebang/hashbang (#!) is necessary to communicate with Unix-based systems, like Linux and macOS. On Windows, it is ignored, but npm tooling bridges the gap by generating wrappers that make the CLI work anyway.
3
3
 
4
4
  import path from "path";
5
5
  import fs from "fs";
@@ -58,7 +58,7 @@ if (!hasGitFolder) {
58
58
  }
59
59
  skipDetails || console.log("git folder noticed. Allowed to proceed.");
60
60
 
61
- // OBTAINS THE VALIDATED FLATTENED CONFIG, REVERSE FLATTENED CONFIG, CONFIG PATH, AND PASSED IGNORES.
61
+ // SORTS OUT THE CONFIG PATH.
62
62
 
63
63
  // extracts the position of the --config flag
64
64
  const configFlagIndex = commands.indexOf(configFlag);
@@ -72,7 +72,7 @@ const passedConfigPath =
72
72
  // defaults to comments.config.js if no --config flag is set
73
73
  let rawConfigPath = passedConfigPath ?? path.join(cwd, defaultConfigFileName);
74
74
 
75
- // HANDLES TUTORIAL MODE
75
+ // HANDLES TUTORIAL MODE.
76
76
 
77
77
  if (!fs.existsSync(rawConfigPath)) {
78
78
  console.log(
@@ -105,7 +105,7 @@ if (!fs.existsSync(rawConfigPath)) {
105
105
  rawConfigPath = templateFilePath;
106
106
  }
107
107
 
108
- // RESOLVES THE CONFIG
108
+ // RESOLVES THE CONFIG.
109
109
 
110
110
  console.log(`Resolving config at ${rawConfigPath}...`);
111
111
 
@@ -126,7 +126,6 @@ const {
126
126
  configPath,
127
127
  passedIgnores,
128
128
  rawConfigAndImportPaths,
129
- // NEW
130
129
  lintConfigImports,
131
130
  myIgnoresOnly,
132
131
  } = resolveConfigResults;
@@ -147,7 +146,6 @@ skipDetails || console.log("myIgnoresOnly are:", myIgnoresOnly);
147
146
 
148
147
  // ADDRESSES THE --lint-config-imports FLAG (lintConfigImports, no longer a flag), GIVEN THAT THE FILES IMPORTED BY THE CONFIG ARE IGNORED BY DEFAULT.
149
148
 
150
- // const lintConfigImports = commands.indexOf(lintConfigImportsFlag) >= 2; // NOW FROM CONFIG
151
149
  const rawConfigPathIgnores = lintConfigImports
152
150
  ? [configPath]
153
151
  : rawConfigAndImportPaths;
@@ -163,15 +161,14 @@ skipDetails ||
163
161
  configPathIgnores
164
162
  );
165
163
 
166
- // ADDRESSES THE --my-ignores-only FLAG (myIgnoresOnly, no longer a flag, GIVEN THAT KNOWN IGNORES ARE IGNORED BY DEFAULT
164
+ // ADDRESSES THE --my-ignores-only FLAG (myIgnoresOnly, no longer a flag, GIVEN THAT KNOWN IGNORES ARE IGNORED BY DEFAULT.
167
165
 
168
- // const myIgnoresOnly = commands.indexOf(myIgnoresOnlyFlag) >= 2; // NOW FROM CONFIG
169
166
  const rawIgnores = [...configPathIgnores, ...passedIgnores];
170
167
  const ignores = myIgnoresOnly ? rawIgnores : [...rawIgnores, ...knownIgnores];
171
168
 
172
169
  skipDetails || console.log("Ignores are:", ignores);
173
170
 
174
- // NEW: AUTOMATICALLY GENERATE THE JSON OUTPUT OF YOUR RESOLVED CONFIG DATA.
171
+ // AUTOMATICALLY GENERATES THE JSON OUTPUT OF YOUR RESOLVED CONFIG DATA.
175
172
 
176
173
  const makeResolvedConfigDataResults =
177
174
  makeResolvedConfigData(resolveConfigResults);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comment-variables",
3
- "version": "0.15.4",
3
+ "version": "0.16.0",
4
4
  "description": "A CLI tool for configuring, managing and maintaining JavaScript comments as JavaScript variables.",
5
5
  "bin": {
6
6
  "comment-variables": "./library/index.js",
@@ -30,7 +30,7 @@
30
30
  "type": "module",
31
31
  "dependencies": {
32
32
  "@eslint/markdown": "^6.5.0",
33
- "comment-variables-resolve-config": "^1.12.3",
33
+ "comment-variables-resolve-config": "^1.13.2",
34
34
  "eslint": "^9.29.0"
35
35
  },
36
36
  "devDependencies": {