Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Maed223 committed Oct 13, 2023
1 parent e27e310 commit fe8c11c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
3 changes: 1 addition & 2 deletions packages/@cdktf/commons/src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ async function getPnpmNodeModuleVersion(
packageName: string
): Promise<string | undefined> {
let output;

try {
output = await exec("pnpm", ["list", packageName, "--json"], {
env: { ...process.env },
});
} catch (e) {
logger.debug(`Unable to run 'pnpm list ${packageName} --json': ${e}`);

return undefined;
}

Expand Down Expand Up @@ -131,7 +131,6 @@ async function getNpmNodeModuleVersion(
packageName: string
): Promise<string | undefined> {
let output;

try {
output = await exec("npm", ["list", packageName, "--json"], {
env: { ...process.env },
Expand Down
53 changes: 42 additions & 11 deletions packages/cdktf-cli/src/bin/cmds/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export async function deploy(argv: any) {

let outputsPath: string | undefined = undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-function
let onOutputsRetrieved: (outputs: NestedTerraformOutputs) => void = () => {};
let onOutputsRetrieved: (outputs: NestedTerraformOutputs) => void = () => { };

if (argv.outputsFile) {
outputsPath = normalizeOutputPath(argv.outputsFile);
Expand Down Expand Up @@ -293,7 +293,7 @@ export async function get(argv: {
}) {
const printPerformanceInfo = argv.showPerformanceInfo
? startPerformanceMonitoring()
: () => {}; // eslint-disable-line @typescript-eslint/no-empty-function
: () => { }; // eslint-disable-line @typescript-eslint/no-empty-function

try {
throwIfNotProjectDirectory();
Expand Down Expand Up @@ -425,7 +425,7 @@ export async function login(argv: { tfeHostname: string }) {
export async function synth(argv: any) {
const printPerformanceInfo = argv.showPerformanceInfo
? startPerformanceMonitoring()
: () => {}; // eslint-disable-line @typescript-eslint/no-empty-function
: () => { }; // eslint-disable-line @typescript-eslint/no-empty-function

try {
await initializErrorReporting(askForCrashReportingConsent);
Expand Down Expand Up @@ -499,7 +499,7 @@ export async function output(argv: any) {
const skipSynth = argv.skipSynth;
let outputsPath: string | undefined = undefined;
// eslint-disable-next-line @typescript-eslint/no-empty-function
let onOutputsRetrieved: (outputs: NestedTerraformOutputs) => void = () => {};
let onOutputsRetrieved: (outputs: NestedTerraformOutputs) => void = () => { };

if (argv.outputsFile) {
outputsPath = normalizeOutputPath(argv.outputsFile);
Expand All @@ -522,15 +522,44 @@ export async function output(argv: any) {
export async function debug(argv: any) {
const jsonOutput = argv.json;
const debugOutput = await collectDebugInformation();

const allProviders = await getProviders();
if (jsonOutput) {
console.log(JSON.stringify(debugOutput, null, 2));
console.log(JSON.stringify({
...debugOutput,
providers: allProviders
}, null, 2))
} else {
console.log(chalkColour`{bold {greenBright cdktf debug}}`);

Object.entries(debugOutput).forEach(([key, value]) => {
console.log(`${key}: ${value === null ? "null" : value}`);
});

//TODO: how to integrate this in well
console.log(
chalkColour`{bold {yellowBright provider versions}}`
)
const data = []
for (const provider of allProviders.local) {
data.push({
"Provider Name": provider.providerName || "",
"Provider Version": provider.providerVersion || "",
CDKTF: "",
Constraint: provider.providerConstraint || "",
"Package Name": "",
"Package Version": "",
});
}
for (const provider of allProviders.prebuilt) {
data.push({
"Provider Name": provider.providerName || "",
"Provider Version": provider.providerVersion || "",
CDKTF: provider.cdktfVersion || "",
Constraint: "",
"Package Name": provider.packageName || "",
"Package Version": provider.packageVersion || "",
});
}
}
}

Expand Down Expand Up @@ -594,8 +623,7 @@ export async function providerUpgrade(argv: any) {
if (constraintsToUpdate.length > 0) {
const singular = constraintsToUpdate.length === 1;
console.log(
`${constraintsToUpdate.length} local provider${
singular ? " has" : "s have"
`${constraintsToUpdate.length} local provider${singular ? " has" : "s have"
} been updated. Running cdktf get to update...`
);

Expand Down Expand Up @@ -624,11 +652,10 @@ export async function providerUpgrade(argv: any) {
}
}

export async function providerList(argv: any) {
async function getProviders() {
const config = CdktfConfig.read();
const language = config.language;
const cdktfVersion = await getPackageVersion(language, "cdktf");

if (!cdktfVersion)
throw Errors.External(
"Could not determine cdktf version. Please make sure you are in a directory containing a cdktf project and have all dependencies installed."
Expand All @@ -639,8 +666,12 @@ export async function providerList(argv: any) {
cdktfVersion,
config.projectDirectory
);
console.log("hits here")
return await manager.allProviders();
}

const allProviders = await manager.allProviders();
export async function providerList(argv: any) {
const allProviders = await getProviders();

if (argv.json) {
console.log(JSON.stringify(allProviders));
Expand Down

0 comments on commit fe8c11c

Please sign in to comment.