Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
`The default Front Matter Format (${chalk.yellow(
"content.frontMatterFormat"
)}) is invalid. These are the valid formats: ${chalk.cyan(
validFrontMatterFormats.join(", ")
)}.`
);
}
}
// Check base url
if (config.baseUrl && config.baseUrl !== "/") {
const isValidUrl = validator.isURL(config.baseUrl);
if (!isValidUrl) {
errors.push(
`The Base URL (${chalk.yellow("baseUrl")}) is invalid: ${
config.baseUrl
}.\nValid Example: ${chalk.cyan("https://status.yourbaseurl.com")}.`
);
} else {
const { pathname } = url.parse(config.baseUrl);
if (pathname && pathname !== "/") {
errors.push(
`Statusfy doesn't support deployments under a subpath (${chalk.cyan(
pathname
)}).`
);
}
}
// Make sure a trailing slash (at the end of the URL) is not defined
module.exports = function validateConfig(config) {
const errors = [];
// Check Front Matter Format
const frontMatterFormat = config.content.frontMatterFormat;
if (frontMatterFormat) {
if (!validFrontMatterFormats.includes(frontMatterFormat)) {
errors.push(
`The default Front Matter Format (${chalk.yellow(
"content.frontMatterFormat"
)}) is invalid. These are the valid formats: ${chalk.cyan(
validFrontMatterFormats.join(", ")
)}.`
);
}
}
// Check base url
if (config.baseUrl && config.baseUrl !== "/") {
const isValidUrl = validator.isURL(config.baseUrl);
if (!isValidUrl) {
errors.push(
`The Base URL (${chalk.yellow("baseUrl")}) is invalid: ${
config.baseUrl
`Statusfy doesn't support deployments under a subpath (${chalk.cyan(
pathname
)}).`
);
}
}
// Make sure a trailing slash (at the end of the URL) is not defined
config.baseUrl = config.baseUrl.replace(/\/$/, "");
}
// Check defaultLocale
const localesCode = config.locales.map(locale => locale.code);
if (!localesCode.includes(config.defaultLocale)) {
errors.push(
`The Default Locale (${chalk.yellow(
"defaultLocale"
)}) value must be included in the locales list. Current value ${chalk.cyan(
config.defaultLocale
)}, defined codes: ${chalk.cyan(localesCode.join(", "))}.`
);
}
// Send errors
return errors;
};
for (let i = 0; i < files.length; i++) {
const f = path.resolve(contentDir, files[i]);
const ext = path.extname(f);
const fileName = path.basename(f);
if (ext === ".md") {
const fileContent = await fse.readFile(f);
const { data } = grayMatter.parse(fileContent);
incidentsList.push({
value: {
name: fileName,
path: f
},
name: `${fileName} > ${chalk.yellow(data.title)} (${chalk.green(
new Date(data.date).toUTCString()
)})`
});
}
}
return incidentsList;
};
validate: value => {
if (localeCode.validateLanguageCode(value)) {
return true;
}
return `You must define a valid language code.\n See the valid language identifiers at ${chalk.yellow(
"http://www.i18nguy.com/unicode/language-identifiers.html"
)}`;
}
},
function parseConfig(filePath) {
const extension = path.extname(filePath);
let data;
logger.info(
`Reading configuration from ${chalk.yellow(`config${extension}`)}`
);
if (extension !== ".js") {
const content = fse.readFileSync(filePath, "utf-8");
if (extension === ".yml") {
data = yaml.parse(content);
} else if (extension === ".toml") {
data = toml.parse(content);
}
} else {
data = require(filePath);
}
return data || {};
}
{
type: "input",
name: "title",
message: "Title of the Website",
validate: value => {
if (value.length > 0) {
return true;
}
return "You must have a Website Title!";
}
},
{
type: "input",
name: "description",
message: `Description of the Website. ${chalk.yellow("(recommended)")}`
},
{
type: "input",
name: "lang",
default: "en-US",
message: `Code of the Default Language ${chalk.yellow("(e.g. en-US)")}`,
validate: value => {
if (localeCode.validateLanguageCode(value)) {
return true;
}
return `You must define a valid language code.\n See the valid language identifiers at ${chalk.yellow(
"http://www.i18nguy.com/unicode/language-identifiers.html"
)}`;
}
},
return true;
}
return "You must have a Website Title!";
}
},
{
type: "input",
name: "description",
message: `Description of the Website. ${chalk.yellow("(recommended)")}`
},
{
type: "input",
name: "lang",
default: "en-US",
message: `Code of the Default Language ${chalk.yellow("(e.g. en-US)")}`,
validate: value => {
if (localeCode.validateLanguageCode(value)) {
return true;
}
return `You must define a valid language code.\n See the valid language identifiers at ${chalk.yellow(
"http://www.i18nguy.com/unicode/language-identifiers.html"
)}`;
}
},
{
type: "list",
name: "incidentFormat",
default: "yaml",
message: "Default Front Matter format for your Incidents",
choices: ["yaml", "toml", "json"]