comment-variables 1.5.0 → 1.5.2

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
@@ -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. (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`. If no configuration file is found, a tutorial mode is triggered, generating a template config file for you.)
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,7 +109,25 @@ 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
- ## **`comments.config.js`**
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
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
 
@@ -62,16 +62,16 @@ const composedVariablesExclusives = [
62
62
  /* variations */
63
63
 
64
64
  const variations = {
65
- // defines all variants that have matching variations duly defined within the top-level keys of `data`
65
+ // Defines all variants that have matching variations duly defined within the top-level keys of `data`.
66
66
  variants: {
67
67
  [EN]: { label: ENGLISH },
68
68
  [FR]: { label: FRANÇAIS },
69
69
  },
70
- // defines the current variant that Comment Variables currently resolves to
70
+ // Defines the current variant that Comment Variables currently resolves to.
71
71
  variant: FR,
72
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
73
  referenceData: enData,
74
- // defines the variant of the reference variation
74
+ // Defines the variant of the reference variation.
75
75
  referenceVariant: EN,
76
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
77
  allowIncompleteVariations: true,
@@ -29,4 +29,4 @@ export const allMDVirtualJSTSFileGlobs = [
29
29
 
30
30
  // prompts choices values
31
31
  export const classic = "classic";
32
- export const withVariations = "with variations";
32
+ export const advanced = "advanced";
package/library/index.js CHANGED
@@ -28,7 +28,7 @@ import {
28
28
  hasPackageJson,
29
29
  hasGitFolder,
30
30
  classic,
31
- withVariations,
31
+ advanced,
32
32
  } from "./_commons/constants/bases.js";
33
33
 
34
34
  import { exitDueToFailure, logError } from "./_commons/utilities/helpers.js";
@@ -96,11 +96,11 @@ if (!fs.existsSync(rawConfigPath)) {
96
96
  generateExampleFilePath: "../generate.example.js",
97
97
  };
98
98
 
99
- const classicOrWithVariations = await prompts({
99
+ const classicOrAdvanced = await prompts({
100
100
  type: "select",
101
101
  name: "value",
102
102
  message:
103
- "Would you like to generate a classic template (simple) or a template with variations (advanced) instead?",
103
+ "Would you like to generate a simple template (classic) or a template with variations (advanced) instead?",
104
104
  choices: [
105
105
  {
106
106
  title: classic,
@@ -109,39 +109,39 @@ if (!fs.existsSync(rawConfigPath)) {
109
109
  value: classic,
110
110
  },
111
111
  {
112
- title: withVariations,
112
+ title: advanced,
113
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,
114
+ "With variations. 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: advanced,
116
116
  },
117
117
  ],
118
118
  initial: 0,
119
119
  });
120
120
 
121
121
  /**
122
- * @type {typeof classic | typeof withVariations}
122
+ * @type {typeof classic | typeof advanced}
123
123
  * `control+C` returns `undefined`.
124
124
  */
125
- const classicOrWithVariationsValue = classicOrWithVariations.value;
125
+ const classicOrAdvancedValue = classicOrAdvanced.value;
126
126
 
127
- if (!classicOrWithVariationsValue) {
127
+ if (!classicOrAdvancedValue) {
128
128
  console.error(
129
129
  "ERROR. No template selected. Please select a template to begin using comment-variables via this CLI."
130
130
  );
131
131
  exitDueToFailure();
132
132
  }
133
133
 
134
- switch (classicOrWithVariationsValue) {
134
+ switch (classicOrAdvancedValue) {
135
135
  case classic:
136
136
  tutorialConfig.generateTemplateFilePath = "../generate.template.js";
137
137
  break;
138
- case withVariations:
138
+ case advanced:
139
139
  tutorialConfig.generateTemplateFilePath = "../generate.variations.js";
140
140
  break;
141
141
 
142
142
  default:
143
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.
144
+ "ERROR. No template selected. Please select a template to begin using comment-variables via this CLI. (Unreachable code.)" // copypasted same as classicOrAdvanced for now, since this is supposed to be unreachable code.
145
145
  );
146
146
  exitDueToFailure();
147
147
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comment-variables",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
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",