Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add axe-config-generator package #6395

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ module.exports = function (grunt) {
const packageValidatorBundlePath = path.join(packageValidatorPath, 'bundle');
const packageValidatorDropPath = path.join(packageValidatorPath, 'drop');

const packageAxeConfigPath = path.join('packages', 'axe-config');
const packageAxeConfigBundlePath = path.join(packageAxeConfigPath, 'bundle');
const packageAxeConfigDropPath = path.join(packageAxeConfigPath, 'drop');

const mockAdbObjPath = path.join('packages', 'mock-adb', 'obj');
const mockAdbBinPath = path.join('packages', 'mock-adb', 'bin');
const mockAdbDropPath = path.join('drop', 'mock-adb');
Expand All @@ -50,6 +54,7 @@ module.exports = function (grunt) {
'package-report': packageReportDropPath,
'package-ui': packageUIDropPath,
'package-validator': packageValidatorDropPath,
'package-axe-config': packageAxeConfigDropPath,
scss: path.join('src', '**/*.scss.d.ts'),
},
concurrent: {
Expand Down Expand Up @@ -171,6 +176,15 @@ module.exports = function (grunt) {
},
],
},
'package-axe-config': {
files: [
{
cwd: '.',
src: path.join(packageAxeConfigPath, 'index.js'),
dest: path.join(packageAxeConfigDropPath, 'index.js'),
},
],
},
},
exec: {
'esbuild-dev': `node esbuild.js`,
Expand All @@ -180,6 +194,11 @@ module.exports = function (grunt) {
'webpack-package-ui': `"${webpackPath}" --config-name package-ui`,
'esbuild-package-validator': `node esbuild.js --env validator`,
'generate-validator': `node ${packageValidatorDropPath}`,
'esbuild-package-axe-config': `node esbuild.js --env axe-config`,
'generate-axe-config': `node ${path.join(
packageAxeConfigBundlePath,
'axe-config-generator.bundle.js',
)} ${path.join(packageAxeConfigDropPath, 'axe-config.json')}`,
'generate-scss-typings': `"${typedScssModulesPath}" src --exportType default`,
'dotnet-publish-mock-adb': {
command: `dotnet publish -c Release -o "${path.resolve(mockAdbDropPath)}"`,
Expand Down Expand Up @@ -710,6 +729,19 @@ module.exports = function (grunt) {
console.log(`package is in ${packageValidatorDropPath}`);
});

grunt.registerTask('package-axe-config', function () {
const mustExistPath = path.join(
packageAxeConfigBundlePath,
'axe-config-generator.bundle.js',
);

mustExist(mustExistPath, 'Have you run esbuild?');

grunt.task.run('clean:package-axe-config');
grunt.task.run('copy:package-axe-config');
console.log(`package is in ${packageAxeConfigDropPath}`);
});

grunt.registerTask('build-mock-adb', function () {
grunt.task.run('exec:dotnet-publish-mock-adb');
});
Expand Down Expand Up @@ -799,6 +831,11 @@ module.exports = function (grunt) {
'exec:esbuild-package-validator',
'package-validator',
]);
grunt.registerTask('generate-axe-config', [
'exec:esbuild-package-axe-config',
'package-axe-config',
'exec:generate-axe-config',
]);
grunt.registerTask('build-all', [
'clean:intermediates',
'exec:generate-scss-typings',
Expand Down
11 changes: 11 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ switch (argsObj.env) {

break;

case 'axe-config':
entryFiles = {
'axe-config-generator': `${src}/packages/axe-config/generate-config-json.ts`,
};
outdir = path.join(__dirname, 'packages/axe-config/bundle');
platform = 'node';

ignoreNodeModules(plugins);

break;

// dev web extension
default:
define = {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"build:package:report": "lerna --scope accessibility-insights-report run build",
"build:package:ui": "lerna --scope accessibility-insights-ui run build",
"build:prod": "grunt build-prod",
"generate-axe-config": "grunt generate-axe-config",
sfoslund marked this conversation as resolved.
Show resolved Hide resolved
"change-log": "node ./tools/get-change-log-for-release.js",
"clean": "grunt clean:*",
"clean:mock-adb": "grunt clean:mock-adb",
Expand Down
18 changes: 18 additions & 0 deletions packages/axe-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!--
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
-->

# @accessibility-insights/axe-config

This library provides the [axe core run options](https://www.deque.com/axe/core-documentation/api-documentation/#options-parameter) currently used by default in Accessibility Insights for Web extension FastPass scans.

## Contributing

To contribute, please visit [accessibility-insights-web](https://github.com/microsoft/accessibility-insights-web/blob/main/README.md) for more information.

### Code of Conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
5 changes: 5 additions & 0 deletions packages/axe-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

const axeScanOptions = require('./axe-config.json');
exports.axeScanOptions = axeScanOptions;
20 changes: 20 additions & 0 deletions packages/axe-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@accessibility-insights/axe-config",
"version": "1.0.0",
"description": "Provides the current axe-core run options used by Accessibility Insights for Web for FastPass scans.",
"license": "MIT",
"files": [
"../../LICENSE",
"drop",
"README.md"
],
"main": "drop/index.js",
"scripts": {
"build": "grunt build-axe-config"
},
"repository": {
"type": "git",
"url": "https://github.com/Microsoft/accessibility-insights-web"
},
"dependencies": {}
}
7 changes: 7 additions & 0 deletions packages/axe-config/prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const baseConfig = require('../../prettier.config');

module.exports = {
...baseConfig,
};
30 changes: 30 additions & 0 deletions src/packages/axe-config/generate-config-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as axe from 'axe-core';
import * as fs from 'fs';
import * as path from 'path';
import { explicitRuleOverrides, getRuleInclusions } from 'scanner/get-rule-inclusions';
import { ScanParameterGenerator } from 'scanner/scan-parameter-generator';

const defaultConfigFilePath = path.join(__dirname, '../../../drop/axe-config.json');
const configFilePath = process.argv[2] || defaultConfigFilePath;

const generateAxeConfig = () => {
console.log('Generating axe config file...');

const ruleIncludedStatus = getRuleInclusions(axe._audit.rules, explicitRuleOverrides);
const scanParameterGenerator = new ScanParameterGenerator(ruleIncludedStatus);
const scanOptions = scanParameterGenerator.getAxeEngineOptions({});
const config = JSON.stringify(scanOptions, null, '\t');

console.log(`Writing config to ${configFilePath}...`);
if (!fs.existsSync(path.dirname(configFilePath))) {
fs.mkdirSync(path.dirname(configFilePath));
}
fs.writeFileSync(configFilePath, config);

console.log('Finished generating axe config file.');
};

generateAxeConfig();