|
|
@ -62,6 +62,86 @@ const asAbsolute = function(path, parent) { |
|
|
|
return resolve(parent, path) |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Returns a list of files in the given |
|
|
|
* directory that are subject to be |
|
|
|
* synchronized for static deployments. |
|
|
|
* |
|
|
|
* @param {String} full path to directory |
|
|
|
* @param {Object} options: |
|
|
|
* - `limit` {Number|null} byte limit |
|
|
|
* - `debug` {Boolean} warn upon ignore |
|
|
|
* @return {Array} comprehensive list of paths to sync |
|
|
|
*/ |
|
|
|
|
|
|
|
async function staticFiles( |
|
|
|
path, |
|
|
|
nowConfig = {}, |
|
|
|
{ limit = null, hasNowJson = false, debug = false } = {} |
|
|
|
) { |
|
|
|
const whitelist = nowConfig.files |
|
|
|
|
|
|
|
// The package.json `files` whitelist still
|
|
|
|
// honors ignores: https://docs.npmjs.com/files/package.json#files
|
|
|
|
const search_ = whitelist || ['.'] |
|
|
|
// Convert all filenames into absolute paths
|
|
|
|
const search = Array.prototype.concat.apply( |
|
|
|
[], |
|
|
|
await Promise.all( |
|
|
|
search_.map(file => glob(file, { cwd: path, absolute: true, dot: true })) |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
// Compile list of ignored patterns and files
|
|
|
|
const gitIgnore = await maybeRead(resolve(path, '.gitignore')) |
|
|
|
|
|
|
|
const filter = ignore() |
|
|
|
.add(IGNORED + '\n' + clearRelative(gitIgnore)) |
|
|
|
.createFilter() |
|
|
|
|
|
|
|
const prefixLength = path.length + 1 |
|
|
|
|
|
|
|
// The package.json `files` whitelist still
|
|
|
|
// honors npmignores: https://docs.npmjs.com/files/package.json#files
|
|
|
|
// but we don't ignore if the user is explicitly listing files
|
|
|
|
// under the now namespace, or using files in combination with gitignore
|
|
|
|
const accepts = file => { |
|
|
|
const relativePath = file.substr(prefixLength) |
|
|
|
|
|
|
|
if (relativePath === '') { |
|
|
|
return true |
|
|
|
} |
|
|
|
|
|
|
|
const accepted = filter(relativePath) |
|
|
|
if (!accepted && debug) { |
|
|
|
console.log('> [debug] ignoring "%s"', file) |
|
|
|
} |
|
|
|
return accepted |
|
|
|
} |
|
|
|
|
|
|
|
// Locate files
|
|
|
|
if (debug) { |
|
|
|
console.time(`> [debug] locating files ${path}`) |
|
|
|
} |
|
|
|
|
|
|
|
const files = await explode(search, { |
|
|
|
accepts, |
|
|
|
limit, |
|
|
|
debug |
|
|
|
}) |
|
|
|
|
|
|
|
if (debug) { |
|
|
|
console.timeEnd(`> [debug] locating files ${path}`) |
|
|
|
} |
|
|
|
|
|
|
|
if (hasNowJson) { |
|
|
|
files.push(asAbsolute('now.json', path)) |
|
|
|
} |
|
|
|
|
|
|
|
// Get files
|
|
|
|
return unique(files) |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Returns a list of files in the given |
|
|
|
* directory that are subject to be |
|
|
@ -299,5 +379,6 @@ async function explode(paths, { accepts, debug }) { |
|
|
|
|
|
|
|
module.exports = { |
|
|
|
npm, |
|
|
|
docker |
|
|
|
docker, |
|
|
|
staticFiles |
|
|
|
} |
|
|
|