Swapped tslint to eslint and fixed files

This commit is contained in:
Arwid Thornström
2023-02-03 12:48:29 +01:00
committed by GitHub
parent 258e0b2dde
commit a7da247cf4
15 changed files with 1136 additions and 386 deletions
@@ -1,4 +1,4 @@
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
import { exit } from 'process';
const chalk = require('chalk');
const { AutoComplete, Input, Confirm } = require('enquirer');
@@ -6,18 +6,20 @@ import { defaultMenuSettings, getSettings } from '../../../../globals';
import { getRepoBranches } from '../../../../services/github_rest';
type Stack = {
name: string
status: string
drift_status: string
branch: string
updated: string
}
name: string;
status: string;
drift_status: string;
branch: string;
updated: string;
};
const getConfirmation = async (branchName: string, stackName: string) => {
const url = stackName.replace('photowall-', '');
const confirm = new Confirm({
name: 'confirm',
message: `Will create ${chalk.yellow(url + '.photowall-test.xx')} and publish ${chalk.green(branchName)} to it, continue?`
message: `Will create ${chalk.yellow(
url + '.photowall-test.xx'
)} and publish ${chalk.green(branchName)} to it, continue?`
});
try {
@@ -26,7 +28,7 @@ const getConfirmation = async (branchName: string, stackName: string) => {
console.error(e);
return false;
}
}
};
module.exports = {
name: 'create',
@@ -35,10 +37,10 @@ module.exports = {
hidden: false,
run: async (toolbox: GluegunMenuToolbox) => {
const { system, strings, print, filesystem } = toolbox;
// Load settings
const config = await getSettings(toolbox);
if (!config || (!config.photowall_repo || config.photowall_repo === "")) {
if (!config || !config.photowall_repo || config.photowall_repo === '') {
print.error(`
The create command requires that you set an absolute path to your local photowall repository.
@@ -47,10 +49,15 @@ module.exports = {
await toolbox.menu.showMenu('setup', defaultMenuSettings);
return;
}
const branches = await getRepoBranches(toolbox, config.gh_token, 'Photowall', 'photowall');
const branches = await getRepoBranches(
toolbox,
config.gh_token,
'Photowall',
'photowall'
);
const branchOptions = branches.map(item => item.name);
const promptBranch = new AutoComplete({
name: 'branchName',
message: 'Select a branch',
@@ -62,7 +69,7 @@ module.exports = {
const stacks = JSON.parse(
strings.trim(await system.run(`aws cloudformation list-stacks`))
)
);
const teststacks: Stack[] = await Promise.all(
stacks.StackSummaries.map(async item => {
if (
@@ -82,40 +89,42 @@ module.exports = {
`aws codepipeline get-pipeline --name ${item.StackName}Pipeline`
)
)
)
);
const branch = pipeline.pipeline.stages.filter(stage => {
return stage.name === 'Source'
})[0].actions[0].configuration.Branch
const lastUpdated = pipeline.metadata.updated
return stage.name === 'Source';
})[0].actions[0].configuration.Branch;
const lastUpdated = pipeline.metadata.updated;
return {
name: item.StackName,
status: item.StackStatus,
drift_status: item.DriftInformation.StackDriftStatus,
branch: branch,
updated: lastUpdated
}
};
}
return Promise.resolve(null)
return Promise.resolve(null);
})
)
);
const curratedStacks: Stack[] = teststacks.filter(Boolean)
const curratedStacks: Stack[] = teststacks.filter(Boolean);
const options = curratedStacks.map(item => {
return item.name;
});
const input = new Input({
type: 'input',
name: 'stack',
message: `Subdomain of new server (${chalk.yellow('test-xxx')})`
});
const stacksuffix = await input.run();
const stackName = `photowall-${stacksuffix}`
const stackName = `photowall-${stacksuffix}`;
if (options.includes(stackName)) {
print.error(`
The stack ${chalk.yellow(stackName)} is already taken, try the update command instead.
The stack ${chalk.yellow(
stackName
)} is already taken, try the update command instead.
`);
if (toolbox.fromMenu()) {
@@ -126,23 +135,35 @@ module.exports = {
} else if (stackName.indexOf('photowall-test-') !== 0) {
print.error(`
The stack must begin with ${chalk.yellow('test-')} and then something after like ${chalk.yellow('test-yourname-1')}.
The stack must begin with ${chalk.yellow(
'test-'
)} and then something after like ${chalk.yellow('test-yourname-1')}.
`);
if (toolbox.fromMenu()) {
await toolbox.menu.showMenu('deployment testservers', defaultMenuSettings);
await toolbox.menu.showMenu(
'deployment testservers',
defaultMenuSettings
);
} else {
exit();
}
}
try {
const shouldRun = await getConfirmation(branchName, stackName);
if (shouldRun) {
const cmd = `make create-stack STACK_ENVIRONMENT_NAME=${stacksuffix} GITHUB_BRANCH=${branchName}`;
print.fancy(`Running [${chalk.yellow(cmd)}] in folder [${`${config.photowall_repo}/cloudformation/`}]`);
const output = await system.run(cmd, {cwd: `${config.photowall_repo}/cloudformation/`, trim: true});
print.fancy(
`Running [${chalk.yellow(
cmd
)}] in folder [${`${config.photowall_repo}/cloudformation/`}]`
);
const output = await system.run(cmd, {
cwd: `${config.photowall_repo}/cloudformation/`,
trim: true
});
print.fancy(output);
}
} catch (e) {
@@ -150,7 +171,10 @@ module.exports = {
}
if (toolbox.fromMenu()) {
await toolbox.menu.showMenu('deployment testservers', defaultMenuSettings);
await toolbox.menu.showMenu(
'deployment testservers',
defaultMenuSettings
);
}
}
}
};