-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·59 lines (52 loc) · 2.74 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
var program = require('commander');
var createFile = require('create-file');
var promptly = require('promptly');
var chalk = require('chalk');
var fs = require('file-system');
var readJSON = require('read-json')
program
.version('0.0.2')
.command('generate <name> [dependencies...]')
.alias('g')
.description('\nGenerate an angular controller, you can pass all the dependencies you want to add to your controller \n'+chalk.bold.yellow('(Remember to add a \\ before characters as \$)'))
.action(function() {
fs.exists('rounded.json', (exists) => {
if (exists) {
var controllerName = arguments[0];
var dependenciesInj = "";
var dependencies = "";
for (var dep in arguments[1]) {
dependencies += arguments[1][dep] + ", ";
dependenciesInj += "'" + arguments[1][dep] + "'" + ", ";
}
var depLength = dependencies.length;
readJSON('rounded.json', function(error, manifest) {
var projName = manifest.projectName;
var path = manifest.pathToController;
if (depLength != 0) {
var controllerContent = "angular.module('" + projName + "').controller('" + controllerName + "', ['$scope', '$rootScope', " + dependenciesInj + " function($scope, $rootScope, " + dependencies + ") { \n\n\n}]);";
} else {
var controllerContent = "angular.module('" + projName + "').controller('" + controllerName + "', ['$scope', '$rootScope', function($scope, $rootScope) { \n\n\n}]);"
}
createFile(path + controllerName + ".js", controllerContent, function(err) {
console.log(chalk.bold.cyan('File created: ') + path + controllerName + ".js");
});
});
} else {
console.log(chalk.bold.red('You need to init Rounded First'));
console.log(chalk.bold.green("Starting Init"));
var projectName = "";
promptly.prompt('Insert project name: ').then(function(value) {
projectName = value;
var pathToController = "";
promptly.prompt('Where should I save the files? ').then(function(value) {
pathToController = value;
var ecosystemJson = '{"projectName" : "' + projectName + '","pathToController" : "' + pathToController + '"}';
createFile("rounded.json", ecosystemJson, function(err) {});
});
});
}
});
});
program.parse(process.argv);