-
Notifications
You must be signed in to change notification settings - Fork 0
/
optionDefinitions.js
166 lines (157 loc) · 6.06 KB
/
optionDefinitions.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import {readFile} from 'fs/promises';
import {dirname, join} from 'path';
import {fileURLToPath} from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const pkg = JSON.parse(await readFile(join(__dirname, '../package.json')));
// Todo: We really need a command-line-args-TO-typedef-jsdoc generator!
/* eslint-disable jsdoc/require-property -- See schema below */
/**
* @typedef {object} LicenseBadgerOptions
*/
/* eslint-enable jsdoc/require-property -- See schema below */
const getChalkTemplateSingleEscape = (s) => {
return s.replaceAll(/[{}\\]/gu, (ch) => {
return `\\u${ch.codePointAt().toString(16).padStart(4, '0')}`;
});
};
const getChalkTemplateEscape = (s) => {
return s.replaceAll(/[{}\\]/gu, (ch) => {
return `\\\\u${ch.codePointAt().toString(16).padStart(4, '0')}`;
});
};
const getBracketedChalkTemplateEscape = (s) => {
return '{' + getChalkTemplateEscape(s) + '}';
};
const optionDefinitions = [
{
name: 'outputPath', type: String, defaultOption: true, alias: 'o',
description: 'Path to which to save the file; defaults to ' +
'"license-badge.svg" in the current working directory',
typeLabel: '{underline outputPath}'
},
{
name: 'packagePath', type: String, alias: 'p',
description: 'Path to the `package.json` directory; defaults to the ' +
'current working directory',
typeLabel: '{underline packagePath}'
},
{
name: 'licenseInfoPath', type: String, alias: 'l',
description: 'Path of licenseInfo.json file relative to the current ' +
'working directory; defaults to "licenseInfo.json" of the current ' +
'working directory. Set to empty string to avoid checking (e.g., if ' +
'setting `production` only).',
typeLabel: '{underline licenseInfoPath}'
},
{
name: 'packageJson', type: Boolean, alias: 'j',
description: 'Whether to include `license` within the `package.json` ' +
'pointed to by `packagePath`) (possibly also using name and version); ' +
'defaults to `false`.'
},
{
name: 'corrections', type: Boolean, alias: 'c',
description: 'Whether to apply corrections of licensee.js. ' +
'Defaults to `false`.'
},
{
name: 'production', type: Boolean,
description: 'Whether to check production dependencies (in addition to ' +
'any whitelisted by `licenseInfoPath`). Defaults to `false`.'
},
{
name: 'allDevelopment', type: Boolean,
description: 'Whether to check all development dependencies. Overrides ' +
'`licenseInfoPath` as will not be limited to the packages whitelisted ' +
'by `bundledDependencies` in the JSON file at `licenseInfoPath`). ' +
'Defaults to `false`.'
},
{
name: 'filteredTypes', type: String, alias: 'f',
description: 'Comma-separated list of specific license types to display ' +
'and/or "nonempty"; defaults to no filter; can be any of ' +
'"publicDomain"|"permissive"|"weaklyProtective"|\n' +
'"protective"|"networkProtective"|"useProtective"|"modifyProtective"|\n' +
'"unlicensed"|"uncategorized"|"nonempty"',
typeLabel: '{underline value or list of values}'
},
{
name: 'textColor', type: String,
description: 'Color for "Licenses" subject. Follow by comma for ' +
'additional (e.g., to add a stroke color). Defaults to "navy".',
typeLabel: getBracketedChalkTemplateEscape(
'underline <typeName>=<color> (<color>: CSS-Color|Hex as: ' +
'ffffff|Hex stroke as s{ffffff})'
)
},
{
name: 'licenseTypeColor', type: String,
multiple: true,
description: 'Key-value set for mapping a license type name to color. ' +
'Reuse for different types. Follow by comma for additional (e.g., to ' +
'add a stroke color). See `src/index.js` for default colors of each ' +
'license type.',
typeLabel: getBracketedChalkTemplateEscape(
'underline <typeName>=<color> (<color>: CSS-Color|Hex as: ' +
'ffffff|Hex stroke as s{ffffff})'
)
},
{
name: 'textTemplate', type: String,
description: 'Template for text of license badge; defaults to: ' +
'"License"; passed `licenseCount`; remember to escape `$` with ' +
'backslash for CLI use',
typeLabel: '{underline textTemplate}'
},
{
name: 'licenseTemplate', type: String,
description: 'Template for listing individual licenses; defaults ' +
getChalkTemplateSingleEscape(
// eslint-disable-next-line no-template-curly-in-string -- User templates
'to: "\n${index}. ${license}"; passed `license` and `index` (1-based); '
) +
'remember to escape `$` with backslash for CLI use',
typeLabel: '{underline licenseTemplate}'
},
{
name: 'uncategorizedLicenseTemplate', type: String,
description: 'Template for listing individual uncategorized projects; ' +
getChalkTemplateSingleEscape(
// eslint-disable-next-line no-template-curly-in-string -- User templates
'defaults to: "${name} (${version})"; passed `license`, `name`, '
) +
'`custom` (license text after "SEE LICENSE IN "), and `version`; ' +
'remember to escape `$` with backslash for CLI use',
typeLabel: '{underline uncategorizedLicenseTemplate}'
},
{
name: 'licenseTypeTemplate', type: String,
description: 'Template for listing individual license types; defaults ' +
getChalkTemplateSingleEscape(
// eslint-disable-next-line no-template-curly-in-string -- User templates
'to: "${text}"; passed `text` and `licenseCount`; remember to escape '
) +
'`$` with backslash for CLI use',
typeLabel: '{underline licenseTypeTemplate}'
},
{
name: 'logging', type: String,
description: 'Logging level; defaults to "off".',
typeLabel: '{underline "verbose"|"off"}'
}
];
const cliSections = [
{
// Add italics: `{italic textToItalicize}`
content: pkg.description +
'\n\n{italic license-badger -p=packagePath ' +
'-l=licenseInfoPath [outputPath]}'
},
{
optionList: optionDefinitions
}
];
export {
getChalkTemplateSingleEscape, getBracketedChalkTemplateEscape,
optionDefinitions as definitions, cliSections as sections
};