-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathngcli.js
77 lines (64 loc) · 2.78 KB
/
ngcli.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var program = require('commander');
var fs = require('fs')
var path = require('path');
program
.version('0.2.0')
.command('createComponent [name]')
.action(function(name){
if(name === undefined){
console.log('no args given')
} else {
console.log(name);
var componentTemplate = require('./templates/component.js')(name);
var controllerTemplate = require('./templates/controller.js')(name);
var viewTemplate = `<h1>Vista: ${name}</h1>`
fs.mkdir(path.join(__dirname, `/src/js/components/${name}Component`), function(err){
if(err)throw err;
console.log(`Folder ${name}Component created successfully!!`);
fs.appendFile(`${__dirname}/src/js/components/${name}Component/${name}.component.js`, componentTemplate, (err)=>{
if(err)throw err;
console.log(`File: ${name}.component.js created successfully!!`);
});
fs.appendFile(`${__dirname}/src/js/components/${name}Component/${name}.ctrl.js`, controllerTemplate, (err)=>{
if(err)throw err;
console.log(`File: ${name}.ctrl.js created successfully!!`);
});
fs.mkdir(path.join(__dirname, `/public/partials/${name}`), function(err){
if(err)throw err;
console.log(`Folder ${name} created successfully!!`);
fs.appendFile(`${__dirname}/public/partials/${name}/${name}.component.html`, viewTemplate, (err)=>{
if(err)throw err;
console.log(`File: ${name}.component.html created successfully!!`);
});
});
});
/*
fs.readFileSync() or fs.readFile('', (err)=>{}) ... Sync or Async
*/
let rawjson = fs.readFileSync('componentServices.json');
let componentServices = JSON.parse(rawjson);
componentServices.components.push(name);
let processedData = JSON.stringify(componentServices, null, 2);
fs.writeFileSync('componentServices.json', processedData);
let processedJSON = JSON.parse(processedData);
let componentModuleTemplate = require('./templates/componentModule.js')(processedJSON);
fs.writeFile(`${__dirname}/src/js/components/components.module.js`, componentModuleTemplate, (err)=>{
if(err)throw err;
console.log(`File: /src/js/components/components.module.js has been updated successfully!!`);
});
}
});
program
.command('createService [name]')
.action(function(name){
if(name === undefined){
console.log('no args given')
}else{
console.log(name);
var serviceTemplate = require('./templates/service.js')(name);
fs.appendFile(`${__dirname}/src/js/services/${name}.service.js`, serviceTemplate, (err)=>{
if(err)throw err;
console.log(`File: ${name}.service.js created successfully!!`);
});
}
});