-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(applets): integrate into toolkit #1039
Changes from 1 commit
7bbe9bb
6d7f8f6
23ce00c
d509d03
f0065c1
ee2826f
e850b13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
applet: npm://@aws-cdk/aws-ecs:Hello | ||
Applets: | ||
Hello: | ||
Type: npm://@aws-cdk/aws-ecs:Hello |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# malformed applet specification | ||
applet: invalid:number:of:components:in:applet:name | ||
Applets: | ||
Applet: | ||
Type: invalid:number:of:components:in:applet:name |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# applet module not found | ||
applet: notfound | ||
Applets: | ||
Applet: | ||
Type: notfound |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# applet class not found | ||
applet: ./test-applet:ClassNotFound | ||
Applets: | ||
Applet: | ||
Type: ./test-applet:ClassNotFound |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# no module | ||
applet: :TestApplet | ||
Applets: | ||
Applet: | ||
Type: :TestApplet |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
--- | ||
- applet: ./test-applet:TestApplet | ||
name: Stack1 | ||
prop1: stack1 | ||
prop2: 123 | ||
- applet: ./test-applet:TestApplet | ||
name: Stack2 | ||
prop1: stack2 | ||
prop2: 456 | ||
Applets: | ||
Stack1: | ||
Type: ./test-applet:TestApplet | ||
Properties: | ||
prop1: stack1 | ||
prop2: 123 | ||
Stack2: | ||
Type: ./test-applet:TestApplet | ||
Properties: | ||
prop1: stack2 | ||
prop2: 456 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#!/usr/bin/env cdk-applet-js | ||
applet: ./test-applet:NoStackApplet | ||
argument: this should be reflected in the template description | ||
Applets: | ||
NoStackApplet: | ||
Type: ./test-applet:NoStackApplet | ||
Properties: | ||
argument: this should be reflected in the template description | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
# applet is loaded from the local ./test-applet.js file | ||
applet: ./test-applet:TestApplet | ||
prop1: hello | ||
prop2: 123 | ||
Applets: | ||
TestApplet: | ||
Type: ./test-applet:TestApplet | ||
Properties: | ||
prop1: hello | ||
prop2: 123 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
# applet is loaded from the local ./test-applet.js file | ||
applet: ./test-applet:TestApplet | ||
prop1: hello | ||
prop2: 123 | ||
prop3: | ||
- hello | ||
- this | ||
- is | ||
- awesome | ||
- 12345 | ||
Applets: | ||
TestApplet: | ||
Type: ./test-applet:TestApplet | ||
Properties: | ||
prop1: hello | ||
prop2: 123 | ||
prop3: | ||
- hello | ||
- this | ||
- is | ||
- awesome | ||
- 12345 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#!/usr/bin/env cdk-applet-js | ||
|
||
# if class name is not specified, 'Applet' is assumed | ||
applet: ./test-applet | ||
desc: this should be reflected in the template description | ||
Applets: | ||
Applet: | ||
Type: ./test-applet | ||
Properties: | ||
desc: this should be reflected in the template description |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,14 +141,53 @@ function appToArray(app: any) { | |
return typeof app === 'string' ? app.split(' ') : app; | ||
} | ||
|
||
type CommandGenerator = (file: string) => string[]; | ||
|
||
/** | ||
* Direct execution of a YAML file, assume that we're deploying an Applet | ||
*/ | ||
function executeApplet(appletFile: string): string[] { | ||
const appletBinary = path.resolve(require.resolve('@aws-cdk/applet-js')); | ||
return [process.execPath, appletBinary, appletFile]; | ||
} | ||
|
||
/** | ||
* Execute the given file with the same 'node' process as is running the current process | ||
*/ | ||
function executeNode(scriptFile: string): string[] { | ||
return [process.execPath, scriptFile]; | ||
} | ||
|
||
/** | ||
* Mapping of extensions to command-line generators | ||
*/ | ||
const EXTENSION_MAP = new Map<string, CommandGenerator>([ | ||
['.yml', executeApplet], | ||
['.yaml', executeApplet], | ||
['.js', executeNode], | ||
]); | ||
|
||
/** | ||
* Guess the executable from the command-line argument | ||
* | ||
* Only do this if the file is NOT marked as executable. If it is, | ||
* we'll defer to the shebang inside the file itself. | ||
* | ||
* If we're on Windows, we ALWAYS take the handler, since it's hard to | ||
* verify if registry associations have or have not been set up for this | ||
* file type, so we'll assume the worst and take control. | ||
*/ | ||
async function guessExecutable(commandLine: string[]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was actually thinking we can design this a bit more generally and make people happy. For example, if app is a I was also thinking that we can introduce auto-detection (i.e. if there's a For now, I think adding support for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that seems reasonable. |
||
if (commandLine.length === 1 && ['.yml', '.yaml'].includes(path.extname(commandLine[0]))) { | ||
// Direct execution of a YAML file, assume that we're deploying an Applet | ||
const appletBinary = path.resolve(require.resolve('@aws-cdk/applet-js')); | ||
return [process.execPath, appletBinary, commandLine[0]]; | ||
if (commandLine.length === 1) { | ||
const fstat = await fs.stat(commandLine[0]); | ||
// tslint:disable-next-line:no-bitwise | ||
const isExecutable = (fstat.mode & fs.constants.X_OK) !== 0; | ||
const isWindows = process.platform === "win32"; | ||
|
||
const handler = EXTENSION_MAP.get(path.extname(commandLine[0])); | ||
if (handler && (!isExecutable || isWindows)) { | ||
return handler(commandLine[0]); | ||
} | ||
} | ||
return commandLine; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance I can convince you to use lower case letters for the schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can, and I'm not liking this either.
But then let's not mimic the CloudFormation schema at all. Otherwise it's just going to be confusing, don't you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both Azure Resource Manager and Google Cloud Deployment Manager use very similar syntaxes. This is basically the standard-de-facto for desired state configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alrighty