Skip to content
Merged
Changes from 1 commit
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
57 changes: 41 additions & 16 deletions packages/@vue/cli-ui/apollo-server/connectors/folders.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const pkgCache = new LRU({

const cwd = require('./cwd')

function isDirectory (file) {
function isDirectorySync (file) {
file = file.replace(/\\/g, path.sep)
try {
return fs.statSync(file).isDirectory()
Expand All @@ -23,6 +23,16 @@ function isDirectory (file) {
return false
}

function isDirectory (file) {
file = file.replace(/\\/g, path.sep)
try {
return fs.stat(file).then(x => x.isDirectory())
} catch (e) {
if (process.env.VUE_APP_CLI_UI_DEV) console.warn(e.message)
}
return false
}

async function list (base, context) {
let dir = base
if (isPlatformWindows) {
Expand All @@ -31,21 +41,37 @@ async function list (base, context) {
}
}
const files = await fs.readdir(dir, 'utf8')
return files.map(
file => {
const folderPath = path.join(base, file)
return {
path: folderPath,
name: file,
hidden: isHidden(folderPath)
}

const f = await Promise.all(files.map(async file => {
const folderPath = path.join(base, file)

const [directory, hidden] = await Promise.all([isDirectory(folderPath), isHidden(folderPath)])
if (!directory) {
return null
}
).filter(
file => isDirectory(file.path)
)
return {
path: folderPath,
name: file,
hidden
}
}))
return f.filter(x => !!x)
}

async function isHiddenWindows (file) {
const windowsFile = file.replace(/\\/g, '\\\\')
return (new Promise((resolve, reject) => {
winattr.get(windowsFile, (file, error) => {
if (error) {
return reject(error)
}
resolve(file)
})
})
.then(x => x.hidden))
}

function isHidden (file) {
async function isHidden (file) {
try {
const prefixed = path.basename(file).charAt(0) === hiddenPrefix
const result = {
Expand All @@ -54,8 +80,7 @@ function isHidden (file) {
}

if (isPlatformWindows) {
const windowsFile = file.replace(/\\/g, '\\\\')
result.windows = winattr.getSync(windowsFile).hidden
result.windows = await isHiddenWindows(file)
}

return (!isPlatformWindows && result.unix) || (isPlatformWindows && result.windows)
Expand Down Expand Up @@ -172,7 +197,7 @@ function createFolder (name, context) {
}

module.exports = {
isDirectory,
isDirectory: isDirectorySync,
getCurrent,
list,
open,
Expand Down