-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/logo building #89
Changes from all commits
4218598
cdcf828
60aec47
cce82a0
7961085
d80181d
1837f49
1238118
294b1e2
e6bfdf2
7a085c2
4d7ce02
d3e71b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"PROJECT_TYPE": "front-tier", | ||
"web": { | ||
"projectName": "@paypal/sdk-logos", | ||
"staticDirectory": "cdn", | ||
"staticNamespace": "js-sdk-logos" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "@krakenjs/babel-config-grumbler/babelrc-node" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/* @flow */ | ||
|
||
import fs from "fs-extra"; | ||
import { $ } from "zx"; | ||
import { html } from "@krakenjs/jsx-pragmatic"; | ||
|
||
import { getSVGFilename } from "../src/lib"; | ||
import { LOGO } from "../src/constants"; | ||
import { | ||
APPLEPAY_LOGO_COLORS, | ||
BANCONTACT_LOGO_COLORS, | ||
BLIK_LOGO_COLORS, | ||
BOLETO_LOGO_COLORS, | ||
EPS_LOGO_COLORS, | ||
getApplepaySVG, | ||
getBancontactSVG, | ||
getBlikSVG, | ||
getBoletoSVG, | ||
getEpsSVG, | ||
getGiropaySVG, | ||
getIdealSVG, | ||
getItauSVG, | ||
getMaximaSVG, | ||
getMercadoPagoSVG, | ||
getMultibancoSVG, | ||
getMybankSVG, | ||
getOxxoSVG, | ||
getP24SVG, | ||
getPaidySVG, | ||
getPayuSVG, | ||
getSatispaySVG, | ||
getSepaSVG, | ||
getSofortSVG, | ||
getTrustlySVG, | ||
getVerkkopankkiSVG, | ||
getWechatpaySVG, | ||
getZimplerSVG, | ||
GIROPAY_LOGO_COLORS, | ||
IDEAL_LOGO_COLORS, | ||
ITAU_LOGO_COLORS, | ||
MAXIMA_LOGO_COLORS, | ||
MERCADOPAGO_LOGO_COLORS, | ||
MULTIBANCO_LOGO_COLORS, | ||
MYBANK_LOGO_COLORS, | ||
OXXO_LOGO_COLORS, | ||
P24_LOGO_COLORS, | ||
PAIDY_LOGO_COLORS, | ||
PAYU_LOGO_COLORS, | ||
SATISPAY_LOGO_COLORS, | ||
SEPA_LOGO_COLORS, | ||
SOFORT_LOGO_COLORS, | ||
TRUSTLY_LOGO_COLORS, | ||
VERKKOPANKKI_LOGO_COLORS, | ||
WECHATPAY_LOGO_COLORS, | ||
ZIMPLER_LOGO_COLORS, | ||
} from "../src/logos"; | ||
import { version } from "../package.json"; | ||
|
||
import { getNodeOps, updateCDNUrl } from "./utils"; | ||
|
||
const LOGO_GETTERS = { | ||
[LOGO.APPLEPAY]: getApplepaySVG, | ||
[LOGO.BANCONTACT]: getBancontactSVG, | ||
[LOGO.BLIK]: getBlikSVG, | ||
[LOGO.BOLETO]: getBoletoSVG, | ||
[LOGO.EPS]: getEpsSVG, | ||
[LOGO.GIROPAY]: getGiropaySVG, | ||
[LOGO.IDEAL]: getIdealSVG, | ||
[LOGO.ITAU]: getItauSVG, | ||
[LOGO.MAXIMA]: getMaximaSVG, | ||
[LOGO.MERCADOPAGO]: getMercadoPagoSVG, | ||
[LOGO.MULTIBANCO]: getMultibancoSVG, | ||
[LOGO.MYBANK]: getMybankSVG, | ||
[LOGO.OXXO]: getOxxoSVG, | ||
[LOGO.P24]: getP24SVG, | ||
[LOGO.PAIDY]: getPaidySVG, | ||
[LOGO.PAYU]: getPayuSVG, | ||
[LOGO.SATISPAY]: getSatispaySVG, | ||
[LOGO.SEPA]: getSepaSVG, | ||
[LOGO.SOFORT]: getSofortSVG, | ||
[LOGO.TRUSTLY]: getTrustlySVG, | ||
[LOGO.VERKKOPANKKI]: getVerkkopankkiSVG, | ||
[LOGO.WECHATPAY]: getWechatpaySVG, | ||
[LOGO.ZIMPLER]: getZimplerSVG, | ||
}; | ||
|
||
const LOGO_COLOR_MAPS = { | ||
[LOGO.APPLEPAY]: APPLEPAY_LOGO_COLORS, | ||
[LOGO.BANCONTACT]: BANCONTACT_LOGO_COLORS, | ||
[LOGO.BLIK]: BLIK_LOGO_COLORS, | ||
[LOGO.BOLETO]: BOLETO_LOGO_COLORS, | ||
[LOGO.EPS]: EPS_LOGO_COLORS, | ||
[LOGO.GIROPAY]: GIROPAY_LOGO_COLORS, | ||
[LOGO.IDEAL]: IDEAL_LOGO_COLORS, | ||
[LOGO.ITAU]: ITAU_LOGO_COLORS, | ||
[LOGO.MAXIMA]: MAXIMA_LOGO_COLORS, | ||
[LOGO.MERCADOPAGO]: MERCADOPAGO_LOGO_COLORS, | ||
[LOGO.MULTIBANCO]: MULTIBANCO_LOGO_COLORS, | ||
[LOGO.MYBANK]: MYBANK_LOGO_COLORS, | ||
[LOGO.OXXO]: OXXO_LOGO_COLORS, | ||
[LOGO.P24]: P24_LOGO_COLORS, | ||
[LOGO.PAIDY]: PAIDY_LOGO_COLORS, | ||
[LOGO.PAYU]: PAYU_LOGO_COLORS, | ||
[LOGO.SATISPAY]: SATISPAY_LOGO_COLORS, | ||
[LOGO.SEPA]: SEPA_LOGO_COLORS, | ||
[LOGO.SOFORT]: SOFORT_LOGO_COLORS, | ||
[LOGO.TRUSTLY]: TRUSTLY_LOGO_COLORS, | ||
[LOGO.VERKKOPANKKI]: VERKKOPANKKI_LOGO_COLORS, | ||
[LOGO.WECHATPAY]: WECHATPAY_LOGO_COLORS, | ||
[LOGO.ZIMPLER]: ZIMPLER_LOGO_COLORS, | ||
}; | ||
|
||
async function buildLogos() { | ||
let shouldCommit = false; | ||
|
||
if (process.argv.includes("--commit")) { | ||
shouldCommit = true; | ||
} | ||
|
||
if (!version) { | ||
throw new Error(`Package version required`); | ||
} | ||
|
||
const cdnNamespace = getNodeOps().web.staticNamespace; | ||
|
||
if (!cdnNamespace) { | ||
throw new Error(`CDN namespace required`); | ||
} | ||
|
||
if (cdnNamespace !== "js-sdk-logos") { | ||
throw new Error("Expected cdnNamespace to be js-sdk-logos"); | ||
} | ||
|
||
// updates CDN URL in src/constants.js with package version | ||
updateCDNUrl(version); | ||
|
||
const outdir = `cdn/${version}`; | ||
|
||
await $`mkdir -p ${outdir}`; | ||
|
||
const logoPromises = []; | ||
|
||
for (const logoName of Object.keys(LOGO_GETTERS)) { | ||
const logoGetter = LOGO_GETTERS[logoName]; | ||
const logoColorMap = LOGO_COLOR_MAPS[logoName]; | ||
|
||
for (const [colorName, logoColors] of Object.entries(logoColorMap)) { | ||
// $FlowFixMe | ||
const svg = logoGetter(logoColors); | ||
|
||
// $FlowFixMe | ||
const filename = getSVGFilename(logoName, colorName); | ||
const filepath = `${outdir}/${filename}`; | ||
|
||
// $FlowFixMe | ||
logoPromises.push(fs.writeFile(filepath, svg.render(html()))); | ||
} | ||
} | ||
|
||
// eslint-disable-next-line no-restricted-globals,compat/compat,promise/no-native | ||
await Promise.all(logoPromises); | ||
|
||
if (shouldCommit) { | ||
await $`git add cdn src/constants.js`; | ||
await $`git commit -m "chore: generate CDN packages"`; | ||
await $`git push`; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
buildLogos(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* @flow */ | ||
|
||
// eslint-disable-next-line import/no-nodejs-modules | ||
import fs from "fs"; | ||
|
||
type NodeOps = {| | ||
web: {| | ||
staticNamespace: string, | ||
|}, | ||
|}; | ||
|
||
export function getNodeOps(): NodeOps { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we use this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah right. Should we use it to update the namespace in the CDN URL, like we do with package version? I like the idea of making it dynamic but it's another point of failure as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the .nodeops file can remain static similar to what we do in paypal/sdk-release. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought it might be confusing if somebody ever tried to change the namespace and the urls didn't update. I don't see why we would ever need to change the namespace, though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh I see your point. We can keep it then to validate the namespace name since its directly tied to the cdn url. |
||
if (!fs.existsSync("./.nodeops")) { | ||
throw new Error(`Node Ops file not found`); | ||
} | ||
return JSON.parse(fs.readFileSync("./.nodeops", "utf-8")); | ||
} | ||
|
||
export function updateCDNUrl(packageVersion: string) { | ||
const filepath = "src/constants.js"; | ||
|
||
let constantsFile = fs.readFileSync(filepath, "utf-8"); | ||
|
||
constantsFile = constantsFile.replace( | ||
/const PACKAGE_VERSION = ".*";/, | ||
`const PACKAGE_VERSION = "${packageVersion}";` | ||
); | ||
|
||
fs.writeFileSync(filepath, constantsFile); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this
--ignore ./fake
part do? Can we remove it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an ignore flag to fix an issue with babel-node:
I'll see if I can find a long-term solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it may be a bug that occurs with
babel-node
when you use the--config-file
flag.babel/babel#11892
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find. We can keep this. I just wanted to understand why it is needed.