oc-template-svelte-compiler 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 OpenComponents community
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # oc-template-svelte-compiler - Compiler module
2
+
3
+ OC template to compile components of type `oc-template-svelte`
@@ -0,0 +1,2 @@
1
+ export * from './lib/compile';
2
+ export * from 'oc-template-svelte';
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ process.env.VITE_CJS_IGNORE_WARNING = 'true';
18
+ __exportStar(require("./lib/compile"), exports);
19
+ __exportStar(require("oc-template-svelte"), exports);
@@ -0,0 +1 @@
1
+ export declare const compile: (options: import("oc-generic-template-compiler").CompilerOptions, callback: (err: Error | null, data: unknown) => void) => void;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.compile = void 0;
7
+ const oc_template_svelte_1 = require("oc-template-svelte");
8
+ const vite_plugin_svelte_1 = require("@sveltejs/vite-plugin-svelte");
9
+ const oc_vite_compiler_1 = require("oc-vite-compiler");
10
+ const svelteOCProviderTemplate_1 = __importDefault(require("./svelteOCProviderTemplate"));
11
+ exports.compile = (0, oc_vite_compiler_1.createCompile)({
12
+ plugins: [(0, vite_plugin_svelte_1.svelte)()],
13
+ viewWrapper: svelteOCProviderTemplate_1.default,
14
+ getInfo: oc_template_svelte_1.getInfo
15
+ });
@@ -0,0 +1,7 @@
1
+ import { svelte as plugin } from '@sveltejs/vite-plugin-svelte';
2
+ export declare const appBlock: ({ name, version, entry }: {
3
+ name: string;
4
+ version: string;
5
+ entry: string;
6
+ }) => string;
7
+ export { plugin };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.plugin = exports.appBlock = void 0;
4
+ const vite_plugin_svelte_1 = require("@sveltejs/vite-plugin-svelte");
5
+ Object.defineProperty(exports, "plugin", { enumerable: true, get: function () { return vite_plugin_svelte_1.svelte; } });
6
+ const appBlock = ({ name, version, entry }) => `
7
+ <div id="root"></div>
8
+ <script type="module">
9
+ const data = __INITIAL_DATA__;
10
+ window.__$$oc_initialData__ = Object.freeze(data);
11
+ const settings = Object.freeze({ baseUrl: '/', id: 'root', name: '${name}', staticPath: '/', version: '${version}' });
12
+ window.__$$oc_Settings__ = settings;
13
+
14
+ window.oc = window.oc || {};
15
+ window.oc.cmd = window.oc.cmd || [];
16
+
17
+ import App from "${entry}";
18
+ import { mount } from 'svelte'
19
+
20
+ const container = document.getElementById('root');
21
+
22
+ window.oc.cmd.push(() => {
23
+ mount(View, {
24
+ target: container,
25
+ props: rest
26
+ });
27
+ window.oc.events.fire('oc:rendered', { ...settings, element: container, });
28
+ });
29
+ </script>
30
+ `;
31
+ exports.appBlock = appBlock;
@@ -0,0 +1,4 @@
1
+ export default function svelteOCProviderTemplate({ viewPath, providerFunctions }: {
2
+ viewPath: string;
3
+ providerFunctions: string;
4
+ }): string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function svelteOCProviderTemplate({ viewPath, providerFunctions }) {
4
+ return `
5
+ import { mount } from 'svelte'
6
+ import View from '${viewPath}';
7
+
8
+ function renderer(props, element, ssr) {
9
+ const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = props;
10
+ ${providerFunctions}
11
+
12
+ rest.getData = getData;
13
+ rest.getSetting = getSetting;
14
+ const app = mount(View, {
15
+ target: element,
16
+ props: rest
17
+ });
18
+ }
19
+
20
+ renderer.component = View;
21
+
22
+ export default renderer;
23
+ `;
24
+ }
25
+ exports.default = svelteOCProviderTemplate;
@@ -0,0 +1,4 @@
1
+ export default function vueOCProviderTemplate({ viewPath, providerFunctions }: {
2
+ viewPath: string;
3
+ providerFunctions: string;
4
+ }): string;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function vueOCProviderTemplate({ viewPath, providerFunctions }) {
4
+ return `
5
+ import { createApp } from 'vue'
6
+ import View from '${viewPath}';
7
+
8
+ function renderer(props, element, ssr) {
9
+ const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = props;
10
+ ${providerFunctions}
11
+
12
+ rest.getData = getData;
13
+ rest.getSetting = getSetting;
14
+ createApp(View, rest).mount(element, ssr);
15
+ }
16
+
17
+ renderer.component = View;
18
+
19
+ export default renderer;
20
+ `;
21
+ }
22
+ exports.default = vueOCProviderTemplate;
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "oc-template-svelte-compiler",
3
+ "version": "0.0.2",
4
+ "description": "Compiler for the Svelte OC template",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/opencomponents/vite-templates.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/opencomponents/vite-templates/issues"
17
+ },
18
+ "homepage": "https://github.com/opencomponents/vite-templates#readme",
19
+ "keywords": [
20
+ "oc",
21
+ "opencomponents",
22
+ "svelte",
23
+ "oc-template"
24
+ ],
25
+ "author": {
26
+ "name": "Ricardo Devis Agullo",
27
+ "email": "mkredz@gmail.com"
28
+ },
29
+ "license": "MIT",
30
+ "dependencies": {
31
+ "@sveltejs/vite-plugin-svelte": "^5.0.3",
32
+ "oc-template-svelte": "^0.0.2",
33
+ "oc-vite-compiler": "^4.1.0",
34
+ "svelte": "^5.23.0"
35
+ },
36
+ "files": [
37
+ "dist/**",
38
+ "scaffold"
39
+ ],
40
+ "devDependencies": {
41
+ "prettier": "^2.3.2",
42
+ "prettier-config-guestline": "2.0.0"
43
+ }
44
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "base-component-svelte",
3
+ "description": "",
4
+ "version": "1.0.0",
5
+ "scripts": {
6
+ "dev": "oc-server dev",
7
+ "build": "npm run check && oc package .",
8
+ "check": "svelte-check --tsconfig ./tsconfig.app.json && tsc -p tsconfig.node.json",
9
+ "test": "vitest"
10
+ },
11
+ "oc": {
12
+ "files": {
13
+ "data": "src/server.ts",
14
+ "template": {
15
+ "src": "src/App.svelte",
16
+ "type": "oc-template-svelte"
17
+ },
18
+ "static": [
19
+ "public"
20
+ ]
21
+ }
22
+ },
23
+ "devDependencies": {
24
+ "@testing-library/jest-dom": "^5.16.5",
25
+ "@types/testing-library__jest-dom": "^5.14.5",
26
+ "@sveltejs/vite-plugin-svelte": "^5.0.3",
27
+ "jsdom": "^21.1.1",
28
+ "oc-server": "^2.0.4",
29
+ "oc-template-svelte-compiler": "^0.0.1",
30
+ "svelte": "^5.23.0",
31
+ "typescript": "5.0.2",
32
+ "vitest": "^0.29.7"
33
+ }
34
+ }
Binary file
@@ -0,0 +1,71 @@
1
+ <script lang="ts">
2
+ import logo from '../public/logo.png';
3
+ import { InitialData, serverClient } from 'oc-server';
4
+
5
+ let funFact: string | null = $state(null);
6
+ let { born, firstName, hobbies, lastName }: InitialData = $props();
7
+ let getFunFact = async () => {
8
+ let response = await serverClient.funFact({ year: born });
9
+ funFact = response.funFact;
10
+ };
11
+ </script>
12
+
13
+ <div class="container">
14
+ <img width="50" height="50" src={logo} alt="Logo" />
15
+
16
+ <h1>
17
+ Hello, <span>{firstName}</span>
18
+ {lastName}
19
+ </h1>
20
+ <div class="info">
21
+ <div class="block">Born: {born}</div>
22
+ <div class="block">
23
+ Hobbies: {hobbies}
24
+ </div>
25
+ </div>
26
+ {#if funFact}
27
+ <div>{funFact}</div>
28
+ {/if}
29
+ <button class="button" onclick={getFunFact}> Fun year fact </button>
30
+ </div>
31
+
32
+ <style>
33
+ .container {
34
+ background-color: #3b246c;
35
+ color: #fff;
36
+ font-family: sans-serif;
37
+ padding: 40px;
38
+ }
39
+
40
+ .button {
41
+ background-color: #a97613;
42
+ border: none;
43
+ padding: 15px 32px;
44
+ text-align: center;
45
+ font-size: 16px;
46
+ text-decoration: none;
47
+ display: inline-block;
48
+ color: inherit;
49
+ cursor: pointer;
50
+ }
51
+
52
+ .button:hover {
53
+ background-color: #c79535;
54
+ }
55
+
56
+ h1 {
57
+ margin: 0 0 20px 0;
58
+ }
59
+
60
+ span {
61
+ text-decoration: underline;
62
+ }
63
+
64
+ .info {
65
+ margin-bottom: 20px;
66
+ }
67
+
68
+ .block {
69
+ margin: 6px 0;
70
+ }
71
+ </style>
@@ -0,0 +1,2 @@
1
+ /// <reference types="svelte" />
2
+ /// <reference types="oc-vite/client" />
@@ -0,0 +1,61 @@
1
+ import { Server } from 'oc-server';
2
+
3
+ const userDatabase = [
4
+ { name: 'John Doe', born: 1986, hobbies: ['Swimming', 'Basketball'] },
5
+ { name: 'Jane Doe', born: 1991, hobbies: ['Running', 'Rugby'] },
6
+ ];
7
+
8
+ const yearsFunFactDatabase: Record<number, string> = {
9
+ 1986: "Halley's Comet made its closest approach to Earth in 1986, visible to the naked eye.",
10
+ 1987: 'The first Final Fantasy game was released in 1987.',
11
+ 1991: 'The first web page was created in 1991 by Tim Berners-Lee.',
12
+ };
13
+
14
+ async function getUser(userId: number) {
15
+ return userDatabase[userId];
16
+ }
17
+
18
+ async function getFunFact(year: number) {
19
+ return yearsFunFactDatabase[year];
20
+ }
21
+
22
+ export const server = new Server()
23
+ .withParameters({
24
+ userId: {
25
+ default: 1,
26
+ description: 'The user id from the user database',
27
+ example: 1,
28
+ mandatory: true,
29
+ type: 'number',
30
+ },
31
+ })
32
+ .handler(async (params) => {
33
+ const { userId } = params;
34
+ const user = await getUser(userId);
35
+ const [firstName, lastName] = user.name.split(/\s+/);
36
+
37
+ if (firstName === 'Invalid') {
38
+ return;
39
+ }
40
+
41
+ return {
42
+ firstName,
43
+ lastName,
44
+ born: user.born,
45
+ hobbies: user.hobbies,
46
+ };
47
+ })
48
+ .action('funFact', async (params: { year: number }) => {
49
+ const { year } = params;
50
+ const funFact = await getFunFact(year);
51
+
52
+ return {
53
+ funFact,
54
+ };
55
+ });
56
+
57
+ declare module 'oc-server' {
58
+ interface Register {
59
+ server: typeof server;
60
+ }
61
+ }
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
@@ -0,0 +1,30 @@
1
+ .container {
2
+ background-color: #3b246c;
3
+ color: #fff;
4
+ font-family: sans-serif;
5
+ padding: 40px;
6
+ }
7
+
8
+ .button {
9
+ background-color: #a97613;
10
+ border: none;
11
+ padding: 15px 32px;
12
+ text-align: center;
13
+ font-size: 16px;
14
+ text-decoration: none;
15
+ display: inline-block;
16
+ color: inherit;
17
+ cursor: pointer;
18
+ }
19
+
20
+ .info {
21
+ margin-bottom: 20px;
22
+ }
23
+
24
+ .block {
25
+ margin: 6px 0;
26
+ }
27
+
28
+ .button:hover {
29
+ background-color: #c79535;
30
+ }
@@ -0,0 +1,15 @@
1
+ export interface OcParameters {
2
+ userId: number;
3
+ getMoreData?: boolean;
4
+ }
5
+
6
+ export interface AdditionalData {
7
+ hobbies: string[];
8
+ age: number;
9
+ }
10
+
11
+ export interface ClientProps extends Partial<AdditionalData> {
12
+ userId: number;
13
+ firstName: string;
14
+ lastName: string;
15
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "extends": "@tsconfig/svelte/tsconfig.json",
3
+ "compilerOptions": {
4
+ "target": "ESNext",
5
+ "useDefineForClassFields": true,
6
+ "module": "ESNext",
7
+ "resolveJsonModule": true,
8
+ /**
9
+ * Typecheck JS in `.svelte` and `.js` files by default.
10
+ * Disable checkJs if you'd like to use dynamic types in JS.
11
+ * Note that setting allowJs false does not prevent the use
12
+ * of JS in `.svelte` files.
13
+ */
14
+ "allowJs": true,
15
+ "checkJs": true,
16
+ "isolatedModules": true,
17
+ "moduleDetection": "force"
18
+ },
19
+ "include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"]
20
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ { "path": "./tsconfig.app.json" },
5
+ { "path": "./tsconfig.node.json" }
6
+ ]
7
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
4
+ "target": "ES2022",
5
+ "lib": ["ES2023"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "isolatedModules": true,
13
+ "moduleDetection": "force",
14
+ "noEmit": true,
15
+
16
+ /* Linting */
17
+ "strict": true,
18
+ "noUnusedLocals": true,
19
+ "noUnusedParameters": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+ "noUncheckedSideEffectImports": true
22
+ },
23
+ "include": ["vite.config.ts"]
24
+ }
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from 'vite';
2
+
3
+ // https://vitejs.dev/config/
4
+ export default defineConfig({
5
+ // Add your own plugins here for thinkgs like eslint or typecheckers
6
+ plugins: [],
7
+ // @ts-ignore Missing test property
8
+ test: {
9
+ environment: 'jsdom'
10
+ }
11
+ });