Skip to content

Commit

Permalink
check gitignore before copying to tmpDir
Browse files Browse the repository at this point in the history
  • Loading branch information
rnegron committed Jan 31, 2024
1 parent 6cfae02 commit 4ff1ba9
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/cli.html
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ <h2 id="build">build</h2>
</blockquote><p><strong>Usage</strong>: <code>zapier build</code></p><p>This command does the following:</p><ul>
<li><p>Creates a temporary folder</p>
</li>
<li><p>Copies all code into the temporary folder</p>
<li><p>Copies all code (excluding files in .gitignore) into the temporary folder</p>
</li>
<li><p>Adds an entry point: <code>zapierwrapper.js</code></p>
</li>
Expand Down
2 changes: 1 addition & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This command does the following:

* Creates a temporary folder

* Copies all code into the temporary folder
* Copies all code (excluding files in .gitignore) into the temporary folder

* Adds an entry point: `zapierwrapper.js`

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/docs/cli.html
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ <h2 id="build">build</h2>
</blockquote><p><strong>Usage</strong>: <code>zapier build</code></p><p>This command does the following:</p><ul>
<li><p>Creates a temporary folder</p>
</li>
<li><p>Copies all code into the temporary folder</p>
<li><p>Copies all code (excluding files in .gitignore) into the temporary folder</p>
</li>
<li><p>Adds an entry point: <code>zapierwrapper.js</code></p>
</li>
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This command does the following:

* Creates a temporary folder

* Copies all code into the temporary folder
* Copies all code (excluding files in .gitignore) into the temporary folder

* Adds an entry point: `zapierwrapper.js`

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/oclif/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ BuildCommand.description = `Build a pushable zip from the current directory.
This command does the following:
* Creates a temporary folder
* Copies all code into the temporary folder
* Copies all code (excluding files in .gitignore) into the temporary folder
* Adds an entry point: \`zapierwrapper.js\`
* Generates and validates app definition.
* Detects dependencies via browserify (optional, on by default)
Expand Down
24 changes: 24 additions & 0 deletions packages/cli/src/utils/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,29 @@ const maybeRunBuildScript = async (options = {}) => {
}
};

const buildCopyDirFilter = ({ wdir, skipNpmInstall = false }) => {
// read and parse .gitignore
const gitIgnorePath = path.join(wdir, '.gitignore');
const gitIgnoreFilter = ignore();

// create an ignore filter from .gitignore, if it exists
if (fs.existsSync(gitIgnorePath)) {
const gitIgnoredPaths = gitIgnore(gitIgnorePath);
const validGitIgnorePaths = gitIgnoredPaths.filter(ignore.isPathValid);
gitIgnoreFilter.add(validGitIgnorePaths);
}

return (file) => {
// exclude any files defined in .gitignore
if (gitIgnoreFilter.ignores(path.relative(wdir, file))) {
return false;
}

// exclude '.zip' files only if skipNpmInstall is true
return !(skipNpmInstall && file.includes('.zip'));
};
};

const _buildFunc = async ({
skipNpmInstall = false,
disableDependencyDetection = false,
Expand Down Expand Up @@ -563,4 +586,5 @@ module.exports = {
listFiles,
requiredFiles,
maybeRunBuildScript,
buildCopyDirFilter,
};
2 changes: 1 addition & 1 deletion packages/cli/src/utils/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const copyFile = (src, dest, mode) => {
Returns a promise that copies a directory recursively.
Options:
- clobber: Overwrite existing files? Default is false.
- filter:
A function that returns true if the file should be copied. By default, it
Expand Down

0 comments on commit 4ff1ba9

Please sign in to comment.