Skip to content

Commit

Permalink
Try to get a more consistent sort (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
tombrunet authored Jan 12, 2022
1 parent af6527c commit fa3a851
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 4,
"useTabs": false
}
23 changes: 19 additions & 4 deletions accessibility-checker-extension/gulp/gulpFile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const fs = require("fs");
const gulp = require('gulp');
var replace = require('gulp-replace');
var ext_replace = require('gulp-ext-replace');
const replace = require('gulp-replace');
const ext_replace = require('gulp-ext-replace');
const gRename = require("gulp-rename");
const gSort = require('gulp-sort');

const componentHeader = `import React, { ReactNode } from "react";
import Markdown from 'markdown-to-jsx';
Expand Down Expand Up @@ -166,8 +168,20 @@ return(
/>);
}
}`;
function helpFileName(s) {
return s.toLowerCase();
}
function copyFiles() {
return gulp.src(["../../accessibility-checker-engine/help/*.mdx"])
.pipe(gRename(function (path) {
// Updates the object in-place
path.basename = helpFileName(path.basename);
}))
.pipe(gSort({
comparator: function(file1, file2) {
return (file1.path.localeCompare(file2.path));
}
}))
.pipe(ext_replace('.tsx'))
.pipe(replace(/`/g, "\\`"))
.pipe(replace("export default ({ children, _frontmatter }) => (<React.Fragment>{children}</React.Fragment>)", ""))
Expand All @@ -189,14 +203,15 @@ function copyFiles() {
}

function fileSwitcher() {
let files = fs.readdirSync("../../accessibility-checker-engine/help/")
let files = fs.readdirSync("../../accessibility-checker-engine/help/");
files.sort((a,b) => a.localeCompare(b));
let imports = "";
let usage = "";
for (const fileName of files) {
let component = fileName.replace(".mdx", "");
let reactName = component.substring(0,1).toUpperCase()+component.substring(1);

imports += `import ${reactName} from "./${component}";\n`;
imports += `import ${reactName} from "./${helpFileName(component)}";\n`;
usage += `{this.props.item.ruleId === '${component}' && <${reactName} report={this.props.report} item={this.props.item} />}\n`;
}
return gulp.src("./helpSwitcher.template")
Expand Down
15 changes: 15 additions & 0 deletions accessibility-checker-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions accessibility-checker-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
"css-loader": "^3.4.2",
"gulp": "^4.0.2",
"gulp-ext-replace": "^0.3.0",
"gulp-rename": "^2.0.0",
"gulp-replace": "^1.0.0",
"gulp-sort": "^2.0.0",
"html-webpack-plugin": "^4.5.0",
"jest": "^24.9.0",
"mini-css-extract-plugin": "^0.12.0",
Expand Down

0 comments on commit fa3a851

Please sign in to comment.