-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcoprogen.js
More file actions
executable file
·79 lines (65 loc) · 2.25 KB
/
coprogen.js
File metadata and controls
executable file
·79 lines (65 loc) · 2.25 KB
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
78
79
#! /usr/bin/env node
'use strict';
var fs = require('fs'),
ContentProviderGenerator = require('./lib'),
argv = require('optimist').argv,
destinationPath = process.cwd(),
contentProviderConfig = process.cwd() + '/content-provider.json',
modelsConfig = process.cwd() + '/models.json',
coprogen = new ContentProviderGenerator(),
data,
usage;
function processData(destination, data) {
var dataJson;
if (argv.data) {
if (fs.existsSync(argv.data)) {
dataJson = require(process.cwd() + '/' + argv.data);
} else {
dataJson = JSON.parse(argv.data);
}
for (var key in dataJson) {
data[key] = dataJson[key];
}
}
if (!data.relationships) {
data.relationships = [];
}
coprogen.generate(destination, data, function(err) {
if (err) console.log('coprogen error: ' + err);
console.log('coprogen has completed successfully!');
});
};
usage = function() {
console.log('\ncoprogen usage:\n\n' +
'Run from a directory that contains a content-provider.json or\n' +
'models.json config file, or provide the path as an argument:\n' +
' coprogen --path <relative path to content provider config file>\n\n' +
'You may also provide the destination directory as an argument:\n' +
' coprogen --dest <relative path to the destination directory>\n\n' +
'Finally, you may also override or provide additional template \n' +
'data with the data parameter:\n' +
' coprogen --data \'{"authority": "com.custom.authority"}\'\n'+
' coprogen --data <relative path to .json file>');
process.exit(1);
};
if (argv.path) {
contentProviderConfig = process.cwd() + '/' + argv.path;
}
if (argv.dest) {
destinationPath = process.cwd() + '/' + argv.dest;
}
fs.exists(contentProviderConfig, function(exists) {
if (exists) {
data = require(contentProviderConfig);
processData(destinationPath, data);
} else {
fs.exists(modelsConfig, function(exists) {
if (exists) {
data = require(modelsConfig);
processData(destinationPath, data);
} else {
usage();
}
});
}
});