comment-variables 1.2.5 → 1.3.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
@@ -1,6 +1,6 @@
1
1
  # comment-variables
2
2
 
3
- ![Name and logo for the Comment Variables ecosystem, dark default variant.](./assets/README/name-dark-default.png)
3
+ ![Logo and name for the Comment Variables ecosystem, dark default variant.](./assets/README/name-dark-default.png)
4
4
 
5
5
  <!-- <picture>
6
6
  <source media="(prefers-color-scheme: dark)" srcset="./assets/README/name-dark-default.png">
@@ -197,4 +197,4 @@ And yes, even comments within JavaScript and TypeScript blocks in Markdown files
197
197
 
198
198
  _Leverage the power of JavaScript to programmatically design your JavaScript comments._
199
199
 
200
- **The Comment Variables VS Code extension is available [here](https://comvar.lemonsqueezy.com/buy/723b0220-ea5d-4b0a-835a-f0843e431639?logo=0&discount=0).**
200
+ **The Comment Variables VS Code extension is available [here](https://comvar.lemonsqueezy.com/buy/723b0220-ea5d-4b0a-835a-f0843e431639).**
@@ -1,141 +1,26 @@
1
- // const obj = { test: "Testing." }; // errors, object string values in config files are reserved for exports from the config.
2
-
3
- const data = {
4
- // for testing
5
- levelOne: {
6
- levelTwo: {
7
- levelThree: "Level three." /* $COMMENT#LEVELONE#LEVELTWO#LEVELTHREE */, // New placeholder structure. Not as sexy, but first and foremost guaranteed to be functional appended right at the end of the value as a Block comment, and last but not least also guaranteed to not modify Value Locations in the process. So `comment-variables placeholders` it is, and this justifies enforcing strings only for values even outside of the use of the VS Code extension.
8
- // levelThreeEscape:
9
- // "Level three. \
10
- // fdff\
11
- // " /* $COMMENT#LEVELONE#LEVELTWO#LEVELTHREEESCAPE */, // NOW ERRORS AS INTENDED, unrecognizedValuesSet
12
- stillLevelThree:
13
- "LEVELONE#LEVELTWO#LEVELTHREE" /* $COMMENT#LEVELONE#LEVELTWO#STILLLEVELTHREE */, // now is an alias
14
- otherLevelThree:
15
- "LEVELONE#LEVELTWO#LEVELTHREE" /* $COMMENT#LEVELONE#LEVELTWO#OTHERLEVELTHREE */, // also an alias
16
- composedVariable:
17
- "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREE $COMMENT#LEVELONE#LEVELTWO#STILLLEVELTHREE" /* $COMMENT#LEVELONE#LEVELTWO#COMPOSEDVARIABLE */, // This is a composed variable. What's the beauty in this? It allows for each comment variable to be its own single source of truth that can be reused still within the Comment Variables ecosystem. All while preventing the use of Comment Variables placeholders as values in the config. AND as a matter of fact, it even works... with aliases.
18
- composedVariableAlias:
19
- "LEVELONE#LEVELTWO#COMPOSEDVARIABLE" /* $COMMENT#LEVELONE#LEVELTWO#COMPOSEDVARIABLEALIAS */, // The alias of a composed variable. SO just like composed variables can incorporate aliases, aliases can be aliases for composed variables.
20
-
21
- // otherLevelThreeAlias:
22
- // "LEVELONE#LEVELTWO#OTHERLEVELTHREE" /* $COMMENT#LEVELONE#LEVELTWO#LEVELTHREE */, // errors, can't be the alias of another alias
23
-
24
- // composedOfAlias:
25
- // "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREE $COMMENT#LEVELONE#LEVELTWO#ALIASOFCOMPOSED" /* $COMMENT#LEVELONE#LEVELTWO#COMPOSEDOFALIAS */, // 1/2 already errored // ERROR. A potential composed variable cannot be used as the comment variable of another composed variable.
26
- // aliasOfComposed:
27
- // "LEVELONE#LEVELTWO#COMPOSEDOFALIAS" /* $COMMENT#LEVELONE#LEVELTWO#ALIASOFCOMPOSED */, // 2/2 What if an alias variable was a segment to a composed variable made of itself? // ERROR. The alias "LEVELONE#LEVELTWO#ALIASOFCOMPOSED" links to composed variable "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREE $COMMENT#LEVELONE#LEVELTWO#ALIASOFCOMPOSED" that includes LEVELONE#LEVELTWO#ALIASOFCOMPOSED's placeholder as a segment.
28
-
29
- // aliasInComposed:
30
- // "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREE $COMMENT#LEVELONE#LEVELTWO#ALIASINCOMPOSED", // What if a composed variable had its own value has one of its segments? Composed variables already cannot compose other composed variables. // errors, "ERROR. A potential composed variable cannot be used as the comment variable of another composed variable."
31
- // wrongComposedVariable:
32
- // "$COMMENT#LEVELONE#LEVELTWO#COMPOSEDVARIABLE $COMMENT#LEVELONE#LEVELTWO#STILLLEVELTHREE", // errors, can't make composed variables with composed variables
33
- // wrongComposedVariableToo:
34
- // "$COMMENT#LEVELONE#LEVELTWO#STILLLEVELTHREE $COMMENT#LEVELONE#LEVELTWO#COMPOSEDVARIABLE", // errors, can't make composed variables with composed variables even as aliases
35
- // levelthree: "Also level three.", // errors, duplicate normalized key
36
- // levelThree: "Also level three.", // errors, duplicate key with original overriden by legal JavaScript object value overrides
37
- // alsoLevelThree: "Level three.", // errors, duplicate value
38
- // tooLevelThree: 2, // errors, value is invalid
39
- // $levelThree: "Dollar sign", // errors, key as "$" character
40
- // "#levelThree": "Hashtag", // errors, key as "#" character
41
- // ".levelThree": "Punctuation", // errors, key is invalid due to punctuation
42
- // unrecognized: `Unrecognized value.`, // errors, is not a string literal
43
- // emptyString: "", // errors, string is empty
44
- // "": "emptyKey", // errors, key is empty caught by the regex
45
- // ownAliasKey: "LEVELONE#LEVELTWO#OWNALIASKEY", // errors, is its own key/alias
46
- // key: "key not allowed", // errors, "key", "value" and "placeholder" not allowed
47
- // value: "value not allowed", // errors, "key", "value" and "placeholder" not allowed
48
- placeholder: "placeholder now allowed", // doesn't error, "placeholder" is now allowed
49
- // noConcat: "no" + "concat", // errors, unrecognized value
50
-
51
- // already error via regex, but now enhanced:
52
- // "//": "key comment error 1",
53
- // "/*": "key comment error 2",
54
- // "*/": "key comment error 3",
55
- // error directly in resolveConfig:
56
- // "key comment error 1": "//",
57
- // "key comment error 2": "/*",
58
- // "key comment error 3": "*/",
59
- },
60
- },
61
- // for deving
62
- jsDoc: Object.freeze({
63
- definitions: Object.freeze({
64
- exitDueToFailure:
65
- "Terminates the whole process with a 'failure' code (`1`)." /* $COMMENT#JSDOC#DEFINITIONS#EXITDUETOFAILURE */,
66
- makeRuleResolve:
67
- "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 */,
68
- makeRuleCompress:
69
- "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 */,
70
- coreCommentsFlow:
71
- "The core flow at the heart of resolving and compressing comments." /* $COMMENT#JSDOC#DEFINITIONS#CORECOMMENTSFLOW */,
72
- resolveCommentsFlow:
73
- "The flow that resolves `$COMMENT` placeholders into actual comments." /* $COMMENT#JSDOC#DEFINITIONS#RESOLVECOMMENTSFLOW */,
74
- compressCommentsFlow:
75
- "The flow that compresses actual comments into `$COMMENT` placeholders." /* $COMMENT#JSDOC#DEFINITIONS#COMPRESSCOMMENTSFLOW */,
76
- placeholdersCommentsFlow:
77
- "The flow that creates `$COMMENT` placeholders right next to where they're defined." /* $COMMENT#JSDOC#DEFINITIONS#PLACEHOLDERSCOMMENTSFLOW */,
78
- logError:
79
- 'Logs an error to the console depending on its type. (`"error"` or `"warning"`.)' /* $COMMENT#JSDOC#DEFINITIONS#LOGERROR */,
80
- }),
81
- params: Object.freeze({
82
- flattenedConfigData:
83
- "The flattened config data, with `$COMMENT` placeholders as keys and actual comments as values." /* $COMMENT#JSDOC#PARAMS#FLATTENEDCONFIGDATA */,
84
- reversedFlattenedConfigData:
85
- "The reversed flattened config data, with actual comments as keys and `$COMMENT` placeholders as values." /* $COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA */,
86
- composedVariablesExclusives:
87
- "The array of comment variables keys (implying their aliases as well) exclusively used to craft composed variables, that should be ignored by both the `resolve` and the `compress` commands." /* $COMMENT#JSDOC#PARAMS#COMPOSEDVARIABLESEXCLUSIVES */,
88
- aliases_flattenedKeys:
89
- "The dictionary that connects aliases to their original flattened keys in case an encountered placeholder is actually an alias." /* $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS */,
90
- ruleName:
91
- 'The name of the rule currently used. (Either `"resolve"` or `"compress"`.)' /* $COMMENT#JSDOC#PARAMS#RULENAME */,
92
- ignores:
93
- "The array of paths and globs for the flow's ESLint instance to ignore." /* $COMMENT#JSDOC#PARAMS#IGNORES */,
94
- eitherFlattenedConfigData:
95
- "Either the flattened config data or the reversed flattened config data, since they share the same structure." /* $COMMENT#JSDOC#PARAMS#EITHERFLATTENEDCONFIGDATA */,
96
- error:
97
- "The error object being handle for the logging." /* $COMMENT#JSDOC#PARAMS#ERROR */,
98
- options:
99
- "The additional options as follows:" /* $COMMENT#JSDOC#PARAMS#OPTIONS */,
100
- settings:
101
- "The required settings as follows:" /* $COMMENT#JSDOC#PARAMS#SETTINGS */,
102
- configPathIgnores:
103
- '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 */,
104
- originalFlattenedConfigData:
105
- "The original flattened config data, before changes to aliases variables and composed variables are applied." /* $COMMENT#JSDOC#PARAMS#ORIGINALFLATTENEDCONFIGDATA */,
106
- relativeMjsPath:
107
- 'The relative path of the generated `.mjs` file to be ignored in the "placeholders" process.' /* $COMMENT#JSDOC#PARAMS#RELATIVEMJSPATH */,
108
- }),
109
- returns: Object.freeze({
110
- exitDueToFailure:
111
- "Never. (Somehow typing needs to be explicit for unreachable code inference.)" /* $COMMENT#JSDOC#RETURNS#EXITDUETOFAILURE */,
112
- makeRuleResolve:
113
- "The resolve rule based on the flattened config data." /* $COMMENT#JSDOC#RETURNS#MAKERULERESOLVE */,
114
- makeRuleCompress:
115
- "The compress rule based on the reversed flattened config data." /* $COMMENT#JSDOC#RETURNS#MAKERULECOMPRESS */,
116
- }),
117
- constants: Object.freeze({
118
- sortedReversedFlattenedConfigData:
119
- "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 */,
120
- composedVariablesExclusivesSet:
121
- "A local Set out of composed variables exclusives for speed." /* $COMMENT#JSDOC#CONSTANTS#COMPOSEDVARIABLESEXCLUSIVESSET */,
122
- }),
123
- }),
124
- };
1
+ import {
2
+ coreData as data,
3
+ composedVariablesExclusives,
4
+ variations,
5
+ } from "./jscomments/core/data.js";
6
+ // import {
7
+ // variationsData as data,
8
+ // composedVariablesExclusives,
9
+ // variations,
10
+ // } from "./jscomments/variations/data.js";
125
11
 
126
12
  const ignores = ["README.md", "generate.template.js", "generate.example.js"];
127
13
 
128
14
  const lintConfigImports = false; // can be omitted
129
15
  const myIgnoresOnly = false; // can be omitted
130
16
 
131
- const composedVariablesExclusives = []; // can be omitted
132
-
133
17
  const config = {
134
18
  data,
135
19
  ignores,
136
20
  lintConfigImports,
137
21
  myIgnoresOnly,
138
22
  composedVariablesExclusives,
23
+ variations,
139
24
  };
140
25
 
141
26
  export default config;
@@ -114,6 +114,10 @@
114
114
  "relativeMjsPath": {
115
115
  "value": "The relative path of the generated `.mjs` file to be ignored in the \"placeholders\" process.",
116
116
  "key": "JSDOC#PARAMS#RELATIVEMJSPATH"
117
+ },
118
+ "variations": {
119
+ "value": "A boolean that determines the format of the generated placeholders according to whether or not the config is enabling variations.",
120
+ "key": "JSDOC#PARAMS#VARIATIONS"
117
121
  }
118
122
  },
119
123
  "returns": {
@@ -1,7 +1,7 @@
1
1
  // A JavaScript file that acts as an example file for the generated Comment Variables template config. Assuming you've yet to produce your own `comments.config.js` file, use the `comment-variables compress` and `comment-variables resolve` commands to see how the following comments go back and forth from Comment Variables placeholders (`$COMMENT`) to actual comments, reversibly.
2
2
 
3
3
  // This is a comment.
4
- // $COMMENT#ALIAS
4
+ // $COMMENT#ALIAS // ALIAS
5
5
  // Yes.
6
6
  // This is a comment. Yes. This is a comment.
7
7
  // $COMMENT#COMMENTS#NO
@@ -0,0 +1,12 @@
1
+ import { forTesting } from "./for-testing.js";
2
+ import { forDeving } from "./for-deving.js";
3
+
4
+ export const coreData = Object.freeze({
5
+ ...forTesting,
6
+ ...forDeving,
7
+ });
8
+
9
+ export const composedVariablesExclusives = []; // can be omitted
10
+
11
+ // NEW from v2
12
+ export const variations = undefined; // can be omitted
@@ -0,0 +1,67 @@
1
+ export const forDeving = {
2
+ // for deving
3
+ jsDoc: Object.freeze({
4
+ definitions: Object.freeze({
5
+ exitDueToFailure:
6
+ "Terminates the whole process with a 'failure' code (`1`)." /* $COMMENT#JSDOC#DEFINITIONS#EXITDUETOFAILURE */,
7
+ makeRuleResolve:
8
+ "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 */,
9
+ makeRuleCompress:
10
+ "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 */,
11
+ coreCommentsFlow:
12
+ "The core flow at the heart of resolving and compressing comments." /* $COMMENT#JSDOC#DEFINITIONS#CORECOMMENTSFLOW */,
13
+ resolveCommentsFlow:
14
+ "The flow that resolves `$COMMENT` placeholders into actual comments." /* $COMMENT#JSDOC#DEFINITIONS#RESOLVECOMMENTSFLOW */,
15
+ compressCommentsFlow:
16
+ "The flow that compresses actual comments into `$COMMENT` placeholders." /* $COMMENT#JSDOC#DEFINITIONS#COMPRESSCOMMENTSFLOW */,
17
+ placeholdersCommentsFlow:
18
+ "The flow that creates `$COMMENT` placeholders right next to where they're defined." /* $COMMENT#JSDOC#DEFINITIONS#PLACEHOLDERSCOMMENTSFLOW */,
19
+ logError:
20
+ 'Logs an error to the console depending on its type. (`"error"` or `"warning"`.)' /* $COMMENT#JSDOC#DEFINITIONS#LOGERROR */,
21
+ }),
22
+ params: Object.freeze({
23
+ flattenedConfigData:
24
+ "The flattened config data, with `$COMMENT` placeholders as keys and actual comments as values." /* $COMMENT#JSDOC#PARAMS#FLATTENEDCONFIGDATA */,
25
+ reversedFlattenedConfigData:
26
+ "The reversed flattened config data, with actual comments as keys and `$COMMENT` placeholders as values." /* $COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA */,
27
+ composedVariablesExclusives:
28
+ "The array of comment variables keys (implying their aliases as well) exclusively used to craft composed variables, that should be ignored by both the `resolve` and the `compress` commands." /* $COMMENT#JSDOC#PARAMS#COMPOSEDVARIABLESEXCLUSIVES */,
29
+ aliases_flattenedKeys:
30
+ "The dictionary that connects aliases to their original flattened keys in case an encountered placeholder is actually an alias." /* $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS */,
31
+ ruleName:
32
+ 'The name of the rule currently used. (Either `"resolve"` or `"compress"`.)' /* $COMMENT#JSDOC#PARAMS#RULENAME */,
33
+ ignores:
34
+ "The array of paths and globs for the flow's ESLint instance to ignore." /* $COMMENT#JSDOC#PARAMS#IGNORES */,
35
+ eitherFlattenedConfigData:
36
+ "Either the flattened config data or the reversed flattened config data, since they share the same structure." /* $COMMENT#JSDOC#PARAMS#EITHERFLATTENEDCONFIGDATA */,
37
+ error:
38
+ "The error object being handle for the logging." /* $COMMENT#JSDOC#PARAMS#ERROR */,
39
+ options:
40
+ "The additional options as follows:" /* $COMMENT#JSDOC#PARAMS#OPTIONS */,
41
+ settings:
42
+ "The required settings as follows:" /* $COMMENT#JSDOC#PARAMS#SETTINGS */,
43
+ configPathIgnores:
44
+ '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 */,
45
+ originalFlattenedConfigData:
46
+ "The original flattened config data, before changes to aliases variables and composed variables are applied." /* $COMMENT#JSDOC#PARAMS#ORIGINALFLATTENEDCONFIGDATA */,
47
+ relativeMjsPath:
48
+ 'The relative path of the generated `.mjs` file to be ignored in the "placeholders" process.' /* $COMMENT#JSDOC#PARAMS#RELATIVEMJSPATH */,
49
+ variations:
50
+ "A boolean that determines the format of the generated placeholders according to whether or not the config is enabling variations." /* $COMMENT#JSDOC#PARAMS#VARIATIONS */,
51
+ }),
52
+ returns: Object.freeze({
53
+ exitDueToFailure:
54
+ "Never. (Somehow typing needs to be explicit for unreachable code inference.)" /* $COMMENT#JSDOC#RETURNS#EXITDUETOFAILURE */,
55
+ makeRuleResolve:
56
+ "The resolve rule based on the flattened config data." /* $COMMENT#JSDOC#RETURNS#MAKERULERESOLVE */,
57
+ makeRuleCompress:
58
+ "The compress rule based on the reversed flattened config data." /* $COMMENT#JSDOC#RETURNS#MAKERULECOMPRESS */,
59
+ }),
60
+ constants: Object.freeze({
61
+ sortedReversedFlattenedConfigData:
62
+ "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 */,
63
+ composedVariablesExclusivesSet:
64
+ "A local Set out of composed variables exclusives for speed." /* $COMMENT#JSDOC#CONSTANTS#COMPOSEDVARIABLESEXCLUSIVESSET */,
65
+ }),
66
+ }),
67
+ };
@@ -0,0 +1,61 @@
1
+ // const obj = { test: "Testing." }; // errors, object string values in config files are reserved for exports from the config.
2
+
3
+ export const forTesting = {
4
+ // for testing (I didn't do the full freeze on this one.)
5
+ levelOne: {
6
+ levelTwo: {
7
+ levelThree: "Level three." /* $COMMENT#LEVELONE#LEVELTWO#LEVELTHREE */, // New placeholder structure. Not as sexy, but first and foremost guaranteed to be functional appended right at the end of the value as a Block comment, and last but not least also guaranteed to not modify Value Locations in the process. So `comment-variables placeholders` it is, and this justifies enforcing strings only for values even outside of the use of the VS Code extension.
8
+ // levelThreeEscape:
9
+ // "Level three. \
10
+ // fdff\
11
+ // " /* $COMMENT#LEVELONE#LEVELTWO#LEVELTHREEESCAPE */, // NOW ERRORS AS INTENDED, unrecognizedValuesSet
12
+ stillLevelThree:
13
+ "LEVELONE#LEVELTWO#LEVELTHREE" /* $COMMENT#LEVELONE#LEVELTWO#STILLLEVELTHREE */, // now is an alias
14
+ otherLevelThree:
15
+ "LEVELONE#LEVELTWO#LEVELTHREE" /* $COMMENT#LEVELONE#LEVELTWO#OTHERLEVELTHREE */, // also an alias
16
+ composedVariable:
17
+ "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREE $COMMENT#LEVELONE#LEVELTWO#STILLLEVELTHREE" /* $COMMENT#LEVELONE#LEVELTWO#COMPOSEDVARIABLE */, // This is a composed variable. What's the beauty in this? It allows for each comment variable to be its own single source of truth that can be reused still within the Comment Variables ecosystem. All while preventing the use of Comment Variables placeholders as values in the config. AND as a matter of fact, it even works... with aliases.
18
+ composedVariableAlias:
19
+ "LEVELONE#LEVELTWO#COMPOSEDVARIABLE" /* $COMMENT#LEVELONE#LEVELTWO#COMPOSEDVARIABLEALIAS */, // The alias of a composed variable. SO just like composed variables can incorporate aliases, aliases can be aliases for composed variables.
20
+
21
+ // otherLevelThreeAlias:
22
+ // "LEVELONE#LEVELTWO#OTHERLEVELTHREE" /* $COMMENT#LEVELONE#LEVELTWO#LEVELTHREE */, // errors, can't be the alias of another alias
23
+
24
+ // composedOfAlias:
25
+ // "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREE $COMMENT#LEVELONE#LEVELTWO#ALIASOFCOMPOSED" /* $COMMENT#LEVELONE#LEVELTWO#COMPOSEDOFALIAS */, // 1/2 already errored // ERROR. A potential composed variable cannot be used as the comment variable of another composed variable.
26
+ // aliasOfComposed:
27
+ // "LEVELONE#LEVELTWO#COMPOSEDOFALIAS" /* $COMMENT#LEVELONE#LEVELTWO#ALIASOFCOMPOSED */, // 2/2 What if an alias variable was a segment to a composed variable made of itself? // ERROR. The alias "LEVELONE#LEVELTWO#ALIASOFCOMPOSED" links to composed variable "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREE $COMMENT#LEVELONE#LEVELTWO#ALIASOFCOMPOSED" that includes LEVELONE#LEVELTWO#ALIASOFCOMPOSED's placeholder as a segment.
28
+
29
+ // aliasInComposed:
30
+ // "$COMMENT#LEVELONE#LEVELTWO#LEVELTHREE $COMMENT#LEVELONE#LEVELTWO#ALIASINCOMPOSED", // What if a composed variable had its own value has one of its segments? Composed variables already cannot compose other composed variables. // errors, "ERROR. A potential composed variable cannot be used as the comment variable of another composed variable."
31
+ // wrongComposedVariable:
32
+ // "$COMMENT#LEVELONE#LEVELTWO#COMPOSEDVARIABLE $COMMENT#LEVELONE#LEVELTWO#STILLLEVELTHREE", // errors, can't make composed variables with composed variables
33
+ // wrongComposedVariableToo:
34
+ // "$COMMENT#LEVELONE#LEVELTWO#STILLLEVELTHREE $COMMENT#LEVELONE#LEVELTWO#COMPOSEDVARIABLE", // errors, can't make composed variables with composed variables even as aliases
35
+ // levelthree: "Also level three.", // errors, duplicate normalized key
36
+ // levelThree: "Also level three.", // errors, duplicate key with original overriden by legal JavaScript object value overrides
37
+ // alsoLevelThree: "Level three.", // errors, duplicate value
38
+ // tooLevelThree: 2, // errors, value is invalid
39
+ // $levelThree: "Dollar sign", // errors, key as "$" character
40
+ // "#levelThree": "Hashtag", // errors, key as "#" character
41
+ // ".levelThree": "Punctuation", // errors, key is invalid due to punctuation
42
+ // unrecognized: `Unrecognized value.`, // errors, is not a string literal
43
+ // emptyString: "", // errors, string is empty
44
+ // "": "emptyKey", // errors, key is empty caught by the regex
45
+ // ownAliasKey: "LEVELONE#LEVELTWO#OWNALIASKEY", // errors, is its own key/alias
46
+ // key: "key not allowed", // errors, "key", "value" and "placeholder" not allowed
47
+ // value: "value not allowed", // errors, "key", "value" and "placeholder" not allowed
48
+ // noConcat: "no" + "concat", // errors, unrecognized value
49
+ placeholder: "placeholder now allowed", // doesn't error, "placeholder" is now allowed
50
+
51
+ // already error via regex, but now enhanced:
52
+ // "//": "key comment error 1",
53
+ // "/*": "key comment error 2",
54
+ // "*/": "key comment error 3",
55
+ // error directly in resolveConfig:
56
+ // "key comment error 1": "//",
57
+ // "key comment error 2": "/*",
58
+ // "key comment error 3": "*/",
59
+ },
60
+ },
61
+ };
@@ -0,0 +1,4 @@
1
+ export const EN = "en";
2
+ export const ENGLISH = "English";
3
+ export const FR = "fr";
4
+ export const FRANÇAIS = "français";
@@ -0,0 +1,25 @@
1
+ import { EN, FR, ENGLISH, FRANÇAIS } from "./constants.js";
2
+ import { enTestData, frTestData } from "./test-data.js";
3
+
4
+ export const variationsData = Object.freeze({
5
+ [EN]: Object.freeze(enTestData),
6
+ [FR]: Object.freeze(frTestData),
7
+ });
8
+
9
+ export const composedVariablesExclusives = ["FORCOMPOSED3"]; // can be omitted
10
+
11
+ // const HELLO = "Hello.";
12
+
13
+ export const variations = {
14
+ variants: {
15
+ [EN]: { label: ENGLISH }, // `English`
16
+ [FR]: { label: FRANÇAIS }, // `français`
17
+ },
18
+ variant: FR,
19
+
20
+ referenceData: enTestData,
21
+ // referenceData: { hello: HELLO }, // correctly errors (reference only) (with OG enTestData)
22
+ // referenceData: { ...enTestData }, // correctly errors (reference only) (with OG enTestData)
23
+ // also
24
+ referenceVariant: EN,
25
+ };
@@ -0,0 +1,40 @@
1
+ // export const enTestData = { hello: "Hello." };
2
+ // export const enTestData = { hello: "Hello.", goodbye: "Goodbye." }; // goodbye is missing (with OG frTestData)
3
+ export const enTestData = Object.freeze({
4
+ hello: "Hello." /* variations: $COMMENT#HELLO / core: $COMMENT#EN#HELLO */,
5
+ goodbye:
6
+ "Goodbye." /* variations: $COMMENT#GOODBYE / core: $COMMENT#EN#GOODBYE */,
7
+ helloAlias:
8
+ "EN#HELLO" /* variations: $COMMENT#HELLOALIAS / core: $COMMENT#EN#HELLOALIAS */,
9
+ forComposed1:
10
+ "Hello" /* variations: $COMMENT#FORCOMPOSED1 / core: $COMMENT#EN#FORCOMPOSED1 */,
11
+ forComposed2:
12
+ "goodbye." /* variations: $COMMENT#FORCOMPOSED2 / core: $COMMENT#EN#FORCOMPOSED2 */,
13
+ composed:
14
+ "$COMMENT#EN#FORCOMPOSED1 $COMMENT#EN#FORCOMPOSED2" /* variations: $COMMENT#COMPOSED / core: $COMMENT#EN#COMPOSED */,
15
+ composedWithAlias:
16
+ "$COMMENT#EN#FORCOMPOSED1 $COMMENT#EN#FORCOMPOSED2 $COMMENT#EN#HELLOALIAS" /* variations: $COMMENT#COMPOSEDWITHALIAS / core: $COMMENT#EN#COMPOSEDWITHALIAS */,
17
+ // fr: "something", // now errors, can't have a variant as top-level key of a variation
18
+ });
19
+
20
+ // export const frTestData = { hello: "Bonjour." };
21
+ // export const frTestData = { hello: "Bonjour.", goodbye: "Au revoir." }; // goodbye is outstanding (with OG enTestData)
22
+ // export const frTestData = {}; // variations are allowed to be empty, at the very least they should begin by being represented by an empty object, to be completed step-by-step with error handling by turning errorOnMissingVariationKey true
23
+ export const frTestData = Object.freeze({
24
+ hello: "Bonjour." /* variations: $COMMENT#HELLO / core: $COMMENT#FR#HELLO */,
25
+ goodbye:
26
+ "Au revoir." /* variations: $COMMENT#GOODBYE / core: $COMMENT#FR#GOODBYE */,
27
+ helloAlias:
28
+ "FR#HELLO" /* variations: $COMMENT#HELLOALIAS / core: $COMMENT#FR#HELLOALIAS */,
29
+ forComposed1:
30
+ "Bonjour" /* variations: $COMMENT#FORCOMPOSED1 / core: $COMMENT#FR#FORCOMPOSED1 */,
31
+ forComposed2:
32
+ "au revoir." /* variations: $COMMENT#FORCOMPOSED2 / core: $COMMENT#FR#FORCOMPOSED2 */,
33
+ forComposed3:
34
+ "au revoir ?" /* variations: $COMMENT#FORCOMPOSED3 / core: $COMMENT#FR#FORCOMPOSED3 */,
35
+ composed:
36
+ "$COMMENT#FR#FORCOMPOSED1 $COMMENT#FR#FORCOMPOSED2" /* variations: $COMMENT#COMPOSED / core: $COMMENT#FR#COMPOSED */,
37
+ composedWithAlias:
38
+ "$COMMENT#FR#FORCOMPOSED1 $COMMENT#FR#FORCOMPOSED2 $COMMENT#FR#HELLOALIAS" /* variations: $COMMENT#COMPOSEDWITHALIAS / core: $COMMENT#FR#COMPOSEDWITHALIAS */,
39
+ // fr: "quelque chose", // now errors, can't have a variant as top-level key of a variation
40
+ });
@@ -0,0 +1,16 @@
1
+ /* TEST START
2
+ $COMMENT#HELLO
3
+ $COMMENT#GOODBYE
4
+ $COMMENT#HELLOALIAS // HELLOALIAS
5
+ $COMMENT#COMPOSED
6
+ $COMMENT#COMPOSEDWITHALIAS
7
+ // Now these should resolve on extension, while these below should not, when variations are specified.
8
+
9
+ $COMMENT#FORCOMPOSED3 // should/does not resolve as exclusive
10
+ $COMMENT#EN#HELLO // should/does not resolve on CLI
11
+ $COMMENT#FR#HELLO // should/does not resolve on extension
12
+ TEST END */
13
+
14
+ /** $COMMENT#COMPOSEDWITHALIAS */
15
+ const _testFunction = () => {};
16
+ // The TypeScript server plugin also needs to be adapted to variations. Done.
@@ -157,13 +157,15 @@ export const compressCommentsFlow = async (
157
157
  * @param {{[k: string]: string;}} originalFlattenedConfigData The original flattened config data, before changes to aliases variables and composed variables are applied.
158
158
  * @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.
159
159
  * @param {string} relativeMjsPath The relative path of the generated `.mjs` file to be ignored in the "placeholders" process.
160
+ * @param {boolean} variations A boolean that determines the format of the generated placeholders according to whether or not the config is enabling variations.
160
161
  * @returns
161
162
  */
162
163
  export const placeholdersCommentsFlow = async (
163
164
  configPathIgnores,
164
165
  originalFlattenedConfigData,
165
166
  aliases_flattenedKeys,
166
- relativeMjsPath
167
+ relativeMjsPath,
168
+ variations
167
169
  ) => {
168
170
  /** @type {Record<string, string>} */
169
171
  const composedValues_originalKeys = {};
@@ -188,6 +190,7 @@ export const placeholdersCommentsFlow = async (
188
190
  aliasValues_originalKeys,
189
191
  regularValuesOnly_originalKeys,
190
192
  aliases_flattenedKeys,
193
+ variations,
191
194
  };
192
195
  const makePlaceholdersAsObject = { makePlaceholders };
193
196
 
package/library/index.js CHANGED
@@ -119,19 +119,37 @@ if (!resolveConfigResults.success) {
119
119
  console.log("Config resolved.");
120
120
 
121
121
  const {
122
- config,
123
- originalFlattenedConfigData,
124
- flattenedConfigData,
125
- reversedFlattenedConfigData,
126
- aliases_flattenedKeys,
127
122
  configPath,
128
123
  passedIgnores,
124
+ config,
125
+ configDataResultsData,
129
126
  rawConfigAndImportPaths,
130
127
  lintConfigImports,
131
128
  myIgnoresOnly,
132
129
  composedVariablesExclusives,
130
+ resolvedCoreData,
133
131
  } = resolveConfigResults;
134
132
 
133
+ let {
134
+ // originalFlattenedConfigData, // currently unused as reassigned
135
+ flattenedConfigData,
136
+ reversedFlattenedConfigData,
137
+ aliases_flattenedKeys,
138
+ } = resolvedCoreData;
139
+
140
+ // Completely reassigns these four keys from resolvedCoreData to resolvedVariationData for the CLI.
141
+
142
+ if (resolveConfigResults.variations) {
143
+ const resolvedVariationData = resolveConfigResults.resolvedVariationData;
144
+ // Reassignments to the variation data. From then on, using data from resolvedCoreData requires using the resolvedCoreData object itself.
145
+ // originalFlattenedConfigData =
146
+ // resolvedVariationData.originalFlattenedConfigData;
147
+ flattenedConfigData = resolvedVariationData.flattenedConfigData;
148
+ reversedFlattenedConfigData =
149
+ resolvedVariationData.reversedFlattenedConfigData;
150
+ aliases_flattenedKeys = resolvedVariationData.aliases_flattenedKeys;
151
+ }
152
+
135
153
  skipDetails || console.log("Running with config:", config);
136
154
  skipDetails || console.log("Flattened config data is:", flattenedConfigData);
137
155
  skipDetails ||
@@ -144,7 +162,6 @@ skipDetails || console.log("Config path is:", configPath);
144
162
  skipDetails || console.log("Passed ignores are:", passedIgnores);
145
163
  skipDetails || console.log("lintConfigImports is:", lintConfigImports);
146
164
  skipDetails || console.log("myIgnoresOnly are:", myIgnoresOnly);
147
- // NEW
148
165
  skipDetails ||
149
166
  console.log(
150
167
  "Composed variables exclusives are:",
@@ -182,21 +199,24 @@ skipDetails || console.log("Ignores are:", ignores);
182
199
 
183
200
  // AUTOMATICALLY GENERATES THE JSON OUTPUT OF YOUR RESOLVED CONFIG DATA.
184
201
 
185
- const makeResolvedConfigDataResults =
186
- makeResolvedConfigData(resolveConfigResults);
202
+ const makeResolvedConfigDataResults = makeResolvedConfigData(
203
+ configDataResultsData,
204
+ resolvedCoreData.flattenedConfigData,
205
+ resolvedCoreData.aliases_flattenedKeys
206
+ );
187
207
  if (!makeResolvedConfigDataResults.success) {
188
208
  makeResolvedConfigDataResults.errors.forEach((e) => logError(e));
189
209
  exitDueToFailure();
190
210
  }
191
211
 
192
- const resolvedConfigData = makeResolvedConfigDataResults.resolvedConfigData;
212
+ const { resolvedConfigData } = makeResolvedConfigDataResults;
193
213
 
194
214
  const jsonData = makeJsonData(resolvedConfigData);
195
215
  fs.writeFileSync(jsonPath, jsonData, "utf8");
196
216
 
197
217
  console.log(makeJsonPathLog(jsonPath));
198
218
 
199
- // NEW!! comments.config.mjs to directly access resolvedConfigData.
219
+ // comments.config.mjs to directly access resolvedConfigData.
200
220
 
201
221
  const mjsData = makeMjsData(resolvedConfigData);
202
222
  fs.writeFileSync(mjsPath, mjsData, "utf8");
@@ -223,13 +243,15 @@ switch (coreCommand) {
223
243
  composedVariablesExclusives
224
244
  );
225
245
  break;
246
+ // I'm noticing I'm not even using valueLocations to create placeholders. Which is in fact more reliable because I'm appending the placeholders specifically to the object string values that I find instead of doing so from locations.
226
247
  case placeholdersRuleName:
227
248
  console.log(`Running ${placeholdersRuleName}...`);
228
249
  await placeholdersCommentsFlow(
229
250
  configPathIgnores,
230
- originalFlattenedConfigData,
231
- aliases_flattenedKeys,
232
- path.relative(cwd, mjsPath)
251
+ resolvedCoreData.originalFlattenedConfigData,
252
+ resolvedCoreData.aliases_flattenedKeys,
253
+ path.relative(cwd, mjsPath),
254
+ resolveConfigResults.variations
233
255
  );
234
256
  break;
235
257
  default:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comment-variables",
3
- "version": "1.2.5",
3
+ "version": "1.3.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",
@@ -13,7 +13,8 @@
13
13
  "comments.config.js",
14
14
  "comments.config.json",
15
15
  "generate.template.js",
16
- "generate.example.js"
16
+ "generate.example.js",
17
+ "jscomments"
17
18
  ],
18
19
  "repository": {
19
20
  "type": "git",
@@ -30,7 +31,7 @@
30
31
  "type": "module",
31
32
  "dependencies": {
32
33
  "@eslint/markdown": "^6.5.0",
33
- "comment-variables-resolve-config": "^1.14.9",
34
+ "comment-variables-resolve-config": "^1.16.1",
34
35
  "eslint": "^9.29.0"
35
36
  },
36
37
  "devDependencies": {