Skip to content
Merged
Changes from all commits
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
51 changes: 37 additions & 14 deletions packages/@vue/cli-ui/apollo-server/connectors/folders.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const cwd = require('./cwd')
function isDirectory (file) {
file = file.replace(/\\/g, path.sep)
try {
return fs.statSync(file).isDirectory()
return fs.stat(file).then((x) => x.isDirectory())
} catch (e) {
if (process.env.VUE_APP_CLI_UI_DEBUG) console.warn(e.message)
}
Expand All @@ -31,21 +31,41 @@ async function list (base, context) {
}
}
const files = await fs.readdir(dir, 'utf8')
return files.map(
file => {

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
}
return {
path: folderPath,
name: file,
hidden: isHidden(folderPath)
hidden
}
}
).filter(
file => isDirectory(file.path)
})
)
return f.filter((x) => !!x)
}

function isHidden (file) {
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)
}

async function isHidden (file) {
try {
const prefixed = path.basename(file).charAt(0) === hiddenPrefix
const result = {
Expand All @@ -54,11 +74,13 @@ 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)
return (
(!isPlatformWindows && result.unix) ||
(isPlatformWindows && result.windows)
)
} catch (e) {
if (process.env.VUE_APP_CLI_UI_DEBUG) {
console.log('file:', file)
Expand Down Expand Up @@ -142,9 +164,10 @@ function isVueProject (file, context) {
}

function listFavorite (context) {
return context.db.get('foldersFavorite').value().map(
file => generateFolder(file.id, context)
)
return context.db
.get('foldersFavorite')
.value()
.map((file) => generateFolder(file.id, context))
}

function isFavorite (file, context) {
Expand Down