create-oc 0.0.8 → 0.0.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-oc",
3
- "version": "0.0.8",
3
+ "version": "0.0.11",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "index.js",
@@ -23,9 +23,9 @@
23
23
  },
24
24
  "dependencies": {},
25
25
  "devDependencies": {
26
- "oc-server": "*",
27
- "oc-template-elm-compiler": "*",
28
- "elm": "*",
29
- "typescript": "*"
26
+ "oc-server": "^0.3.0",
27
+ "oc-template-elm-compiler": "^0.3.0",
28
+ "elm": "^0.19.1-6",
29
+ "typescript": "^5.3.3"
30
30
  }
31
31
  }
@@ -0,0 +1,3 @@
1
+ {
2
+ "recommendations": ["Tobermory.es6-string-html"]
3
+ }
@@ -4,28 +4,27 @@
4
4
  "version": "1.0.0",
5
5
  "oc": {
6
6
  "files": {
7
- "data": "server.js",
7
+ "data": "src/server.ts",
8
8
  "static": [
9
- "img",
10
- "css"
9
+ "public"
11
10
  ],
12
11
  "template": {
13
- "src": "view.js",
12
+ "src": "src/view.ts",
14
13
  "type": "oc-template-es6"
15
14
  }
16
15
  },
17
16
  "parameters": {
18
- "name": {
19
- "default": "Jane Doe",
20
- "description": "Your name",
21
- "example": "Jane Doe",
22
- "mandatory": false,
23
- "type": "string"
17
+ "userId": {
18
+ "default": 1,
19
+ "description": "The user id from the user database",
20
+ "example": 1,
21
+ "mandatory": true,
22
+ "type": "number"
24
23
  }
25
24
  }
26
25
  },
27
26
  "devDependencies": {
28
- "oc-server": "*",
29
- "oc-template-es6-compiler": "*"
27
+ "oc-server": "^0.3.0",
28
+ "oc-template-es6-compiler": "^4.0.3"
30
29
  }
31
30
  }
Binary file
@@ -0,0 +1,50 @@
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(async (params: { userId: number }) => {
23
+ const { userId } = params;
24
+ const user = await getUser(userId);
25
+ const [firstName, lastName] = user.name.split(/\s+/);
26
+
27
+ if (firstName === 'Invalid') {
28
+ return;
29
+ }
30
+
31
+ return {
32
+ firstName,
33
+ lastName,
34
+ born: user.born,
35
+ hobbies: user.hobbies,
36
+ };
37
+ }).action('funFact', async (params: { year: number }) => {
38
+ const { year } = params;
39
+ const funFact = await getFunFact(year);
40
+
41
+ return {
42
+ funFact,
43
+ };
44
+ });
45
+
46
+ declare module 'oc-server' {
47
+ interface Register {
48
+ server: typeof server;
49
+ }
50
+ }
@@ -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,33 @@
1
+ import { InitialData, serverClient } from 'oc-server';
2
+ import styles from './styles.css';
3
+ import logo from '../public/logo.png';
4
+
5
+ declare const window: Window & {
6
+ getFunFact: () => Promise<void>;
7
+ };
8
+
9
+ export default ({ firstName, lastName, hobbies, born }: InitialData) => {
10
+ window.getFunFact = async () => {
11
+ const { funFact } = await serverClient.funFact({ year: born });
12
+ document.querySelector('#funfact')!.innerHTML = funFact;
13
+ };
14
+
15
+ return /* html */ `
16
+ <div class="${styles.container}">
17
+ <img width="50" height="50" src="${logo}" alt="Logo" />
18
+ <h1 style="margin: 0 0 20px 0;">
19
+ Hello, <span style="text-decoration: underline;">${firstName}</span> ${lastName}
20
+ </h1>
21
+ <div class=${styles.info}>
22
+ <div class=${styles.block}>Born: ${born}</div>
23
+ <div class=${styles.block}>
24
+ <div>Hobbies: ${hobbies.map((x) => x.toLowerCase()).join(', ')}</div>
25
+ </div>
26
+ </div>
27
+ <div id="funfact"></div>
28
+ <button class=${styles.button} onclick="getFunFact()">
29
+ Fun year fact
30
+ </button>
31
+ </div>
32
+ `;
33
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "base-component-react",
2
+ "name": "base-component-preact",
3
3
  "description": "",
4
4
  "version": "1.0.0",
5
5
  "scripts": {
@@ -33,8 +33,8 @@
33
33
  "@testing-library/react": "^14.0.0",
34
34
  "@testing-library/user-event": "^14.4.3",
35
35
  "jsdom": "^21.1.1",
36
- "oc-server": "*",
37
- "oc-template-preact-compiler": "0.2.0",
36
+ "oc-server": "^0.3.0",
37
+ "oc-template-preact-compiler": "^0.4.0",
38
38
  "preact": "^10.13.2",
39
39
  "typescript": "5.0.2",
40
40
  "vitest": "^0.29.7"
@@ -1,23 +1,21 @@
1
1
  import { useState } from 'preact/hooks';
2
- import { useData } from 'oc-template-preact-compiler/dist/utils/useData';
3
- import { serverClient } from 'oc-server';
2
+ import { ActionOutput, InitialData, serverClient } from 'oc-server';
4
3
  import styles from './styles.css';
5
- import type { AdditionalData, ClientProps } from './types';
4
+ import logo from '../public/logo.png';
6
5
 
7
- interface AppProps extends ClientProps {
8
- getMoreData?: boolean;
9
- }
6
+ type AdditionalData = ActionOutput<'funFact'>;
10
7
 
11
- const App = () => {
12
- const { firstName, lastName, userId, getData, getSetting } = useData<AppProps>();
13
- const staticPath = getSetting('staticPath');
14
- const [additionalData, setAdditionalData] = useState<AdditionalData | null>(null);
8
+ const App = (props: InitialData) => {
9
+ const { firstName, lastName, born, hobbies } = props;
10
+ const [additionalData, setAdditionalData] = useState<AdditionalData | null>(
11
+ null
12
+ );
15
13
  const [error, setError] = useState('');
16
14
 
17
- const fetchMoreData = async () => {
15
+ const getFunFact = async () => {
18
16
  setError('');
19
17
  try {
20
- const data = await serverClient.getMoreData({ userId });
18
+ const data = await serverClient.funFact({ year: born });
21
19
  setAdditionalData(data);
22
20
  } catch (err) {
23
21
  setError(String(err));
@@ -30,20 +28,20 @@ const App = () => {
30
28
 
31
29
  return (
32
30
  <div className={styles.container}>
33
- <img width="50" height="50" src={`${staticPath}/public/logo.png`} alt="Logo" />
31
+ <img width="50" height="50" src={logo} alt="Logo" />
34
32
  <h1 style={{ margin: '0 0 20px 0' }}>
35
- Hello, <span style={{ textDecoration: 'underline' }}>{firstName}</span> {lastName}
33
+ Hello, <span style={{ textDecoration: 'underline' }}>{firstName}</span>{' '}
34
+ {lastName}
36
35
  </h1>
37
- {additionalData && (
38
- <div className={styles.info}>
39
- <div className={styles.block}>Age: {additionalData.age}</div>
40
- <div className={styles.block}>
41
- Hobbies: {additionalData.hobbies.map((x) => x.toLowerCase()).join(', ')}
42
- </div>
36
+ <div className={styles.info}>
37
+ <div className={styles.block}>Born: {born}</div>
38
+ <div className={styles.block}>
39
+ Hobbies: {hobbies.map((x) => x.toLowerCase()).join(', ')}
43
40
  </div>
44
- )}
45
- <button className={styles.button} onClick={fetchMoreData}>
46
- Get extra information
41
+ </div>
42
+ {additionalData && <div>{additionalData.funFact}</div>}
43
+ <button className={styles.button} onClick={getFunFact}>
44
+ Fun year fact
47
45
  </button>
48
46
  </div>
49
47
  );
@@ -1,30 +1,45 @@
1
1
  import { Server } from 'oc-server';
2
- import { AdditionalData, ClientProps, OcParameters } from './types';
3
2
 
4
- const database = [
5
- { name: 'John Doe', age: 34, hobbies: ['Swimming', 'Basketball'] },
6
- { name: 'Jane Doe', age: 35, hobbies: ['Running', 'Rugby'] }
3
+ const userDatabase = [
4
+ { name: 'John Doe', born: 1986, hobbies: ['Swimming', 'Basketball'] },
5
+ { name: 'Jane Doe', born: 1991, hobbies: ['Running', 'Rugby'] },
7
6
  ];
8
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
+
9
14
  async function getUser(userId: number) {
10
- return database[userId];
15
+ return userDatabase[userId];
16
+ }
17
+
18
+ async function getFunFact(year: number) {
19
+ return yearsFunFactDatabase[year];
11
20
  }
12
21
 
13
- export const server = new Server(async (params: OcParameters): Promise<ClientProps> => {
14
- const user = await getUser(params.userId);
22
+ export const server = new Server(async (params: { userId: number }) => {
23
+ const { userId } = params;
24
+ const user = await getUser(userId);
15
25
  const [firstName, lastName] = user.name.split(/\s+/);
16
26
 
27
+ if (firstName === 'Invalid') {
28
+ return;
29
+ }
30
+
17
31
  return {
18
- userId: params.userId,
19
32
  firstName,
20
- lastName
33
+ lastName,
34
+ born: user.born,
35
+ hobbies: user.hobbies,
21
36
  };
22
- }).action('getMoreData', async (params: OcParameters): Promise<AdditionalData> => {
23
- const user = await getUser(params.userId);
37
+ }).action('funFact', async (params: { year: number }) => {
38
+ const { year } = params;
39
+ const funFact = await getFunFact(year);
24
40
 
25
41
  return {
26
- age: user.age,
27
- hobbies: user.hobbies
42
+ funFact,
28
43
  };
29
44
  });
30
45
 
@@ -20,7 +20,11 @@
20
20
  "resolveJsonModule": true,
21
21
  "isolatedModules": true,
22
22
  "jsx": "react-jsx",
23
- "jsxImportSource": "preact"
23
+ "jsxImportSource": "preact",
24
+ "paths": {
25
+ "react": ["./node_modules/preact/compat/"],
26
+ "react-dom": ["./node_modules/preact/compat/"]
27
+ }
24
28
  },
25
29
  "include": ["src"],
26
30
  "exclude": ["src/_package"]
@@ -34,8 +34,8 @@
34
34
  "@testing-library/user-event": "^14.4.3",
35
35
  "@types/react": "^18.0.28",
36
36
  "jsdom": "^21.1.1",
37
- "oc-server": "*",
38
- "oc-template-react-compiler": "6.0.0",
37
+ "oc-server": "^0.3.0",
38
+ "oc-template-react-compiler": "^6.1.0",
39
39
  "react": "18.2.0",
40
40
  "react-dom": "18.2.0",
41
41
  "typescript": "5.1.3",
@@ -1,23 +1,21 @@
1
1
  import { useState } from 'react';
2
- import { useData } from 'oc-template-react-compiler/dist/utils/useData';
3
- import { serverClient } from 'oc-server';
2
+ import { serverClient, InitialData, ActionOutput } from 'oc-server';
4
3
  import styles from './styles.css';
5
4
  import logo from '../public/logo.png';
6
- import type { AdditionalData, ClientProps } from './types';
7
5
 
8
- interface AppProps extends ClientProps {
9
- getMoreData?: boolean;
10
- }
6
+ type AdditionalData = ActionOutput<'funFact'>;
11
7
 
12
- const App: React.FC<ClientProps> = () => {
13
- const { firstName, lastName, userId, getData } = useData<AppProps>();
14
- const [additionalData, setAdditionalData] = useState<AdditionalData | null>(null);
8
+ const App: React.FC<InitialData> = (props: InitialData) => {
9
+ const { firstName, lastName, born, hobbies } = props;
10
+ const [additionalData, setAdditionalData] = useState<AdditionalData | null>(
11
+ null
12
+ );
15
13
  const [error, setError] = useState('');
16
14
 
17
- const fetchMoreData = async () => {
15
+ const getFunFact = async () => {
18
16
  setError('');
19
17
  try {
20
- const data = await serverClient.getMoreData({ userId });
18
+ const data = await serverClient.funFact({ year: born });
21
19
  setAdditionalData(data);
22
20
  } catch (err) {
23
21
  setError(String(err));
@@ -32,18 +30,18 @@ const App: React.FC<ClientProps> = () => {
32
30
  <div className={styles.container}>
33
31
  <img width="50" height="50" src={logo} alt="Logo" />
34
32
  <h1 style={{ margin: '0 0 20px 0' }}>
35
- Hello, <span style={{ textDecoration: 'underline' }}>{firstName}</span> {lastName}
33
+ Hello, <span style={{ textDecoration: 'underline' }}>{firstName}</span>{' '}
34
+ {lastName}
36
35
  </h1>
37
- {additionalData && (
38
- <div className={styles.info}>
39
- <div className={styles.block}>Age: {additionalData.age}</div>
40
- <div className={styles.block}>
41
- Hobbies: {additionalData.hobbies.map((x) => x.toLowerCase()).join(', ')}
42
- </div>
36
+ <div className={styles.info}>
37
+ <div className={styles.block}>Born: {born}</div>
38
+ <div className={styles.block}>
39
+ Hobbies: {hobbies.map((x) => x.toLowerCase()).join(', ')}
43
40
  </div>
44
- )}
45
- <button className={styles.button} onClick={fetchMoreData}>
46
- Get extra information
41
+ </div>
42
+ {additionalData && <div>{additionalData.funFact}</div>}
43
+ <button className={styles.button} onClick={getFunFact}>
44
+ Fun year fact
47
45
  </button>
48
46
  </div>
49
47
  );
@@ -1,32 +1,45 @@
1
1
  import { Server } from 'oc-server';
2
- import { AdditionalData, ClientProps, OcParameters } from './types';
3
2
 
4
- const database = [
5
- { name: 'John Doe', age: 34, hobbies: ['Swimming', 'Basketball'] },
6
- { name: 'Jane Doe', age: 35, hobbies: ['Running', 'Rugby'] }
3
+ const userDatabase = [
4
+ { name: 'John Doe', born: 1986, hobbies: ['Swimming', 'Basketball'] },
5
+ { name: 'Jane Doe', born: 1991, hobbies: ['Running', 'Rugby'] },
7
6
  ];
8
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
+
9
14
  async function getUser(userId: number) {
10
- return database[userId];
15
+ return userDatabase[userId];
16
+ }
17
+
18
+ async function getFunFact(year: number) {
19
+ return yearsFunFactDatabase[year];
11
20
  }
12
21
 
13
- export const server = new Server(async (params: OcParameters): Promise<ClientProps> => {
22
+ export const server = new Server(async (params: { userId: number }) => {
14
23
  const { userId } = params;
15
24
  const user = await getUser(userId);
16
25
  const [firstName, lastName] = user.name.split(/\s+/);
17
26
 
27
+ if (firstName === 'Invalid') {
28
+ return;
29
+ }
30
+
18
31
  return {
19
- userId,
20
32
  firstName,
21
- lastName
33
+ lastName,
34
+ born: user.born,
35
+ hobbies: user.hobbies,
22
36
  };
23
- }).action('getMoreData', async (params: OcParameters): Promise<AdditionalData> => {
24
- const { userId } = params;
25
- const user = await getUser(userId);
37
+ }).action('funFact', async (params: { year: number }) => {
38
+ const { year } = params;
39
+ const funFact = await getFunFact(year);
26
40
 
27
41
  return {
28
- age: user.age,
29
- hobbies: user.hobbies
42
+ funFact,
30
43
  };
31
44
  });
32
45
 
@@ -33,8 +33,8 @@
33
33
  "@testing-library/jest-dom": "^5.16.5",
34
34
  "@types/testing-library__jest-dom": "^5.14.5",
35
35
  "jsdom": "^21.1.1",
36
- "oc-server": "*",
37
- "oc-template-solid-compiler": "*",
36
+ "oc-server": "^0.3.0",
37
+ "oc-template-solid-compiler": "^0.7.0",
38
38
  "solid-js": "^1.8.7",
39
39
  "typescript": "5.0.2",
40
40
  "vitest": "^0.29.7"
@@ -4,7 +4,7 @@
4
4
  "version": "1.0.0",
5
5
  "scripts": {
6
6
  "lint": "eslint --max-warnings 0 --ext .js,.jsx,.ts,.tsx src",
7
- "build": "tsc --noEmit && oc package .",
7
+ "build": "vue-tsc --noEmit && oc package .",
8
8
  "test": "vitest"
9
9
  },
10
10
  "oc": {
@@ -33,8 +33,8 @@
33
33
  "@types/testing-library__jest-dom": "^5.14.5",
34
34
  "@vitejs/plugin-vue": "^5.0.0",
35
35
  "jsdom": "^21.1.1",
36
- "oc-server": "*",
37
- "oc-template-vue-compiler": "*",
36
+ "oc-server": "^0.3.0",
37
+ "oc-template-vue-compiler": "^0.2.0",
38
38
  "typescript": "5.0.2",
39
39
  "vitest": "^0.29.7",
40
40
  "vue": "^3.3.11",
@@ -1,3 +0,0 @@
1
- .awesome {
2
- background: palevioletred;
3
- }
Binary file
@@ -1,11 +0,0 @@
1
- import { Server } from "oc-server";
2
-
3
- export const server = new Server((params: { name: string }, context) => {
4
- const { name } = params;
5
- const { staticPath } = context;
6
-
7
- return {
8
- name,
9
- staticPath,
10
- };
11
- });
@@ -1,10 +0,0 @@
1
- import logo from "./img/logo.png";
2
- import styles from "./css/styles.css";
3
-
4
- export default (props: { name: string }) => {
5
- console.log("PR::", props);
6
- return `<div class=${styles.awesome}>
7
- Hello ${props.name}!
8
- <img src="${logo}" />
9
- </div>`;
10
- };
@@ -1,15 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
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
- }