-
Notifications
You must be signed in to change notification settings - Fork 11
/
gen.js
231 lines (189 loc) · 8.19 KB
/
gen.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
var fs = require("fs");
var packageDescription = require("./package.json");
var packageProperties = packageDescription.contributes.configuration.properties;
var markdownText = "";
// Title
markdownText += "# " + packageDescription.displayName + "\n\n";
// Description
markdownText += packageDescription.description + "\n\n";
markdownText += '<img src="./images/screenshot.png" width="300">\n\n';
// Options
markdownText += "## Configuration Options\n\n";
var field = function (parameters) {
parameters.maximumLength = 0;
return parameters;
};
var fields = [
field({ title: "Option", name: "name", isCode: true }),
field({ title: "Default", name: "default", isCode: true }),
field({ title: "Description", name: "description" }),
field({ title: "Example", name: "dateTime_example" }),
];
fields.forEach(function (field) {
field.maximumLength = field.title.length;
});
var renderValue = function (value) {
if (value === void 0) {
return "";
} else if (value === null) {
return "null";
} else if (typeof value === "boolean") {
return value ? "true" : "false";
} else {
return value.toString();
}
};
var properties = Object.keys(packageProperties).map(function (key) {
var property = {};
fields.forEach(function (field, index) {
var rawProperty = packageProperties[key];
var value = renderValue(index === 0 ? key : rawProperty[field.name]);
if (field.isCode) {
value = "`" + value + "`";
}
var length = value.length;
if (length > field.maximumLength) {
field.maximumLength = length;
}
property[field.name] = value;
});
return property;
});
var pad = function (value, length, character) {
length -= value.length;
for (var i = 0; i < length; i++) {
value += character;
}
return value;
};
markdownText += "|";
fields.forEach(function (field) {
markdownText += pad(field.title, field.maximumLength, " ");
markdownText += "|";
});
markdownText += "\n";
markdownText += "|";
fields.forEach(function (field) {
markdownText += pad(
"",
Math.max(field.title.length, field.maximumLength),
"-"
);
markdownText += "|";
});
markdownText += "\n";
properties.forEach(function (property) {
markdownText += "|";
fields.forEach(function (field) {
markdownText += pad(property[field.name], field.maximumLength, " ");
markdownText += "|";
});
markdownText += "\n";
});
markdownText +=
"" +
`
### Example usage
\`\`\`javascript
// 28 Feb 18:47
"dateTime.showDayOfMonth": true,
"dateTime.showMonth": true
// 9:30 AM
"dateTime.use24HourClock": false,
"dateTime.showAMPM": true
\`\`\`
## Custom date & time format
Custom date & time formats can be specified using the following format:
| |Token |Output |
|--------------------------|-------|--------------------------------------|
|Month |\`M\` |1 2 ... 11 12 |
| |\`Mo\` |1st 2nd ... 11th 12th |
| |\`MM\` |01 02 ... 11 12 |
| |\`MMM\` |Jan Feb ... Nov Dec |
| |\`MMMM\` |January February ... November December|
|Quarter |\`Q\` |1 2 3 4 |
| |\`Qo\` |1st 2nd 3rd 4th |
|Day of Month |\`D\` |1 2 ... 30 31 |
| |\`Do\` |1st 2nd ... 30th 31st |
| |\`DD\` |01 02 ... 30 31 |
|Day of Year |\`DDD\` |1 2 ... 364 365 |
| |\`DDDo\` |1st 2nd ... 364th 365th |
| |\`DDDD\` |001 002 ... 364 365 |
|Day of Week |\`d\` |0 1 ... 5 6 |
| |\`do\` |0th 1st ... 5th 6th |
| |\`dd\` |Su Mo ... Fr Sa |
| |\`ddd\` |Sun Mon ... Fri Sat |
| |\`dddd\` |Sunday Monday ... Friday Saturday |
|Day of Week (Locale) |\`e\` |0 1 ... 5 6 |
| |\`eo\` |0th 1st ... 5th 6th |
|Day of Week (ISO) |\`E\` |1 2 ... 6 7 |
| |\`Eo\` |1st 2nd ... 6th 7th |
|Week of Year |\`w\` |1 2 ... 52 53 |
| |\`wo\` |1st 2nd ... 52nd 53rd |
| |\`ww\` |01 02 ... 52 53 |
|Week of Year (ISO) |\`W\` |1 2 ... 52 53 |
| |\`Wo\` |1st 2nd ... 52nd 53rd |
| |\`WW\` |01 02 ... 52 53 |
|Year |\`YY\` |70 71 ... 29 30 |
| |\`YYYY\` |1970 1971 ... 2029 2030 |
|Week Year |\`gg\` |70 71 ... 29 30 |
| |\`gggg\` |1970 1971 ... 2029 2030 |
|Week Year (ISO) |\`GG\` |70 71 ... 29 30 |
| |\`GGGG\` |1970 1971 ... 2029 2030 |
|AM/PM |\`A\` |AM PM |
| |\`a\` |am pm |
|Hour |\`H\` |0 1 ... 22 23 |
| |\`HH\` |00 01 ... 22 23 |
| |\`h\` |1 2 ... 11 12 |
| |\`hh\` |01 02 ... 11 12 |
|Minute |\`m\` |0 1 ... 58 59 |
| |\`mm\` |00 01 ... 58 59 |
|Second |\`s\` |0 1 ... 58 59 |
| |\`ss\` |00 01 ... 58 59 |
|Fractional Second |\`S\` |0 1 ... 8 9 |
| |\`SS\` |00 01 ... 98 99 |
| |\`SSS\` |000 001 ... 998 999 |
|Unix Timestamp |\`X\` |1360013296 |
|Unix Millisecond Timestamp|\`x\` |1360013296123 |
|Abbreviated Timezone |\`z\` |EST |
|Unabbreviated Timezone |\`zzz\` |Eastern Standard Time |
|Escape |\`[...]\`|Text between \`[\` and \`]\` is escaped |
### Example usage
\`\`\`javascript
// Friday, January the 1st, 2016
"dateTime.customFormat": "dddd, MMMM [the] Do, YYYY"
// 2016-01-01 10:12:03
"dateTime.customFormat": "YYYY-MM-DD HH:mm:ss"
\`\`\`
## Date & time locale
The locale can be one of:
- ${
packageDescription.contributes.configuration.properties["dateTime.locale"]
.enum = [],
fs
.readdirSync("./node_modules/dayjs/esm/locale")
.filter((fileName) => (
fileName.indexOf(".js") === fileName.length - 3 &&
fileName.indexOf("x-pseudo") === -1
))
.map((fileName) => {
const [name, abbr] = (
fs.readFileSync(
"./node_modules/dayjs/esm/locale/" + fileName, "utf8"
).split("\n")[0].replace("//", "")
).split("[").map(p => p.replace("]", "").trim());
packageDescription.contributes.configuration
.properties["dateTime.locale"].enum.push(abbr);
return abbr + " - *" + name + "*";
})
.join("\n- ")}
## Time Zones
The time zone can be one of:
- ${packageDescription.contributes.configuration.properties["dateTime.timeZone"]
.enum.join("\n- ")}
`;
fs.writeFileSync("./README.md", markdownText);
fs.writeFileSync(
"./package.json",
JSON.stringify(packageDescription, null, 4) + "\n"
);