Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function doesAnyDirectoryExist(
basePath: string,
directories: string[]
): Promise {
let foundDirectories: string | undefined;
try {
foundDirectories = fsHelpers.getFirstMatchingDirectory(
basePath,
directories
);
} catch {
foundDirectories = undefined;
}
if (typeof foundDirectories !== 'undefined') {
return true;
}
return false;
}
export async function writeFiles(
files: TemplateFileInfo[],
targetDir: string,
namespace: string
): Promise {
const functionsDir = fsHelpers.getFirstMatchingDirectory(targetDir, [
'functions',
'src',
]);
const assetsDir = fsHelpers.getFirstMatchingDirectory(targetDir, [
'assets',
'static',
]);
const functionsTargetDir = path.join(functionsDir, namespace);
const assetsTargetDir = path.join(assetsDir, namespace);
if (functionsTargetDir !== functionsDir) {
if (hasFilesOfType(files, 'functions')) {
try {
await mkdir(functionsTargetDir);
} catch (err) {
debug(err);
export async function writeFiles(
files: TemplateFileInfo[],
targetDir: string,
namespace: string
): Promise {
const functionsDir = fsHelpers.getFirstMatchingDirectory(targetDir, [
'functions',
'src',
]);
const assetsDir = fsHelpers.getFirstMatchingDirectory(targetDir, [
'assets',
'static',
]);
const functionsTargetDir = path.join(functionsDir, namespace);
const assetsTargetDir = path.join(assetsDir, namespace);
if (functionsTargetDir !== functionsDir) {
if (hasFilesOfType(files, 'functions')) {
try {
await mkdir(functionsTargetDir);
} catch (err) {
debug(err);
throw new Error(
`Template with name "${namespace}" already exists in "${functionsDir}"`
);
}