forked from intershop/intershop-pwa
-
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.
feat: provide deploy-url as runtime property (intershop#630)
- Loading branch information
Showing
12 changed files
with
149 additions
and
28 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 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// tslint:disable: ish-ordered-imports ban-specific-imports no-console | ||
import * as fs from 'fs'; | ||
import * as glob from 'glob'; | ||
import * as path from 'path'; | ||
import { setDeployUrlInFile } from '../src/ssr/deploy-url'; | ||
|
||
if (process.argv.length < 3) { | ||
console.error('required argument deployUrl missing'); | ||
process.exit(1); | ||
} | ||
|
||
let deployUrl = process.argv[2]; | ||
|
||
if (!deployUrl.endsWith('/')) { | ||
deployUrl += '/'; | ||
} | ||
|
||
glob.sync('dist/browser/*.{js,css,html}').forEach(file => { | ||
console.log(`setting deployUrl "${deployUrl}" in`, file); | ||
|
||
const input = fs.readFileSync(file, { encoding: 'utf-8' }); | ||
|
||
const output = setDeployUrlInFile(deployUrl, path.basename(file), input); | ||
|
||
fs.writeFileSync(file, output); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export function getDeployURLFromEnv(): string { | ||
const envDeployUrl = process.env.DEPLOY_URL || '/'; | ||
|
||
return `${envDeployUrl}${envDeployUrl.endsWith('/') ? '' : '/'}`; | ||
} | ||
|
||
export function setDeployUrlInFile(deployUrl: string, path: string, input: string): string { | ||
if (input) { | ||
if (path.startsWith('runtime') && path.endsWith('.js')) { | ||
return input.replace(/DEPLOY_URL_PLACEHOLDER/g, deployUrl); | ||
} | ||
|
||
let newInput = input; | ||
|
||
const cssRegex = /url\((?!http)\/?(assets.*?|[a-zA-Z].*?woff2?)\)/g; | ||
if (cssRegex.test(newInput)) { | ||
newInput = newInput.replace(cssRegex, (...args) => `url(${deployUrl}${args[1]})`); | ||
} | ||
|
||
const assetsRegex = /"\/?(assets[^"]*\.(\w{2,5}|webmanifest)|[a-z0-9]+\.css)"/g; | ||
if (assetsRegex.test(newInput)) { | ||
newInput = newInput.replace(assetsRegex, (...args) => `"${deployUrl}${args[1]}"`); | ||
} | ||
|
||
const javascriptRegex = /"(DEPLOY_URL_PLACEHOLDER|\/)?((runtime|vendor|main|polyfills|styles)[^"]*\.(js|css))"/g; | ||
if (javascriptRegex.test(newInput)) { | ||
newInput = newInput.replace(javascriptRegex, (...args) => `"${deployUrl}${args[2]}"`); | ||
} | ||
|
||
return newInput; | ||
} | ||
return input; | ||
} |
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 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