|
@ -1,4 +1,5 @@ |
|
|
import fs, { readFile as read } from 'fs-promise'; |
|
|
import { stat } from 'fs-promise'; |
|
|
|
|
|
import { readdir, readFile } from './graceful-fs'; |
|
|
import { resolve } from 'path'; |
|
|
import { resolve } from 'path'; |
|
|
import flatten from 'arr-flatten'; |
|
|
import flatten from 'arr-flatten'; |
|
|
import unique from 'array-unique'; |
|
|
import unique from 'array-unique'; |
|
@ -16,7 +17,8 @@ import IGNORED from './ignored'; |
|
|
|
|
|
|
|
|
export default async function getFiles (path, pkg) { |
|
|
export default async function getFiles (path, pkg) { |
|
|
if (!pkg) { |
|
|
if (!pkg) { |
|
|
const pkgData = await read(resolve(path, 'package.json'), 'utf8'); |
|
|
const pkgPath = resolve(path, 'package.json'); |
|
|
|
|
|
const pkgData = await readFile(pkgPath, 'utf8'); |
|
|
pkg = JSON.parse(pkgData); |
|
|
pkg = JSON.parse(pkgData); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -103,19 +105,19 @@ const explode = async function (paths) { |
|
|
|
|
|
|
|
|
const list = async (file) => { |
|
|
const list = async (file) => { |
|
|
let path = file; |
|
|
let path = file; |
|
|
let stat; |
|
|
let s; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
stat = await fs.stat(path); |
|
|
s = await stat(path); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
// in case the file comes from `files` or `main`
|
|
|
// in case the file comes from `files` or `main`
|
|
|
// and it wasn't specified with `.js` by the user
|
|
|
// and it wasn't specified with `.js` by the user
|
|
|
path = file + '.js'; |
|
|
path = file + '.js'; |
|
|
stat = await fs.stat(path); |
|
|
s = await stat(path); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (stat.isDirectory()) { |
|
|
if (s.isDirectory()) { |
|
|
const all = await fs.readdir(file); |
|
|
const all = await readdir(file); |
|
|
return many(all.map(subdir => asAbsolute(subdir, file))); |
|
|
return many(all.map(subdir => asAbsolute(subdir, file))); |
|
|
} else { |
|
|
} else { |
|
|
return path; |
|
|
return path; |
|
@ -133,7 +135,7 @@ const explode = async function (paths) { |
|
|
|
|
|
|
|
|
const maybeRead = async function (path) { |
|
|
const maybeRead = async function (path) { |
|
|
try { |
|
|
try { |
|
|
return (await fs.readFile(path, 'utf8')); |
|
|
return (await readFile(path, 'utf8')); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
return ''; |
|
|
return ''; |
|
|
} |
|
|
} |
|
|