-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug with bundle analyzer
- Loading branch information
Marvin Heilemann
committed
Sep 26, 2019
1 parent
a3408b3
commit 2bc4dd5
Showing
8 changed files
with
81 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,75 @@ | ||
const pkg = require('../package.json') | ||
|
||
/** | ||
* Get env info. | ||
*/ | ||
const activeEnv = | ||
process.env.GATSBY_ACTIVE_ENV || process.env.NODE_ENV || 'development' | ||
const isDev = activeEnv === 'development' | ||
const isProd = activeEnv === 'production' | ||
|
||
/** | ||
* Slugify a string. | ||
*/ | ||
const slugify = (text, separator) => { | ||
text = text | ||
.toString() | ||
.toLowerCase() | ||
.trim() | ||
.replace(/\s+/g, '-') // Replace spaces with - | ||
.replace(/&/g, '-and-') // Replace & with 'and' | ||
.replace(/[^\w-]+/g, '') // Remove all non-word chars | ||
.replace(/-+/g, '-') // Replace multiple - with single - | ||
.replace(/^-+/, '') // Trim - from start of text | ||
.replace(/-+$/, '') // Trim - from end of text | ||
.replace(/[·/_,:;']/g, '-') // Replace unwanted characters with - | ||
|
||
if (separator && separator !== '-') { | ||
text = text.replace(/-/g, separator) | ||
} | ||
|
||
return text | ||
} | ||
|
||
/** | ||
* Print a image to the console. | ||
*/ | ||
const consoleImage = (src, scale = 50) => { | ||
const img = new Image() | ||
|
||
img.onload = function() { | ||
const width = Math.floor((this.width / 100) * scale) | ||
const height = Math.floor((this.height / 100) * scale) | ||
const style = ` | ||
font-size: 1px; | ||
padding: ${height}px ${width}px; | ||
background: url(${src}) no-repeat; | ||
background-size: contain; | ||
` | ||
console.log('%c ', style) | ||
} | ||
|
||
img.src = src | ||
} | ||
|
||
/** | ||
* Return current version, but only minor, major, patches will always be zero. | ||
* | ||
* @param {boolean} dots Remove dots from version | ||
*/ | ||
function getNewVersion(dots = true) { | ||
const getPkgVersion = (dots = true) => { | ||
let version = pkg.version.replace(/\.(?:.(?!\.))+$/, '.0') | ||
if (!dots) { | ||
version = version.replace(/\./g, '') | ||
} | ||
return version | ||
} | ||
|
||
module.exports = { getNewVersion } | ||
module.exports = { | ||
getPkgVersion, | ||
activeEnv, | ||
isDev, | ||
isProd, | ||
slugify, | ||
consoleImage, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters