comment-variables 0.13.0 → 0.14.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/generate.example.js +7 -0
- package/generate.template.js +31 -0
- package/library/_commons/constants/bases.js +2 -3
- package/library/_commons/rules/compress.js +3 -3
- package/library/_commons/rules/resolve.js +4 -4
- package/library/_commons/utilities/flows.js +16 -16
- package/library/_commons/utilities/helpers.js +4 -4
- package/library/index.js +36 -2
- package/package.json +4 -4
- package/comments.example.js +0 -1
- package/comments.template.js +0 -1
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
|
|
3
|
+
// This is a comment.
|
|
4
|
+
// $COMMENT#ALIAS
|
|
5
|
+
// Yes.
|
|
6
|
+
// This is a comment. Yes. This is a comment.
|
|
7
|
+
// $COMMENT#COMMENTS#NO
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// A Comment Variables config template generated in case no config file has been found. Feel free to use it as a stepping stone to learn how to use Comment Variables.
|
|
2
|
+
|
|
3
|
+
// As a first step, go ahead and run the command `comment-variables placeholders`.
|
|
4
|
+
// Then rename the `$COMMENT#COMMENT` placeholder next to `alias` to `$COMMENT#ALIAS` and run `comment-variables placeholders` to see what happens.
|
|
5
|
+
// You can now use and explore Comment Variables on the accompanying `comments.example.js` file that has also been generated.
|
|
6
|
+
|
|
7
|
+
const data = Object.freeze({
|
|
8
|
+
comment: "This is a comment.",
|
|
9
|
+
alias: "COMMENT",
|
|
10
|
+
composed: "$COMMENT#COMMENT $COMMENT#COMMENTS#YES $COMMENT#ALIAS",
|
|
11
|
+
comments: Object.freeze({
|
|
12
|
+
yes: "Yes.",
|
|
13
|
+
no: "No.",
|
|
14
|
+
}),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const ignores = [];
|
|
18
|
+
|
|
19
|
+
const lintConfigImports = false; // can be ommitted
|
|
20
|
+
const myIgnoresOnly = false; // can be ommitted
|
|
21
|
+
|
|
22
|
+
const config = {
|
|
23
|
+
data,
|
|
24
|
+
ignores,
|
|
25
|
+
lintConfigImports,
|
|
26
|
+
myIgnoresOnly,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default config;
|
|
30
|
+
|
|
31
|
+
// Once you've grasped these concepts, simply copy or rename this file to `comments.config.js` and you're good to go.
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
|
|
4
|
+
import { cwd } from "comment-variables-resolve-config";
|
|
5
|
+
|
|
4
6
|
// rule names
|
|
5
7
|
export const resolveRuleName = "resolve";
|
|
6
8
|
export const compressRuleName = "compress";
|
|
7
9
|
export const placeholdersRuleName = "placeholders"; // rule?
|
|
8
10
|
|
|
9
|
-
// current working directory
|
|
10
|
-
export const cwd = process.cwd();
|
|
11
|
-
|
|
12
11
|
// to prevent accidental changes
|
|
13
12
|
export const hasPackageJson = fs.existsSync(path.join(cwd, "package.json"));
|
|
14
13
|
// to prevent irreversible changes
|
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
} from "comment-variables-resolve-config";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @param {{[key: string]: string}} reversedFlattenedConfigData
|
|
10
|
-
* @returns
|
|
8
|
+
* $COMMENT#JSDOC#DEFINITIONS#MAKERULECOMPRESS
|
|
9
|
+
* @param {{[key: string]: string}} reversedFlattenedConfigData $COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA
|
|
10
|
+
* @returns $COMMENT#JSDOC#RETURNS#MAKERULECOMPRESS
|
|
11
11
|
*/
|
|
12
12
|
const makeRule = (reversedFlattenedConfigData) => {
|
|
13
13
|
/** 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. */
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
} from "comment-variables-resolve-config";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @param {{[key: string]: string}} flattenedConfigData
|
|
9
|
-
* @param {{[key: string]: string}} aliases_flattenedKeys
|
|
10
|
-
* @returns
|
|
7
|
+
* $COMMENT#JSDOC#DEFINITIONS#MAKERULERESOLVE
|
|
8
|
+
* @param {{[key: string]: string}} flattenedConfigData $COMMENT#JSDOC#PARAMS#FLATTENEDCONFIGDATA
|
|
9
|
+
* @param {{[key: string]: string}} aliases_flattenedKeys $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS
|
|
10
|
+
* @returns $COMMENT#JSDOC#RETURNS#MAKERULERESOLVE
|
|
11
11
|
*/
|
|
12
12
|
const makeRule = (flattenedConfigData, aliases_flattenedKeys) => {
|
|
13
13
|
/** @type {import('@typescript-eslint/utils').TSESLint.RuleModule<typeof placeholderMessageId, []>} */
|
|
@@ -21,11 +21,11 @@ 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 {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 {Record<string, string> | undefined} aliases_flattenedKeys $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS
|
|
29
29
|
* @returns
|
|
30
30
|
*/
|
|
31
31
|
const coreCommentsFlow = async (
|
|
@@ -104,10 +104,10 @@ const coreCommentsFlow = async (
|
|
|
104
104
|
/* resolveCommentsFlow */
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
|
-
*
|
|
108
|
-
* @param {string[]} ignores
|
|
109
|
-
* @param {Record<string, string>} flattenedConfigData
|
|
110
|
-
* @param {Record<string, string>} aliases_flattenedKeys
|
|
107
|
+
* $COMMENT#JSDOC#DEFINITIONS#RESOLVECOMMENTSFLOW
|
|
108
|
+
* @param {string[]} ignores $COMMENT#JSDOC#PARAMS#IGNORES
|
|
109
|
+
* @param {Record<string, string>} flattenedConfigData $COMMENT#JSDOC#PARAMS#FLATTENEDCONFIGDATA
|
|
110
|
+
* @param {Record<string, string>} aliases_flattenedKeys $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS
|
|
111
111
|
* @returns
|
|
112
112
|
*/
|
|
113
113
|
export const resolveCommentsFlow = async (
|
|
@@ -125,9 +125,9 @@ export const resolveCommentsFlow = async (
|
|
|
125
125
|
/* compressCommentsFlow */
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
|
-
*
|
|
129
|
-
* @param {string[]} ignores
|
|
130
|
-
* @param {{[key: string]: string}} reversedFlattenedConfigData
|
|
128
|
+
* $COMMENT#JSDOC#DEFINITIONS#COMPRESSCOMMENTSFLOW
|
|
129
|
+
* @param {string[]} ignores $COMMENT#JSDOC#PARAMS#IGNORES
|
|
130
|
+
* @param {{[key: string]: string}} reversedFlattenedConfigData $COMMENT#JSDOC#PARAMS#REVERSEDFLATTENEDCONFIGDATA
|
|
131
131
|
* @returns
|
|
132
132
|
*/
|
|
133
133
|
export const compressCommentsFlow = async (
|
|
@@ -138,10 +138,10 @@ export const compressCommentsFlow = async (
|
|
|
138
138
|
/* placeholdersCommentsFlow */
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
|
-
*
|
|
142
|
-
* @param {string[]} configPathIgnores
|
|
143
|
-
* @param {{[k: string]: string;}} originalFlattenedConfigData
|
|
144
|
-
* @param {Record<string, string>} aliases_flattenedKeys
|
|
141
|
+
* $COMMENT#JSDOC#DEFINITIONS#PLACEHOLDERSCOMMENTSFLOW
|
|
142
|
+
* @param {string[]} configPathIgnores $COMMENT#JSDOC#PARAMS#CONFIGPATHIGNORES
|
|
143
|
+
* @param {{[k: string]: string;}} originalFlattenedConfigData $COMMENT#JSDOC#PARAMS#ORIGINALFLATTENEDCONFIGDATA
|
|
144
|
+
* @param {Record<string, string>} aliases_flattenedKeys $COMMENT#JSDOC#PARAMS#ALIASES_FLATTENEDKEYS
|
|
145
145
|
* @returns
|
|
146
146
|
*/
|
|
147
147
|
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
|
@@ -3,16 +3,19 @@
|
|
|
3
3
|
|
|
4
4
|
import path from "path";
|
|
5
5
|
import fs from "fs";
|
|
6
|
+
import url from "url";
|
|
6
7
|
|
|
7
8
|
import resolveConfig, {
|
|
8
9
|
defaultConfigFileName,
|
|
10
|
+
templateFileName,
|
|
11
|
+
exampleFileName,
|
|
9
12
|
configFlag,
|
|
13
|
+
cwd,
|
|
10
14
|
knownIgnores,
|
|
11
15
|
makeResolvedConfigData,
|
|
12
16
|
} from "comment-variables-resolve-config";
|
|
13
17
|
|
|
14
18
|
import {
|
|
15
|
-
cwd,
|
|
16
19
|
hasPackageJson,
|
|
17
20
|
hasGitFolder,
|
|
18
21
|
resolveRuleName,
|
|
@@ -67,7 +70,38 @@ const passedConfig = commands[configFlagIndex + 1];
|
|
|
67
70
|
const passedConfigPath =
|
|
68
71
|
hasConfigFlag && passedConfig ? path.join(cwd, passedConfig) : null;
|
|
69
72
|
// defaults to comments.config.js if no --config flag is set
|
|
70
|
-
|
|
73
|
+
let rawConfigPath = passedConfigPath ?? path.join(cwd, defaultConfigFileName);
|
|
74
|
+
|
|
75
|
+
if (!fs.existsSync(rawConfigPath)) {
|
|
76
|
+
console.log(
|
|
77
|
+
`No Comment Variables config file found at ${rawConfigPath}. Switching to tutorial mode.`
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const templateFilePath = path.join(cwd, templateFileName);
|
|
81
|
+
const exampleFilePath = path.join(cwd, exampleFileName);
|
|
82
|
+
const dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
83
|
+
|
|
84
|
+
if (fs.existsSync(templateFilePath)) {
|
|
85
|
+
console.log(`Proceeding with template file found at ${templateFilePath}.`);
|
|
86
|
+
} else {
|
|
87
|
+
const sourceTemplateFilePath = path.join(
|
|
88
|
+
dirname,
|
|
89
|
+
"../generate.template.js"
|
|
90
|
+
);
|
|
91
|
+
console.log(`Generating template file at ${templateFilePath}.`);
|
|
92
|
+
fs.copyFileSync(sourceTemplateFilePath, templateFilePath);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (fs.existsSync(exampleFilePath)) {
|
|
96
|
+
console.log(`Proceeding with example file found at ${exampleFilePath}.`);
|
|
97
|
+
} else {
|
|
98
|
+
const sourceExampleFilePath = path.join(dirname, "../generate.example.js");
|
|
99
|
+
console.log(`Generating example file at ${exampleFilePath}.`);
|
|
100
|
+
fs.copyFileSync(sourceExampleFilePath, exampleFilePath);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
rawConfigPath = templateFilePath;
|
|
104
|
+
}
|
|
71
105
|
|
|
72
106
|
console.log(`Resolving config at ${rawConfigPath}...`);
|
|
73
107
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comment-variables",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"description": "A CLI tool for configuring, managing and maintaining JavaScript comments as JavaScript variables.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"jscomments": "./library/index.js",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"library",
|
|
12
12
|
"comments.config.js",
|
|
13
13
|
"comments.config.json",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"generate.template.js",
|
|
15
|
+
"generate.example.js"
|
|
16
16
|
],
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"type": "module",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@eslint/markdown": "^6.5.0",
|
|
32
|
-
"comment-variables-resolve-config": "^1.12.
|
|
32
|
+
"comment-variables-resolve-config": "^1.12.3",
|
|
33
33
|
"eslint": "^9.29.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
package/comments.example.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// A JavaScript file that acts as an example file for the generated Comment Variables template config. Use the `comment-variables compress` and `comment-variables resolve` commands to see how the following comments go back and forth from Comment Variables placeholders to actual comments reversibly.
|
package/comments.template.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// A Comment Variables config template generated upon approval in case no config file has been found. Feel free to use it as a steping stone to learn how to use Comment Variables.
|