Extract the version extract from webpack config (#5798)

This commit is contained in:
Paulus Schoutsen 2020-05-07 10:26:02 -07:00 committed by GitHub
parent b69d5e0fa3
commit b6309cfd16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 11 deletions

View File

@ -1,3 +1,7 @@
const fs = require("fs");
const path = require("path");
const paths = require("./paths.js");
module.exports = { module.exports = {
isProdBuild() { isProdBuild() {
return process.env.NODE_ENV === "production"; return process.env.NODE_ENV === "production";
@ -11,4 +15,13 @@ module.exports = {
isNetlify() { isNetlify() {
return process.env.NETLIFY === "true"; return process.env.NETLIFY === "true";
}, },
version() {
const version = fs
.readFileSync(path.resolve(paths.polymer_dir, "setup.py"), "utf8")
.match(/\d{8}\.\d+/);
if (!version) {
throw Error("Version not found");
}
return version[0];
},
}; };

View File

@ -1,20 +1,12 @@
const webpack = require("webpack"); const webpack = require("webpack");
const fs = require("fs");
const path = require("path"); const path = require("path");
const TerserPlugin = require("terser-webpack-plugin"); const TerserPlugin = require("terser-webpack-plugin");
const WorkboxPlugin = require("workbox-webpack-plugin"); const WorkboxPlugin = require("workbox-webpack-plugin");
const ManifestPlugin = require("webpack-manifest-plugin"); const ManifestPlugin = require("webpack-manifest-plugin");
const paths = require("./paths.js"); const paths = require("./paths.js");
const env = require("./env.js");
const { babelLoaderConfig } = require("./babel.js"); const { babelLoaderConfig } = require("./babel.js");
let version = fs
.readFileSync(path.resolve(paths.polymer_dir, "setup.py"), "utf8")
.match(/\d{8}\.\d+/);
if (!version) {
throw Error("Version not found");
}
version = version[0];
const createWebpackConfig = ({ const createWebpackConfig = ({
entry, entry,
outputRoot, outputRoot,
@ -71,7 +63,7 @@ const createWebpackConfig = ({
new webpack.DefinePlugin({ new webpack.DefinePlugin({
__DEV__: !isProdBuild, __DEV__: !isProdBuild,
__BUILD__: JSON.stringify(latestBuild ? "latest" : "es5"), __BUILD__: JSON.stringify(latestBuild ? "latest" : "es5"),
__VERSION__: JSON.stringify(version), __VERSION__: JSON.stringify(env.version()),
__DEMO__: false, __DEMO__: false,
__BACKWARDS_COMPAT__: false, __BACKWARDS_COMPAT__: false,
__STATIC_PATH__: "/static/", __STATIC_PATH__: "/static/",
@ -193,7 +185,7 @@ const createDemoConfig = ({ isProdBuild, latestBuild, isStatsBuild }) => {
}, },
outputRoot: paths.demo_root, outputRoot: paths.demo_root,
defineOverlay: { defineOverlay: {
__VERSION__: JSON.stringify(`DEMO-${version}`), __VERSION__: JSON.stringify(`DEMO-${env.version()}`),
__DEMO__: true, __DEMO__: true,
}, },
isProdBuild, isProdBuild,