-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into huijbers/diff-refactor
- Loading branch information
Showing
45 changed files
with
5,978 additions
and
5,302 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
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,4 +1,2 @@ | ||
jsii-experimental/embedded/* | ||
jsii-calc | ||
|
||
!jsii-experimental/embedded/.gitkeep | ||
/jsii-calc/ | ||
*.generated.go |
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,14 +1,73 @@ | ||
#!/usr/bin/env npx ts-node | ||
|
||
import { copyFileSync, readdirSync } from 'fs'; | ||
import { join, resolve } from 'path'; | ||
import { CodeMaker } from 'codemaker'; | ||
import { readdirSync, readFileSync } from 'fs'; | ||
import { resolve } from 'path'; | ||
|
||
const EMBEDDED_SOURCE = resolve(__dirname, '..', '..', 'runtime', 'webpack'); | ||
const EMBEDDED_RUNTIME_ROOT = resolve( | ||
__dirname, | ||
'..', | ||
'..', | ||
'runtime', | ||
'webpack', | ||
); | ||
|
||
for (const filename of readdirSync(EMBEDDED_SOURCE)) { | ||
const filepath = join(EMBEDDED_SOURCE, filename); | ||
copyFileSync( | ||
filepath, | ||
resolve(__dirname, '..', 'jsii-experimental', 'embedded', filename), | ||
const OUTPUT_DIR = resolve(__dirname, '..', 'jsii-experimental'); | ||
|
||
const RUNTIME_FILE = 'embeddedruntime.generated.go'; | ||
const VERSION_FILE = 'version.generated.go'; | ||
|
||
const code = new CodeMaker({ indentationLevel: 1, indentCharacter: '\t' }); | ||
|
||
code.openFile(RUNTIME_FILE); | ||
code.line('package jsii'); | ||
code.line(); | ||
code.open('var embeddedruntime = map[string][]byte{'); | ||
const bytesPerLine = 16; | ||
const files = readdirSync(EMBEDDED_RUNTIME_ROOT); | ||
const fileSize: Record<string, number> = {}; | ||
for (const file of files) { | ||
const byteSlice = getByteSlice(resolve(EMBEDDED_RUNTIME_ROOT, file)); | ||
fileSize[file] = byteSlice.length; | ||
code.open(`${JSON.stringify(file)}: []byte{`); | ||
for (let i = 0; i < byteSlice.length; i += bytesPerLine) { | ||
const line = byteSlice.slice(i, i + bytesPerLine); | ||
code.line(`${line.join(', ')},`); | ||
} | ||
code.close('},'); | ||
} | ||
code.close('}'); | ||
code.line(); | ||
const mainKey = JSON.stringify(files.find((f) => f.endsWith('.js')))!; | ||
code.line(`const embeddedruntimeMain = ${mainKey}`); | ||
code.line(); | ||
// This performs sanity tests upon initialization | ||
code.open('func init() {'); | ||
for (const [file, size] of Object.entries(fileSize)) { | ||
code.open(`if len(embeddedruntime[${JSON.stringify(file)}]) != ${size} {`); | ||
code.line( | ||
`panic("Embedded runtime file ${file} does not have expected size of ${size} bytes!")`, | ||
); | ||
code.close('}'); | ||
} | ||
code.close('}'); | ||
code.closeFile(RUNTIME_FILE); | ||
|
||
code.openFile(VERSION_FILE); | ||
code.line('package jsii'); | ||
code.line(); | ||
const thisVersion = require('../package.json').version; | ||
code.line(`const version = ${JSON.stringify(thisVersion)}`); | ||
code.closeFile(VERSION_FILE); | ||
|
||
code.save(OUTPUT_DIR); | ||
|
||
function getByteSlice(path: string) { | ||
const fileData = readFileSync(path).toString('hex'); | ||
const result = []; | ||
for (let i = 0; i < fileData.length; i += 2) { | ||
result.push(`0x${fileData[i]}${fileData[i + 1]}`); | ||
} | ||
|
||
return result; | ||
} |
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,21 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
// "log" | ||
"fmt" | ||
jsiicalc "github.com/aws-cdk/jsii/jsii-calc/golang/jsiicalc" | ||
// "fmt" | ||
calc "github.com/aws-cdk/jsii/jsii-calc/golang/jsiicalc" | ||
"github.com/aws-cdk/jsii/jsii-experimental" | ||
"math" | ||
) | ||
|
||
func main() { | ||
fmt.Println("Hello, JSII") | ||
// client, err := jsii.InitClient() | ||
defer jsii.Close() | ||
|
||
// if err !=nil { | ||
// log.Fatal(err) | ||
// } | ||
fmt.Print(jsii.Client{RuntimeVersion: "100.100.100"}) | ||
calculator := calc.NewCalculator(calc.CalculatorProps{InitialValue: 0, MaximumValue: math.MaxFloat64}) | ||
calculator.Add(1337) | ||
calculator.Mul(42) | ||
|
||
// fmt.Printf("Client init successful\nRuntime version: %s", client.RuntimeVersion) | ||
fmt.Println(jsiicalc.AbstractClass{}) | ||
if calculator.GetValue() != 1337.*42. { | ||
// TODO: right now implementations are just NOOP. | ||
// panic(fmt.Sprintf("Unexpected calculator value: expected %f, but received %f", 1337.*42., calculator.GetValue())) | ||
} | ||
} |
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.