Skip to content

Commit

Permalink
Merge pull request #2 from arboshiki/master
Browse files Browse the repository at this point in the history
Update gulp module-generator
  • Loading branch information
GiorgiB97 authored May 4, 2017
2 parents c1f31f5 + 1e77e59 commit f222770
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
29 changes: 18 additions & 11 deletions gulp/generators/module-generator/generator.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* eslint-disable no-console */
/**
* Created by george on 4/18/17.
*/

var gulp = require('gulp');
var replace = require('gulp-replace');
var rename = require('gulp-rename');
var colors = require('colors');
var fs = require('fs');


function processArguments(args) {
//Creating empty hash map
var argsMap = {};
Expand Down Expand Up @@ -48,6 +49,7 @@ function processArguments(args) {
function validateArgs(argsMap) {
//Defining path value
var path = argsMap["--path"];
var errorSuffix = "The path is relative to src/app folder";

//Checking if there is '--path' argument in hashmap
if (argsMap.hasOwnProperty("--path") != false) {
Expand All @@ -62,42 +64,47 @@ function validateArgs(argsMap) {
return true;
}
}
//If no value is defined for path
//If no value is defined for --path
else {
console.log("NO PATH VALUE DEFINED");
console.log(("--path argument requires full path (including module name). " + errorSuffix).red);
return false;
}
}
//If no path argument is defined
//If no --path argument is defined
else {
console.log("NO PATH ARGUMENT DEFINED");
console.log(("Please specify --path argument with full path (including module name). " + errorSuffix).red);
return false;
}
}

function generateModule(params) {
var streams = {
var fileSuffix = {
'module.txt': ".module.js",
'controller.txt': ".controller.js",
'html.txt': ".html",
'less.txt': ".less"
};

for (var s in streams) {
for (var s in fileSuffix) {

//Creating stream
var stream = gulp.src('gulp/generators/module-generator/template/'+s);
var stream = gulp.src('gulp/generators/module-generator/template/' + s);

//Replacing all matching strings with custom strings
for (var i in params) {
stream.pipe(replace("{{" + i + "}}", params[i]));
}

var filePath = 'src/app/' + params.ModulePath + '/' + params.FolderName + fileSuffix[s];
if (fs.existsSync(filePath)) {
console.log(("[Skipping] ".yellow + filePath).yellow);
continue;
}
//Saving
stream.pipe(rename(params.ModulePath.split("/").pop() + streams[s]))
stream.pipe(rename(params.FolderName + fileSuffix[s]))
.pipe(gulp.dest('src/app/' + params.ModulePath + '/'));

console.log("src/app/"+params['ModulePath']+"/"+params['FolderName']+streams[s]+" Generated");
console.log("[Creating] ".green + filePath);
}
}

Expand Down Expand Up @@ -129,4 +136,4 @@ String.prototype.ucFirst = function () {
};
String.prototype.lcFirst = function () {
return this.valueOf()[0].toLowerCase() + this.valueOf().substring(1);
};
};
14 changes: 7 additions & 7 deletions gulp/generators/module-generator/template/controller.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

/** @ngInject */
function {{ControllerName}}Fn(){
// var vm = this;
// var vm = this;

// Data
// Data


// Methods
// Methods


init();
init();

///////////
///////////

function init(){
function init(){

}
}
}
})();
2 changes: 1 addition & 1 deletion gulp/generators/module-generator/template/html.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div id="{{ModuleName}}">
{{ModuleContent}}
{{ModuleContent}}
</div>
2 changes: 1 addition & 1 deletion gulp/generators/module-generator/template/less.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#{{ModuleName}}{

}
}
1 change: 0 additions & 1 deletion gulp/generators/module-generator/template/module.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
text: '{{ModuleDisplayName}}',
state: 'app.{{ModuleName}}',
weight: 1
// icon: 'fa fa-table'
});
}
})();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"browser-sync": "~2.9.11",
"browser-sync-spa": "~1.0.3",
"chalk": "~1.1.1",
"colors": "^1.1.2",
"del": "~2.0.2",
"eslint-plugin-angular": "~0.12.0",
"estraverse": "~4.1.0",
Expand Down

0 comments on commit f222770

Please sign in to comment.