Skip to content

Commit

Permalink
bump to 0.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLedesma committed Mar 28, 2022
1 parent a959273 commit 2cee064
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
4 changes: 2 additions & 2 deletions install-wp-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
const tmpDir = await doesFileExist( '/tmp' ) ? '/tmp' : await fs.mkdtemp( os.tmpdir() );

const wpTestsDir = `${ tmpDir }/wordpress-tests-lib`;
const wpCoreDir = `${ tmpDir }/wordpress/`;
const wpCoreDir = `${ tmpDir }/wordpress`;

/**
* @async
Expand All @@ -46,7 +46,7 @@
}

await download( `https://wordpress.org/${ archiveName }.zip`, `${ tmpDir }/wordpress.zip` );
await unzip( `${ tmpDir }/wordpress.zip`, wpCoreDir );
await unzip( `${ tmpDir }/wordpress.zip`, tmpDir );

await download( 'https://raw.github.com/markoheijnen/wp-mysqli/master/db.php', `${ wpCoreDir }/wp-content/db.php` );
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@godaddy-wordpress/scripts",
"version": "0.3.2",
"version": "0.3.3",
"description": "Collection of scripts used for management of CI pipelines as well as general development scripts.",
"homepage": "https://github.com/godaddy-wordpress/scripts",
"repository": "godaddy-wordpress/scripts",
Expand Down
29 changes: 19 additions & 10 deletions utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { createWriteStream } = require( 'fs' );
const { constants } = require( 'fs' );
const { pipeline } = require( 'stream' );
const { promisify } = require( 'util' );
const path = require( 'path' );
const AdmZip = require( 'adm-zip' );
const fs = require( 'fs' ).promises;

Expand All @@ -21,10 +22,11 @@ const RESET = '\x1b[0m';

/**
* @function download File downloader.
* @param {string} url The URL to download.
* @param {string} path The path to save the file to.
* @param {string} url The URL to download.
* @param filePath
* @param {string} path The path to save the file to.
*/
const download = async ( url, path ) => {
const download = async ( url, filePath ) => {
const streamPipeline = promisify( pipeline );
const response = await fetch( url, {
headers: {
Expand All @@ -37,26 +39,33 @@ const download = async ( url, path ) => {
throw new Error( `unexpected response ${ response.statusText }` );
}

await streamPipeline( response.body, createWriteStream( path ) );
const checkPath = path.dirname( filePath );
const pathExists = await doesFileExist( checkPath );

if ( ! pathExists ) {
await fs.mkdir( checkPath, { recursive: true } );
}

await streamPipeline( response.body, createWriteStream( filePath ) );
};

/**
* @function unzip Extract a zip file to a destination.
* @param {*} file
* @param {string} path
* @param {string} filePath
*/
const unzip = async ( file, path ) => {
const unzip = async ( file, filePath ) => {
const zip = new AdmZip( file );
zip.extractAllTo( path, true );
zip.extractAllTo( filePath, true );
};

/**
* @function doesFileExist Async check if a inode exists and handle error messages.
* @param {path} path Path to the inode to check
* @param {path} filePath Path to the inode to check
* @return {boolean} True if the folder exists false otherwise.
*/
const doesFileExist = async ( path ) => {
const pathWithoutTrailingSlash = path.replace( /\/$/, '' );
const doesFileExist = async ( filePath ) => {
const pathWithoutTrailingSlash = filePath.replace( /\/$/, '' );
// Access has no return value if file exists.
// Catch error if occurs otherwise the file exists.
const fileCheck = await fs.access( pathWithoutTrailingSlash, constants.F_OK ).catch( () => false );
Expand Down

0 comments on commit 2cee064

Please sign in to comment.