cleanup
This commit is contained in:
@@ -1,25 +1,15 @@
|
|||||||
# pwcli CLI
|
# Photowall CLI
|
||||||
|
|
||||||
A CLI for pwcli.
|
A CLI for Photowall, a platform for doing any type of commands or automation
|
||||||
|
needed for the photowall organisation.
|
||||||
|
|
||||||
## Customizing your CLI
|
# Installation
|
||||||
|
|
||||||
Check out the documentation at https://github.com/infinitered/gluegun/tree/master/docs.
|
1. Clone the repo to a local folder.
|
||||||
|
2. Build the project with `yarn build`
|
||||||
|
3. Connect a runnable command with `yarn link`
|
||||||
|
4. Open a new terminal window and run `pwcli`
|
||||||
|
|
||||||
## Publishing to NPM
|
# Usage
|
||||||
|
|
||||||
To package your CLI up for NPM, do this:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ npm login
|
|
||||||
$ npm whoami
|
|
||||||
$ npm lint
|
|
||||||
$ npm test
|
|
||||||
(if typescript, run `npm run build` here)
|
|
||||||
$ npm publish
|
|
||||||
```
|
|
||||||
|
|
||||||
# License
|
|
||||||
|
|
||||||
MIT - see LICENSE
|
|
||||||
|
|
||||||
|
When running `pwcli` command in the terminal is will open a interactive view but all commands are accessable through shortcuts. So if you want to run status on development testservers its possible to run `pwcli d ts s` for d = development, ts = test servers, s = status. Shortcuts are listed in the interactive view.
|
||||||
|
|||||||
+4
-4
@@ -1,4 +1,4 @@
|
|||||||
const { build } = require('gluegun');
|
const { build } = require('gluegun')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the cli and kick it off
|
* Create the cli and kick it off
|
||||||
@@ -21,15 +21,15 @@ async function run(argv) {
|
|||||||
run: toolbox => toolbox.print.info('No help for you!')
|
run: toolbox => toolbox.print.info('No help for you!')
|
||||||
}) // provides default for help, h, --help, -h
|
}) // provides default for help, h, --help, -h
|
||||||
.version() // provides default for version, v, --version, -v
|
.version() // provides default for version, v, --version, -v
|
||||||
.create();
|
.create()
|
||||||
// enable the following method if you'd like to skip loading one of these core extensions
|
// enable the following method if you'd like to skip loading one of these core extensions
|
||||||
// this can improve performance if they're not necessary for your project:
|
// this can improve performance if they're not necessary for your project:
|
||||||
// .exclude(['meta', 'strings', 'print', 'filesystem', 'semver', 'system', 'prompt', 'http', 'template', 'patching', 'package-manager'])
|
// .exclude(['meta', 'strings', 'print', 'filesystem', 'semver', 'system', 'prompt', 'http', 'template', 'patching', 'package-manager'])
|
||||||
// and run it
|
// and run it
|
||||||
const toolbox = await cli.run(argv);
|
const toolbox = await cli.run(argv)
|
||||||
|
|
||||||
// send it back (for testing, mostly)
|
// send it back (for testing, mostly)
|
||||||
return toolbox;
|
return toolbox
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { run }
|
module.exports = { run }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'
|
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const { AutoComplete, Input, Confirm } = require('enquirer');
|
const { Input, Confirm } = require('enquirer');
|
||||||
import { Octokit } from "@octokit/core";
|
import { Octokit } from "@octokit/core";
|
||||||
import { GluegunPrint } from 'gluegun';
|
import { GluegunPrint } from 'gluegun';
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
@@ -38,7 +38,6 @@ const getDownloadFileFromRepoCommand = (token: string, org: string, repo: string
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getCreateStackCommand = (stackName: string, branch: string, templateFile: string, dockerImage: string, githubToken: string, composerAuth: string) => {
|
const getCreateStackCommand = (stackName: string, branch: string, templateFile: string, dockerImage: string, githubToken: string, composerAuth: string) => {
|
||||||
const stack = 'photowall';
|
|
||||||
const stackDomain = stackName.replace('photowall-', '');
|
const stackDomain = stackName.replace('photowall-', '');
|
||||||
const cmd = [
|
const cmd = [
|
||||||
`aws cloudformation create-stack --stack-name ${stackName}`,
|
`aws cloudformation create-stack --stack-name ${stackName}`,
|
||||||
@@ -110,9 +109,6 @@ const getConfirmation = async (branchName: string, stackName: string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Subsection1 menu
|
|
||||||
*/
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'create',
|
name: 'create',
|
||||||
alias: ['c'],
|
alias: ['c'],
|
||||||
@@ -222,22 +218,22 @@ module.exports = {
|
|||||||
await system.run(getDownloadFileFromRepoCommand(config.gh_token, 'Photowall', 'photowall', 'cloudformation/ecr-lifecycle-policy.json'));
|
await system.run(getDownloadFileFromRepoCommand(config.gh_token, 'Photowall', 'photowall', 'cloudformation/ecr-lifecycle-policy.json'));
|
||||||
await system.run(getDownloadFileFromRepoCommand(config.gh_token, 'Photowall', 'photowall', 'cloudformation/ecs-service.yaml'));
|
await system.run(getDownloadFileFromRepoCommand(config.gh_token, 'Photowall', 'photowall', 'cloudformation/ecs-service.yaml'));
|
||||||
|
|
||||||
const aws_account_id = strings.trim(await system.run(`aws sts get-caller-identity --query Account --output text`));
|
const awsAccountId = strings.trim(await system.run(`aws sts get-caller-identity --query Account --output text`));
|
||||||
const aws_region = strings.trim(await system.run(`aws configure get region`));
|
const awsRegion = strings.trim(await system.run(`aws configure get region`));
|
||||||
const github_token = strings.trim(await system.run(`aws ssm get-parameter --with-decryption --name /github/CODE_PIPELINE_TOKEN --output text --query Parameter.Value`));
|
const githubToken = strings.trim(await system.run(`aws ssm get-parameter --with-decryption --name /github/CODE_PIPELINE_TOKEN --output text --query Parameter.Value`));
|
||||||
|
|
||||||
print.fancy(await system.run(`aws ecr create-repository --repository ${stackName}`));
|
print.fancy(await system.run(`aws ecr create-repository --repository ${stackName}`));
|
||||||
print.fancy(await system.run(`aws ecr get-login-password --region ${aws_region} | docker login --username AWS --password-stdin ${aws_account_id}.dkr.ecr.${aws_region}.amazonaws.com`));
|
print.fancy(await system.run(`aws ecr get-login-password --region ${awsRegion} | docker login --username AWS --password-stdin ${awsAccountId}.dkr.ecr.${awsRegion}.amazonaws.com`));
|
||||||
print.fancy(await system.run(`docker pull nginx`));
|
print.fancy(await system.run(`docker pull nginx`));
|
||||||
print.fancy(await system.run(`docker tag nginx ${aws_account_id}.dkr.ecr.${aws_region}.amazonaws.com/${stackName}:latest`));
|
print.fancy(await system.run(`docker tag nginx ${awsAccountId}.dkr.ecr.${awsRegion}.amazonaws.com/${stackName}:latest`));
|
||||||
print.fancy(await system.run(`docker push ${aws_account_id}.dkr.ecr.${aws_region}.amazonaws.com/${stackName}:latest`));
|
print.fancy(await system.run(`docker push ${awsAccountId}.dkr.ecr.${awsRegion}.amazonaws.com/${stackName}:latest`));
|
||||||
|
|
||||||
const dockerImage = `${aws_account_id}.dkr.ecr.${aws_region}.amazonaws.com/${stackName}`;
|
const dockerImage = `${awsAccountId}.dkr.ecr.${awsRegion}.amazonaws.com/${stackName}`;
|
||||||
let composerAuthToken = await system.run(`aws ssm get-parameter --with-decryption --name /github/COMPOSER_TOKEN --output text --query Parameter.Value`);
|
let composerAuthToken = await system.run(`aws ssm get-parameter --with-decryption --name /github/COMPOSER_TOKEN --output text --query Parameter.Value`);
|
||||||
composerAuthToken = composerAuthToken.replace('\n', '');
|
composerAuthToken = composerAuthToken.replace('\n', '');
|
||||||
const composer_auth = `'{\"github-oauth\":{\"github.com\":\"${composerAuthToken}\"}}'`;
|
const composerAuth = `'{\"github-oauth\":{\"github.com\":\"${composerAuthToken}\"}}'`;
|
||||||
|
|
||||||
const createCommand = getCreateStackCommand(stackName, branchName, 'file://ecs-service.yaml', dockerImage, github_token, composer_auth);
|
const createCommand = getCreateStackCommand(stackName, branchName, 'file://ecs-service.yaml', dockerImage, githubToken, composerAuth);
|
||||||
print.fancy(await system.run(createCommand, {cwd: '/tmp/', trim: true}));
|
print.fancy(await system.run(createCommand, {cwd: '/tmp/', trim: true}));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -48,9 +48,6 @@ const runCommand = async (system: GluegunSystem, cmd : string | null) => {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Subsection1 menu
|
|
||||||
*/
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'delete',
|
name: 'delete',
|
||||||
alias: ['d'],
|
alias: ['d'],
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ type Stack = {
|
|||||||
updated: string,
|
updated: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Subsection1 menu
|
|
||||||
*/
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'status',
|
name: 'status',
|
||||||
alias: ['s'],
|
alias: ['s'],
|
||||||
|
|||||||
@@ -107,9 +107,6 @@ const getConfirmation = async (branchName: string, stackName: string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Subsection1 menu
|
|
||||||
*/
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'update',
|
name: 'update',
|
||||||
alias: ['u'],
|
alias: ['u'],
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ module.exports = {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
system.run('touch ~/.pwcli_settings');
|
await system.run('touch ~/.pwcli_settings');
|
||||||
print.info(`Created configuration file ${chalk.yellow(`~/.pwcli_settings`)}`);
|
print.info(`Created configuration file ${chalk.yellow(`~/.pwcli_settings`)}`);
|
||||||
const config = {
|
const config = {
|
||||||
gh_token: '',
|
gh_token: '',
|
||||||
@@ -120,7 +120,7 @@ module.exports = {
|
|||||||
if (await (new Confirm({
|
if (await (new Confirm({
|
||||||
message: `Ok to save the these settings to ${chalk.yellow(`~/.pwcli_settings`)}?`
|
message: `Ok to save the these settings to ${chalk.yellow(`~/.pwcli_settings`)}?`
|
||||||
})).run()) {
|
})).run()) {
|
||||||
system.run(`echo '${JSON.stringify(config)}' > ~/.pwcli_settings`);
|
await system.run(`echo '${JSON.stringify(config)}' > ~/.pwcli_settings`);
|
||||||
} else {
|
} else {
|
||||||
print.info('Ok then.');
|
print.info('Ok then.');
|
||||||
if (toolbox.fromMenu()) await toolbox.menu.showMenu();
|
if (toolbox.fromMenu()) await toolbox.menu.showMenu();
|
||||||
|
|||||||
Reference in New Issue
Block a user