Skip to content

Commit

Permalink
Compile the product zip files (#2)
Browse files Browse the repository at this point in the history
* Implement Archiver

* Compile the zip files
  • Loading branch information
Luehrsen authored Mar 24, 2022
1 parent 055d48a commit 111f50a
Show file tree
Hide file tree
Showing 7 changed files with 825 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/node_modules/
/wp/
/vendor/
/archives/*.zip

# THEME
/theme/dist
Expand Down
Empty file added archives/.gitkeep
Empty file.
66 changes: 66 additions & 0 deletions bin/archiveProject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* External Dependencies
*/
const fs = require('fs');
const archiver = require('archiver');
const ignore = require('ignore');
const glob = require('glob');
const pkg = require('./../package.json');

const createArchive = (path, srcPath, slug) => {
// Define the output stream
const output = fs.createWriteStream(path + '/' + slug + '.zip');

// Initialize the archive
const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});

// Listen for all archive data to be written
archive.pipe(output);

// Initialize the ignorer
const ig = ignore();

// We ignore files defined in a potential .distignore file
if( fs.existsSync(srcPath + '/.distignore') ) {
ig.add(fs.readFileSync(srcPath + '/.distignore', 'utf8').toString());
}

glob('**/*',
{
cwd: srcPath,
nodir: true,
},
(err, files) => {
if( err ) {
console.error(err);
return;
}

// Add all files to the archive
files.forEach(file => {

// Skip ignored files
if( ig.ignores(file) ) {
return;
}

// Construct the file path
const filePath = srcPath + '/' + file;

// Add the file to the archive
archive.file(filePath, {
name: file,
prefix: slug,
});
});

// Finalize the archive
archive.finalize();
}
);
}

createArchive('./archives', './plugin', pkg.slug + 'p' );
createArchive('./archives', './theme', pkg.slug + 't' );
Loading

0 comments on commit 111f50a

Please sign in to comment.