Skip to content

Commit

Permalink
Central function
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed May 2, 2024
1 parent 87fff56 commit 154358d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
15 changes: 4 additions & 11 deletions bin/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,21 @@
/* eslint-disable no-console */

import {equal, match, ok} from 'node:assert/strict';
import {readdir} from 'node:fs/promises';
import {basename, dirname, join as pathJoin} from 'node:path';
import {fileURLToPath} from 'node:url';
import {basename} from 'node:path';

import {read as packaged} from '../util/packages.mjs';
import {read as packaged, prefixes} from '../util/packages.mjs';
import {walk} from '../util/util.mjs';

const __dirname = dirname(fileURLToPath(import.meta.url));

async function properties() {
const directory = pathJoin(__dirname, '..', 'packages');
const packages = await packaged();
const prefixes = (await readdir(directory, {withFileTypes: true}))
.filter(e => e.isDirectory() && /^[a-z0-9-]+$/.test(e.name))
.map(e => e.name);
const expectedPrefixes = await prefixes();

const validatorsRoot = {
name: (root, value) => {
equal(typeof value, 'string');
match(value, /^[a-z][-a-z0-9_.]*[a-z0-9]$/);
let prefixed = false;
for (const prefix of prefixes) {
for (const prefix of expectedPrefixes) {
if (value.startsWith(`${prefix}-`)) {
prefixed = true;
break;
Expand Down
7 changes: 7 additions & 0 deletions util/packages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ function comparePaths(a, b) {
return 0;
}

export async function prefixes() {
const directory = pathJoin(__dirname, '..', 'packages');
return (await readdir(directory, {withFileTypes: true}))
.filter(e => e.isDirectory() && /^[a-z0-9-]+$/.test(e.name))
.map(e => e.name);
}

export async function read() {
const packagesDir = pathJoin(__dirname, '..', 'packages');
const files = (await readdir(packagesDir, {recursive: true}))
Expand Down

0 comments on commit 154358d

Please sign in to comment.