Skip to content
Merged
Changes from all 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
8 changes: 7 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ function scrub(data: any) {
return data as FeatureData;
}

const identifierPattern = /^[a-z0-9-]*$/;

function* yamlEntries(root: string): Generator<[string, any]> {
const filePaths = new fdir()
.withBasePath()
Expand All @@ -48,9 +50,13 @@ function* yamlEntries(root: string): Generator<[string, any]> {
for (const fp of filePaths) {
// The feature identifier/key is the filename without extension.
const { name: key } = path.parse(fp);
const distPath = `${fp}.dist`;

if (!identifierPattern.test(key)) {
throw new Error(`${key} is not a valid identifier (must be lowercase a-z, 0-9, and hyphens)`);
}

const data = YAML.parse(fs.readFileSync(fp, { encoding: 'utf-8'}));
const distPath = `${fp}.dist`;
if (fs.existsSync(distPath)) {
const dist = YAML.parse(fs.readFileSync(distPath, { encoding: 'utf-8'}));
Object.assign(data, dist);
Expand Down