-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(applets): integrate into toolkit (#1039)
Integrate the Applet runner into the toolkit. When the --app argument points to a .yml or .yaml file, the target will be assumed to be a JavaScript applet, and run through the applet interpreter. Enhancements to JS applet interpreter: - Allow using non-Stack constructs. - Multiple Stacks in one applet file by supplying an array. - Allow referencing packages directly from NPM. Non-Stack constructs can now be used as applets. If a non-Stack applet is selected, a Stack will be constructed around it. This makes it possible to reuse Applet constructs in regular CDK applications (if they meet the requirements). BREAKING CHANGE: The applet schema has changed to allow Multiple applets can be define in one file by structuring the files like this: BREAKING CHANGE: The applet schema has changed to allow definition of multiple applets in the same file. The schema now looks like this: applets: MyApplet: type: ./my-applet-file properties: property1: value ... By starting an applet specifier with npm://, applet modules can directly be referenced in NPM. You can include a version specifier (@1.2.3) to reference specific versions. Fixes #849, #342, #291.
- Loading branch information
Showing
28 changed files
with
6,202 additions
and
455 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 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Determine whether this constructorFunction is going to create an object that inherits from Stack | ||
* | ||
* We do structural typing. | ||
*/ | ||
export function isStackConstructor(constructorFn: any) { | ||
// Test for a public method that Stack has | ||
return constructorFn.prototype.findResource !== undefined; | ||
} | ||
|
||
/** | ||
* Extract module name from a NPM package specification | ||
*/ | ||
export function extractModuleName(packageSpec: string) { | ||
const m = /^((?:@[a-zA-Z-]+\/)?[a-zA-Z-]+)/i.exec(packageSpec); | ||
if (!m) { throw new Error(`Could not find package name in ${packageSpec}`); } | ||
return m[1]; | ||
} | ||
|
||
export function parseApplet(applet: string): AppletSpec { | ||
const m = /^(npm:\/\/)?([a-z0-9_@./-]+)(:[a-z_0-9]+)?$/i.exec(applet); | ||
if (!m) { | ||
throw new Error(`"applet" value is "${applet}" but it must be in the form "[npm://]<js-module>[:<applet-class>]". | ||
If <applet-class> is not specified, "Applet" is the default`); | ||
} | ||
|
||
if (m[1] === 'npm://') { | ||
return { | ||
npmPackage: m[2], | ||
moduleName: extractModuleName(m[2]), | ||
className: className(m[3]), | ||
}; | ||
} else { | ||
return { | ||
moduleName: m[2], | ||
className: className(m[3]), | ||
}; | ||
} | ||
|
||
function className(s: string | undefined) { | ||
if (s) { | ||
return s.substr(1); | ||
} | ||
return 'Applet'; | ||
} | ||
} | ||
|
||
export interface AppletSpec { | ||
npmPackage?: string; | ||
moduleName: string; | ||
className: string; | ||
} |
Oops, something went wrong.