comment-variables 1.4.1 → 1.5.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 +25 -3
- package/comments.config.js +7 -7
- package/comments.config.json +61 -139
- package/generate.example.js +0 -1
- package/generate.template.js +3 -0
- package/generate.variations.js +93 -0
- package/library/_commons/constants/bases.js +4 -0
- package/library/_commons/rules/compress.js +6 -6
- package/library/_commons/rules/resolve.js +6 -6
- package/library/_commons/utilities/flows.js +21 -21
- package/library/_commons/utilities/helpers.js +4 -4
- package/library/index.js +78 -8
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -26,7 +26,11 @@ npm install -g comment-variables
|
|
|
26
26
|
comment-variables
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
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.
|
|
29
|
+
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.
|
|
30
|
+
|
|
31
|
+
Additionally creates a resolved version of your config data as a JSON file, and as a .mjs file exporting both the typedef `ResolvedConfigData` and the object `resolvedConfigData`.
|
|
32
|
+
|
|
33
|
+
If no configuration file is found, a **tutorial mode** is triggered, generating a template config file for you.
|
|
30
34
|
|
|
31
35
|
```
|
|
32
36
|
comment-variables placeholders
|
|
@@ -105,9 +109,27 @@ composedVariablesExclusives:
|
|
|
105
109
|
|
|
106
110
|
In due time, you may end up creating Comment Variables that are exclusively meant to be used to create other Comment Variables – the latter classified as composed variables. Passing an array to this config option, comprised of the keys of these original comment variables (for example, if a Comment Variable placeholder is `$COMMENT#COMMENT` its related key is `COMMENT`), prevents these original comment variables from being affected by the `compress` and `resolve` commands.
|
|
107
111
|
|
|
108
|
-
|
|
112
|
+
**`comment-variables` v2 introduces the concept of variations:**
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
variations:
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Variations provide native support for internationalization to the Comment Variables ecosystem. In fact, since variations aren't limited to languages, they can be applied to any solution of your own based on variants.
|
|
119
|
+
|
|
120
|
+
The `variations` key as an option takes as value an object with the following properties:
|
|
121
|
+
|
|
122
|
+
- `variations.variants`: Defines all variants that have matching variations duly defined within the top-level keys of `data`.
|
|
123
|
+
- `variations.variant`: Defines the current variant that Comment Variables currently resolves to.
|
|
124
|
+
- `variations.referenceData`: 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]`.
|
|
125
|
+
- `variations.referenceVariant`: Defines the variant of the reference variation.
|
|
126
|
+
- `variations.allowIncompleteVariations`: 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.
|
|
127
|
+
|
|
128
|
+
When triggering **tutorial mode**, please select `with variations` for a thorough and actionable example.
|
|
129
|
+
|
|
130
|
+
## `comments.config.js`
|
|
109
131
|
|
|
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.)
|
|
132
|
+
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
133
|
|
|
112
134
|
```js
|
|
113
135
|
const data = {
|
package/comments.config.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
coreData as data,
|
|
3
|
-
composedVariablesExclusives,
|
|
4
|
-
variations,
|
|
5
|
-
} from "./jscomments/core/data.js";
|
|
6
1
|
// import {
|
|
7
|
-
//
|
|
2
|
+
// coreData as data,
|
|
8
3
|
// composedVariablesExclusives,
|
|
9
4
|
// variations,
|
|
10
|
-
// } from "./jscomments/
|
|
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
|
|
package/comments.config.json
CHANGED
|
@@ -1,148 +1,70 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
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
|
-
"
|
|
66
|
-
"
|
|
67
|
-
|
|
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
|
-
"
|
|
124
|
-
"
|
|
125
|
-
|
|
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
|
-
"
|
|
138
|
-
"
|
|
139
|
-
|
|
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
|
}
|
package/generate.example.js
CHANGED
package/generate.template.js
CHANGED
|
@@ -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.
|
|
@@ -5,18 +5,18 @@ import {
|
|
|
5
5
|
} from "comment-variables-resolve-config";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @param {{[key: string]: string}} reversedFlattenedConfigData
|
|
10
|
-
* @param {string[]} composedVariablesExclusives
|
|
11
|
-
* @returns
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
8
|
-
* @param {{[key: string]: string}} flattenedConfigData
|
|
9
|
-
* @param {string[]} composedVariablesExclusives
|
|
10
|
-
* @param {{[key: string]: string}} aliases_flattenedKeys
|
|
11
|
-
* @returns
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
25
|
-
* @param {typeof resolveRuleName | typeof compressRuleName} ruleName
|
|
26
|
-
* @param {string[]} ignores
|
|
27
|
-
* @param {{[key: string]: string}} flattenedConfigData
|
|
28
|
-
* @param {string[]} composedVariablesExclusives
|
|
29
|
-
* @param {Record<string, string> | undefined} aliases_flattenedKeys
|
|
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
|
-
*
|
|
111
|
-
* @param {string[]} ignores
|
|
112
|
-
* @param {Record<string, string>} flattenedConfigData
|
|
113
|
-
* @param {string[]} composedVariablesExclusives
|
|
114
|
-
* @param {Record<string, string>} aliases_flattenedKeys
|
|
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
|
-
*
|
|
135
|
-
* @param {string[]} ignores
|
|
136
|
-
* @param {{[key: string]: string}} reversedFlattenedConfigData
|
|
137
|
-
* @param {string[]} composedVariablesExclusives
|
|
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
|
-
*
|
|
156
|
-
* @param {string[]} configPathIgnores
|
|
157
|
-
* @param {{[k: string]: string;}} originalFlattenedConfigData
|
|
158
|
-
* @param {Record<string, string>} aliases_flattenedKeys
|
|
159
|
-
* @param {string} relativeMjsPath
|
|
160
|
-
* @param {boolean} 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
|
-
*
|
|
5
|
-
* @returns {never}
|
|
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
|
-
*
|
|
13
|
-
* @param {{type: "error" | "warning"; message: string}} error
|
|
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 {
|
|
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
|
-
|
|
84
|
-
|
|
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,
|
|
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.
|
|
3
|
+
"version": "1.5.1",
|
|
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"
|