Skip to content
This repository was archived by the owner on Aug 26, 2021. It is now read-only.

helper.js: GetFolders -> GetModules, add package.json existence check #697

Closed
wants to merge 5 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions scripts/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ const Chalk = require(`chalk`);
const Path = require(`path`);
const Fs = require(`fs`);
const Os = require(`os`);
const Util = require('util');

const PKG = require( Path.normalize(`${ process.cwd() }/package.json`) );
const Readdir = Util.promisify(Fs.readdir);
const Access = Util.promisify(Fs.access);


//--------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -145,24 +148,33 @@ const GetDepTree = ( name ) => {


/**
* Get all folders within a given path
* Get all modules within a given path
* The 'module' is a component folder
*
* @param {string} thisPath - The path that contains the desired folders
* @param {boolean} verbose - Verbose flag either undefined or true
*
* @return {array} - An array of names of each folder
* @return {Promise<array>} - A promise to an array of names of each folder
*/
const GetFolders = ( thisPath, verbose ) => {
const GetModules = async ( thisPath, verbose ) => {
try {
let folders = Fs.readdirSync( thisPath ).filter(
thisFile => Fs.statSync(`${ thisPath }/${ thisFile }`).isDirectory()
).filter(
thisFile => thisFile !== 'core'
);
let dirContent = await Readdir( thisPath );
let folders = ( await Promise.all(
dirContent.map( dirItem => {
let pkg = Path.normalize( `${ thisPath }/${ dirItem }/package.json` );
return ( async () => {
try {
return await Access( pkg ) || dirItem;
} catch ( e ) {
return ''
}
} )()
} )
) )
.filter( folder => folder !== '' && folder !== 'core' );

return ['core', ...folders ]; // moving core to top
}
catch( error ) {
return [ 'core', ...folders ]; // moving core to top
} catch (e) {
return [];
}
};
Expand Down Expand Up @@ -620,11 +632,11 @@ HELPER.generate = (() => {
*/
init: () => {
const packagesPath = Path.normalize(`${ __dirname }/../packages/`);
const allModules = GetFolders( packagesPath );

HELPER.generate.json( allModules );
HELPER.generate.index( allModules );
HELPER.generate.readme( allModules );
GetModules( packagesPath ).then(allModules => {
HELPER.generate.json( allModules );
HELPER.generate.index( allModules );
HELPER.generate.readme( allModules );
});
},

/**
Expand Down Expand Up @@ -889,11 +901,11 @@ HELPER.test = (() => {
return {
init: () => {
const packagesPath = Path.normalize(`${ __dirname }/../packages/`);
const allModules = GetFolders( packagesPath );

HELPER.test.dependencies( allModules );
HELPER.test.packagejson( allModules );
HELPER.test.changelog( allModules );
GetModules( packagesPath ).then(allModules => {
HELPER.test.dependencies( allModules );
HELPER.test.packagejson( allModules );
HELPER.test.changelog( allModules );
});
},

/**
Expand Down