create-oc 1.1.0 → 1.1.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/index.js CHANGED
@@ -22,6 +22,7 @@ const { componentName, template } = await prompts([
22
22
  { title: 'Solid', value: 'solid' },
23
23
  { title: 'Preact', value: 'preact' },
24
24
  { title: 'Vue', value: 'vue' },
25
+ { title: 'Svelte', value: 'svelte' },
25
26
  { title: 'Elm', value: 'elm' },
26
27
  ],
27
28
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-oc",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "index.js",
@@ -17,8 +17,8 @@
17
17
  },
18
18
  "dependencies": {},
19
19
  "devDependencies": {
20
- "oc-server": "^2.0.4",
21
- "oc-template-elm-compiler": "^1.0.3",
20
+ "oc-server": "^2.0.5",
21
+ "oc-template-elm-compiler": "^1.1.1",
22
22
  "elm": "^0.19.1-6",
23
23
  "typescript": "^5.3.3"
24
24
  }
@@ -18,7 +18,7 @@
18
18
  }
19
19
  },
20
20
  "devDependencies": {
21
- "oc-server": "^2.0.4",
22
- "oc-template-es6-compiler": "^5.0.3"
21
+ "oc-server": "^2.0.5",
22
+ "oc-template-es6-compiler": "^5.1.1"
23
23
  }
24
24
  }
@@ -26,8 +26,8 @@
26
26
  "@testing-library/react": "^14.0.0",
27
27
  "@testing-library/user-event": "^14.4.3",
28
28
  "jsdom": "^21.1.1",
29
- "oc-server": "^2.0.4",
30
- "oc-template-preact-compiler": "^1.0.3",
29
+ "oc-server": "^2.0.5",
30
+ "oc-template-preact-compiler": "^1.1.1",
31
31
  "preact": "^10.13.2",
32
32
  "typescript": "5.0.2",
33
33
  "vitest": "^0.29.7"
@@ -26,8 +26,8 @@
26
26
  "@testing-library/user-event": "^14.4.3",
27
27
  "@types/react": "^18.0.28",
28
28
  "jsdom": "^21.1.1",
29
- "oc-server": "^2.0.4",
30
- "oc-template-react-compiler": "^7.0.3",
29
+ "oc-server": "^2.0.5",
30
+ "oc-template-react-compiler": "^7.1.1",
31
31
  "react": "18.3.1",
32
32
  "react-dom": "18.3.1",
33
33
  "typescript": "5.1.3",
@@ -25,8 +25,8 @@
25
25
  "@testing-library/jest-dom": "^6.5.0",
26
26
  "@types/testing-library__jest-dom": "^5.14.5",
27
27
  "jsdom": "^21.1.1",
28
- "oc-server": "^2.0.4",
29
- "oc-template-solid-compiler": "^1.0.3",
28
+ "oc-server": "^2.0.5",
29
+ "oc-template-solid-compiler": "^1.1.1",
30
30
  "solid-js": "^1.8.21",
31
31
  "typescript": "5.5.4",
32
32
  "vitest": "^2.0.5"
@@ -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.5",
29
+ "oc-template-svelte-compiler": "^0.0.2",
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
+ });
@@ -25,8 +25,8 @@
25
25
  "@types/testing-library__jest-dom": "^5.14.5",
26
26
  "@vitejs/plugin-vue": "^5.0.0",
27
27
  "jsdom": "^21.1.1",
28
- "oc-server": "^2.0.4",
29
- "oc-template-vue-compiler": "^1.0.3",
28
+ "oc-server": "^2.0.5",
29
+ "oc-template-vue-compiler": "^1.1.1",
30
30
  "typescript": "5.0.2",
31
31
  "vitest": "^0.29.7",
32
32
  "vue": "^3.3.11",