Skip to content

Commit 0e34144

Browse files
blurfxse030
authored andcommitted
Add create-yorkie-app (#690)
Provides CLI starter kit to allow npm users to conveniently scaffold yorkie-based cooperative apps --------- Co-authored-by: se030 <se030.kim@gmail.com>
1 parent e11047d commit 0e34144

13 files changed

+696
-5
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: create-yorkie-app-publish
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- tools/create-yorkie-app/**
9+
- examples/**
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
id-token: write
16+
steps:
17+
- name: Checkout 🛎️
18+
uses: actions/checkout@v2
19+
- name: Setup Node 🔧
20+
uses: actions/setup-node@v2
21+
with:
22+
node-version: '18'
23+
cache: 'npm'
24+
cache-dependency-path: package-lock.json
25+
registry-url: 'https://registry.npmjs.org'
26+
- run: npm install
27+
- run: cd tools/create-yorkie-app && npm run build
28+
- run: cd tools/create-yorkie-app && npm publish --provenance
29+
continue-on-error: true
30+
env:
31+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

examples/CONTRIBUTING.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Contributing
2+
3+
See [CONTRIBUTING.md](../CONTRIBUTING.md) for the general guides for contribution.
4+
5+
## Keeping create-yorkie-app in sync with examples
6+
7+
When adding a new example, you have to update create-yorkie-app's [frameworks.ts](../tools//create-yorkie-app/frameworks.ts).
8+
9+
Add FrameworkVariant to the variants array under appropriate category like:
10+
11+
```js
12+
export const FRAMEWORKS: Array<Framework> = [
13+
{
14+
name: 'vanilla',
15+
display: 'Vanilla',
16+
color: yellow,
17+
variants: [
18+
{
19+
name: 'vanilla-codemirror6',
20+
display: 'codemirror',
21+
},
22+
{
23+
name: 'vanilla-quill',
24+
display: 'quill',
25+
},
26+
{
27+
name: 'profile-stack',
28+
display: 'profile-stack',
29+
},
30+
// Your yorkie example in Vanilla JS
31+
{
32+
name: 'directory-name',
33+
display: 'display-name',
34+
},
35+
],
36+
},
37+
// ...
38+
];
39+
```

package-lock.json

Lines changed: 76 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"build": "webpack --config ./config/webpack.config.js && npm run api-report && npm run prune",
1212
"build:proto": "protoc -I=./src/api --js_out=import_style=commonjs:./src/api --grpc-web_out=import_style=commonjs+dts,mode=grpcwebtext:./src/api ./src/api/yorkie/v1/*.proto",
1313
"build:docs": "npm run predoc && api-documenter markdown --input temp --output docs",
14-
"build:examples": "npm run build --workspaces",
14+
"build:examples": "npm run build --workspace examples",
15+
"build:create-yorkie-app": "npm run build --workspace create-yorkie-app",
1516
"build:ghpages": "mkdir -p ghpages/examples && cp -r docs ghpages/api-reference && find examples -name 'dist' -type d -exec sh -c 'cp -r {} ghpages/examples/$(basename $(dirname {}))' \\;",
1617
"api-report": "api-extractor run --local --verbose --config ./config/api-extractor.json",
1718
"prune": "ts-node-script ./scripts/prune-dts.ts --input ./dist/yorkie-js-sdk.d.ts --output ./dist/yorkie-js-sdk.d.ts",
@@ -94,6 +95,7 @@
9495
}
9596
},
9697
"workspaces": [
97-
"examples/*"
98+
"examples/*",
99+
"tools/*"
98100
]
99101
}

tools/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Tools
2+
3+
This directory contains tools for yorkie-js-sdk.
4+
5+
For usage, refer to the README.md of each project.

tools/create-yorkie-app/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VITE_YORKIE_API_ADDR='https://api.yorkie.dev'
2+
VITE_YORKIE_API_KEY=
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Maintaining create-yorkie-app
2+
3+
This package is an automated tool to scaffold an example project that shows practical usage of yorkie-js-sdk.
4+
5+
```bash
6+
.
7+
├── MAINTAINING.md
8+
├── README.md
9+
├── frameworks.ts # abstract data object representing examples/ directory
10+
├── index.ts # main script
11+
├── package.json
12+
├── tsconfig.json
13+
└── webpack.config.js
14+
```
15+
16+
## Adding a New Example
17+
18+
Add information about your new example in [frameworks.ts](https://github.com/yorkie-team/yorkie-js-sdk/blob/main/tools/create-yorkie-app/frameworks.ts).
19+
20+
Choose or create an appropriate category (e.g. vanilla, react, nextjs, vue, ...) and add an object like below to variants array.
21+
22+
```ts
23+
{
24+
name: directory_name,
25+
display: displayed_name_in_prompt
26+
}
27+
```
28+
29+
## Publishing a New Version
30+
31+
Update the version in [package.json](https://github.com/yorkie-team/yorkie-js-sdk/blob/main/tools/create-yorkie-app/package.json#L3).
32+
33+
Publication will be done via [create-yorkie-app-publish.yml](https://github.com/yorkie-team/yorkie-js-sdk/blob/main/.github/workflows/create-yorkie-app-publish.yml) when changes are pushed into main branch.

tools/create-yorkie-app/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# create-yorkie-app
2+
3+
## Usage
4+
5+
You can scaffold yorkie-js-sdk examples by:
6+
7+
```bash
8+
$ npx create-yorkie-app
9+
```
10+
11+
The examples have own local dependencies. So you should install dependencies before running examples.
12+
13+
```bash
14+
# In the directory of the example.
15+
$ npm install
16+
```
17+
18+
Then you can run the examples.
19+
20+
```bash
21+
# In the directory of the example.
22+
$ npm run dev
23+
```
24+
25+
Open the browser and go to the URL that is printed in the terminal.
26+
27+
## Note
28+
29+
Yorkie API key or local server is necessary to run each example.
30+
You can create and manage your projects and API keys at [Yorkie Dashboard](https://yorkie.dev/dashboard). If you want to configure your own server, refer to [this README](../../examples/README.md).

tools/create-yorkie-app/frameworks.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { cyan, lightGreen, reset, yellow } from 'kolorist';
2+
3+
/**
4+
* @see https://github.com/marvinhagemeister/kolorist#readme
5+
*/
6+
type ColorFunc = (str: string | number) => string;
7+
8+
export type Framework = {
9+
name: string;
10+
display: string;
11+
color: ColorFunc;
12+
variants: Array<FrameworkVariant>;
13+
};
14+
15+
type FrameworkVariant = {
16+
/**
17+
* directory name of the example
18+
*/
19+
name: string;
20+
/**
21+
* display name (in prompt) of the example
22+
*/
23+
display: string;
24+
};
25+
26+
export const FRAMEWORKS: Array<Framework> = [
27+
{
28+
name: 'vanilla',
29+
display: 'Vanilla',
30+
color: yellow,
31+
variants: [
32+
{
33+
name: 'vanilla-codemirror6',
34+
display: 'codemirror',
35+
},
36+
{
37+
name: 'vanilla-quill',
38+
display: 'quill',
39+
},
40+
{
41+
name: 'profile-stack',
42+
display: 'profile-stack',
43+
},
44+
],
45+
},
46+
{
47+
name: 'react',
48+
display: 'React',
49+
color: cyan,
50+
variants: [
51+
{
52+
name: 'react-tldraw',
53+
display: 'tldraw',
54+
},
55+
{
56+
name: 'react-todomvc',
57+
display: 'todomvc',
58+
},
59+
{
60+
name: 'simultaneous-cursors',
61+
display: 'simultaneous-cursors',
62+
},
63+
],
64+
},
65+
{
66+
name: 'nextjs',
67+
display: 'Next.js',
68+
color: reset,
69+
variants: [
70+
{
71+
name: 'nextjs-scheduler',
72+
display: 'scheduler',
73+
},
74+
],
75+
},
76+
{
77+
name: 'vue',
78+
display: 'Vue',
79+
color: lightGreen,
80+
variants: [
81+
{
82+
name: 'vuejs-kanban',
83+
display: 'kanban',
84+
},
85+
],
86+
},
87+
];

0 commit comments

Comments
 (0)