Skip to content

Commit

Permalink
Build: Initial CLI up to deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Avery-Littlemore committed Jul 22, 2024
0 parents commit 5041660
Show file tree
Hide file tree
Showing 41 changed files with 11,838 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*
6 changes: 6 additions & 0 deletions bin/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env -S node --loader ts-node/esm --disable-warning=ExperimentalWarning

// eslint-disable-next-line n/shebang
import {execute} from '@oclif/core'

await execute({development: true, dir: import.meta.url})
3 changes: 3 additions & 0 deletions bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
5 changes: 5 additions & 0 deletions bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

import {execute} from '@oclif/core'

await execute({dir: import.meta.url})
5 changes: 5 additions & 0 deletions dist/commands/init.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Command } from "@oclif/core";
export default class Init extends Command {
static description: string;
run(): Promise<void>;
}
29 changes: 29 additions & 0 deletions dist/commands/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Command } from "@oclif/core";
import ora from "ora";
import { exec } from "child_process";
import { promisify } from "util";
import configureAWS from "../utils/configureAWS.js";
// Promisify exec for async/await usage
const execPromise = promisify(exec);
const spinner = ora();
export default class Init extends Command {
static description = "Initialize the CDK project";
// TODOS
// - What happens if the stack fails? -> give cdk deploy responsibilities to user
// - How to retrieve information from user (# of caches, names in DB, etc), and how to enter those values into CDK
async run() {
console.log("Welcome to the Cerebellum CLI!");
// await confirmAwsCliInstall();
await configureAWS();
// await cloneCDK();
// await npmInstallCDK();
// await npmInstallLambda();
// await confirmAwsCdkInstall();
// await cdkSynth();
// await cdkBootstrap();
// await cdkDeploy() // better to let them deploy so they can see progress and address any errors that arise
console.log("Success! You are now ready to deploy your infrastructure!");
console.log("When ready, enter `cd cdk && cdk deploy` and follow the prompts.");
console.log("Deployment can take 10-20 minutes, depending on complexity.");
}
}
1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { run } from '@oclif/core';
1 change: 1 addition & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { run } from '@oclif/core';
2 changes: 2 additions & 0 deletions dist/utils/cdkBootstrap.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const cdkBootstrap: () => Promise<void>;
export default cdkBootstrap;
18 changes: 18 additions & 0 deletions dist/utils/cdkBootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import ora from 'ora';
import { exec } from 'child_process';
import { promisify } from 'util';
// Promisify exec for async/await usage
const execPromise = promisify(exec);
const spinner = ora();
const cdkBootstrap = async () => {
spinner.start('Creating bootstrap resources for CDK...');
try {
await execPromise('cd cdk && cdk bootstrap');
spinner.succeed('CDK bootstrap creation success!');
}
catch (error) {
spinner.fail('An error occurred creating cdk bootstrap');
console.error(error);
}
};
export default cdkBootstrap;
2 changes: 2 additions & 0 deletions dist/utils/cdkDeploy.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const cdkDeploy: () => Promise<void>;
export default cdkDeploy;
17 changes: 17 additions & 0 deletions dist/utils/cdkDeploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import ora from 'ora';
import { exec } from 'child_process';
import { promisify } from 'util';
const execPromise = promisify(exec);
const spinner = ora();
const cdkDeploy = async () => {
spinner.start('Deploying CDK... (this may take 10-20 minutes, depending on the complexity)');
try {
await execPromise('cd cdk && cdk deploy --require-approval never');
spinner.succeed('CDK successfuly deployed!');
}
catch (error) {
spinner.fail('An error occurred');
console.error(error);
}
};
export default cdkDeploy;
2 changes: 2 additions & 0 deletions dist/utils/cdkSynth.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const cdkSynth: () => Promise<void>;
export default cdkSynth;
18 changes: 18 additions & 0 deletions dist/utils/cdkSynth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import ora from 'ora';
import { exec } from 'child_process';
import { promisify } from 'util';
// Promisify exec for async/await usage
const execPromise = promisify(exec);
const spinner = ora();
const cdkSynth = async () => {
spinner.start('Running cdk synth...');
try {
await execPromise('cd cdk && cdk synth');
spinner.succeed('CDK successfully synthesized!');
}
catch (error) {
spinner.fail('An error occurred');
console.error(error);
}
};
export default cdkSynth;
2 changes: 2 additions & 0 deletions dist/utils/cloneCDK.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const cloneCDK: () => Promise<void>;
export default cloneCDK;
18 changes: 18 additions & 0 deletions dist/utils/cloneCDK.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import ora from 'ora';
import { exec } from 'child_process';
import { promisify } from 'util';
// Promisify exec for async/await usage
const execPromise = promisify(exec);
const spinner = ora();
const cloneCDK = async () => {
spinner.start('Cloning CDK repo from Github...');
try {
await execPromise('git clone https://github.com/Capstone2408-Team-2/cdk.git');
spinner.succeed('CDK successfully cloned!');
}
catch (error) {
spinner.fail('An error occurred');
console.error(error);
}
};
export default cloneCDK;
2 changes: 2 additions & 0 deletions dist/utils/configureAWS.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const configureAWS: () => Promise<void>;
export default configureAWS;
31 changes: 31 additions & 0 deletions dist/utils/configureAWS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import ora from "ora";
import { spawn } from "child_process";
const spinner = ora();
const configureAWS = async () => {
try {
console.log("Loading AWS Configure...");
await new Promise((resolve, reject) => {
const child = spawn("aws", ["configure"], {
stdio: "inherit", // This allows for interactive input/output
});
child.stdout?.on("data", () => {
console.log("Here");
});
child.on("close", (code) => {
if (code === 0) {
resolve(null);
}
else {
reject(new Error(`Command failed with exit code ${code}`));
}
});
});
// Restart the spinner after the command completes
spinner.succeed("AWS configure success!");
}
catch (error) {
spinner.fail("An error occurred");
console.error(error);
}
};
export default configureAWS;
2 changes: 2 additions & 0 deletions dist/utils/confirmAwsCdkInstall.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const confirmAwsCdkInstall: () => Promise<void>;
export default confirmAwsCdkInstall;
30 changes: 30 additions & 0 deletions dist/utils/confirmAwsCdkInstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import ora from 'ora';
import { exec } from 'child_process';
import { promisify } from 'util';
import { cli } from 'cli-ux';
// Promisify exec for async/await usage
const execPromise = promisify(exec);
const spinner = ora();
const confirmAwsCdkInstall = async () => {
spinner.start('Checking if aws-cli is installed...');
const alreadyInstalled = await execPromise('cdk --version').catch(() => false);
if (alreadyInstalled) {
spinner.succeed('aws-cdk is installed!');
return;
}
spinner.stop();
try {
const response = await cli.prompt('You will need aws-cdk to be globally installed to deploy the infrastructure.\n Would you like it to be installed? (y/n)');
if (response.toLowerCase() === 'n') {
throw new Error('Permission denied by user. Please globally install aws-cdk independently or run script again.');
}
spinner.start('Globally installing aws-cdk!');
await execPromise('npm install -g aws-cdk');
spinner.succeed('aws-cdk globally installed!');
}
catch (error) {
spinner.fail('An error occurred');
console.error(error);
}
};
export default confirmAwsCdkInstall;
2 changes: 2 additions & 0 deletions dist/utils/confirmAwsCliInstall.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const confirmAwsCliInstall: () => Promise<void>;
export default confirmAwsCliInstall;
30 changes: 30 additions & 0 deletions dist/utils/confirmAwsCliInstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import ora from 'ora';
import { exec } from 'child_process';
import { promisify } from 'util';
import { cli } from 'cli-ux';
// Promisify exec for async/await usage
const execPromise = promisify(exec);
const spinner = ora();
const confirmAwsCliInstall = async () => {
spinner.start('Checking if aws-cli is installed...');
const alreadyInstalled = await execPromise('aws --version').catch(() => false);
if (alreadyInstalled) {
spinner.succeed('aws-cli is installed!');
return;
}
spinner.stop();
try {
const response = await cli.prompt('You will need aws-cli to be globally installed to deploy the infrastructure.\n Would you like it to be installed? (y/n)');
if (response.toLowerCase() === 'n') {
throw new Error('Permission denied by user. Please globally install aws-cli independently or run script again.');
}
spinner.start('Globally installing aws-cli!');
await execPromise('npm install -g aws-cli');
spinner.succeed('aws-cli globally installed!');
}
catch (error) {
spinner.fail('An error occurred');
console.error(error);
}
};
export default confirmAwsCliInstall;
2 changes: 2 additions & 0 deletions dist/utils/npmInstallCDK.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const npmInstallCDK: () => Promise<void>;
export default npmInstallCDK;
18 changes: 18 additions & 0 deletions dist/utils/npmInstallCDK.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import ora from 'ora';
import { exec } from 'child_process';
import { promisify } from 'util';
// Promisify exec for async/await usage
const execPromise = promisify(exec);
const spinner = ora();
const npmInstallCDK = async () => {
spinner.start('Installing dependencies in the CDK...');
try {
await execPromise('cd cdk && npm install');
spinner.succeed('Dependencies within the CDK successfully installed!');
}
catch (error) {
spinner.fail('An error occurred');
console.error(error);
}
};
export default npmInstallCDK;
2 changes: 2 additions & 0 deletions dist/utils/npmInstallLambda.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const npmInstallLambda: () => Promise<void>;
export default npmInstallLambda;
17 changes: 17 additions & 0 deletions dist/utils/npmInstallLambda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import ora from 'ora';
import { exec } from 'child_process';
import { promisify } from 'util';
const execPromise = promisify(exec);
const spinner = ora();
const npmInstallLambda = async () => {
spinner.start('Installing dependencies for lambda functions...');
try {
await execPromise('cd cdk/lambda && npm install');
spinner.succeed('Lambda dependencies installed successfully!');
}
catch (error) {
spinner.fail('An error occurred');
console.error(error);
}
};
export default npmInstallLambda;
Loading

0 comments on commit 5041660

Please sign in to comment.