Skip to content
This repository has been archived by the owner on Jan 24, 2019. It is now read-only.

Commit

Permalink
I now have the bundle, client library and the component mechanisms wo…
Browse files Browse the repository at this point in the history
…rking and usable
  • Loading branch information
Westrate, Benjamin authored and Westrate, Benjamin committed May 25, 2016
1 parent 15c64e5 commit 24951a2
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 23 deletions.
39 changes: 34 additions & 5 deletions lib/operations/create-bundle.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
var shell = require( 'shelljs' );
var rc = require( 'rc' );
var inquirer = require( 'inquirer' );
var fs = require( 'fs' );

var getTemplates = require( '../utils/getTemplates' );
var utils = require( '../utils' );
var makeClientLib = require( './create-clientlib' );

module.exports = function( programs ){
module.exports = function( program ){

var templates = getTemplates();
//make sure we are in the project iron build folder
utils.pathToProjectRoot();
var givenBundleName = false;

// TODO : build out a new bundle
if( program.clientlib !== true && program.clientlib !== false ){
givenBundleName = program.clientlib;
}

var ironRc = rc( 'iron' );
var templates = utils.get.templates();
var bundlePath = '';
var bundleInfo = {
bundle_name : givenBundleName ? givenBundleName : program.bundle
};

console.log(templates);
shell.mkdir( 'aem-bundles/' + bundleInfo.bundle_name );
shell.mkdir( 'aem-bundles/' + bundleInfo.bundle_name + '/styles' );
shell.cd( 'aem-bundles/' + bundleInfo.bundle_name );

bundlePath = shell.pwd().stdout;

bundleInfo.bundle_name = bundleInfo.bundle_name
bundleInfo.clientLibPath = '../' + ironRc.clinetlib_root + '/' + bundleInfo.bundle_name;
bundleInfo.components = [ ];

utils.templateRenderer( bundlePath + '/' + bundleInfo.bundle_name + '.js', templates.bundles.mainJs.value, bundleInfo )
utils.templateRenderer( bundlePath + '/styles/' + bundleInfo.bundle_name + '.scss', templates.bundles.mainScss.value, bundleInfo )
utils.templateRenderer( bundlePath + '/config.json', templates.bundles.bundleConfig.value, bundleInfo )
utils.templateRenderer( bundlePath + '/' + bundleInfo.bundle_name + '.components.js', templates.bundles.componentReferance.value, bundleInfo )
utils.templateRenderer( bundlePath + '/styles/' + bundleInfo.bundle_name + '.components.scss', templates.bundles.componentReferanceCss.value, bundleInfo )

}
37 changes: 35 additions & 2 deletions lib/operations/create-clientlib.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
var shell = require( 'shelljs' );
var rc = require( 'rc' );
var inquirer = require( 'inquirer' );
var fs = require( 'fs' );

var utils = require( '../utils' );
var makeClientLib = require( './create-clientlib' );

module.exports = function( program ){

module.exports = function(){
//make sure we are in the project iron build folder
utils.pathToProjectRoot();


shell.cd( '..' );

var givenLibName = false;

if( program.bundle !== true && program.bundle !== false ){
givenLibName = program.bundle;
}

var ironRc = rc( 'iron' );
var templates = utils.get.templates();
var libPath = '';
var libInfo = {
clientlib_name : givenLibName ? givenLibName : program.clinetlib
};

libInfo.clientlib_category = ironRc.clientlib_base_category + '.' + libInfo.clientlib_name,
libInfo.clientlib_path = './' + ironRc.clinetlib_root + '/' + libInfo.clientlib_name

shell.mkdir( libInfo.clientlib_path );
shell.mkdir( libInfo.clientlib_path + '/js');
shell.mkdir( libInfo.clientlib_path + '/css');
shell.cd( libInfo.clientlib_path );

utils.templateRenderer( 'css.txt', templates.clientlibs.css.value, libInfo );
utils.templateRenderer( 'js.txt', templates.clientlibs.js.value, libInfo );
utils.templateRenderer( '.content.xml', templates.clientlibs.content.value, libInfo );

}
26 changes: 24 additions & 2 deletions lib/operations/create-component.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
var shell = require( 'shelljs' );
var rc = require( 'rc' );
var inquirer = require( 'inquirer' );
var fs = require( 'fs' );

var utils = require( '../utils' );
var makeClientLib = require( './create-clientlib' );

module.exports = function( program ){

module.exports = function(){
//make sure we are in the project iron build folder
utils.pathToProjectRoot();

console.log("Yo Broseph");
var ironRc = rc( 'iron' );
var templates = utils.get.templates();
var componentPath = '';
var componentInfo = {
component_name : program.component
};

shell.mkdir( 'components/' + componentInfo.component_name );
shell.mkdir( 'components/' + componentInfo.component_name + '/styles' );
shell.cd( 'components/' + componentInfo.component_name );

componentPath = shell.pwd().stdout;

utils.templateRenderer( componentPath + '/' + componentInfo.component_name + '.js', templates.components.mainJS.value, componentInfo )
utils.templateRenderer( componentPath + '/styles/' + componentInfo.component_name + '.scss', templates.components.mainSCSS.value, componentInfo )

}
36 changes: 36 additions & 0 deletions lib/operations/create-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,37 @@ var exit = require('../exit');
// maven_goal: 'gulp',
// maven_exacutions: 'build' }

function buildCatArray ( catArray ) {

var upperCassedCatArray = catArray.map( function( cat, index ) {
if( index !== 0 ){
return cat.charAt(0).toUpperCase() + cat.slice(1)
} else {
return cat;
}

} );

return upperCassedCatArray;
}

function createClientLibBaseCat ( projectName ) {

var hasDash = projectName.indexOf( "-" );
var hasUnderscore = projectName.indexOf( "_" );

if( hasDash !== -1 ){
projectName = projectName.split( '-' );
return buildCatArray( projectName ).join('');
}

if( hasUnderscore !== -1 ){
projectName = projectName.split( '_' );
return buildCatArray( projectName ).join('');
}

}

module.exports = function( program ){

var currentDir = shell.pwd().stdout.split("/")[ shell.pwd().stdout.split("/").length - 1 ];
Expand All @@ -30,6 +61,8 @@ module.exports = function( program ){
iron_build_root : program.args[0] + '-iron-fe'
};

config.clientlib_base_category = createClientLibBaseCat( config.name );

shell.mkdir( config.iron_build_root );
shell.mkdir( config.iron_build_root + '/components' );
shell.mkdir( config.iron_build_root + '/aem-bundles' );
Expand Down Expand Up @@ -69,6 +102,9 @@ module.exports = function( program ){
.indexOf( currentDir ) + 1 )
.join('/');

shell.mkdir( config.clinetlib_root + '/' + config.name );
config.clinetlib_root = config.clinetlib_root + '/' + config.name;

fs.writeFileSync( '.ironrc' , JSON.stringify( config, null, 4 ) );

} )
Expand Down
13 changes: 13 additions & 0 deletions lib/templates/bundles/bundleConfig.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"clientLibPath": "{{clientLibPath}}",
"autoGenerate" : {
"js" : true,
"styles" : true
},
"useGlobalComponents" : true,
"components" : [
{{#each components}}
"{{this}}",
{{/each}}
]
}
4 changes: 1 addition & 3 deletions lib/templates/bundles/componentReferance.js.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

module.exports = {
{{#each components}}
{{#unless this.isGlobal }}
"{{ this.name }}" : require( './../../components/{{ this.name }}' ),
{{/unless}}
"{{ this }}" : require( './../../components/{{ this }}/{{ this }}.js' ),
{{/each}}
}
2 changes: 1 addition & 1 deletion lib/templates/bundles/componentReferanceCss.css.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@


{{#each components}}
@import "../../../components/{{this.name}}/styles/{{this.name}}";
@import "../../../components/{{this}}/styles/{{this}}";
{{/each}}
4 changes: 2 additions & 2 deletions lib/templates/bundles/mainJs.js.template
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* This is the main file for {{clientlib_name}}
* This is the main file for {{bundle_name}}
*/

var components = require( './{{clientlib_name}}.components' );
var components = require( './{{bundle_name}}.components' );
var globalComponent = require( '../../components/global' );

globalComponent.init( components );
4 changes: 2 additions & 2 deletions lib/templates/bundles/mainScss.scss.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Main css for {{clientlib_name}}
* Main css for {{bundle_name}}
*/

@import "{{clientlib_name}}.components";
@import "{{bundle_name}}.components";
11 changes: 11 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
componentLinker : require( './component-linker' ),
get : {
clinetlibs : require( './getClientLibs' ),
templates : require( './getTemplates' )
},
manageRC : require( './manageRC' ),
pathToProjectRoot : require( './pathToProjectRoot' ),
pomBuilder : require( './pom-builder' ),
templateRenderer : require( './template-renderer' )
}
18 changes: 14 additions & 4 deletions lib/utils/pathToProjectRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ var shell = require( 'shelljs' );
module.exports = function( ) {

var ironRc = require( 'rc' )( 'iron' );
var currentPath = shell.pwd().split("/");
var currentPath = shell.pwd().stdout.split("/");
var newPath = "";

if( ironRc.hasOwnProperty( 'iron_build_root' ) ){
var ggpIndex = currentPath.indexOf( ironRc.root );
newPath = currentPath.splice(0, ggpIndex + 1).join('/') + "/";
var index = currentPath.indexOf( ironRc.iron_build_root );

if( index !== -1 ){
currentPath = currentPath.splice(0, index + 1);
} else {
currentPath.push( ironRc.iron_build_root )
}

} else {
newPath = currentPath.join('/') + "/";
currentPath.push( ironRc.iron_build_root );
}

newPath = currentPath.join('/') + '/';

shell.cd( newPath );

return newPath;

}
11 changes: 11 additions & 0 deletions sampleBundleConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"clientLibPath": "../project-name/src/main/content/jcr_root/etc/clientlibs/project-name/commons",
"autoGenerate" : {
"js" : true,
"styles" : true
},
"useGlobalComponents" : true,
"components" : [

]
}
5 changes: 3 additions & 2 deletions sampleProjectConfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name" : "GGP",
"aem_clientlibs_base_path" : "ggp-ui/src/main/content/jcr_root/etc/clientlibs/ggp",
"name" : "project-name",
"clinetlib_root" : "project-name/src/main/content/jcr_root/etc/clientlibs/project-name",
"clientlib_base_category" : "projectName",
"default_components" : [],
"iron_build_root" : "ggp-ui-build"
}

0 comments on commit 24951a2

Please sign in to comment.