iron-fe
Version:
An opinionated - yet flexible - front end development framework for use with Adobe Experience Manager
99 lines (69 loc) • 2.32 kB
JavaScript
var rc = require('rc');
var fs = require( 'fs' );
var path = require( 'path' );
var shell = require( 'shelljs' );
var chalk = require( 'chalk' );
var utils = require( '../../utils' );
module.exports = {
getBundles : function () {
// Make sure we are at the iron build root
utils.pathToProjectRoot();
var bundlesArray = fs.readdirSync( 'aem-bundles' )
.filter( function ( dir ) {
// return true if `dir` does not start with a `.`
// to avoid dotfiles causing ENOTDIR (not a directory) errors
return !dir.match( /^\.[\w -]/ );
} );
return bundlesArray;
},
all : function(){
var bundlesArray = this.getBundles();
var bundles = {
bundleNames: [],
bundleCount: bundlesArray.length,
bundlePaths: [],
bundles: []
};
for ( let i = 0; i < bundlesArray.length; i++ ) {
let bundle = this.one( bundlesArray[ i ] );
bundles.bundles.push( bundle );
bundles.bundleNames.push( bundle.name );
}
return bundles;
},
one : function( bundleName ){
var bundlesArray = this.getBundles()
.filter( function ( dir ) {
return dir === bundleName
} );
let bundle = {
components : []
};
bundle.name = bundlesArray[ 0 ];
bundle.path = 'aem-bundles/' + bundle.name;
bundle.main = 'main.' + bundle.name + ".js";
let hasConfig = fs.existsSync( './' + bundle.path + '/config.json' );
if ( hasConfig ) {
bundle.config = require( shell.pwd().stdout + '/' + bundle.path + '/config.json' );
} else {
let error = 'Confg json file is required. Your bundle located here: ' +
chalk.bgRed.white( bundle.path ) + ' is missing the config. Add one or delete the folder';
console.log( error );
}
if ( fs.existsSync( path.resolve( bundle.config.clientLibPath ) ) ) {
bundle.config.clientLibPath = path.resolve( bundle.config.clientLibPath );
} else {
let error = 'Please defign a valid path to the bundle\'s clientlib in the config.json for : ' +
chalk.bgRed.white( bundle.path );
throw error
}
for( let i in bundle.config.components ){
let component = bundle.config.components[ i ];
bundle.components.push( {
name : component,
isGlobal : component === 'global'
} );
}
return bundle;
}
}