Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore does not work in the subfolder in the archive. #634

Open
BeycanDeveloper opened this issue Dec 31, 2022 · 0 comments
Open

Ignore does not work in the subfolder in the archive. #634

BeycanDeveloper opened this issue Dec 31, 2022 · 0 comments

Comments

@BeycanDeveloper
Copy link

My code is as follows and what I want to do is this. Exporting everything in the current folder into a zip. However, a folder will be created in the zip and this folder will be the name of the current folder. So far everything ok. But the ignore parameter doesn't work. If I don't use an "archive.directory" method ignore works and dumps everything else into the zip without getting the ".git" folder. However, I want to have a folder in the zip. When I do this, "ignore" doesn't work and it also zips the ".git" folder.

How can I solve this?

#!/usr/bin/env node

const path = require('path');
const fs = require('fs');
const fse = require('fs-extra');
const archiver = require('archiver');

const currentFolder = process.cwd();
const fileName = path.basename(currentFolder);
const parentFolder = path.resolve(currentFolder, '..');
const outputZipFile = fs.createWriteStream(currentFolder + '/'+fileName+'.zip');

module.exports = function() {
    const archive = archiver('zip', { zlib: { level: 9 } });

    outputZipFile.on('close', function () {
        console.log(archive.pointer() + ' total bytes');
        console.log('archiver has been finalized and the output file descriptor has closed.');
    });
    
    archive.on('error', function(err){
        throw err;
    });

    archive.pipe(outputZipFile);

    archive.directory(currentFolder, fileName);

    archive.glob('**', {
        cwd: currentFolder,
        ignore: ['.git', 'node_modules', '*.zip'],
        expand:true, flatten:true
    });

    archive.finalize(function(err, bytes) {
		if(err) {
			console.log(err);
		}
	});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant