-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement Archiver * Compile the zip files
- Loading branch information
Showing
7 changed files
with
825 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/node_modules/ | ||
/wp/ | ||
/vendor/ | ||
/archives/*.zip | ||
|
||
# THEME | ||
/theme/dist | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); |
Oops, something went wrong.