-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·69 lines (50 loc) · 1.71 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
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env node
var argv = process.argv;
argv.shift();
var file_path = __dirname;
var current_path = process.cwd();
var home_dir = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
argv.shift();
var clo_home = home_dir + '/.clo'
var module_name = argv.shift();
var module_home = clo_home + '/' + module_name;
// argv.shift();
console.log('clo_home= ' + clo_home)
console.log('module_home= ' + module_home)
console.log('tpl params=' + argv)
var clo_json = module_home + '/clo.json';
console.log('clo_json=' + clo_json)
var loadjson = require('loadjson')
var config = loadjson(clo_json)
if (!config.error){
generate(module_name, module_home, config, argv);
}else{
console.log(config.error);
process.exit();
}
// console.log(home_dir);
function generate(module_name, module_home, config, arg){
var files = config.files;
console.log('----------------generate start----------------');
console.log('tpl files=' + files);
console.log('tpl arg=' + arg);
files.forEach(function(file){
generate_one(config, module_name, module_home, file, arg)
})
console.log('----------------generate end----------------');
}
function generate_one(config, module_name, module_home, file, arg){
var Inflector = require('inflected');
var tpl = require('tpl_apply');
var file_post = file.split('.')[1];
var new_file = config.file_pre + Inflector.camelize(arg[0]) + config.file_post + "." + file_post
var source = module_home + '/' + file
var dest = process.cwd() + '/' + new_file;
var obj_params = {}
for(var i=0; i < arg.length; i++){
var p = "arg" + i;
var script = "obj_params." + p + " ='" + arg[i] + "'";
obj_params[p] = arg[i]
}
tpl.tpl_apply(source, obj_params, dest);
}