-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into merge-back/2.96.2
- Loading branch information
Showing
30 changed files
with
172 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
const baseConfig = require('@aws-cdk/cdk-build-tools/config/eslintrc'); | ||
baseConfig.ignorePatterns.push('lib/init-templates/**/typescript/**/*.ts'); | ||
baseConfig.ignorePatterns.push('test/integ/cli/sam_cdk_integ_app/**/*.ts'); | ||
baseConfig.ignorePatterns.push('vendor/noctilucent/**/*.ts'); | ||
baseConfig.parserOptions.project = __dirname + '/tsconfig.json'; | ||
module.exports = baseConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,3 @@ tsconfig.json | |
junit.xml | ||
|
||
generate.sh | ||
lib/vendor/noctilucent/Dockerfile | ||
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,78 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { initializeProject, availableInitTemplates } from '../../lib/init'; | ||
import * as cdk_from_cfn from 'cdk-from-cfn'; | ||
import { cliInit } from '../../lib/init'; | ||
import { warning } from '../logging'; | ||
import * as nocti from '../vendor/noctilucent'; | ||
|
||
/* eslint-disable @typescript-eslint/no-var-requires */ // Packages don't have @types module | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
const camelCase = require('camelcase'); | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
const decamelize = require('decamelize'); | ||
|
||
/** The list of languages supported by the built-in noctilucent binary. */ | ||
export const MIGRATE_SUPPORTED_LANGUAGES: readonly string[] = nocti.supported_languages(); | ||
export const MIGRATE_SUPPORTED_LANGUAGES: readonly string[] = cdk_from_cfn.supported_languages(); | ||
|
||
export async function cliMigrate( | ||
inputpath: string = process.cwd() + '/../template.txt', | ||
language = MIGRATE_SUPPORTED_LANGUAGES[0], | ||
generateOnly = false, | ||
outputpath = process.cwd(), | ||
) { | ||
warning('This is an experimental feature. We make no guarantees about the outcome or stability of the functionality.'); | ||
const type = 'default'; // "default" is the default type (and maps to 'app') | ||
const template = (await availableInitTemplates()).find(t => t.hasName(type!)); | ||
if (!template) { | ||
throw new Error(`couldn't find template for ${type} app type, this should never happen`); | ||
} | ||
export interface CliMigrateOptions { | ||
readonly stackName: string; | ||
readonly language?: string; | ||
readonly fromPath?: string; | ||
readonly outputPath?: string; | ||
} | ||
|
||
if (!MIGRATE_SUPPORTED_LANGUAGES.includes(language)) { | ||
throw new Error(`Unsupported language for cdk migrate: ${language}. Supported languages are: ${MIGRATE_SUPPORTED_LANGUAGES.join(', ')}`); | ||
} | ||
export async function cliMigrate(options: CliMigrateOptions) { | ||
warning('This is an experimental feature. We make no guarantees about the outcome or stability of the functionality.'); | ||
|
||
await initializeProject(template, language, true, generateOnly, outputpath); | ||
const template_file = fs.readFileSync(inputpath, 'utf8'); | ||
const generated_app = nocti.transmute(template_file, language); | ||
// TODO: Validate stack name | ||
|
||
// clear out the init'd bin/lib files to replace with our own | ||
delete_files(outputpath + '/lib/'); | ||
const language = options.language ?? 'typescript'; | ||
const outputPath = path.join(options.outputPath ?? process.cwd(), options.stackName); | ||
|
||
// we hardcode everything to be called noctstack still so this works for now. | ||
// Will change this to be much smarter once we can change stack name in noct | ||
const bin_app = `#!/usr/bin/env node | ||
import 'source-map-support/register'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { NoctStack } from '../lib/generated_stack'; | ||
const generatedStack = generateStack(options, language); | ||
const stackName = decamelize(options.stackName); | ||
|
||
const app = new cdk.App(); | ||
new NoctStack(app, 'NoctStack', { | ||
/* If you don't specify 'env', this stack will be environment-agnostic. | ||
* Account/Region-dependent features and context lookups will not work, | ||
* but a single synthesized template can be deployed anywhere. */ | ||
try { | ||
fs.rmSync(outputPath, { recursive: true, force: true }); | ||
fs.mkdirSync(outputPath, { recursive: true }); | ||
await cliInit('app', language, true, false, outputPath, options.stackName); | ||
|
||
/* Uncomment the next line to specialize this stack for the AWS Account | ||
* and Region that are implied by the current CLI configuration. */ | ||
// env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION }, | ||
let stackFileName: string; | ||
switch (language) { | ||
case 'typescript': | ||
stackFileName = `${outputPath}/lib/${stackName}-stack.ts`; | ||
break; | ||
case 'java': | ||
stackFileName = `${outputPath}/src/main/java/com/myorg/${camelCase(stackName, { pascalCase: true })}Stack.java`; | ||
break; | ||
case 'python': | ||
stackFileName = `${outputPath}/${stackName.replace(/-/g, '_')}/${stackName.replace(/-/g, '_')}_stack.py`; | ||
break; | ||
case 'csharp': | ||
stackFileName = `${outputPath}/src/${camelCase(stackName, { pascalCase: true })}/${camelCase(stackName, { pascalCase: true })}Stack.cs`; | ||
break; | ||
// TODO: Add Go support | ||
default: | ||
throw new Error(`${language} is not supported by CDK Migrate. Please choose from: ${MIGRATE_SUPPORTED_LANGUAGES.join(', ')}`); | ||
} | ||
fs.writeFileSync(stackFileName!, generatedStack); | ||
} catch (error) { | ||
fs.rmSync(outputPath, { recursive: true, force: true }); | ||
throw error; | ||
} | ||
|
||
/* Uncomment the next line if you know exactly what Account and Region you | ||
* want to deploy the stack to. */ | ||
// env: { account: '123456789012', region: 'us-east-1' }, | ||
} | ||
|
||
/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */ | ||
});`; | ||
const myname = path.basename(outputpath); | ||
fs.writeFileSync(outputpath + '/lib/' + 'generated_stack.ts', generated_app); | ||
fs.writeFileSync(outputpath + '/bin/' + `${myname}.ts`, bin_app); | ||
function generateStack(options: CliMigrateOptions, language: string) { | ||
const stackName = `${camelCase(decamelize(options.stackName), { pascalCase: true })}Stack`; | ||
// We will add other options here in a future change. | ||
if (options.fromPath) { | ||
return fromPath(stackName, options.fromPath, language); | ||
} | ||
// TODO: replace with actual output for other options. | ||
return ''; | ||
} | ||
|
||
function delete_files(filepath: string) { | ||
fs.readdir(filepath, (err, files) => { | ||
if (err) throw err; | ||
for (const file of files) { | ||
fs.unlink(filepath + file, (cause) => { | ||
if (cause) throw cause; | ||
}); | ||
} | ||
}); | ||
function fromPath(stackName: string, inputPath: string, language: string): string { | ||
const templateFile = fs.readFileSync(inputPath, 'utf8'); | ||
return cdk_from_cfn.transmute(templateFile, language, stackName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.