Delete the custom bundle script in favor of an npm package (#1433)
This commit is contained in:
parent
759502c763
commit
ef77ee91d4
2 changed files with 2 additions and 94 deletions
|
@ -1,92 +0,0 @@
|
||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
const path = require( 'path' );
|
|
||||||
const fs = require( 'fs' );
|
|
||||||
const archiver = require('archiver');
|
|
||||||
|
|
||||||
// Contains the excluded files and folders.
|
|
||||||
const excludes = [
|
|
||||||
'.DS_Store',
|
|
||||||
'.stylelintrc.json',
|
|
||||||
'.eslintrc',
|
|
||||||
'.git',
|
|
||||||
'.gitattributes',
|
|
||||||
'.github',
|
|
||||||
'.gitignore',
|
|
||||||
'README.md',
|
|
||||||
'bin',
|
|
||||||
'composer.json',
|
|
||||||
'composer.lock',
|
|
||||||
'node_modules',
|
|
||||||
'package-lock.json',
|
|
||||||
'package.json',
|
|
||||||
'vendor',
|
|
||||||
'.travis.yml',
|
|
||||||
'phpcs.xml.dist',
|
|
||||||
'sass',
|
|
||||||
'style.css.map',
|
|
||||||
];
|
|
||||||
|
|
||||||
// The path of the zip file.
|
|
||||||
const zipPath = path.join(
|
|
||||||
__dirname,
|
|
||||||
'/../../',
|
|
||||||
path.basename(path.dirname(__dirname))
|
|
||||||
) + '.zip';
|
|
||||||
|
|
||||||
|
|
||||||
// Create a file to stream archive data to.
|
|
||||||
let output = fs.createWriteStream( zipPath );
|
|
||||||
let archive = archiver('zip', {
|
|
||||||
zlib: { level: 9 }
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recursively traverse the directory tree and append the files to the archive.
|
|
||||||
* @param {string} directoryPath - The path of the directory being looped through.
|
|
||||||
*/
|
|
||||||
function traverseDirectoryTree( directoryPath ) {
|
|
||||||
const files = fs.readdirSync( directoryPath );
|
|
||||||
for ( const i in files ) {
|
|
||||||
const currentPath = directoryPath + '/' + files[i];
|
|
||||||
const stats = fs.statSync( currentPath );
|
|
||||||
let relativePath = path.relative(process.cwd(), currentPath);
|
|
||||||
if ( stats.isFile() && ! excludes.includes( files[i] ) ) {
|
|
||||||
archive.file(currentPath, {
|
|
||||||
name: `${relativePath}`
|
|
||||||
});
|
|
||||||
} else if ( stats.isDirectory() && ! excludes.includes( files[i] ) ) {
|
|
||||||
traverseDirectoryTree( currentPath );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Listen for all archive data to be written.
|
|
||||||
output.on('close', function () {
|
|
||||||
console.log(`Created ${path.basename(path.dirname(__dirname))}.zip of ${archive.pointer()} bytes`);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Catch warnings during archiving.
|
|
||||||
archive.on('warning', function(err) {
|
|
||||||
if (err.code === 'ENOENT') {
|
|
||||||
// log warning
|
|
||||||
console.log(err);
|
|
||||||
} else {
|
|
||||||
// throw error
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Catch errors during archiving.
|
|
||||||
archive.on('error', function(err){
|
|
||||||
throw err;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Pipe archive data to the file.
|
|
||||||
archive.pipe(output);
|
|
||||||
|
|
||||||
// Append the files to the archive.
|
|
||||||
traverseDirectoryTree( '.' );
|
|
||||||
|
|
||||||
// Finalize the archive.
|
|
||||||
archive.finalize();
|
|
|
@ -18,7 +18,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@wordpress/scripts": "^9.0.0",
|
"@wordpress/scripts": "^9.0.0",
|
||||||
"archiver": "^4.0.1",
|
"dir-archiver": "^1.1.1",
|
||||||
"node-sass": "^4.14.0",
|
"node-sass": "^4.14.0",
|
||||||
"rtlcss": "^2.5.0"
|
"rtlcss": "^2.5.0"
|
||||||
},
|
},
|
||||||
|
@ -41,6 +41,6 @@
|
||||||
"compile:rtl": "rtlcss style.css style-rtl.css",
|
"compile:rtl": "rtlcss style.css style-rtl.css",
|
||||||
"lint:scss": "wp-scripts lint-style 'sass/**/*.scss'",
|
"lint:scss": "wp-scripts lint-style 'sass/**/*.scss'",
|
||||||
"lint:js": "wp-scripts lint-js 'js/*.js'",
|
"lint:js": "wp-scripts lint-js 'js/*.js'",
|
||||||
"bundle": "node bin/bundle.js"
|
"bundle": "dir-archiver --src . --dest ../_s.zip --exclude .DS_Store .stylelintrc.json .eslintrc .git .gitattributes .github .gitignore README.md composer.json composer.lock node_modules vendor package-lock.json package.json .travis.yml phpcs.xml.dist sass style.css.map"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue