Reduce code duplication by declaring copyDir() once
This commit is contained in:
parent
cf16154caa
commit
0e710bfaf1
|
|
@ -1,22 +1,7 @@
|
||||||
const { promises: fs } = require( 'fs' );
|
const utils = require( './utils' );
|
||||||
const path = require( 'path' );
|
|
||||||
|
|
||||||
async function copyDir( src, dest ) {
|
|
||||||
await fs.mkdir( dest, { recursive: true } );
|
|
||||||
const entries = await fs.readdir( src, { withFileTypes: true } );
|
|
||||||
|
|
||||||
for ( let entry of entries ) {
|
|
||||||
let srcPath = path.join( src, entry.name );
|
|
||||||
let destPath = path.join( dest, entry.name );
|
|
||||||
|
|
||||||
entry.isDirectory()
|
|
||||||
? await copyDir( srcPath, destPath )
|
|
||||||
: await fs.copyFile( srcPath, destPath );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy all Bootstrap SCSS files.
|
// Copy all Bootstrap SCSS files.
|
||||||
copyDir( './node_modules/bootstrap4/scss', './src/sass/assets/bootstrap4' );
|
utils.copyDir( './node_modules/bootstrap4/scss', './src/sass/assets/bootstrap4' );
|
||||||
copyDir( './node_modules/bootstrap/scss', './src/sass/assets/bootstrap5' );
|
utils.copyDir( './node_modules/bootstrap/scss', './src/sass/assets/bootstrap5' );
|
||||||
// Copy all Font Awesome SCSS files.
|
// Copy all Font Awesome SCSS files.
|
||||||
copyDir( './node_modules/font-awesome/scss', './src/sass/assets/fontawesome' );
|
utils.copyDir( './node_modules/font-awesome/scss', './src/sass/assets/fontawesome' );
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,19 @@
|
||||||
const { promises: fs } = require( 'fs' );
|
const utils = require( './utils' );
|
||||||
const path = require( 'path' );
|
|
||||||
const pkg = require( '../../package.json' );
|
const pkg = require( '../../package.json' );
|
||||||
|
const ignore = [
|
||||||
|
'dist',
|
||||||
|
'node_modules',
|
||||||
|
'src',
|
||||||
|
'vendor',
|
||||||
|
'composer.json',
|
||||||
|
'composer.lock',
|
||||||
|
'package.json',
|
||||||
|
'package-lock.json',
|
||||||
|
'phpcs.xml.dist',
|
||||||
|
'phpmd.baseline.xml',
|
||||||
|
'phpmd.xml',
|
||||||
|
'phpstan-baseline.neon',
|
||||||
|
'phpstan.neon.dist',
|
||||||
|
];
|
||||||
|
|
||||||
async function copyDir( src, dest ) {
|
utils.copyDir( './', `./dist/${ pkg.name }-${ pkg.version }`, ignore );
|
||||||
await fs.mkdir( dest, { recursive: true } );
|
|
||||||
let entries = await fs.readdir( src, { withFileTypes: true } );
|
|
||||||
// Exclude all dot files and directories.
|
|
||||||
entries = entries.filter( dirent => ! dirent.name.startsWith('.') );
|
|
||||||
const ignore = [
|
|
||||||
'dist',
|
|
||||||
'node_modules',
|
|
||||||
'src',
|
|
||||||
'vendor',
|
|
||||||
'composer.json',
|
|
||||||
'composer.lock',
|
|
||||||
'package.json',
|
|
||||||
'package-lock.json',
|
|
||||||
'phpcs.xml.dist',
|
|
||||||
'phpmd.baseline.xml',
|
|
||||||
'phpmd.xml',
|
|
||||||
'phpstan-baseline.neon',
|
|
||||||
'phpstan.neon.dist',
|
|
||||||
];
|
|
||||||
|
|
||||||
for ( const entry of entries ) {
|
|
||||||
if ( ignore.indexOf( entry.name ) != -1 ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let srcPath = path.join( src, entry.name );
|
|
||||||
let destPath = path.join( dest, entry.name );
|
|
||||||
|
|
||||||
entry.isDirectory()
|
|
||||||
? await copyDir( srcPath, destPath )
|
|
||||||
: await fs.copyFile( srcPath, destPath );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
copyDir( './', `./dist/${ pkg.name }-${ pkg.version }` );
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
const { promises: fs } = require( 'fs' );
|
||||||
|
const path = require( 'path' );
|
||||||
|
|
||||||
|
module.exports.copyDir = async function copyDir( src, dest, ignore ) {
|
||||||
|
await fs.mkdir( dest, { recursive: true } );
|
||||||
|
let entries = await fs.readdir( src, { withFileTypes: true } );
|
||||||
|
// Exclude all dot files and directories.
|
||||||
|
entries = entries.filter( dirent => ! dirent.name.startsWith('.') );
|
||||||
|
ignore = ignore || [];
|
||||||
|
|
||||||
|
for ( const entry of entries ) {
|
||||||
|
if ( ignore.indexOf( entry.name ) != -1 ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const srcPath = path.join( src, entry.name );
|
||||||
|
const destPath = path.join( dest, entry.name );
|
||||||
|
|
||||||
|
entry.isDirectory()
|
||||||
|
? await copyDir( srcPath, destPath )
|
||||||
|
: await fs.copyFile( srcPath, destPath );
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue