Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

feat(command-deploy): support hidden deployment folders #150

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,14 @@ The following paths can be passed in the options:

- `configPath` (path to a `netlify.toml` file that includes redirect rules for the deploy, etc.)
- `fnDir` (a folder with lambda functions to deploy)
- `deployDir` (the name of the folder you want to deploy, should be the folder name referenced by `buildDir` above)

Optional `opts` include:

```js
{
fnDir: null, // path to a folder of functions to deploy
deployDir: null // name of the folder in the `buildDir` path
branch: null, // branch to pass onto the netlify api
configPath: null, // path to a netlify.toml file to include in the deploy (e.g. redirect support for manual deploys)
draft: false, // draft deploy or production deploy
Expand Down
2 changes: 1 addition & 1 deletion src/deploy/hash-files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { defaultFilter } = require('./util')

test('hashes files in a folder', async t => {
const { files, filesShaMap } = await hashFiles(__dirname, path.resolve(__dirname, '../../fixtures/netlify.toml'), {
filter: defaultFilter
filter: filePath => defaultFilter(filePath)
})
t.truthy(files['netlify.toml'], 'includes the netlify.toml file')
Object.keys(files).forEach(path => t.truthy(path, 'each file has a path'))
Expand Down
2 changes: 1 addition & 1 deletion src/deploy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = async (api, siteId, dir, opts) => {
deployTimeout: 1.2e6, // local deploy timeout: 20 mins
concurrentHash: 100, // concurrent file hash calls
concurrentUpload: 15, // Number of concurrent uploads
filter: defaultFilter,
filter: filePath => defaultFilter(filePath, opts.deployDir),
syncFileLimit: 7000, // number of files
maxRetry: 5, // number of times to retry an upload
statusCb: () => {
Expand Down
24 changes: 17 additions & 7 deletions src/deploy/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ const path = require('path')
const flatten = require('lodash.flatten')
const pWaitFor = require('p-wait-for')

// Default filter when scanning for files
exports.defaultFilter = filename => {
if (filename == null) return false
const n = path.basename(filename)
const removeSlashes = path => path && path.replace(/\/+$/, '')

/**
* Default filter when scanning for files
* @param {string} filePath - path to file to test filter on
* @param {string} [baseDir] - base directory to whitelist
*/
exports.defaultFilter = (filePath, baseDir = null) => {
if (filePath == null) return false
const fileName = path.basename(filePath)

// Always allow scanning files in the base directory
if (fileName === removeSlashes(baseDir)) return true

switch (true) {
case n === 'node_modules':
case n.startsWith('.') && n !== '.well-known':
case n.match(/(\/__MACOSX|\/\.)/):
case fileName === 'node_modules':
case fileName.startsWith('.') && fileName !== '.well-known':
case fileName.match(/(\/__MACOSX|\/\.)/):
return false
default:
return true
Expand Down