Updates definition build script for babel 7.0 (#5024)

* Updates definition build script for babel 7.0

* run eslint on staged files
This commit is contained in:
Florent Vilmart
2018-09-08 14:12:23 -04:00
committed by GitHub
parent fefecfeb9a
commit 617e8405ff
4 changed files with 103 additions and 68 deletions

View File

@@ -56,23 +56,35 @@ function getENVPrefix(iface) {
function processProperty(property, iface) {
const firstComment = getCommentValue(last(property.leadingComments || []));
const lastComment = getCommentValue((property.trailingComments || [])[0]);
const name = property.key.name;
const prefix = getENVPrefix(iface);
if (!firstComment) {
return;
}
const components = firstComment.split(':ENV:').map((elt) => {
return elt.trim();
const lines = firstComment.split('\n').map((line) => line.trim());
let help = '';
let envLine;
let defaultLine;
lines.forEach((line) => {
if (line.indexOf(':ENV:') === 0) {
envLine = line;
} else if (line.indexOf(':DEFAULT:') === 0) {
defaultLine = line;
} else {
help += line;
}
});
let defaultValue;
if (lastComment && lastComment.indexOf('=') >= 0) {
const slice = lastComment.slice(lastComment.indexOf('=') + 1, lastComment.length).trim();
defaultValue = slice;
let env;
if (envLine) {
env = envLine.split(' ')[1];
} else {
env = (prefix + toENV(name));
}
let defaultValue;
if (defaultLine) {
defaultValue = defaultLine.split(' ')[1];
}
const help = components[0];
const env = components[1] || (prefix + toENV(name));
let type = property.value.type;
let isRequired = true;
if (type == 'NullableTypeAnnotation') {
@@ -249,8 +261,7 @@ This code has been generated by resources/buildConfigDefinitions.js
Do not edit manually, but update Options/index.js
`
const babel = require("babel-core");
const res = babel.transformFileSync('./src/Options/index.js', { plugins: [ plugin ], auxiliaryCommentBefore, sourceMaps: false });
const babel = require("@babel/core");
const res = babel.transformFileSync('./src/Options/index.js', { plugins: [ plugin, '@babel/transform-flow-strip-types' ], babelrc: false, auxiliaryCommentBefore, sourceMaps: false });
require('fs').writeFileSync('./src/Options/Definitions.js', res.code + '\n');
require('fs').writeFileSync('./src/Options/docs.js', docs);