comment-variables 0.12.4 → 0.14.1

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
@@ -44,26 +44,27 @@ Creates Comment Variables placeholders right next to the single sources of truth
44
44
  comment-variables --config <your-config.js>
45
45
  ```
46
46
 
47
- Pass a different file as your config instead of the default `comments.config.js` (like `comment-variables --config your-config.js`).
47
+ 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.
48
48
 
49
49
  ```
50
- comment-variables --lint-config-imports
50
+ --lint-config-imports now part of the config at the `lintConfigImports` key
51
51
  ```
52
52
 
53
53
  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.)
54
54
 
55
55
  ```
56
- comment-variables --my-ignores-only
56
+ --my-ignores-only now part of the config at the `myIgnoresOnly` key
57
57
  ```
58
58
 
59
59
  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.
60
60
 
61
- _All three flags can be composed together, and with any of the three commands:_
61
+ _The --config flag can be composed with any of the commands:_
62
62
 
63
63
  ```
64
64
  comment-variables --config your-config.js
65
- comment-variables compress --config your-config.js --lint-config-imports
66
- comment-variables resolve --config your-config.js --lint-config-imports --my-ignores-only
65
+ comment-variables compress --config your-config.js
66
+ comment-variables resolve --config your-config.js
67
+ comment-variables placeholders --config your-config.js
67
68
  ```
68
69
 
69
70
  ## **`comments.config.js`**
@@ -128,9 +129,14 @@ const data = {
128
129
 
129
130
  const ignores = ["README.md"];
130
131
 
132
+ const lintConfigImports = false; // can be ommitted
133
+ const myIgnoresOnly = false; // can be ommitted
134
+
131
135
  const config = {
132
136
  data,
133
137
  ignores,
138
+ lintConfigImports,
139
+ myIgnoresOnly,
134
140
  };
135
141
 
136
142
  export default config;
@@ -106,9 +106,16 @@ const data = {
106
106
 
107
107
  const ignores = ["README.md"];
108
108
 
109
+ // FORMER CLI FLAGS NOW TO BE INCLUDED INSIDE THE CONFIG ITSELF
110
+
111
+ const lintConfigImports = false; // can be ommitted
112
+ const myIgnoresOnly = false; // can be ommitted
113
+
109
114
  const config = {
110
115
  data,
111
116
  ignores,
117
+ lintConfigImports,
118
+ myIgnoresOnly,
112
119
  };
113
120
 
114
121
  export default config;
@@ -1,14 +1,13 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
3
 
4
+ import { cwd } from "comment-variables-resolve-config";
5
+
4
6
  // rule names
5
7
  export const resolveRuleName = "resolve";
6
8
  export const compressRuleName = "compress";
7
9
  export const placeholdersRuleName = "placeholders"; // rule?
8
10
 
9
- // current working directory
10
- export const cwd = process.cwd();
11
-
12
11
  // to prevent accidental changes
13
12
  export const hasPackageJson = fs.existsSync(path.join(cwd, "package.json"));
14
13
  // to prevent irreversible changes
package/library/index.js CHANGED
@@ -3,18 +3,19 @@
3
3
 
4
4
  import path from "path";
5
5
  import fs from "fs";
6
+ import url from "url";
6
7
 
7
8
  import resolveConfig, {
8
9
  defaultConfigFileName,
10
+ templateFileName,
11
+ exampleFileName,
9
12
  configFlag,
10
- lintConfigImportsFlag,
11
- myIgnoresOnlyFlag,
13
+ cwd,
12
14
  knownIgnores,
13
15
  makeResolvedConfigData,
14
16
  } from "comment-variables-resolve-config";
15
17
 
16
18
  import {
17
- cwd,
18
19
  hasPackageJson,
19
20
  hasGitFolder,
20
21
  resolveRuleName,
@@ -29,6 +30,16 @@ import {
29
30
  placeholdersCommentsFlow,
30
31
  } from "./_commons/utilities/flows.js";
31
32
 
33
+ // GATHERS COMMANDS.
34
+
35
+ const commands = process.argv;
36
+ const coreCommand = commands[2];
37
+
38
+ const skipDetails =
39
+ coreCommand === resolveRuleName ||
40
+ coreCommand === compressRuleName ||
41
+ coreCommand === placeholdersRuleName;
42
+
32
43
  // ENSURES THE CLI TOOL ONLY RUNS IN FOLDERS THAT POSSESS A package.json FILE AND A .git FOLDER.
33
44
 
34
45
  if (!hasPackageJson) {
@@ -37,22 +48,15 @@ if (!hasPackageJson) {
37
48
  );
38
49
  exitDueToFailure();
39
50
  }
51
+ skipDetails || console.log("package.json file noticed. Allowed to proceed.");
52
+
40
53
  if (!hasGitFolder) {
41
54
  console.error(
42
55
  "ERROR. No git folder found in this directory. Aborting to prevent irreversible changes."
43
56
  );
44
57
  exitDueToFailure();
45
58
  }
46
-
47
- // GATHERS COMMANDS.
48
-
49
- const commands = process.argv;
50
- const coreCommand = commands[2];
51
-
52
- const skipDetails =
53
- coreCommand === resolveRuleName ||
54
- coreCommand === compressRuleName ||
55
- coreCommand === placeholdersRuleName;
59
+ skipDetails || console.log("git folder noticed. Allowed to proceed.");
56
60
 
57
61
  // OBTAINS THE VALIDATED FLATTENED CONFIG, REVERSE FLATTENED CONFIG, CONFIG PATH, AND PASSED IGNORES.
58
62
 
@@ -66,7 +70,38 @@ const passedConfig = commands[configFlagIndex + 1];
66
70
  const passedConfigPath =
67
71
  hasConfigFlag && passedConfig ? path.join(cwd, passedConfig) : null;
68
72
  // defaults to comments.config.js if no --config flag is set
69
- const rawConfigPath = passedConfigPath ?? path.join(cwd, defaultConfigFileName);
73
+ let rawConfigPath = passedConfigPath ?? path.join(cwd, defaultConfigFileName);
74
+
75
+ if (!fs.existsSync(rawConfigPath)) {
76
+ console.log(
77
+ `No Comment Variables config file found at ${rawConfigPath}. Switching to tutorial mode.`
78
+ );
79
+
80
+ const templateFilePath = path.join(cwd, templateFileName);
81
+ const exampleFilePath = path.join(cwd, exampleFileName);
82
+ const dirname = path.dirname(url.fileURLToPath(import.meta.url));
83
+
84
+ if (fs.existsSync(templateFilePath)) {
85
+ console.log(`Proceeding with template file found at ${templateFilePath}.`);
86
+ } else {
87
+ const sourceTemplateFilePath = path.join(
88
+ dirname,
89
+ "../generate.template.js"
90
+ );
91
+ console.log(`Generating template file at ${templateFilePath}.`);
92
+ fs.copyFileSync(sourceTemplateFilePath, templateFilePath);
93
+ }
94
+
95
+ if (fs.existsSync(exampleFilePath)) {
96
+ console.log(`Proceeding with example file found at ${exampleFilePath}.`);
97
+ } else {
98
+ const sourceExampleFilePath = path.join(dirname, "../generate.example.js");
99
+ console.log(`Generating example file at ${exampleFilePath}.`);
100
+ fs.copyFileSync(sourceExampleFilePath, exampleFilePath);
101
+ }
102
+
103
+ rawConfigPath = templateFilePath;
104
+ }
70
105
 
71
106
  console.log(`Resolving config at ${rawConfigPath}...`);
72
107
 
@@ -87,6 +122,9 @@ const {
87
122
  configPath,
88
123
  passedIgnores,
89
124
  rawConfigAndImportPaths,
125
+ // NEW
126
+ lintConfigImports,
127
+ myIgnoresOnly,
90
128
  } = resolveConfigResults;
91
129
 
92
130
  skipDetails || console.log("Running with config:", config);
@@ -99,10 +137,19 @@ skipDetails ||
99
137
  skipDetails || console.log("Aliases are:", aliases_flattenedKeys);
100
138
  skipDetails || console.log("Config path is:", configPath);
101
139
  skipDetails || console.log("Passed ignores are:", passedIgnores);
140
+ // NEW
141
+ skipDetails || console.log("lintConfigImports is:", lintConfigImports);
142
+ skipDetails || console.log("myIgnoresOnly are:", myIgnoresOnly);
143
+
144
+ /* IMPORTANT
145
+ Aside from the config flag, all other flags (`--lint-config-imports`, `--my-ignores-only`) should be included in the config so that they can be shared across the CLI and the extension within a single source of truth, invalidating the need to scream " (And DON'T FORGET YOUR FLAGS!)".
146
+ This didn't come to mind originally because the idea of these flags came into play before I reliably made the VS Code extension.
147
+ The goal therefore becomes that ONLY the config path remains the SOLE available flag for the CLI and config option for the extension that users will have to manage manually across both solutions.
148
+ And then I can start working on the template for Comment Variables to unleash upon asking if no config file is found. comments.template.js */
102
149
 
103
- // ADDRESSES THE --lint-config-imports FLAG, GIVEN THAT THE FILES IMPORTED BY THE CONFIG ARE IGNORED BY DEFAULT.
150
+ // ADDRESSES THE --lint-config-imports FLAG (lintConfigImports, no longer a flag), GIVEN THAT THE FILES IMPORTED BY THE CONFIG ARE IGNORED BY DEFAULT.
104
151
 
105
- const lintConfigImports = commands.indexOf(lintConfigImportsFlag) >= 2;
152
+ // const lintConfigImports = commands.indexOf(lintConfigImportsFlag) >= 2; // NOW FROM CONFIG
106
153
  const rawConfigPathIgnores = lintConfigImports
107
154
  ? [configPath]
108
155
  : rawConfigAndImportPaths;
@@ -118,9 +165,9 @@ skipDetails ||
118
165
  configPathIgnores
119
166
  );
120
167
 
121
- // ADDRESSES THE --my-ignores-only FLAG, GIVEN THAT KNOWN IGNORES ARE IGNORED BY DEFAULT
168
+ // ADDRESSES THE --my-ignores-only FLAG (myIgnoresOnly, no longer a flag, GIVEN THAT KNOWN IGNORES ARE IGNORED BY DEFAULT
122
169
 
123
- const myIgnoresOnly = commands.indexOf(myIgnoresOnlyFlag) >= 2;
170
+ // const myIgnoresOnly = commands.indexOf(myIgnoresOnlyFlag) >= 2; // NOW FROM CONFIG
124
171
  const rawIgnores = [...configPathIgnores, ...passedIgnores];
125
172
  const ignores = myIgnoresOnly ? rawIgnores : [...rawIgnores, ...knownIgnores];
126
173
 
@@ -176,9 +223,7 @@ switch (coreCommand) {
176
223
  else
177
224
  console.log(
178
225
  `If these settings are correct with you, feel free to initiate the command "${resolveRuleName}" to resolve comments, or "${compressRuleName}" to compress them back to their $COMMENT forms. You can also generate the placeholders at their definitions locations with the command "${placeholdersRuleName}".${
179
- passedConfigPath || lintConfigImports || myIgnoresOnly
180
- ? " (And DON'T FORGET YOUR FLAGS!)"
181
- : ""
226
+ passedConfigPath ? " (And DON'T FORGET YOUR --config FLAG!)" : ""
182
227
  }`
183
228
  );
184
229
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comment-variables",
3
- "version": "0.12.4",
3
+ "version": "0.14.1",
4
4
  "description": "A CLI tool for configuring, managing and maintaining JavaScript comments as JavaScript variables.",
5
5
  "bin": {
6
6
  "jscomments": "./library/index.js",
@@ -10,7 +10,9 @@
10
10
  "files": [
11
11
  "library",
12
12
  "comments.config.js",
13
- "comments.config.json"
13
+ "comments.config.json",
14
+ "comments.template.js",
15
+ "comments.example.js"
14
16
  ],
15
17
  "repository": {
16
18
  "type": "git",
@@ -27,7 +29,7 @@
27
29
  "type": "module",
28
30
  "dependencies": {
29
31
  "@eslint/markdown": "^6.5.0",
30
- "comment-variables-resolve-config": "^1.11.0",
32
+ "comment-variables-resolve-config": "^1.12.3",
31
33
  "eslint": "^9.29.0"
32
34
  },
33
35
  "devDependencies": {