Repository navigation
Expand file tree
/
Copy pathbuildInjector.js
More file actions
53 lines (44 loc) · 1.54 KB
/
Copy pathbuildInjector.js
File metadata and controls
53 lines (44 loc) · 1.54 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
/* global buildInjectorJs:true */
buildInjectorJs = function buildInjectorJs (deps, moduleNames) {
var str = `/** THIS FILE IS AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n`
str += `let deps = {}\n\n`
var i = 0
for (var key in deps) {
if (
(deps[key].indexOf('client') !== -1 && deps[key].indexOf('server') !== -1) ||
(deps[key].indexOf('client') === -1 && deps[key].indexOf('server') === -1)
) {
str += `import * as dep_${i} from 'meteor/${key.toLowerCase()}'\n`
str += `deps = Object.assign(deps, dep_${i})\n\n`
} else {
var locus = deps[key].indexOf('client') !== -1
? 'Client'
: 'Server'
str += `if (Meteor.is${locus}) {\n`
str += ` import * as dep_${i} from 'meteor/${key.toLowerCase()}'\n`
str += ` deps = Object.assign(deps, dep_${i})\n`
str += `}\n\n`
}
i++
}
for (var moduleName of moduleNames) {
str += `try {\n`
str += ` const { inject: inject_${i} } = require('${moduleName}/node_modules/@webantic/meteor-deps')\n`
str += ` inject_${i} && inject_${i}(deps)\n`
str += `} catch (ex) {\n`
str += ` if (process.env.INJECTOR_DEBUG) {\n`
str += ` console.error(ex)\n`
str += ` }\n`
str += `}\n\n`
i++
}
str += `try {\n`
str += ` const { inject: inject_${i} } = require('@webantic/meteor-deps')\n`
str += ` inject_${i} && inject_${i}(deps)\n`
str += `} catch (ex) {\n`
str += ` if (process.env.INJECTOR_DEBUG) {\n`
str += ` console.error(ex)\n`
str += ` }\n`
str += `}\n\n`
return str
}