@d-zero/a11y-check 0.4.0
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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/a11y-check.d.ts +11 -0
- package/dist/a11y-check.js +43 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +51 -0
- package/dist/read-config.d.ts +11 -0
- package/dist/read-config.js +19 -0
- package/dist/spreadsheet.d.ts +7 -0
- package/dist/spreadsheet.js +112 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 D-ZERO Co., Ltd.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# `@d-zero/a11y-check`
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { A11yCheckOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param urlList
|
|
5
|
+
* @param out
|
|
6
|
+
* @param options
|
|
7
|
+
*/
|
|
8
|
+
export declare function a11yCheck(urlList: readonly (string | {
|
|
9
|
+
id: string | null;
|
|
10
|
+
url: string;
|
|
11
|
+
})[], out?: string, options?: A11yCheckOptions): Promise<void>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { scenarioAxe } from '@d-zero/a11y-check-axe-scenario';
|
|
2
|
+
import { scenarioRunner } from '@d-zero/a11y-check-core';
|
|
3
|
+
import { scenario01, scenario02 } from '@d-zero/a11y-check-scenarios';
|
|
4
|
+
import dayjs from 'dayjs';
|
|
5
|
+
import { SpreadsheetReporter } from './spreadsheet.js';
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param urlList
|
|
9
|
+
* @param out
|
|
10
|
+
* @param options
|
|
11
|
+
*/
|
|
12
|
+
export async function a11yCheck(urlList, out, options) {
|
|
13
|
+
let sheet = null;
|
|
14
|
+
if (out) {
|
|
15
|
+
let sheetName = dayjs().format('YYYY-MM-DD');
|
|
16
|
+
if (options?.debug) {
|
|
17
|
+
sheetName += `-debug-${Date.now()}`;
|
|
18
|
+
}
|
|
19
|
+
sheet = await SpreadsheetReporter.setup(out, sheetName);
|
|
20
|
+
}
|
|
21
|
+
const scenarioList = options?.scenarios ?? ['axe'];
|
|
22
|
+
const scenarios = scenarioList.map((s) => {
|
|
23
|
+
switch (s) {
|
|
24
|
+
case 'axe': {
|
|
25
|
+
return scenarioAxe(options);
|
|
26
|
+
}
|
|
27
|
+
case '01': {
|
|
28
|
+
return scenario01(options);
|
|
29
|
+
}
|
|
30
|
+
case '02': {
|
|
31
|
+
return scenario02(options);
|
|
32
|
+
}
|
|
33
|
+
default: {
|
|
34
|
+
throw new Error(`Unknown scenario: ${s}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const result = await scenarioRunner(urlList, scenarios, options);
|
|
39
|
+
if (out && sheet) {
|
|
40
|
+
process.stdout.write(`Report to ${out}\n`);
|
|
41
|
+
await sheet.report(result.violations);
|
|
42
|
+
}
|
|
43
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createCLI, parseCommonOptions } from '@d-zero/cli-core';
|
|
3
|
+
import { a11yCheck } from './a11y-check.js';
|
|
4
|
+
import { readConfig } from './read-config.js';
|
|
5
|
+
const { options, args, hasConfigFile } = createCLI({
|
|
6
|
+
aliases: {
|
|
7
|
+
f: 'listfile',
|
|
8
|
+
s: 'screenshot',
|
|
9
|
+
o: 'out',
|
|
10
|
+
},
|
|
11
|
+
usage: [
|
|
12
|
+
'Usage:',
|
|
13
|
+
'\ta11y-check -f <listfile> [-o <out>] [--limit <limit>] [--cache <true|false>] [--debug] [--verbose]',
|
|
14
|
+
],
|
|
15
|
+
parseArgs: (cli) => ({
|
|
16
|
+
...parseCommonOptions(cli),
|
|
17
|
+
listfile: cli.listfile,
|
|
18
|
+
scenarios: cli.scenarios,
|
|
19
|
+
cache: cli.cache?.trim().toLowerCase() === 'false' ? false : true,
|
|
20
|
+
cacheDir: cli.cacheDir ?? '.cache',
|
|
21
|
+
locale: cli.locale,
|
|
22
|
+
screenshot: !!cli.screenshot,
|
|
23
|
+
out: cli.out?.trim() || undefined,
|
|
24
|
+
}),
|
|
25
|
+
validateArgs: (options, cli) => {
|
|
26
|
+
return !!(options.listfile?.length || cli._.length > 0);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const list = [];
|
|
30
|
+
let a11yOptions = {
|
|
31
|
+
scenarios: options.scenarios?.split(',').map((s) => s.trim().toLowerCase()),
|
|
32
|
+
screenshot: options.screenshot,
|
|
33
|
+
locale: options.locale,
|
|
34
|
+
limit: options.limit,
|
|
35
|
+
cache: options.cache,
|
|
36
|
+
cacheDir: options.cacheDir,
|
|
37
|
+
debug: options.debug,
|
|
38
|
+
verbose: options.verbose,
|
|
39
|
+
};
|
|
40
|
+
if (hasConfigFile) {
|
|
41
|
+
const { urlList, hooks } = await readConfig(options.listfile);
|
|
42
|
+
list.push(...urlList);
|
|
43
|
+
a11yOptions = {
|
|
44
|
+
...a11yOptions,
|
|
45
|
+
hooks,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
list.push(...args);
|
|
50
|
+
}
|
|
51
|
+
await a11yCheck(list, options.out, a11yOptions);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { readPageHooks } from '@d-zero/puppeteer-page-scan';
|
|
2
|
+
import { toKvList } from '@d-zero/readtext/list';
|
|
3
|
+
import { readConfigFile } from '@d-zero/shared/config-reader';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param filePath
|
|
7
|
+
*/
|
|
8
|
+
export async function readConfig(filePath) {
|
|
9
|
+
const { content, baseDir } = await readConfigFile(filePath);
|
|
10
|
+
const urlList = toKvList(content.body).map((kv) => ({
|
|
11
|
+
id: kv.value ? kv.key : null,
|
|
12
|
+
url: kv.value || kv.key,
|
|
13
|
+
}));
|
|
14
|
+
const hooks = await readPageHooks(content.attributes?.hooks ?? [], baseDir);
|
|
15
|
+
return {
|
|
16
|
+
urlList,
|
|
17
|
+
hooks,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Violation } from '@d-zero/a11y-check-core';
|
|
2
|
+
export declare class SpreadsheetReporter {
|
|
3
|
+
#private;
|
|
4
|
+
private constructor();
|
|
5
|
+
report(results: readonly Violation[]): Promise<void>;
|
|
6
|
+
static setup(sheetUrl: string, sheetName: string): Promise<SpreadsheetReporter>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { authentication } from '@d-zero/google-auth';
|
|
2
|
+
import { SheetTable } from '@d-zero/google-sheets';
|
|
3
|
+
import { parseUrl } from '@d-zero/shared/parse-url';
|
|
4
|
+
import dotenv from 'dotenv';
|
|
5
|
+
export class SpreadsheetReporter {
|
|
6
|
+
#table;
|
|
7
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
8
|
+
constructor(sheetUrl, sheetName, auth) {
|
|
9
|
+
this.#table = new SheetTable(sheetUrl, sheetName, auth, {
|
|
10
|
+
id: 'No.',
|
|
11
|
+
url: '対象画面URL',
|
|
12
|
+
tool: 'テスト方法',
|
|
13
|
+
timestamp: '日時',
|
|
14
|
+
component: 'パーツ',
|
|
15
|
+
environment: '環境',
|
|
16
|
+
targetNode: '対象箇所',
|
|
17
|
+
asIs: 'AS IS',
|
|
18
|
+
toBe: {
|
|
19
|
+
label: 'TO BE',
|
|
20
|
+
conditionalFormatRules: [
|
|
21
|
+
{
|
|
22
|
+
booleanRule: {
|
|
23
|
+
condition: { type: 'BLANK' },
|
|
24
|
+
format: {
|
|
25
|
+
backgroundColor: { red: 0.9 },
|
|
26
|
+
textFormat: { foregroundColor: { red: 1, green: 1, blue: 1 } },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
explanation: {
|
|
33
|
+
label: 'TO BE(補足)',
|
|
34
|
+
conditionalFormatRules: [
|
|
35
|
+
{
|
|
36
|
+
booleanRule: {
|
|
37
|
+
condition: {
|
|
38
|
+
type: 'TEXT_STARTS_WITH',
|
|
39
|
+
values: [{ userEnteredValue: 'N/A' }],
|
|
40
|
+
},
|
|
41
|
+
format: {
|
|
42
|
+
backgroundColor: { red: 0.9 },
|
|
43
|
+
textFormat: { foregroundColor: { red: 1, green: 1, blue: 1 } },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
booleanRule: {
|
|
49
|
+
condition: {
|
|
50
|
+
type: 'TEXT_STARTS_WITH',
|
|
51
|
+
values: [{ userEnteredValue: 'WARNING' }],
|
|
52
|
+
},
|
|
53
|
+
format: {
|
|
54
|
+
backgroundColor: { red: 1, green: 0.5, blue: 0 },
|
|
55
|
+
textFormat: { foregroundColor: { red: 1, green: 1, blue: 1 } },
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
wcagVersion: 'WCAGバージョン',
|
|
62
|
+
scNumber: '達成基準番号',
|
|
63
|
+
level: '適合レベル',
|
|
64
|
+
screenshot: 'スクリーンショット',
|
|
65
|
+
}, {
|
|
66
|
+
frozen: {
|
|
67
|
+
rows: 1,
|
|
68
|
+
cols: 2,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async report(results) {
|
|
73
|
+
await this.#table.update(results.map((result) => {
|
|
74
|
+
const url = parseUrl(result.url);
|
|
75
|
+
return {
|
|
76
|
+
id: { value: result.id },
|
|
77
|
+
url: {
|
|
78
|
+
value: url.withoutHashAndAuth,
|
|
79
|
+
textFormat: { link: { uri: url.withoutHashAndAuth } },
|
|
80
|
+
},
|
|
81
|
+
tool: { value: result.tool },
|
|
82
|
+
timestamp: { value: result.timestamp },
|
|
83
|
+
component: { value: result.component },
|
|
84
|
+
environment: { value: result.environment },
|
|
85
|
+
targetNode: {
|
|
86
|
+
value: result.targetNode.value,
|
|
87
|
+
note: result.targetNode.note,
|
|
88
|
+
},
|
|
89
|
+
asIs: { value: result.asIs.value, note: result.asIs.note },
|
|
90
|
+
toBe: { value: result.toBe.value, note: result.toBe.note },
|
|
91
|
+
explanation: {
|
|
92
|
+
value: result.explanation.value,
|
|
93
|
+
note: result.explanation.note,
|
|
94
|
+
},
|
|
95
|
+
wcagVersion: { value: result.wcagVersion },
|
|
96
|
+
scNumber: { value: result.scNumber },
|
|
97
|
+
level: { value: result.level },
|
|
98
|
+
screenshot: { value: result.screenshot },
|
|
99
|
+
};
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
static async setup(sheetUrl, sheetName) {
|
|
103
|
+
dotenv.config();
|
|
104
|
+
if (!process.env.GOOGLE_AUTH_CREDENTIALS) {
|
|
105
|
+
throw new Error('GOOGLE_AUTH_CREDENTIALS is not set');
|
|
106
|
+
}
|
|
107
|
+
const auth = await authentication(process.env.GOOGLE_AUTH_CREDENTIALS, [
|
|
108
|
+
'https://www.googleapis.com/auth/spreadsheets',
|
|
109
|
+
]);
|
|
110
|
+
return new SpreadsheetReporter(sheetUrl, sheetName, auth);
|
|
111
|
+
}
|
|
112
|
+
}
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@d-zero/a11y-check",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Accessibility Checker CLI",
|
|
5
|
+
"author": "D-ZERO",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"private": false,
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/a11y-check.js",
|
|
15
|
+
"types": "./dist/a11y-check.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"a11y-check": "./dist/cli.js"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"watch": "tsc --watch",
|
|
27
|
+
"clean": "tsc --build --clean"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@d-zero/a11y-check-axe-scenario": "0.4.0",
|
|
31
|
+
"@d-zero/a11y-check-core": "0.5.0",
|
|
32
|
+
"@d-zero/a11y-check-scenarios": "0.4.0",
|
|
33
|
+
"@d-zero/cli-core": "1.1.0",
|
|
34
|
+
"@d-zero/google-auth": "0.4.0",
|
|
35
|
+
"@d-zero/google-sheets": "0.3.2",
|
|
36
|
+
"@d-zero/puppeteer-page-scan": "4.0.1",
|
|
37
|
+
"@d-zero/readtext": "1.1.4",
|
|
38
|
+
"@d-zero/shared": "0.9.0",
|
|
39
|
+
"ansi-colors": "4.1.3",
|
|
40
|
+
"dayjs": "1.11.13",
|
|
41
|
+
"dotenv": "16.5.0",
|
|
42
|
+
"front-matter": "4.0.2",
|
|
43
|
+
"minimist": "1.2.8"
|
|
44
|
+
},
|
|
45
|
+
"gitHead": "04c6969564182c36ee38ef41e78130936dfa4863"
|
|
46
|
+
}
|