forked from apla/dataflo.ws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
116 lines (93 loc) · 2.72 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
var define;
if (typeof define === "undefined") {
define = function (classInstance) {
classInstance (require, exports, module);
};
}
var registry = {};
define (function (require, exports, module) {
var MODULE_NAME = 'dataflo.ws';
var INITIATOR_PATH = 'initiator';
var path = require ('path');
fs = require ('fs');
common = require ('./common');
if ($isServerSide) {
}
var instanceTypes = [ 'initiator', 'task' ];
// - - -
function registryLookup (instanceType, instanceName) {
var instanceClass = registry[instanceType] &&
registry[instanceType][instanceName];
if (!instanceClass) {
if ($isClientSide) {
console.error (
'you need to run dataflows.register ("'
+instanceType+'", "'+instanceName
+'", instance) before using this task');
}
var fixedName = instanceName;
if (instanceType == 'initiator') {
fixedName = instanceName.replace(/d$/, '');
if (fixedName !== instanceName) {
console.warn(
'[DEPRECATED] Remove trailing "d" from "%s" in your initiator config',
instanceName
);
}
} else if (instanceType == 'task') {
fixedName = instanceName.replace(/^(dataflo\.ws\/)?task\//, '');
if (fixedName !== instanceName) {
console.warn(
'[DEPRECATED] Remove preceding "task/" from "%s" in your task config',
instanceName
);
}
}
var project = common.getProject();
instanceClass = project.getModule (instanceType, fixedName);
}
return registry[instanceType][instanceName] = instanceClass;
};
instanceTypes.forEach(function(instanceType) {
registry[instanceType] = {};
module.exports[instanceType] = function (instanceName) {
return registryLookup (instanceType, instanceName);
};
});
// - - -
/**
* Makes symlinks from modules to base dataflo.ws directory.
*/
module.exports.install = function (moduleName) {
var baseDir = path.dirname(require.resolve(MODULE_NAME));
var nodePath = path.dirname(baseDir);
var moduleDir = path.join(nodePath, moduleName);
instanceTypes.forEach(function (dir) {
var srcDir = path.join(moduleDir, dir);
var destDir = path.join(baseDir, dir);
if (fs.existsSync(srcDir)) {
var files = fs.readdirSync(srcDir);
files.forEach(function (fileName) {
var srcPath = path.join(srcDir, fileName);
var destPath = path.join(destDir, fileName);
if (!fs.existsSync(destPath)) {
fs.symlinkSync(srcPath, destPath);
}
});
}
});
};
/**
* Register base entities for dataflo.ws processing.
*/
module.exports.register = function (instanceType, instanceName, instanceClass) {
if (!registry[instanceType]) {
console.warn(
'Unexpected instance type. Predefined types is: ['+instanceTypes.join(', ')+']'
);
return;
}
registry[instanceType][instanceName] = instanceClass;
};
module.exports.common = common;
});