-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial "playground" for examples (#314)
Initial "playground" for examples
- Loading branch information
Showing
16 changed files
with
696 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
(ignored_subdirs (node_modules _esy)) | ||
(ignored_subdirs (node_modules _esy playground)) |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* Notify external environments of switching tabs */ | ||
external notifyExampleSwitched: string => unit = | ||
"revery_example_notify_changed"; |
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,5 @@ | ||
(library | ||
(name ExampleStubs) | ||
(c_names example_stubs) | ||
(js_of_ocaml (javascript_files example_stubs.js)) | ||
) |
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,14 @@ | ||
#include <stdio.h> | ||
|
||
#include <caml/alloc.h> | ||
#include <caml/callback.h> | ||
#include <caml/memory.h> | ||
#include <caml/mlvalues.h> | ||
|
||
CAMLprim value revery_example_notify_changed(value vExample) { | ||
CAMLparam1(vExample); | ||
const char *szExampleSource = String_val(vExample); | ||
|
||
printf("Switched to example: %s\n", szExampleSource); | ||
return Val_unit; | ||
} |
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,7 @@ | ||
// Provides: revery_example_notify_changed | ||
function revery_example_notify_changed(src) { | ||
var window = joo_global_object.window; | ||
if (window && window["__revery_playground_example_notify_changed"]) { | ||
window["__revery_playground_example_notify_changed"](caml_to_js_string(src)); | ||
} | ||
} |
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,3 @@ | ||
_build/ | ||
host/ | ||
sources/ |
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,18 @@ | ||
# revery-playground | ||
|
||
### Examples w/ code alongside | ||
|
||
## Build | ||
|
||
### Prerequisites | ||
|
||
- Make sure you have run `esy build` from the root directory | ||
|
||
### Build | ||
|
||
- `npm install` | ||
- `npm run build` | ||
|
||
### Testing | ||
|
||
- `npm start` |
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,83 @@ | ||
// Simple build script to copy over files from the release folder | ||
|
||
let cp = require("child_process"); | ||
let fs = require("fs-extra"); | ||
let os = require("os"); | ||
let path = require("path"); | ||
|
||
let playgroundRoot = __dirname | ||
let playgroundSources = path.join(playgroundRoot, "src"); | ||
let reveryRoot = path.join(playgroundRoot, ".."); | ||
let playgroundBuild = path.join(playgroundRoot, "_build"); | ||
|
||
let nodeModulesSrc = path.join(playgroundRoot, "node_modules"); | ||
let nodeModulesDest = path.join(playgroundBuild, "node_modules"); | ||
|
||
let playgroundExampleSources = path.join(playgroundRoot, "_build", "sources"); | ||
let playgroundExampleHost = path.join(playgroundRoot, "_build", "host"); | ||
|
||
let reveryExampleSources = path.join(reveryRoot, "examples"); | ||
|
||
let getEsyPath = () => { | ||
let result = cp.execSync("where esy"); | ||
let found = result.toString("utf8"); | ||
|
||
let candidates = found.trim().split(os.EOL); | ||
return candidates[candidates.length - 1]; | ||
}; | ||
|
||
let getCommit = () => { | ||
let result = cp.execSync("git rev-parse --short HEAD"); | ||
return result.toString("utf8").trim(); | ||
} | ||
|
||
let getVersion = () => { | ||
let packageJson = fs.readFileSync(path.join(reveryRoot, "package.json")).toString("utf8"); | ||
return JSON.parse(packageJson).version; | ||
} | ||
|
||
let esyPath = getEsyPath(); | ||
let commitId = getCommit(); | ||
let version = getVersion(); | ||
console.log("Esy path: " + esyPath); | ||
console.log("Commit id: " + commitId); | ||
console.log("Version: " + version); | ||
|
||
let getBuildArtifactFolder = () => { | ||
let result = cp.spawnSync(esyPath, ["bash", "-c", "echo $cur__bin"], { cwd: reveryRoot }); | ||
return result.stdout.toString("utf8").trim(); | ||
}; | ||
|
||
let replace = (str, val, newVal) => { | ||
return str.split(val).join(newVal); | ||
}; | ||
|
||
let artifactFolder = getBuildArtifactFolder(); | ||
|
||
console.log("Artifact folder: " + artifactFolder); | ||
|
||
console.log(`Copying sources from ${playgroundSources} to ${playgroundBuild}...`); | ||
fs.copySync(playgroundSources, playgroundBuild); | ||
console.log("Sources copied."); | ||
|
||
console.log(`Copying examples from ${reveryExampleSources} to ${playgroundExampleSources}...`); | ||
fs.copySync(reveryExampleSources, playgroundExampleSources); | ||
console.log("Examples copied."); | ||
|
||
console.log("Copying artifacts..."); | ||
fs.copySync(artifactFolder, playgroundExampleHost); | ||
console.log("Artifacts copied."); | ||
|
||
console.log("Copying node_modules..."); | ||
fs.copySync(nodeModulesSrc, nodeModulesDest); | ||
console.log("node_modules copied."); | ||
|
||
console.log("Replacing constaints in index.html"); | ||
let indexHtmlPath = path.join(playgroundBuild, "index.html"); | ||
|
||
let indexHtml = fs.readFileSync(indexHtmlPath).toString("utf8"); | ||
indexHtml = replace(indexHtml, "{#VERSION}", version); | ||
indexHtml = replace(indexHtml, "{#COMMIT}", commitId); | ||
|
||
fs.writeFileSync(indexHtmlPath, indexHtml); | ||
console.log("Done!"); |
Oops, something went wrong.