-
Notifications
You must be signed in to change notification settings - Fork 360
/
Copy pathbabel-plugin-inject-package-version.js
57 lines (53 loc) · 1.63 KB
/
babel-plugin-inject-package-version.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
/*!
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
*/
const t = require('@babel/types');
const {version} = require('../packages/webex/package.json');
/**
* Simple babel transform for ensuring that every WebexPlugin (and WebexCore)
* have the correct version property
* @returns {Object}
*/
module.exports = function injectPackageVersion() {
return {
visitor: {
/**
* Adds a version property to all SparkPlugins
* @param {Object} path
*/
CallExpression(path) {
if (t.isMemberExpression(path.get('callee'))) {
if (
path.node.callee.object.name === 'WebexPlugin' &&
path.node.callee.property.name === 'extend'
) {
const def = path.node.arguments[0];
const visited = def.properties.reduce(
(acc, p) => acc || t.isObjectProperty(p, {key: 'version'}),
false
);
/**
* TODO: We need to find a way to avoid injection while running locally.
* Also need to figure out version injection into CDN before releasing
* Calling SDK.
*/
if (!visited) {
def.properties.push(
t.objectProperty(t.identifier('version'), t.stringLiteral('0.0.0-next'))
);
}
}
}
},
/**
* Replaces the PACKAGE_VERSION constant with the current version
* @param {Object} path
*/
Identifier(path) {
if (path.node.name === 'PACKAGE_VERSION') {
path.replaceWithSourceString(`\`${version}\``);
}
},
},
};
};