1 |
|
2 | (function() {
|
3 | module.exports = function(path) {
|
4 | var cson, fs, i, j, k, len, len1, model_data, model_file, model_files, model_name, model_path, ref, spec, yaml;
|
5 | cson = require('season');
|
6 | fs = require('fs');
|
7 | yaml = require('js-yaml');
|
8 | if (!path) {
|
9 | if (!this.path) {
|
10 | return false;
|
11 | }
|
12 | path = this.path + "/src/spec";
|
13 | }
|
14 | if (this.config.type === 'generator') {
|
15 | if (this.config.specifications && this.config.specifications["default"]) {
|
16 | ref = this.config.specifications["default"];
|
17 | for (j = 0, len = ref.length; j < len; j++) {
|
18 | i = ref[j];
|
19 | path = userHome + "/.autocode/spec/" + i + "/src/spec";
|
20 | break;
|
21 | }
|
22 | }
|
23 | }
|
24 | spec = {};
|
25 | model_path = path + "/model/";
|
26 | if (fs.existsSync(model_path)) {
|
27 | model_files = fs.readdirSync(model_path);
|
28 | if (model_files.length) {
|
29 | spec.models = {};
|
30 | for (k = 0, len1 = model_files.length; k < len1; k++) {
|
31 | model_file = model_files[k];
|
32 | model_file = model_path + model_file;
|
33 | model_name = model_file.split('/');
|
34 | model_name = model_name[model_name.length - 1];
|
35 | model_name = model_name.split('.');
|
36 | model_name = model_name[0];
|
37 | model_data = (function() {
|
38 | switch (true) {
|
39 | case model_file.match(/\.yml$/i) !== null:
|
40 | case model_file.match(/\.yaml$/i) !== null:
|
41 | return yaml.safeLoad(fs.readFileSync(model_file));
|
42 | case model_file.match(/\.cson$/i) !== null:
|
43 | return cson.readFileSync(model_file);
|
44 | default:
|
45 | throw new Error("Unknown file format for model (" + model_name + ")");
|
46 | }
|
47 | })();
|
48 | spec.models[model_name] = model_data;
|
49 | }
|
50 | }
|
51 | }
|
52 | return spec;
|
53 | };
|
54 |
|
55 | }).call(this);
|