@optro/create-trello-powerup
Version:
Easily create Trello Power-Ups from the Command Line
116 lines (115 loc) • 5.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEnv = exports.getCapabilityModule = exports.getCapabilityImport = exports.getCardButtonMonetizationEndTag = exports.getCardButtonMonetizationStartTag = exports.getLicenseStatusTag = exports.getCardButtonMonetizationImport = exports.getReactRouterMonetizationProviderClose = exports.getReactRouterMonetizationProvider = exports.getReactRouterMonetizationClient = exports.getReactRouterMonetizationImport = exports.getReactRouterLoader = exports.getReactRouterRoute = exports.getWebpackHtmlPlugin = exports.getPascalCase = exports.getIndent = void 0;
const tslib_1 = require("tslib");
const camelcase_1 = tslib_1.__importDefault(require("camelcase"));
const constants_1 = require("./constants");
function getCapabilityFolderName(capability) {
return capability.endsWith('s') && capability !== 'show-settings' ? capability.slice(0, -1) : capability;
}
function getIndent(i) {
return ' '.repeat(i * 4);
}
exports.getIndent = getIndent;
function getPascalCase(capability) {
return camelcase_1.default(capability, { pascalCase: true });
}
exports.getPascalCase = getPascalCase;
function getWebpackHtmlPlugin(capability) {
return `${constants_1.WEBPACK_REPLACEMENT_STRING}
${getIndent(2)}new HtmlWebpackPlugin({\r
${getIndent(3)}chunks: ['addon'],\r
${getIndent(3)}template: 'templates/react.hbs',\r
${getIndent(3)}filename: '${getCapabilityFolderName(capability)}.html',\r
${getIndent(3)}templateParameters: {\r
${getIndent(4)}powerup_name: process.env.POWERUP_NAME,\r
${getIndent(4)}powerup_app_key: process.env.POWERUP_APP_KEY\r
${getIndent(3)}}\r
${getIndent(2)}}),`;
}
exports.getWebpackHtmlPlugin = getWebpackHtmlPlugin;
function getReactRouterRoute(capability) {
const name = getCapabilityFolderName(capability);
return `${constants_1.REACT_ROUTER_MODULE_REPLACEMENT_STRING}
${getIndent(4)}<Route path={\`/${name}.html\`}>
${getIndent(5)}<${getPascalCase(name)} />
${getIndent(4)}</Route>`;
}
exports.getReactRouterRoute = getReactRouterRoute;
function getReactRouterLoader(capability) {
const folder = getCapabilityFolderName(capability);
return `${constants_1.REACT_ROUTER_LOADER_REPLACEMENT_STRING}
const ${getPascalCase(folder)} = React.lazy(() => import('./${folder}/${getPascalCase(folder)}'))`;
}
exports.getReactRouterLoader = getReactRouterLoader;
function getReactRouterMonetizationImport() {
return `import {LicenseProvider, TrelloProvider} from '@optro/ui-react';
import {OptroLicenseApi} from '@optro/api-client';
import '@optro/ui-react/bundle.css';`;
}
exports.getReactRouterMonetizationImport = getReactRouterMonetizationImport;
function getReactRouterMonetizationClient() {
return `${constants_1.REACT_ROUTER_CLIENT_REPLACEMENT_STRING}
const optroClient = new OptroLicenseApi(process.env.OPTRO_API_KEY as string, process.env.POWERUP_ID as string);`;
}
exports.getReactRouterMonetizationClient = getReactRouterMonetizationClient;
function getReactRouterMonetizationProvider() {
return `${constants_1.REACT_ROUTER_CLIENT_PROVIDER_REPLACEMENT_STRING}
<LicenseProvider optroClient={optroClient} apiKey={process.env.OPTRO_API_KEY as string} licenseType={'board'} powerupId={process.env.POWERUP_ID as string}>`;
}
exports.getReactRouterMonetizationProvider = getReactRouterMonetizationProvider;
function getReactRouterMonetizationProviderClose() {
return `${constants_1.REACT_ROUTER_CLIENT_PROVIDER_CLOSE_REPLACEMENT_STRING}
</LicenseProvider>`;
}
exports.getReactRouterMonetizationProviderClose = getReactRouterMonetizationProviderClose;
function getCardButtonMonetizationImport() {
return 'import { useProvidedTrello , LicenseConditional, LicenseStatus} from \'@optro/ui-react\';';
}
exports.getCardButtonMonetizationImport = getCardButtonMonetizationImport;
function getLicenseStatusTag() {
return `${constants_1.CARD_BUTTON_STATUS_REPLACEMENT_STRING}
<LicenseStatus/>`;
}
exports.getLicenseStatusTag = getLicenseStatusTag;
function getCardButtonMonetizationStartTag() {
return `<LicenseConditional unlicensed={
<div className="color-picker-container unlicensed">
<CirclePicker
color={'#0079bf'}
colors={['#0079bf', '#70b500', '#ff9f1a', '#eb5a46', '#f2d600', '#c377e0']}
/>
</div>
}
>
${constants_1.CARD_BUTTON_CONDITIONAL_START_REPLACEMENT_STRING}`;
}
exports.getCardButtonMonetizationStartTag = getCardButtonMonetizationStartTag;
function getCardButtonMonetizationEndTag() {
return `</LicenseConditional>
${constants_1.CARD_BUTTON_CONDITIONAL_END_REPLACEMENT_STRING}`;
}
exports.getCardButtonMonetizationEndTag = getCardButtonMonetizationEndTag;
function getCapabilityImport(capability) {
const folder = getCapabilityFolderName(capability);
return `${constants_1.CAPABILITIES_IMPORT_REPLACEMENT_STRING}
import {get${getPascalCase(folder)}} from './${folder}/capability'`;
}
exports.getCapabilityImport = getCapabilityImport;
function getCapabilityModule(capability) {
return `${constants_1.CAPABILITIES_REPLACEMENT_STRING}
'${capability}': ${constants_1.CAPABILITY_MODULES[capability]},`;
}
exports.getCapabilityModule = getCapabilityModule;
function getEnv(id, name, optroApiKey, licenseType) {
return `NODE_ENV=development
PORT=3000
POWERUP_NAME=${name}
POWERUP_ID=${id}
POWERUP_APP_KEY=UNSPECIFIED
POWERUP_URL=https://optro-cloud.github.io/trello-powerup-full-sample
CONTEXT_PATH=/
OPTRO_API_KEY=${optroApiKey}
OPTRO_LICENSE_TYPE=${licenseType}`;
}
exports.getEnv = getEnv;