Skip to content

Commit

Permalink
Template svelte (hyperbrew#26)
Browse files Browse the repository at this point in the history
* add svelte template

* dependency fixes, App > main, won't run on build

* improvements to tempate testing

* svelte fixes

* svelte fully functional

Co-authored-by: Martin Lindberg <[email protected]>
  • Loading branch information
justintaylor-dev and fartinmartin authored May 27, 2022
1 parent 0c4b2eb commit ba544c3
Show file tree
Hide file tree
Showing 19 changed files with 478 additions and 87 deletions.
26 changes: 26 additions & 0 deletions cep.config.debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export const debugAll = [
{
mainPath: "./template-react/index.html", // DEBUG the React Template
name: "template-react",
panelDisplayName: "Bolt CEP - React",
autoVisible: true,
width: 600,
height: 650,
},
{
mainPath: "./template-vue/index.html", // DEBUG the Vue Template
name: "template-vue",
panelDisplayName: "Bolt CEP - Vue",
autoVisible: true,
width: 600,
height: 650,
},
{
mainPath: "./template-svelte/index.html", // DEBUG the Svelte Template
name: "template-svelte",
panelDisplayName: "Bolt CEP - Svelte",
autoVisible: true,
width: 600,
height: 650,
},
];
2 changes: 2 additions & 0 deletions cep.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CEP_Config } from "vite-cep-plugin";
import { version } from "./package.json";
// import { debugAll } from "./cep.config.debug"; // DEBUG-ONLY

const config: CEP_Config = {
version,
Expand Down Expand Up @@ -44,6 +45,7 @@ const config: CEP_Config = {
width: 600,
height: 650,
},
// ...debugAll, // DEBUG-ONLY
],

build: {
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bolt-cep",
"version": "0.2.0",
"version": "0.3.0",
"scripts": {
"dev": "vite",
"debug": "cross-env DEBUG_REACT=true vite build --watch true",
Expand Down Expand Up @@ -33,6 +33,8 @@
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-replace": "^4.0.0",
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
"@tsconfig/svelte": "^3.0.0",
"@types/fs-extra": "^9.0.13",
"@types/node": "^16.11.7",
"@types/react": "^17.0.43",
Expand All @@ -53,11 +55,14 @@
"rollup-plugin-node-copy": "^1.0.4",
"rollup-plugin-scss": "^3.0.0",
"sass": "^1.43.4",
"svelte": "^3.44.0",
"svelte-check": "^2.7.1",
"svelte-preprocess": "^4.10.6",
"types-for-adobe": "^7.0.0",
"types-for-adobe-extras": "^0.0.1",
"typescript": "^4.4.4",
"vite": "^2.9.1",
"vite-cep-plugin": "^0.2.3",
"vite-cep-plugin": "^0.2.5",
"yarn": "^1.22.17"
},
"main": "index.js",
Expand Down
10 changes: 10 additions & 0 deletions src/js/assets/svelte.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 7 additions & 18 deletions src/js/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ code {
text-align: center;
}



.app-header {
background-color: #282c34;
min-height: 100vh;
Expand All @@ -33,15 +31,6 @@ code {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

button {
font-size: 1.25rem;
background-color: #3f4653;
Expand All @@ -67,30 +56,30 @@ button:active {
column-gap: 1rem;
}

.stack-icons{
.stack-icons {
display: flex;
margin: 2rem 0rem 2rem 0rem;
font-size: 2.5rem;
>div{
> div {
display: flex;
flex-direction: column;
text-align: center;
justify-content: center;
font-size: 1rem;
margin: 0rem 1rem 0rem 1rem;
}
img{
img {
margin: auto;
display: block;
height: 3rem;
width: 3rem;
}
}
.icon{
.icon {
width: 250px;
height: 250px;
}
.icon-button{
.icon-button {
width: 20px;
height: 20px;;
}
height: 20px;
}
22 changes: 10 additions & 12 deletions src/js/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@ export const openLinkInBrowser = (url: string) => {

export const evalES = (script: string, isGlobal = false): Promise<string> => {
return new Promise(function (resolve, reject) {
const pre = isGlobal
? ""
: `var host = typeof $ !== 'undefined' ? $ : window; host["${ns}"].`;
const fullString = pre + script;
csi.evalScript(
`try{
${
isGlobal
? ""
: `var host = typeof $ !== 'undefined' ? $ : window; host["${ns}"].`
}${script};
}catch(e){
alert(e);
}`,
"try{" + fullString + "}catch(e){alert(e);}",
(res: string) => {
resolve(res);
}
Expand All @@ -34,9 +30,11 @@ export const evalES = (script: string, isGlobal = false): Promise<string> => {

export const evalFile = (file: string) => {
return evalES(
`typeof $ !== 'undefined' ?
$.evalFile("${file}") :
fl.runScript(FLfile.platformPathToURI("${file}"));`,
"typeof $ !== 'undefined' ? $.evalFile(\"" +
file +
'") : fl.runScript(FLfile.platformPathToURI("' +
file +
'"));',
true
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/js/main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="/main/index.tsx"></script>
<script type="module" src="./index.tsx"></script>
</body>
</html>
1 change: 1 addition & 0 deletions src/js/main/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "../variables.scss";
2 changes: 1 addition & 1 deletion src/js/main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const Main = () => {
</button>
</div>
<p>
Edit <code>app.tsx</code> and save to test HMR updates.
Edit <code>main.tsx</code> and save to test HMR updates.
</p>
<p>
<button
Expand Down
2 changes: 1 addition & 1 deletion src/js/template-react/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="/main/index.tsx"></script>
<script type="module" src="./index.tsx"></script>
</body>
</html>
1 change: 1 addition & 0 deletions src/js/template-react/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "../variables.scss";
13 changes: 13 additions & 0 deletions src/js/template-svelte/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bolt CEP Svelte</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="./main.ts"></script>
</body>
</html>
1 change: 1 addition & 0 deletions src/js/template-svelte/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "../variables.scss";
106 changes: 106 additions & 0 deletions src/js/template-svelte/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<script lang="ts">
import { onMount } from "svelte";
import { fs, os, path } from "../lib/node";
import { csi, evalES, evalFile, openLinkInBrowser } from "../lib/utils";
import viteLogo from "../assets/vite.svg";
import svelteLogo from "../assets/svelte.svg";
import tsLogo from "../assets/typescript.svg";
import sassLogo from "../assets/sass.svg";
import nodeJs from "../assets/node-js.svg";
import adobe from "../assets/adobe.svg";
import bolt from "../assets/bolt-cep.svg";
import "../index.scss";
import "./main.scss";
let count = 0;
const jsxTest = () => {
console.log(evalES(`helloWorld("${csi.getApplicationID()}")`));
};
const nodeTest = () => {
alert(
`Node.js ${process.version}\nPlatform: ${
os.platform
}\nFolder: ${path.basename(window.cep_node.global.__dirname)}`
);
};
onMount(() => {
if (window.cep) {
const extRoot = csi.getSystemPath("extension");
const jsxSrc = `${extRoot}/jsx/index.js`;
const jsxBinSrc = `${extRoot}/jsx/index.jsxbin`;
if (fs.existsSync(jsxSrc)) {
console.log(jsxSrc);
evalFile(jsxSrc);
} else if (fs.existsSync(jsxBinSrc)) {
console.log(jsxBinSrc);
evalFile(jsxBinSrc);
}
}
});
</script>

<div class="app">
<header class="app-header">
<img src={bolt} class="icon" alt="" />
<div class="stack-icons">
<div>
<img src={viteLogo} alt="" />
Vite
</div>
+
<div>
<img src={svelteLogo} alt="" />
Svelte
</div>
+
<div>
<img src={tsLogo} alt="" />
TypeScript
</div>
+
<div>
<img src={sassLogo} alt="" />
Sass
</div>
</div>
<div class="button-group">
<button on:click={() => (count += 1)}>Count is: {count}</button>
<button on:click={nodeTest}>
<img class="icon-button" src={nodeJs} alt="" />
</button>
<button on:click={jsxTest}>
<img class="icon-button" src={adobe} alt="" />
</button>
</div>

<p>Edit <code>main.svelte</code> and save to test HMR updates.</p>
<p>
<button
on:click={() =>
openLinkInBrowser("https://github.com/hyperbrew/bolt-cep")}
>
Bolt Docs
</button>
|
<button on:click={() => openLinkInBrowser("https://svelte.dev/docs")}>
Svelte Docs
</button>
|
<button
on:click={() =>
openLinkInBrowser("https://vitejs.dev/guide/features.html")}
>
Vite Docs
</button>
</p>
</header>
</div>

<style>
</style>
7 changes: 7 additions & 0 deletions src/js/template-svelte/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import App from "./main.svelte";

const app = new App({
target: document.getElementById("root") as Element,
});

export default app;
2 changes: 2 additions & 0 deletions src/js/template-svelte/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="svelte" />
/// <reference types="vite/client" />
2 changes: 1 addition & 1 deletion src/js/template-vue/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="/main/main.ts"></script>
<script type="module" src="./main.ts"></script>
</body>
</html>
16 changes: 11 additions & 5 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { defineConfig, preview } from "vite";
import react from "@vitejs/plugin-react";
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";

import react from "@vitejs/plugin-react"; // BOLT-CEP_REACT-ONLY
import vue from "@vitejs/plugin-vue"; // BOLT-CEP_VUE-ONLY
import { svelte } from "@sveltejs/vite-plugin-svelte"; // BOLT-CEP_SVELTE-ONLY

import { cep, runAction } from "vite-cep-plugin";
import cepConfig from "./cep.config";
Expand Down Expand Up @@ -46,7 +48,12 @@ if (action) {

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), vue(), cep(config)],
plugins: [
react(), // BOLT-CEP_REACT-ONLY
vue(), // BOLT-CEP_VUE-ONLY
svelte(), // BOLT-CEP_SVELTE-ONLY
cep(config),
],
root,
clearScreen: false,
server: {
Expand All @@ -57,7 +64,6 @@ export default defineConfig({
},

build: {
// emptyOutDir: true,
sourcemap: isPackage ? cepConfig.zxp.sourceMap : cepConfig.build?.sourceMap,
watch: {
include: "src/jsx/**",
Expand Down
Loading

0 comments on commit ba544c3

Please sign in to comment.