Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const assertDirectory = (t, directory, mode = 0o777 & (~process.umask())) => {
// Setting `mode` on `fs.mkdir` on Windows doesn't seem to work
if (process.platform === 'win32') {
mode = 0o666;
}
t.true(pathType.isDirectorySync(directory));
t.is(fs.statSync(directory).mode & 0o777, mode);
};
} else if (!relatedExists) { // If not exists return an error 404
return httpRequest.micro({
req,
res,
code: 404
});
}
const streamOptions = {};
if (flags.cache) {
streamOptions.maxAge = flags.cache;
}
// Check if directory
if (pathType.isDirectorySync(related)) {
const url = parse(req.url);
// If the url doesn't end with a slash, add it and redirect the page
if (url.pathname.substr(-1) !== '/') {
url.pathname += '/';
const newPath = format(url);
httpRequest.logRequests({
req,
res,
code: 301
}, 301);
res.writeHead(301, {
Location: newPath
});
server.close();
global.utils.logger.log(chalk.red(pkg.name + ' stopped.'));
process.exit(0);
};
process.on('SIGINT', () => {
stopServer();
});
process.on('kill', () => {
stopServer();
});
let isDir;
try {
isDir = pathType.isDirectorySync(current);
} catch (err) {
isDir = false;
}
if (!isDir) {
const base = basename(current);
console.error(
chalk.red(`Specified directory ${chalk.bold(`"${base}"`)} doesn't exist!`)
);
process.exit(1);
}
let message = '\n' + chalk.blue(pkg.title + ' is Online!') + ' 🚀';
let notificationTxt = 'The server is running.';
if (!fs.existsSync(dir)) {
return false;
}
filesRaw = yield fs.readdir(dir);
let files = [];
for (const file of filesRaw) {
const filePath = path.resolve(dir, file);
const details = path.parse(filePath);
details.title = details.base;
details.stats = {};
if (pathType.isDirectorySync(filePath)) {
details.base += '/';
details.type = 'dir';
details.stats.size = '—';
} else {
details.ext = details.ext.split('.')[1] || '';
details.type = 'file';
}
details.relative = path.join(subPath, details.base);
if (fu.isNotIgnoredPath(details.relative)) {
const fileStats = yield fs.stat(filePath);
if (!_.isString(details.stats.size)) {
details.stats.sizeRaw = fileStats.size;
details.stats.size = filesize(fileStats.size, {
function getDirectorySync(filepath: string): string {
const filePathIsDirectory = isDirectorySync(filepath);
if (filePathIsDirectory === true) {
return filepath;
}
const directory = path.dirname(filepath);
return directory;
}
const globs = [].concat(input).map(x => pathType.isDirectorySync(getPath(x, options.cwd)) ? getGlob(x, options) : x);