Files
30-seconds-of-code/node_modules/gatsby-page-utils/dist/validate-path.js
2019-08-20 15:52:05 +02:00

21 lines
855 B
JavaScript

"use strict";
var systemPath = require("path");
var mm = require("micromatch");
var tsDeclarationExtTest = /\.d\.tsx?$/;
var jsonYamlExtTest = /\.(json|ya?ml)$/; // https://github.com/facebook/jest/blob/v24.0.0-alpha.4/packages/jest-config/src/Defaults.js#L71
function isTestFile(filePath) {
var testPatterns = ["**/__tests__/**/*.(js|ts)?(x)", "**/(*.)+(spec|test).(js|ts)?(x)"];
return mm.isMatch(filePath, testPatterns);
}
module.exports = function (path) {
// Disallow paths starting with an underscore (_) or dot (.)
// and template-.
// and .d.ts
var parsedPath = systemPath.parse(path);
return parsedPath.name.slice(0, 1) !== "_" && parsedPath.name.slice(0, 1) !== "." && parsedPath.name.slice(0, 9) !== "template-" && !tsDeclarationExtTest.test(parsedPath.base) && !jsonYamlExtTest.test(parsedPath.base) && !isTestFile(path);
};