-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
91 lines (86 loc) · 2.68 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// cli usage for webgme-cli
var Q = require("q");
var utils = require("./src/utils");
var _ = require("lodash");
var webgme = {};
[
require("./src/PluginManager"),
require("./src/AddonManager"),
require("./src/SeedManager"),
require("./src/LayoutManager"),
require("./src/DecoratorManager"),
require("./src/RouterManager"),
require("./src/VisualizerManager"),
].forEach(function (Component) {
var component = new Component();
webgme[component._name] = component;
});
// Add 'all' option
webgme.all = {};
webgme.all.import = function (projectName, opts, callback) {
let rootPath;
opts = opts || {};
return Q()
.then(() => {
// ensure in a webgme app dir. Move to the root.
rootPath = utils.getRootPath();
if (!rootPath) {
throw new Error(
"Could not find a project in current or any parent directories"
);
}
process.chdir(rootPath);
})
.then(() => {
// install the project
let deferred = Q.defer();
utils.installProject(projectName, false, (err, config) => {
if (err) return deferred.reject(err);
deferred.resolve(config);
});
return deferred.promise;
})
.then(() => {
// read in the webgme-cli config for the given project
projectName = opts.packageName || utils.getPackageName(projectName);
projectName = projectName.toLowerCase();
let configPath = utils.getConfigPath(projectName);
let config = require(configPath);
return config;
})
.then((config) => {
// import each of the components
const components = config.components;
const types = Object.keys(components);
return Q.all(
types.map((type) => {
const managerId = type.replace(/s$/, ""); // make it singular...
const names = Object.keys(components[type]);
const imports = names.map((name) => {
const args = {
name: name,
project: projectName,
skipInstall: true,
};
return webgme[managerId].import(args);
});
return Q.all(imports);
})
).then(() => config);
})
.then((config) => {
// import-all on each of the dependencies
const deps = config.dependencies;
const types = Object.keys(deps);
const allProjects = types
.map((type) => {
const names = Object.keys(deps[type]);
return names.map((name) => deps[type][name].project);
})
.reduce((l1, l2) => l1.concat(l2), []);
const projects = _.uniq(allProjects);
return Q.all(projects.map((project) => webgme.all.import(project)));
})
.nodeify(callback);
};
module.exports = webgme;