Skip to content

Commit

Permalink
update glob
Browse files Browse the repository at this point in the history
  • Loading branch information
rmccar committed Sep 21, 2023
1 parent 6d5e003 commit 3099f46
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12,678 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package-lock.json
# Generated from visual regression tests
backstop_data/bitmaps_test/
backstop_data/html_report/
backstop.config-for-docker.json

# npm package folders
/components/
Expand Down
8 changes: 4 additions & 4 deletions lib/create-page-list.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import path from 'path';
import glob from 'glob';
import { glob } from 'glob';

function buildEntries(templatePath, type) {
templatePath = path.resolve(templatePath);
Expand All @@ -18,13 +18,13 @@ export default async function createPageList(res, type = null, name = null) {
if (!fs.existsSync(`./src/${type}/${name}`)) {
return res.status(404).send({ error: `${type} not found` });
}
pages = glob.sync(`./src/${type}/${name}/example-*.njk`).map(templatePath => buildEntries(templatePath, type));
pages = glob.sync(`./src/${type}/${name}/example-*.njk`).map((templatePath) => buildEntries(templatePath, type));
} else if (type) {
const hasExample = glob.sync(`./src/${type}/**/*example-*`);
const templatePath = Array.from(new Set(hasExample.map(filePath => path.dirname(filePath))));
const templatePath = Array.from(new Set(hasExample.map((filePath) => path.dirname(filePath))));

if (templatePath.length) {
pages = templatePath.map(folderPath => buildEntries(folderPath, type));
pages = templatePath.map((folderPath) => buildEntries(folderPath, type));
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/generate-static-pages.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import glob from 'glob';
import { glob } from 'glob';
import path from 'path';

import renderPageList from './render-page-list';
Expand All @@ -14,7 +14,7 @@ export default async function generateStaticPages() {
fs.writeFileSync('./build/index.html', indexPage);

// Loop through each page type and generate the pages
const types = pages.map(page => page.uri.slice(1));
const types = pages.map((page) => page.uri.slice(1));
for (const type of types) {
const folderNames = getFolderNames(type);
const typePage = await generateTypePages(type, folderNames);
Expand All @@ -32,13 +32,13 @@ function createBuildDirectory() {

function getFolderNames(type) {
const path = `./src/${type}`;
return fs.readdirSync(path, { withFileTypes: true }).map(dir => dir.name);
return fs.readdirSync(path, { withFileTypes: true }).map((dir) => dir.name);
}

async function generateExamplePages(type, folderNames) {
const dir = `./build/${type}`;
for (const name of folderNames) {
const exampleFiles = glob.sync(`./src/${type}/${name}/example-*.njk`).map(filePath => path.basename(filePath, '.njk'));
const exampleFiles = glob.sync(`./src/${type}/${name}/example-*.njk`).map((filePath) => path.basename(filePath, '.njk'));
for (const file of exampleFiles) {
const exampleName = path.basename(file, '.njk');
const output = await handleExamplesRoute(type, name, exampleName);
Expand Down
2 changes: 1 addition & 1 deletion lighthouse/lighthouse-get-urls.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const util = require('util');
const glob = util.promisify(require('glob'));
const glob = require('glob-promise');
const readdir = util.promisify(fs.readdir);

async function createURLsFile() {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"front-matter": "^4.0.2",
"fs-extra": "^11.1.1",
"fuse.js": "^3.6.1",
"glob": "^7.1.3",
"glob": "^8.0.3",
"glob-promise": "^6.0.5",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-cli": "^2.3.0",
Expand Down
6 changes: 2 additions & 4 deletions src/tests/helpers/url-generator.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const fs = require('fs');
const util = require('util');
const glob = require('glob');

const globUtil = util.promisify(glob);
const glob = require('glob-promise');
const readdir = util.promisify(fs.readdir);

const testURL = `http://host.docker.internal:3010`;
Expand All @@ -23,7 +21,7 @@ export default async () => {
for (const directory of directories) {
const folders = await readdir(directory.path);
for (const folder of folders) {
const files = await globUtil(`${directory.path}/${folder}/**/example-*.njk`);
const files = await glob(`${directory.path}/${folder}/**/example-*.njk`);
for (const file of files) {
const urlPath = file.replace(/^\.\/src\/(.*\/example-.*?)\.njk$/, '/$1');
urls.push({ url: `${testURL}${urlPath}`, label: urlPath, delay: 1000 });
Expand Down
Loading

0 comments on commit 3099f46

Please sign in to comment.