-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.js
More file actions
24 lines (24 loc) · 1021 Bytes
/
plugin.js
File metadata and controls
24 lines (24 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module.exports = function (babel, options) {
const { types: t } = babel;
const { version, env } = options;
return {
name: "push elements in array",
visitor: {
VariableDeclarator(path) {
const node = path.node;
if (node.id.name == "service_config") {
// 获取环境索引
let envIndex = node.init.properties.findIndex(item=>item.key.name===env)
// 获取版本号变量索引
let versionRecordIndex = node.init.properties[envIndex].value.properties.findIndex(item=>item.key.name==='versionRecord')
if(env==='development'){
node.init.properties[envIndex].value.properties[versionRecordIndex].value.elements=[t.identifier(`"${version}"`)];
}else{
node.init.properties[envIndex].value.properties[versionRecordIndex].value.elements.unshift(t.identifier(`"${version}"`));
}
// node.init.elements = [ t.identifier(`"${version}"`),...node.init.elements];
}
},
},
};
};