@shipengine/connect
Version:
The official developer tooling for building ShipEngine connect apps
160 lines • 5.85 kB
JavaScript
"use strict";
const tslib_1 = require("tslib");
const fs_1 = require("fs");
const path = tslib_1.__importStar(require("path"));
const Generator = require("yeoman-generator");
class InfraNew extends Generator {
path;
// Prompted fields used for templating
appName;
type;
beta;
organization;
image;
repo;
hasBuild;
constructor(args, opts) {
super(args, opts);
const pjson = this.fs.readJSON('package.json', {});
const dependencies = Object.keys({
...pjson.dependencies,
...pjson.devDependencies,
});
this.appName = pjson.name;
this.beta = opts.beta || dependencies.includes('@shipengine/connect-runtime');
this.hasBuild = !!pjson.scripts?.build;
this.path = opts.path;
this.type = this._normalizeType(opts.type);
}
_normalizeType(integrationType) {
if (integrationType === 'carrier') {
return 'shipping';
}
if (integrationType === 'order') {
return 'ecommerce';
}
return integrationType;
}
async prompting() {
if (this.path) {
this.destinationRoot(path.resolve(this.path));
process.chdir(this.destinationRoot());
}
const currentDir = path.resolve().split(path.sep).pop();
const integrationsDir = path
.resolve()
.split(path.sep)
.find((part) => part.includes('integrations-'));
let answers = {
name: this.appName || currentDir,
type: this.type || 'shipping',
repo: integrationsDir || '',
};
if (!this.options.useDefaults) {
answers = await this.prompt([
{
type: 'input',
name: 'name',
message: 'What is the name of this integration?',
default: answers.name,
},
{
type: 'list',
name: 'type',
message: 'What type of integration is this?',
choices: [
{
name: 'Carrier',
value: 'shipping',
},
{
name: 'Freight',
value: 'freight',
},
{
name: 'Order',
value: 'ecommerce',
},
],
default: answers.type,
},
{
type: 'input',
name: 'repo',
message: 'Which GitHub repo is this for?',
default: answers.repo,
},
]);
}
this.appName = answers.name || '';
this.type = answers.type;
const integrationsRegex = /integrations-(.*)/;
const matches = answers.repo.match(integrationsRegex) || [];
if (matches?.length >= 2) {
switch (matches[1]) {
case 'ecommerce':
case 'shipping':
case 'freight':
case 'fulfillment':
// These internal repos use a different prefix
this.organization = 'ips';
break;
default:
this.organization = matches[1];
break;
}
}
else {
// If we end up here something went wrong, but we can catch it in code review
this.organization = answers.repo;
}
if (this.type === 'shipping') {
this.image =
'813448775391.dkr.ecr.us-east-1.amazonaws.com/ipaas-dip-functions:shipping-dx-base-latest';
}
else if (this.type === 'ecommerce') {
this.image =
'813448775391.dkr.ecr.us-east-1.amazonaws.com/ipaas-dip-functions:order-source-dx-base-latest';
}
if (this.organization === 'ips') {
this.repo = `integrations-${this.type}`;
}
else {
this.repo = `integrations-${this.organization}`;
}
}
writing() {
this.sourceRoot(path.join(__dirname, '../../../templates/infra'));
const filesToCopy = [{ src: 'dockerignore.ejs', dest: '.dockerignore' }];
try {
(0, fs_1.accessSync)(path.resolve(path.join(this.path || path.resolve(), '../../infra')));
filesToCopy.push({
src: 'helm/Chart.yaml.ejs',
dest: `../../infra/helm/${this.appName}/Chart.yaml`,
}, {
src: 'helm/values-dev.yaml.ejs',
dest: `../../infra/helm/${this.appName}/values-dev.yaml`,
}, {
src: 'helm/values-intg.yaml.ejs',
dest: `../../infra/helm/${this.appName}/values-intg.yaml`,
}, {
src: 'helm/values-prod.yaml.ejs',
dest: `../../infra/helm/${this.appName}/values-prod.yaml`,
}, {
src: 'helm/values-stage.yaml.ejs',
dest: `../../infra/helm/${this.appName}/values-stage.yaml`,
}, {
src: 'helm/values.yaml.ejs',
dest: `../../infra/helm/${this.appName}/values.yaml`,
}, { src: 'Makefile.ejs', dest: 'Makefile' });
}
catch (err) {
this.log('Helm configuration directory not found. Skipping.');
}
filesToCopy.forEach((fileToCopy) => {
this.fs.copyTpl(this.templatePath(fileToCopy.src), this.destinationPath(fileToCopy.dest), this);
});
}
}
module.exports = InfraNew;
//# sourceMappingURL=infra-new.js.map