comment-variables 1.4.1 → 1.5.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
@@ -107,7 +107,7 @@ In due time, you may end up creating Comment Variables that are exclusively mean
107
107
 
108
108
  ## **`comments.config.js`**
109
109
 
110
- 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.)
110
+ A root `comments.config.js` file looks like this. (This is an earlier version of the config file I'm using to manage my JavaScript comments in this library.)
111
111
 
112
112
  ```js
113
113
  const data = {
@@ -1,13 +1,13 @@
1
- import {
2
- coreData as data,
3
- composedVariablesExclusives,
4
- variations,
5
- } from "./jscomments/core/data.js";
6
1
  // import {
7
- // variationsData as data,
2
+ // coreData as data,
8
3
  // composedVariablesExclusives,
9
4
  // variations,
10
- // } from "./jscomments/variations/data.js";
5
+ // } from "./jscomments/core/data.js";
6
+ import {
7
+ variationsData as data,
8
+ composedVariablesExclusives,
9
+ variations,
10
+ } from "./jscomments/variations/data.js";
11
11
 
12
12
  const ignores = ["README.md", "generate.template.js", "generate.example.js"];
13
13
 
@@ -1,148 +1,70 @@
1
1
  {
2
- "levelOne": {
3
- "levelTwo": {
4
- "levelThree": {
5
- "value": "Level three.",
6
- "key": "LEVELONE#LEVELTWO#LEVELTHREE"
7
- },
8
- "stillLevelThree": {
9
- "value": "Level three.",
10
- "key": "LEVELONE#LEVELTWO#STILLLEVELTHREE"
11
- },
12
- "otherLevelThree": {
13
- "value": "Level three.",
14
- "key": "LEVELONE#LEVELTWO#OTHERLEVELTHREE"
15
- },
16
- "composedVariable": {
17
- "value": "Level three. Level three.",
18
- "key": "LEVELONE#LEVELTWO#COMPOSEDVARIABLE"
19
- },
20
- "composedVariableAlias": {
21
- "value": "Level three. Level three.",
22
- "key": "LEVELONE#LEVELTWO#COMPOSEDVARIABLEALIAS"
23
- },
24
- "placeholder": {
25
- "value": "placeholder now allowed",
26
- "key": "LEVELONE#LEVELTWO#PLACEHOLDER"
27
- }
2
+ "en": {
3
+ "hello": {
4
+ "value": "Hello.",
5
+ "key": "EN#HELLO"
6
+ },
7
+ "goodbye": {
8
+ "value": "Goodbye.",
9
+ "key": "EN#GOODBYE"
10
+ },
11
+ "helloAlias": {
12
+ "value": "Hello.",
13
+ "key": "EN#HELLOALIAS"
14
+ },
15
+ "forComposed1": {
16
+ "value": "Hello",
17
+ "key": "EN#FORCOMPOSED1"
18
+ },
19
+ "forComposed2": {
20
+ "value": "goodbye.",
21
+ "key": "EN#FORCOMPOSED2"
22
+ },
23
+ "composed": {
24
+ "value": "Hello goodbye.",
25
+ "key": "EN#COMPOSED"
26
+ },
27
+ "composedWithAlias": {
28
+ "value": "Hello goodbye. Hello.",
29
+ "key": "EN#COMPOSEDWITHALIAS"
30
+ },
31
+ "_testFunction": {
32
+ "value": "A test function, with its JSDoc appropriately shifting between English and French.",
33
+ "key": "EN#_TESTFUNCTION"
28
34
  }
29
35
  },
30
- "jsDoc": {
31
- "definitions": {
32
- "exitDueToFailure": {
33
- "value": "Terminates the whole process with a 'failure' code (`1`).",
34
- "key": "JSDOC#DEFINITIONS#EXITDUETOFAILURE"
35
- },
36
- "makeRuleResolve": {
37
- "value": "The utility that creates the resolve rule based on the flattened config data, used to transform `$COMMENT` placeholders into actual comments.",
38
- "key": "JSDOC#DEFINITIONS#MAKERULERESOLVE"
39
- },
40
- "makeRuleCompress": {
41
- "value": "The utility that creates the compress rule based on the reversed flattened config data, used to transform actual comments into `$COMMENT` placeholders.",
42
- "key": "JSDOC#DEFINITIONS#MAKERULECOMPRESS"
43
- },
44
- "coreCommentsFlow": {
45
- "value": "The core flow at the heart of resolving and compressing comments.",
46
- "key": "JSDOC#DEFINITIONS#CORECOMMENTSFLOW"
47
- },
48
- "resolveCommentsFlow": {
49
- "value": "The flow that resolves `$COMMENT` placeholders into actual comments.",
50
- "key": "JSDOC#DEFINITIONS#RESOLVECOMMENTSFLOW"
51
- },
52
- "compressCommentsFlow": {
53
- "value": "The flow that compresses actual comments into `$COMMENT` placeholders.",
54
- "key": "JSDOC#DEFINITIONS#COMPRESSCOMMENTSFLOW"
55
- },
56
- "placeholdersCommentsFlow": {
57
- "value": "The flow that creates `$COMMENT` placeholders right next to where they're defined.",
58
- "key": "JSDOC#DEFINITIONS#PLACEHOLDERSCOMMENTSFLOW"
59
- },
60
- "logError": {
61
- "value": "Logs an error to the console depending on its type. (`\"error\"` or `\"warning\"`.)",
62
- "key": "JSDOC#DEFINITIONS#LOGERROR"
63
- }
36
+ "fr": {
37
+ "hello": {
38
+ "value": "Bonjour.",
39
+ "key": "FR#HELLO"
40
+ },
41
+ "goodbye": {
42
+ "value": "Au revoir.",
43
+ "key": "FR#GOODBYE"
44
+ },
45
+ "helloAlias": {
46
+ "value": "Bonjour.",
47
+ "key": "FR#HELLOALIAS"
48
+ },
49
+ "forComposed1": {
50
+ "value": "Bonjour",
51
+ "key": "FR#FORCOMPOSED1"
52
+ },
53
+ "forComposed2": {
54
+ "value": "au revoir.",
55
+ "key": "FR#FORCOMPOSED2"
64
56
  },
65
- "params": {
66
- "flattenedConfigData": {
67
- "value": "The flattened config data, with `$COMMENT` placeholders as keys and actual comments as values.",
68
- "key": "JSDOC#PARAMS#FLATTENEDCONFIGDATA"
69
- },
70
- "reversedFlattenedConfigData": {
71
- "value": "The reversed flattened config data, with actual comments as keys and `$COMMENT` placeholders as values.",
72
- "key": "JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA"
73
- },
74
- "composedVariablesExclusives": {
75
- "value": "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.",
76
- "key": "JSDOC#PARAMS#COMPOSEDVARIABLESEXCLUSIVES"
77
- },
78
- "aliases_flattenedKeys": {
79
- "value": "The dictionary that connects aliases to their original flattened keys in case an encountered placeholder is actually an alias.",
80
- "key": "JSDOC#PARAMS#ALIASES_FLATTENEDKEYS"
81
- },
82
- "ruleName": {
83
- "value": "The name of the rule currently used. (Either `\"resolve\"` or `\"compress\"`.)",
84
- "key": "JSDOC#PARAMS#RULENAME"
85
- },
86
- "ignores": {
87
- "value": "The array of paths and globs for the flow's ESLint instance to ignore.",
88
- "key": "JSDOC#PARAMS#IGNORES"
89
- },
90
- "eitherFlattenedConfigData": {
91
- "value": "Either the flattened config data or the reversed flattened config data, since they share the same structure.",
92
- "key": "JSDOC#PARAMS#EITHERFLATTENEDCONFIGDATA"
93
- },
94
- "error": {
95
- "value": "The error object being handle for the logging.",
96
- "key": "JSDOC#PARAMS#ERROR"
97
- },
98
- "options": {
99
- "value": "The additional options as follows:",
100
- "key": "JSDOC#PARAMS#OPTIONS"
101
- },
102
- "settings": {
103
- "value": "The required settings as follows:",
104
- "key": "JSDOC#PARAMS#SETTINGS"
105
- },
106
- "configPathIgnores": {
107
- "value": "The array of paths linked to the config file, (named \"ignores\" given it is ignored by the \"compress\" and \"resolve\" commands).",
108
- "key": "JSDOC#PARAMS#CONFIGPATHIGNORES"
109
- },
110
- "originalFlattenedConfigData": {
111
- "value": "The original flattened config data, before changes to aliases variables and composed variables are applied.",
112
- "key": "JSDOC#PARAMS#ORIGINALFLATTENEDCONFIGDATA"
113
- },
114
- "relativeMjsPath": {
115
- "value": "The relative path of the generated `.mjs` file to be ignored in the \"placeholders\" process.",
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"
121
- }
57
+ "forComposed3": {
58
+ "value": "au revoir ?",
59
+ "key": "FR#FORCOMPOSED3"
122
60
  },
123
- "returns": {
124
- "exitDueToFailure": {
125
- "value": "Never. (Somehow typing needs to be explicit for unreachable code inference.)",
126
- "key": "JSDOC#RETURNS#EXITDUETOFAILURE"
127
- },
128
- "makeRuleResolve": {
129
- "value": "The resolve rule based on the flattened config data.",
130
- "key": "JSDOC#RETURNS#MAKERULERESOLVE"
131
- },
132
- "makeRuleCompress": {
133
- "value": "The compress rule based on the reversed flattened config data.",
134
- "key": "JSDOC#RETURNS#MAKERULECOMPRESS"
135
- }
61
+ "composed": {
62
+ "value": "Bonjour au revoir.",
63
+ "key": "FR#COMPOSED"
136
64
  },
137
- "constants": {
138
- "sortedReversedFlattenedConfigData": {
139
- "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.",
140
- "key": "JSDOC#CONSTANTS#SORTEDREVERSEDFLATTENEDCONFIGDATA"
141
- },
142
- "composedVariablesExclusivesSet": {
143
- "value": "A local Set out of composed variables exclusives for speed.",
144
- "key": "JSDOC#CONSTANTS#COMPOSEDVARIABLESEXCLUSIVESSET"
145
- }
65
+ "composedWithAlias": {
66
+ "value": "Bonjour au revoir. Bonjour.",
67
+ "key": "FR#COMPOSEDWITHALIAS"
146
68
  }
147
69
  }
148
70
  }
@@ -2,6 +2,5 @@
2
2
 
3
3
  // This is a comment.
4
4
  // $COMMENT#ALIAS // ALIAS
5
- // Yes.
6
5
  // This is a comment. Yes. This is a comment.
7
6
  // $COMMENT#COMMENTS#NO
@@ -22,12 +22,15 @@ const myIgnoresOnly = false; // can be omitted
22
22
 
23
23
  const composedVariablesExclusives = []; // can be omitted
24
24
 
25
+ const variations = undefined; // can be omitted
26
+
25
27
  const config = {
26
28
  data,
27
29
  ignores,
28
30
  lintConfigImports,
29
31
  myIgnoresOnly,
30
32
  composedVariablesExclusives,
33
+ variations,
31
34
  };
32
35
 
33
36
  export default config;
@@ -0,0 +1,93 @@
1
+ // The Comment Variables config template generated in case no config file has been found.
2
+
3
+ // Just flip the `variations` object's `variant` key back and forth between `EN` and `FR` and see what happens on the accompanying `comments.example.js` file that has also been generated.
4
+
5
+ /* variants */
6
+
7
+ const EN = "en";
8
+ const ENGLISH = "English";
9
+ const FR = "fr";
10
+ const FRANÇAIS = "français";
11
+
12
+ /* data */
13
+
14
+ const enData = Object.freeze({
15
+ comment: "This is a comment.",
16
+ alias: "EN#COMMENT",
17
+ composed: "$COMMENT#EN#COMMENT $COMMENT#EN#COMMENTS#YES $COMMENT#EN#ALIAS",
18
+ comments: Object.freeze({
19
+ yes: "Yes.",
20
+ no: "No.",
21
+ }),
22
+ });
23
+
24
+ const frData = Object.freeze({
25
+ comment: "Ceci est un commentaire.",
26
+ alias: "FR#COMMENT",
27
+ composed: "$COMMENT#FR#COMMENT $COMMENT#FR#COMMENTS#YES $COMMENT#FR#ALIAS",
28
+ comments: Object.freeze({
29
+ yes: "Oui.",
30
+ no: "Non.",
31
+ }),
32
+ });
33
+
34
+ const data = Object.freeze({
35
+ [EN]: enData,
36
+ [FR]: frData,
37
+ });
38
+
39
+ /* ignores */
40
+
41
+ const ignores = [];
42
+
43
+ /* lintConfigImports */
44
+
45
+ const lintConfigImports = false; // can be omitted
46
+
47
+ /* myIgnoresOnly */
48
+
49
+ const myIgnoresOnly = false; // can be omitted
50
+
51
+ /* composedVariablesExclusives */
52
+
53
+ const enComposedVariablesExclusives = ["EN#COMMENTS#YES"];
54
+
55
+ const frComposedVariablesExclusives = ["FR#COMMENTS#YES"];
56
+
57
+ const composedVariablesExclusives = [
58
+ ...enComposedVariablesExclusives,
59
+ ...frComposedVariablesExclusives,
60
+ ]; // can be omitted
61
+
62
+ /* variations */
63
+
64
+ const variations = {
65
+ // defines all variants that have matching variations duly defined within the top-level keys of `data`
66
+ variants: {
67
+ [EN]: { label: ENGLISH },
68
+ [FR]: { label: FRANÇAIS },
69
+ },
70
+ // defines the current variant that Comment Variables currently resolves to
71
+ variant: FR,
72
+ // Defines the reference variation that all other variations need to have (or aim to have) matching keys with. Requires a JavaScript variable as it needs to be the exact same object as the one referenced at `data[variations.referenceVariant]`.
73
+ referenceData: enData,
74
+ // defines the variant of the reference variation
75
+ referenceVariant: EN,
76
+ // Defines the behavior of the error handling in case of variations that do not match one-to-one with the reference variation. If `true`, allows incomplete variations data to remain. If `false`, errors and guides the fixing of missing variations data.
77
+ allowIncompleteVariations: true,
78
+ }; // can be omitted
79
+
80
+ const config = {
81
+ data,
82
+ ignores,
83
+ lintConfigImports,
84
+ myIgnoresOnly,
85
+ composedVariablesExclusives,
86
+ variations,
87
+ };
88
+
89
+ export default config;
90
+
91
+ // Once you've grasped these concepts, simply rename this file, its JSON counterpart and its `.mjs` counterpart to `comments.config.js`, `comments.config.json` and `comments.config.mjs` respectively and you're good to go. (If you're using the extension, make sure to run VS Code's "Developer: Reload Window" command for the extension to operate based on your new `comments.config.js` file.)
92
+
93
+ // When it comes to the VS Code extension, variations are only compatible with versions 2 and above.
@@ -26,3 +26,7 @@ export const allMDVirtualJSTSFileGlobs = [
26
26
  "**/*.md/*.cjs",
27
27
  "**/*.md/*.mjs",
28
28
  ];
29
+
30
+ // prompts choices values
31
+ export const classic = "classic";
32
+ export const withVariations = "with variations";
@@ -5,18 +5,18 @@ import {
5
5
  } from "comment-variables-resolve-config";
6
6
 
7
7
  /**
8
- * The utility that creates the compress rule based on the reversed flattened config data, used to transform actual comments into `$COMMENT` placeholders.
9
- * @param {{[key: string]: string}} reversedFlattenedConfigData The reversed flattened config data, with actual comments as keys and `$COMMENT` placeholders as values.
10
- * @param {string[]} composedVariablesExclusives 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.
11
- * @returns The compress rule based on the reversed flattened config data.
8
+ * $COMMENT#JSDOC#DEFINITIONS#MAKERULECOMPRESS
9
+ * @param {{[key: string]: string}} reversedFlattenedConfigData $COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA
10
+ * @param {string[]} composedVariablesExclusives $COMMENT#JSDOC#PARAMS#COMPOSEDVARIABLESEXCLUSIVES
11
+ * @returns $COMMENT#JSDOC#RETURNS#MAKERULECOMPRESS
12
12
  */
13
13
  const makeRule = (reversedFlattenedConfigData, composedVariablesExclusives) => {
14
- /** 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. */
14
+ /** $COMMENT#JSDOC#CONSTANTS#SORTEDREVERSEDFLATTENEDCONFIGDATA */
15
15
  const sortedReversedFlattenedConfigData = Object.entries(
16
16
  reversedFlattenedConfigData
17
17
  ).sort(([a], [b]) => b.length - a.length);
18
18
 
19
- /** A local Set out of composed variables exclusives for speed. */
19
+ /** $COMMENT#JSDOC#CONSTANTS#COMPOSEDVARIABLESEXCLUSIVESSET */
20
20
  const composedVariablesExclusivesSet = new Set(composedVariablesExclusives);
21
21
 
22
22
  /** @type {import('@typescript-eslint/utils').TSESLint.RuleModule<typeof placeholderMessageId, []>} */
@@ -4,18 +4,18 @@ import {
4
4
  } from "comment-variables-resolve-config";
5
5
 
6
6
  /**
7
- * The utility that creates the resolve rule based on the flattened config data, used to transform `$COMMENT` placeholders into actual comments.
8
- * @param {{[key: string]: string}} flattenedConfigData The flattened config data, with `$COMMENT` placeholders as keys and actual comments as values.
9
- * @param {string[]} composedVariablesExclusives 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.
10
- * @param {{[key: string]: string}} aliases_flattenedKeys The dictionary that connects aliases to their original flattened keys in case an encountered placeholder is actually an alias.
11
- * @returns The resolve rule based on the flattened config data.
7
+ * $COMMENT#JSDOC#DEFINITIONS#MAKERULERESOLVE
8
+ * @param {{[key: string]: string}} flattenedConfigData $COMMENT#JSDOC#PARAMS#FLATTENEDCONFIGDATA
9
+ * @param {string[]} composedVariablesExclusives $COMMENT#JSDOC#PARAMS#COMPOSEDVARIABLESEXCLUSIVES
10
+ * @param {{[key: string]: string}} aliases_flattenedKeys $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS
11
+ * @returns $COMMENT#JSDOC#RETURNS#MAKERULERESOLVE
12
12
  */
13
13
  const makeRule = (
14
14
  flattenedConfigData,
15
15
  composedVariablesExclusives,
16
16
  aliases_flattenedKeys
17
17
  ) => {
18
- /** A local Set out of composed variables exclusives for speed. */
18
+ /** $COMMENT#JSDOC#CONSTANTS#COMPOSEDVARIABLESEXCLUSIVESSET */
19
19
  const composedVariablesExclusivesSet = new Set(composedVariablesExclusives);
20
20
 
21
21
  /** @type {import('@typescript-eslint/utils').TSESLint.RuleModule<typeof placeholderMessageId, []>} */
@@ -21,12 +21,12 @@ import { ruleNames_makeRules } from "../constants/rules.js";
21
21
  /* coreCommentsFlow */
22
22
 
23
23
  /**
24
- * The core flow at the heart of resolving and compressing comments.
25
- * @param {typeof resolveRuleName | typeof compressRuleName} ruleName The name of the rule currently used. (Either `"resolve"` or `"compress"`.)
26
- * @param {string[]} ignores The array of paths and globs for the flow's ESLint instance to ignore.
27
- * @param {{[key: string]: string}} flattenedConfigData Either the flattened config data or the reversed flattened config data, since they share the same structure.
28
- * @param {string[]} composedVariablesExclusives 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.
29
- * @param {Record<string, string> | undefined} aliases_flattenedKeys The dictionary that connects aliases to their original flattened keys in case an encountered placeholder is actually an alias.
24
+ * $COMMENT#JSDOC#DEFINITIONS#CORECOMMENTSFLOW
25
+ * @param {typeof resolveRuleName | typeof compressRuleName} ruleName $COMMENT#JSDOC#PARAMS#RULENAME
26
+ * @param {string[]} ignores $COMMENT#JSDOC#PARAMS#IGNORES
27
+ * @param {{[key: string]: string}} flattenedConfigData $COMMENT#JSDOC#PARAMS#EITHERFLATTENEDCONFIGDATA
28
+ * @param {string[]} composedVariablesExclusives $COMMENT#JSDOC#PARAMS#COMPOSEDVARIABLESEXCLUSIVES
29
+ * @param {Record<string, string> | undefined} aliases_flattenedKeys $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS
30
30
  * @returns
31
31
  */
32
32
  const coreCommentsFlow = async (
@@ -107,11 +107,11 @@ const coreCommentsFlow = async (
107
107
  /* resolveCommentsFlow */
108
108
 
109
109
  /**
110
- * The flow that resolves `$COMMENT` placeholders into actual comments.
111
- * @param {string[]} ignores The array of paths and globs for the flow's ESLint instance to ignore.
112
- * @param {Record<string, string>} flattenedConfigData The flattened config data, with `$COMMENT` placeholders as keys and actual comments as values.
113
- * @param {string[]} composedVariablesExclusives 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.
114
- * @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.
110
+ * $COMMENT#JSDOC#DEFINITIONS#RESOLVECOMMENTSFLOW
111
+ * @param {string[]} ignores $COMMENT#JSDOC#PARAMS#IGNORES
112
+ * @param {Record<string, string>} flattenedConfigData $COMMENT#JSDOC#PARAMS#FLATTENEDCONFIGDATA
113
+ * @param {string[]} composedVariablesExclusives $COMMENT#JSDOC#PARAMS#COMPOSEDVARIABLESEXCLUSIVES
114
+ * @param {Record<string, string>} aliases_flattenedKeys $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS
115
115
  * @returns
116
116
  */
117
117
  export const resolveCommentsFlow = async (
@@ -131,10 +131,10 @@ export const resolveCommentsFlow = async (
131
131
  /* compressCommentsFlow */
132
132
 
133
133
  /**
134
- * The flow that compresses actual comments into `$COMMENT` placeholders.
135
- * @param {string[]} ignores The array of paths and globs for the flow's ESLint instance to ignore.
136
- * @param {{[key: string]: string}} reversedFlattenedConfigData The reversed flattened config data, with actual comments as keys and `$COMMENT` placeholders as values.
137
- * @param {string[]} composedVariablesExclusives 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.
134
+ * $COMMENT#JSDOC#DEFINITIONS#COMPRESSCOMMENTSFLOW
135
+ * @param {string[]} ignores $COMMENT#JSDOC#PARAMS#IGNORES
136
+ * @param {{[key: string]: string}} reversedFlattenedConfigData $COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA
137
+ * @param {string[]} composedVariablesExclusives $COMMENT#JSDOC#PARAMS#COMPOSEDVARIABLESEXCLUSIVES
138
138
  * @returns
139
139
  */
140
140
  export const compressCommentsFlow = async (
@@ -152,12 +152,12 @@ export const compressCommentsFlow = async (
152
152
  /* placeholdersCommentsFlow */
153
153
 
154
154
  /**
155
- * The flow that creates `$COMMENT` placeholders right next to where they're defined.
156
- * @param {string[]} configPathIgnores The array of paths linked to the config file, (named "ignores" given it is ignored by the "compress" and "resolve" commands).
157
- * @param {{[k: string]: string;}} originalFlattenedConfigData The original flattened config data, before changes to aliases variables and composed variables are applied.
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
- * @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.
155
+ * $COMMENT#JSDOC#DEFINITIONS#PLACEHOLDERSCOMMENTSFLOW
156
+ * @param {string[]} configPathIgnores $COMMENT#JSDOC#PARAMS#CONFIGPATHIGNORES
157
+ * @param {{[k: string]: string;}} originalFlattenedConfigData $COMMENT#JSDOC#PARAMS#ORIGINALFLATTENEDCONFIGDATA
158
+ * @param {Record<string, string>} aliases_flattenedKeys $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS
159
+ * @param {string} relativeMjsPath $COMMENT#JSDOC#PARAMS#RELATIVEMJSPATH
160
+ * @param {boolean} variations $COMMENT#JSDOC#PARAMS#VARIATIONS
161
161
  * @returns
162
162
  */
163
163
  export const placeholdersCommentsFlow = async (
@@ -1,16 +1,16 @@
1
1
  /* exitDueToFailure */
2
2
 
3
3
  /**
4
- * Terminates the whole process with a 'failure' code (`1`).
5
- * @returns {never} Never. (Somehow typing needs to be explicit for unreachable code inference.)
4
+ * $COMMENT#JSDOC#DEFINITIONS#EXITDUETOFAILURE
5
+ * @returns {never} $COMMENT#JSDOC#RETURNS#EXITDUETOFAILURE
6
6
  */
7
7
  export const exitDueToFailure = () => process.exit(1);
8
8
 
9
9
  /* logError */
10
10
 
11
11
  /**
12
- * Logs an error to the console depending on its type. (`"error"` or `"warning"`.)
13
- * @param {{type: "error" | "warning"; message: string}} error The error object being handle for the logging.
12
+ * $COMMENT#JSDOC#DEFINITIONS#LOGERROR
13
+ * @param {{type: "error" | "warning"; message: string}} error $COMMENT#JSDOC#PARAMS#ERROR
14
14
  * @returns
15
15
  */
16
16
  export const logError = (error) => {
package/library/index.js CHANGED
@@ -5,6 +5,8 @@ import path from "path";
5
5
  import fs from "fs";
6
6
  import url from "url";
7
7
 
8
+ import prompts from "prompts";
9
+
8
10
  import resolveConfig, {
9
11
  defaultConfigFileName,
10
12
  templateFileName,
@@ -22,7 +24,12 @@ import resolveConfig, {
22
24
  makeMjsPathLog,
23
25
  } from "comment-variables-resolve-config";
24
26
 
25
- import { hasPackageJson, hasGitFolder } from "./_commons/constants/bases.js";
27
+ import {
28
+ hasPackageJson,
29
+ hasGitFolder,
30
+ classic,
31
+ withVariations,
32
+ } from "./_commons/constants/bases.js";
26
33
 
27
34
  import { exitDueToFailure, logError } from "./_commons/utilities/helpers.js";
28
35
  import {
@@ -80,17 +87,80 @@ if (!fs.existsSync(rawConfigPath)) {
80
87
  `No Comment Variables config file found at ${rawConfigPath}. Switching to tutorial mode.`
81
88
  );
82
89
 
83
- const templateFilePath = path.join(cwd, templateFileName);
84
- const exampleFilePath = path.join(cwd, exampleFileName);
90
+ /* TEST START (success) */
91
+
92
+ const tutorialConfig = {
93
+ templateFilePath: path.join(cwd, templateFileName),
94
+ generateTemplateFilePath: "",
95
+ exampleFilePath: path.join(cwd, exampleFileName), // common to "classic" and "with variations", highlights compatibility
96
+ generateExampleFilePath: "../generate.example.js",
97
+ };
98
+
99
+ const classicOrWithVariations = await prompts({
100
+ type: "select",
101
+ name: "value",
102
+ message:
103
+ "Would you like to generate a classic template (simple) or a template with variations (advanced) instead?",
104
+ choices: [
105
+ {
106
+ title: classic,
107
+ description:
108
+ "Simple. For those who discover Comment Variables and have no immediate need for internationalization.",
109
+ value: classic,
110
+ },
111
+ {
112
+ title: withVariations,
113
+ description:
114
+ "Advanced. For those who know their way around Comment Variables and may want to use its native internationalization features or any configuration of their own that relies on variants.",
115
+ value: withVariations,
116
+ },
117
+ ],
118
+ initial: 0,
119
+ });
120
+
121
+ /**
122
+ * @type {typeof classic | typeof withVariations}
123
+ * `control+C` returns `undefined`.
124
+ */
125
+ const classicOrWithVariationsValue = classicOrWithVariations.value;
126
+
127
+ if (!classicOrWithVariationsValue) {
128
+ console.error(
129
+ "ERROR. No template selected. Please select a template to begin using comment-variables via this CLI."
130
+ );
131
+ exitDueToFailure();
132
+ }
133
+
134
+ switch (classicOrWithVariationsValue) {
135
+ case classic:
136
+ tutorialConfig.generateTemplateFilePath = "../generate.template.js";
137
+ break;
138
+ case withVariations:
139
+ tutorialConfig.generateTemplateFilePath = "../generate.variations.js";
140
+ break;
141
+
142
+ default:
143
+ console.error(
144
+ "ERROR. No template selected. Please select a template to begin using comment-variables via this CLI. (Unreachable code.)" // copypasted same as classicOrWithVariations for now, since this is supposed to be unreachable code.
145
+ );
146
+ exitDueToFailure();
147
+ }
148
+
149
+ const {
150
+ templateFilePath,
151
+ generateTemplateFilePath,
152
+ exampleFilePath,
153
+ generateExampleFilePath,
154
+ } = tutorialConfig;
155
+
156
+ /* TEST END */
157
+
85
158
  const dirname = path.dirname(url.fileURLToPath(import.meta.url));
86
159
 
87
160
  if (fs.existsSync(templateFilePath)) {
88
161
  console.log(`Proceeding with template file found at ${templateFilePath}.`);
89
162
  } else {
90
- const sourceTemplateFilePath = path.join(
91
- dirname,
92
- "../generate.template.js"
93
- );
163
+ const sourceTemplateFilePath = path.join(dirname, generateTemplateFilePath);
94
164
  console.log(`Generating template file at ${templateFilePath}.`);
95
165
  fs.copyFileSync(sourceTemplateFilePath, templateFilePath);
96
166
  }
@@ -98,7 +168,7 @@ if (!fs.existsSync(rawConfigPath)) {
98
168
  if (fs.existsSync(exampleFilePath)) {
99
169
  console.log(`Proceeding with example file found at ${exampleFilePath}.`);
100
170
  } else {
101
- const sourceExampleFilePath = path.join(dirname, "../generate.example.js");
171
+ const sourceExampleFilePath = path.join(dirname, generateExampleFilePath);
102
172
  console.log(`Generating example file at ${exampleFilePath}.`);
103
173
  fs.copyFileSync(sourceExampleFilePath, exampleFilePath);
104
174
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comment-variables",
3
- "version": "1.4.1",
3
+ "version": "1.5.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,6 +13,7 @@
13
13
  "comments.config.js",
14
14
  "comments.config.json",
15
15
  "generate.template.js",
16
+ "generate.variations.js",
16
17
  "generate.example.js",
17
18
  "jscomments"
18
19
  ],
@@ -32,7 +33,8 @@
32
33
  "dependencies": {
33
34
  "@eslint/markdown": "^6.5.0",
34
35
  "comment-variables-resolve-config": "^1.17.1",
35
- "eslint": "^9.29.0"
36
+ "eslint": "^9.29.0",
37
+ "prompts": "^2.4.2"
36
38
  },
37
39
  "devDependencies": {
38
40
  "@typescript-eslint/utils": "^8.34.0"