color-name-list 11.24.1 → 11.24.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/CONTRIBUTING.md +1 -1
- package/package.json +4 -3
- package/scripts/build.js +43 -36
- package/scripts/sortSrc.js +16 -10
- package/tests/sorting.test.js +45 -0
package/CONTRIBUTING.md
CHANGED
|
@@ -41,7 +41,7 @@ interactions with the project.
|
|
|
41
41
|
- Write your commit messages in imperative form:
|
|
42
42
|
**feat(colors): Add fantastic new colors names.** rather then
|
|
43
43
|
feat(colors): Added new names.
|
|
44
|
-
- Make sure to run `npm run
|
|
44
|
+
- Make sure to run `npm run test` before committing. (No need to `npm ci` the
|
|
45
45
|
dependencies are only needed if you need to run the API)
|
|
46
46
|
|
|
47
47
|
### Attribution
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "color-name-list",
|
|
3
|
-
"version": "11.24.
|
|
3
|
+
"version": "11.24.2",
|
|
4
4
|
"description": "long list of color names",
|
|
5
5
|
"main": "dist/colornames.json",
|
|
6
6
|
"browser": "dist/colornames.umd.js",
|
|
@@ -24,9 +24,10 @@
|
|
|
24
24
|
"scripts": {
|
|
25
25
|
"commit": "git-cz",
|
|
26
26
|
"pull-colors": "curl -L 'https://docs.google.com/spreadsheets/d/e/2PACX-1vQube6Y0wHyEtJnjg0eU3N7VseoxVnD4L9uDqvWZdl_tzzrHDVN10IPP7cdFipX8j70atNMLfPCB0Q6/pub?gid=40578722&single=true&output=csv' -o src/colornames.csv",
|
|
27
|
-
"test": "npm run test:precommit &&
|
|
27
|
+
"test": "npm run test:precommit && vitest run",
|
|
28
28
|
"test:watch": "vitest",
|
|
29
|
-
"test:precommit": "npm run build
|
|
29
|
+
"test:precommit": "npm run build:test",
|
|
30
|
+
"build:test": "node scripts/build.js --testonly",
|
|
30
31
|
"build": "node scripts/build.js && npm run prettier",
|
|
31
32
|
"prettier": "prettier --write ./dist/*",
|
|
32
33
|
"lint": "npm run lint:scripts && npm run lint:markdown",
|
package/scripts/build.js
CHANGED
|
@@ -4,7 +4,8 @@ import { parseCSVString, findDuplicates, objArrToString } from './lib.js';
|
|
|
4
4
|
import { exec } from 'child_process';
|
|
5
5
|
|
|
6
6
|
const args = process.argv;
|
|
7
|
-
|
|
7
|
+
// treat --testonly / --testOnly the same
|
|
8
|
+
const isTestRun = args.some((arg) => arg.toLowerCase() === '--testonly');
|
|
8
9
|
|
|
9
10
|
// only hex colors with 6 values
|
|
10
11
|
const hexColorValidation = /^#[0-9a-f]{6}$/;
|
|
@@ -88,10 +89,10 @@ colorsSrc.values[bestOfKey].forEach((str) => {
|
|
|
88
89
|
});
|
|
89
90
|
|
|
90
91
|
showLog();
|
|
91
|
-
|
|
92
|
+
// In test mode we still perform the build so tests can import dist artifacts,
|
|
93
|
+
// but we avoid mutating repository files like README.md or generating the SVG.
|
|
92
94
|
if (isTestRun) {
|
|
93
|
-
console.log('
|
|
94
|
-
process.exit();
|
|
95
|
+
console.log('Test mode: skipping README & SVG generation.');
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
// creates JS related files
|
|
@@ -336,37 +337,41 @@ for (const outputFormat in outputFormats) {
|
|
|
336
337
|
}
|
|
337
338
|
}
|
|
338
339
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
fs
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
)
|
|
340
|
+
if (!isTestRun) {
|
|
341
|
+
// updates the color count in readme file
|
|
342
|
+
const readme = fs
|
|
343
|
+
.readFileSync(path.normalize(`${baseFolder}${readmeFileName}`), 'utf8')
|
|
344
|
+
.toString();
|
|
345
|
+
fs.writeFileSync(
|
|
346
|
+
path.normalize(`${baseFolder}${readmeFileName}`),
|
|
347
|
+
readme
|
|
348
|
+
.replace(
|
|
349
|
+
// update color count in text
|
|
350
|
+
/__\d+__/g,
|
|
351
|
+
`__${colorsSrc.entries.length}__`
|
|
352
|
+
)
|
|
353
|
+
.replace(
|
|
354
|
+
// update color count in badge
|
|
355
|
+
/\d+-colors-orange/,
|
|
356
|
+
`${colorsSrc.entries.length}-colors-orange`
|
|
357
|
+
)
|
|
358
|
+
.replace(
|
|
359
|
+
// update color count in percentage
|
|
360
|
+
/__\d+(\.\d+)?%__/,
|
|
361
|
+
`__${((colorsSrc.entries.length / (256 * 256 * 256)) * 100).toFixed(2)}%__`
|
|
362
|
+
)
|
|
363
|
+
.replace(
|
|
364
|
+
// update file size
|
|
365
|
+
/\d+(\.\d+)? MB\)__/, // no global to only hit first occurrence
|
|
366
|
+
`${(
|
|
367
|
+
fs.statSync(path.normalize(`${baseFolder}${folderDist}${fileNameSrc}.json`)).size /
|
|
368
|
+
1024 /
|
|
369
|
+
1024
|
|
370
|
+
).toFixed(2)} MB)__`
|
|
371
|
+
),
|
|
372
|
+
'utf8'
|
|
373
|
+
);
|
|
374
|
+
}
|
|
370
375
|
|
|
371
376
|
/**
|
|
372
377
|
* outputs the collected logs
|
|
@@ -479,4 +484,6 @@ function diffSVG() {
|
|
|
479
484
|
);
|
|
480
485
|
}
|
|
481
486
|
|
|
482
|
-
|
|
487
|
+
if (!isTestRun) {
|
|
488
|
+
diffSVG();
|
|
489
|
+
}
|
package/scripts/sortSrc.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
* Script to sort the colornames.csv file alphabetically by name
|
|
5
|
+
* This helps maintain order when new colors are added to the list
|
|
6
|
+
*/
|
|
7
7
|
|
|
8
8
|
import fs from 'fs';
|
|
9
9
|
import path from 'path';
|
|
@@ -18,11 +18,17 @@ const csvPath = path.join(__dirname, '..', 'src', 'colornames.csv');
|
|
|
18
18
|
// Read the CSV file
|
|
19
19
|
const readAndSortCSV = () => {
|
|
20
20
|
try {
|
|
21
|
-
// Read
|
|
22
|
-
const
|
|
21
|
+
// Read file & normalise line endings to LF
|
|
22
|
+
const raw = fs.readFileSync(csvPath, 'utf8').replace(/\r\n?/g, '\n');
|
|
23
23
|
|
|
24
|
-
// Split
|
|
25
|
-
|
|
24
|
+
// Split (keeping possible last empty line which we'll drop below)
|
|
25
|
+
let lines = raw.split('\n');
|
|
26
|
+
|
|
27
|
+
// Drop trailing empty / whitespace-only lines
|
|
28
|
+
while (lines.length && !lines[lines.length - 1].trim()) lines.pop();
|
|
29
|
+
|
|
30
|
+
// Trim trailing whitespace on each line
|
|
31
|
+
lines = lines.map(l => l.replace(/\s+$/,''));
|
|
26
32
|
|
|
27
33
|
// The header should be kept as the first line
|
|
28
34
|
const header = lines[0];
|
|
@@ -38,10 +44,10 @@ const readAndSortCSV = () => {
|
|
|
38
44
|
return nameA.localeCompare(nameB);
|
|
39
45
|
});
|
|
40
46
|
|
|
41
|
-
// Combine
|
|
42
|
-
const sortedData = [header, ...sortedColorLines].join('\n');
|
|
47
|
+
// Combine header & sorted lines (no blank line). Ensure exactly one final newline.
|
|
48
|
+
const sortedData = [header, ...sortedColorLines].join('\n') + '\n';
|
|
43
49
|
|
|
44
|
-
// Write
|
|
50
|
+
// Write back
|
|
45
51
|
fs.writeFileSync(csvPath, sortedData, 'utf8');
|
|
46
52
|
|
|
47
53
|
console.log(`✅ Successfully sorted ${sortedColorLines.length} colors alphabetically by name`);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Ensures that the source CSV file is already sorted alphabetically (case-insensitive)
|
|
7
|
+
* by the color name. If not, it throws with a helpful message telling how to fix it.
|
|
8
|
+
*/
|
|
9
|
+
describe('Source CSV sorting', () => {
|
|
10
|
+
it('colornames.csv should be sorted by name (case-insensitive)', () => {
|
|
11
|
+
const csvPath = path.resolve('./src/colornames.csv');
|
|
12
|
+
const raw = fs.readFileSync(csvPath, 'utf8').replace(/\r\n/g, '\n').trimEnd();
|
|
13
|
+
const lines = raw.split('\n');
|
|
14
|
+
expect(lines.length).toBeGreaterThan(1);
|
|
15
|
+
|
|
16
|
+
const header = lines.shift();
|
|
17
|
+
expect(header.startsWith('name,hex')).toBe(true);
|
|
18
|
+
|
|
19
|
+
const entries = lines
|
|
20
|
+
.filter((l) => l.trim().length)
|
|
21
|
+
.map((l, idx) => {
|
|
22
|
+
const [name, hex] = l.split(',');
|
|
23
|
+
return { originalIndex: idx + 2, line: l, name, lower: name.toLowerCase(), hex };
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
for (let i = 1; i < entries.length; i++) {
|
|
27
|
+
const prev = entries[i - 1];
|
|
28
|
+
const curr = entries[i];
|
|
29
|
+
if (prev.lower.localeCompare(curr.lower) > 0) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
[
|
|
32
|
+
'Source file src/colornames.csv is not sorted alphabetically by name.',
|
|
33
|
+
`Out of order around lines ${prev.originalIndex} -> ${curr.originalIndex}:`,
|
|
34
|
+
` "${prev.name}" should come AFTER "${curr.name}"`,
|
|
35
|
+
'',
|
|
36
|
+
'To fix automatically run:',
|
|
37
|
+
' npm run sort-colors',
|
|
38
|
+
'',
|
|
39
|
+
'Commit the updated src/colornames.csv after sorting.'
|
|
40
|
+
].join('\n')
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|