Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive components in playground #139

Draft
wants to merge 74 commits into
base: 1.4
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
414385b
WIP: Interactive Playgrounds
mariuswilms Aug 28, 2021
2cd3c10
Rough draft of what the JS/HTML template building might look like
wegry Jun 16, 2021
bd46f3c
Only parse JS/HTML templates on startup
wegry Jun 20, 2021
cccf735
Fix rebase
mariuswilms Aug 29, 2021
6c11e2f
Use newly introduced file based templates
mariuswilms Aug 29, 2021
ab1c98f
Fit both code brtanches together again
mariuswilms Aug 29, 2021
a666fbc
Bring back nodeLinker
mariuswilms Aug 29, 2021
ac4fdcc
Vend yarn 3
wegry Sep 2, 2021
77b3c28
Patch up client GitHub actions pathing
wegry Sep 3, 2021
a7a3941
WIP
mariuswilms Sep 3, 2021
6d78000
WIP
mariuswilms Sep 3, 2021
7444c19
WIP
mariuswilms Sep 3, 2021
33ae977
Seperate IndexJS handler
mariuswilms Sep 3, 2021
ab5e902
Unbreak package.json
mariuswilms Sep 12, 2021
bd61602
Unbreak package.json
mariuswilms Sep 12, 2021
127c6d2
clean
mariuswilms Sep 12, 2021
354b291
Unbreak
mariuswilms Sep 12, 2021
62148e4
Use matching dev branch
mariuswilms Sep 12, 2021
bf80c69
Running built playground iframe, now onwards to the layout
wegry Sep 12, 2021
d9795f8
Remove local module resolution
wegry Sep 12, 2021
16ed500
Patch up lock file
wegry Sep 12, 2021
d4bb04d
Load custom css index and ham in custom component rendering
wegry Sep 19, 2021
80a85a3
Run prettier
ChristophLabacher Sep 22, 2021
3dabcd2
Merge branch '1.4' into user-components
mariuswilms Sep 30, 2021
d2ade6a
Merge branch '1.4' into user-components
mariuswilms Sep 30, 2021
c6681ac
Try a few different css entry point names
wegry Oct 4, 2021
f548b98
Frontend WIP
ChristophLabacher Oct 5, 2021
e66c0e0
Frontend Refactoring – Remove useGlobal, switch to React Router
ChristophLabacher Oct 6, 2021
6583933
Make sure Id for NodeDocComponent is unique
ChristophLabacher Oct 6, 2021
e4cfd13
Fixes
ChristophLabacher Oct 6, 2021
e8f3002
Patch up lock file
wegry Oct 7, 2021
f47ac58
Look up js entry point based on esbuild module resolution
wegry Oct 7, 2021
b5b4fe5
Update contributing example component directory path
wegry Oct 7, 2021
9147eb2
Use automatic jsx transform that's part of CRA@>4
wegry Oct 7, 2021
20bde52
Get front end tests running with react 17
wegry Oct 7, 2021
9bd9fec
Only add the source to a link when it is not explicitly set
ChristophLabacher Oct 7, 2021
d21f376
Styling
ChristophLabacher Oct 7, 2021
72c094b
Restructure frontend direcotries to modern React standards
ChristophLabacher Oct 8, 2021
50269f0
Use ESM instead of IIFE for playground format
wegry Oct 8, 2021
9582bec
Target ES2020 with playgrounds
wegry Oct 8, 2021
a896f81
Output paths are stable once again for playgrounds
wegry Oct 8, 2021
918dfc2
Add componets to docs in API, pass them to transform
ChristophLabacher Oct 9, 2021
437ac14
Fix API Routing for root node
ChristophLabacher Oct 9, 2021
80d8afe
Fix linting
mariuswilms Oct 14, 2021
ec65ed6
Format
mariuswilms Oct 14, 2021
8396d27
CodeBlock content is now always escaped
ChristophLabacher Oct 14, 2021
6a238a5
Heading styling improvements
ChristophLabacher Oct 14, 2021
0c57555
Add support for component CSS path „style.css“
ChristophLabacher Oct 14, 2021
3cf741f
Add „Show Source“ Button to ReactPlaygrounds
ChristophLabacher Oct 14, 2021
0fecad8
Move runtime.jsx, use embed, rename vars
mariuswilms Oct 14, 2021
d1bd01d
Use temporary outdir
mariuswilms Oct 14, 2021
09d0714
Unsupport react nodes in CodeBlock
mariuswilms Oct 15, 2021
38bc232
Optimize bundle size, use less highlighting langs
mariuswilms Oct 15, 2021
67c66bf
Format
mariuswilms Oct 15, 2021
6764f36
Fixup CodeBlock unsupporting
mariuswilms Oct 15, 2021
9083745
Unbreak tests
mariuswilms Oct 15, 2021
b7c2a15
Fix lint issue in Node.Id
mariuswilms Oct 15, 2021
54b9404
Add resize observer to playground runtime
ChristophLabacher Oct 15, 2021
8a57355
Fix import order in CodeBlock
ChristophLabacher Oct 15, 2021
d8ac507
Encode API Response for “Souce” Tab
ChristophLabacher Oct 15, 2021
448a39c
Fix mobile navigation
ChristophLabacher Oct 15, 2021
52af789
Add Code Highlighting support for HTML, Markdown, SCSS
ChristophLabacher Oct 15, 2021
6da6a22
Try living without public path
mariuswilms Oct 15, 2021
904216a
When parsing components, only skip content in backticks when we are n…
ChristophLabacher Oct 15, 2021
55f6d6e
TypographySpecimen Styling
ChristophLabacher Oct 15, 2021
ccfbc33
Switch from highlight.js to prism
wegry Oct 15, 2021
82741e7
If COMPONENTS doesn't match package.json's name, shim it for NODE_PAT…
wegry Oct 16, 2021
9b0bf1a
Patch up front end tests once more, and bump react-helmet to remove r…
wegry Oct 16, 2021
fda2230
Fix Prism styling + theme
ChristophLabacher Oct 16, 2021
df59676
Fix unwanted scrolling in Playground
ChristophLabacher Oct 16, 2021
e9eaa68
Remove whitespace sensativity in test
wegry Oct 16, 2021
aa58deb
Various Frontend Fixes
ChristophLabacher Nov 4, 2022
717af5c
Fix wording in frontend
ChristophLabacher Nov 4, 2022
5827729
Frontend: Remove local resolution to js-sdk
ChristophLabacher Nov 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ jobs:
path: frontend/.yarn/cache
key: ${{ runner.os }}-yarn-${{ hashFiles('frontend/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-
- run: yarn --cwd frontend
- run: make -C frontend lint
- run: yarn
working-directory: ./frontend
- run: make lint
working-directory: ./frontend
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: '16'
- run: yarn --cwd frontend
- run: make -C frontend build
- run: yarn
working-directory: ./frontend
- run: make build
working-directory: ./frontend
env:
# Don't convert warnings to errors, we love our warnings.
CI: false
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ jobs:
path: frontend/.yarn/cache
key: ${{ runner.os }}-yarn-${{ hashFiles('frontend/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-
- run: yarn --cwd frontend
- run: make -C frontend test
- run: yarn
working-directory: ./frontend
- run: make test
working-directory: ./frontend
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 1.4.0

- Components of a user provided component library can now be used inside
`<Playground>` to create interactive demos of components.
- Support _Table of Contents_ on documents.
- Introduced new `<ImageGrid>` documentation component.

Expand Down
57 changes: 24 additions & 33 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,58 +33,49 @@ export PATH=$PATH:$(go env GOPATH)/bin

## Setup

Clone the official repository, switch into the directory and checkout the branch
you want to work on.
First we'll be setting up an umbrella directory where the main dsk repository
and supporting repositories will live, which we'll clone into it.

```
$ git clone github.com/rundsk/dsk
$ git checkout 1.2
$ cd dsk
```

When using the built-in frontend, the `frontend/build` folder must be
present and contain the compiled version of the frontend. After a new
checkout you can create it, using the following command.
mkdir rundsk
cd rundsk

git clone [email protected]:rundsk/dsk.git
git clone [email protected]:rundsk/js-sdk.git
git clone [email protected]:rundsk/example-component-library.git @rundsk/example-component-library
git clone [email protected]:rundsk/example-design-system.git
mariuswilms marked this conversation as resolved.
Show resolved Hide resolved
```
$ make -C frontend build
```

## Improving the frontend

There are two ways to work on the built-in frontend and verify changes
in your browser easily at the same time while you go.
All the following documentation will assume that you are working from inside the
main repository checkout.

First start the backend which will also serve the frontend.
```
$ make dev
cd dsk
```

Each time you change the source of the frontend run the following
command and reload the browser window to see the changes.
## Developing

```
$ make -C frontend build
```
First we'll start the backend in development mode and after that do the same
with the frontend.

Alternatively you can start the frontend (using a development server)
and the backend separately on different ports, having the frontend use
backend over its HTTP API.
On a fresh checkout we'll have to install the dependencie of the frontend
first, and then start the frontend's development server.

Start the backend, first. By default it'll be reachable over port 8080.
```
$ make dev
cd frontend
yarn
make dev
```

Second, start the frontend using a development server. It will be
reachable over port 3000 and proxy requests through to the backend.
You should now be able to reach the frontend when opening http://127.0.0.1:3000
in your browser. You might see some errors as we not yet have started the backend.

Now inside another terminal we'll start the backend.

```
$ make -C frontend dev
make dev
```

Now open http://127.0.0.1:3000 in your browser.

## Debugging

When running the tests the search indexes are store to disk, to ease
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

FRONTEND ?= $(shell pwd)/frontend/build
DDT ?= $(shell pwd)/../example-design-system
COMPONENTS ?= $(shell pwd)/../@rundsk/example-component-library

VERSION ?= head-$(shell git rev-parse --short HEAD)
LDFLAGS = -X main.Version=$(VERSION)
Expand All @@ -32,7 +33,7 @@ lint: internal/frontend/vfsdata.go
.PHONY: dev
dev: internal/frontend/vfsdata.go
go build -tags=dev -ldflags "$(LDFLAGS)" $(CMD_PKG)
./dsk -frontend $(FRONTEND) "$(DDT)"
./dsk -frontend $(FRONTEND) -components $(COMPONENTS) "$(DDT)"
rm dsk

.PHONY: clean
Expand All @@ -45,7 +46,7 @@ clean:
if [ -f ./mem.prof ]; then rm ./mem.prof; fi

.PHONY: dist
dist: dist/dsk-darwin-amd64 dist/dsk-linux-amd64 dist/dsk-windows-386.exe
dist: dist/dsk-darwin-amd64 dist/dsk-linux-amd64 dist/dsk-windows-386.exe
dist: dist/dsk-darwin-amd64.zip dist/dsk-linux-amd64.tar.gz dist/dsk-windows-386.zip
dist: container-image
ls -lh dist
Expand Down Expand Up @@ -82,5 +83,5 @@ dist/%-linux-amd64: $(ANY_DEPS) internal/frontend/vfsdata.go
dist/%-windows-386.exe: $(ANY_DEPS) internal/frontend/vfsdata.go
GOOS=windows GOARCH=386 go build -ldflags "$(LDFLAGS) -s -w" -o $@ $(CMD_PKG)

internal/frontend/vfsdata.go: $(shell find $(FRONTEND) -type f)
internal/frontend/vfsdata.go: $(shell find $(FRONTEND) -type f)
FRONTEND=$(FRONTEND) go run cmd/frontend/generate.go
38 changes: 28 additions & 10 deletions cmd/dsk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ func main() {
}
}()

host := flag.String("host", "127.0.0.1", "host IP to bind to")
port := flag.String("port", "8080", "port to bind to")
version := flag.Bool("version", false, "print DSK version")
noColor := flag.Bool("no-color", false, "disables color output")
fhost := flag.String("host", "127.0.0.1", "host IP to bind to")
fport := flag.String("port", "8080", "port to bind to")
fversion := flag.Bool("version", false, "print DSK version")
fnoColor := flag.Bool("no-color", false, "disables color output")
fcomponents := flag.String("components", "", "path to component library assets")
ffrontend := flag.String("frontend", "", "path to a frontend, to use instead of the built-in")
fallowOrigin := flag.String("allow-origin", "", "origins from which browsers can access the HTTP API; for multiple origins, use a comma as a separator, the wildcard * is supported; to allow all use *")
flag.Parse()
Expand All @@ -70,14 +71,14 @@ func main() {
log.Fatalf("Too many arguments given, expecting exactly 0 or 1")
}

if *version {
if *fversion {
fmt.Println(Version)
os.Exit(1)
}

// Color package automatically disables colors when not a TTY. We
// don't need to check for an interactive terminal here again.
if *noColor {
if *fnoColor {
color.NoColor = true
}
whiteOnBlue := color.New(color.FgWhite, color.BgBlue)
Expand Down Expand Up @@ -114,7 +115,17 @@ func main() {
if err != nil {
panic(err)
}
log.Printf("Detected live path: %s", livePath)
log.Printf("Using live path: %s", livePath)

var componentsPath string
if *fcomponents != "" {
componentsPath = *fcomponents
}

var frontendPath string
if *ffrontend != "" {
frontendPath = *ffrontend
}

allowOrigins := strings.Split(*fallowOrigin, ",")
if len(allowOrigins) != 0 {
Expand All @@ -124,7 +135,8 @@ func main() {
app = plex.NewApp( // assign to global
Version,
livePath,
*ffrontend,
componentsPath,
frontendPath,
)
ctx, cancel := context.WithCancel(context.Background())
app.Teardown.AddCancelFunc(cancel)
Expand All @@ -133,6 +145,12 @@ func main() {
log.Fatal(red.Sprintf("Failed to initialize application: %s", err))
}

if componentsPath != "" {
if err := app.OpenComponents(ctx); err != nil {
log.Fatal(red.Sprintf("Failed to start application: %s", err))
}
}

if app.HasMultiVersionsSupport() {
log.Printf("Detected support for multi-versions")

Expand All @@ -145,7 +163,7 @@ func main() {

apis := map[int]httputil.Mountable{
1: api.NewV1(app.Sources, app.Version, app.Broker, allowOrigins),
2: api.NewV2(app.Sources, app.Version, app.Broker, allowOrigins),
2: api.NewV2(app.Sources, app.Components, app.Version, app.Broker, allowOrigins),
}
for av, a := range apis {
log.Printf("Mounting APIv%d HTTP mux...", av)
Expand All @@ -159,7 +177,7 @@ func main() {
log.Print("Mounting frontend HTTP mux...")
mux.Handle("/", app.Frontend.HTTPMux())

addr := fmt.Sprintf("%s:%s", *host, *port)
addr := fmt.Sprintf("%s:%s", *fhost, *fport)
if isTerminal {
log.Print("-------------------------------------------")
log.Printf("Please visit: %s", green.Sprint("http://"+addr))
Expand Down
1 change: 1 addition & 0 deletions frontend/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
"printWidth": 120,
"bracketSpacing": true,
"trailingComma": "es5",
"arrowParens": "always"
}
7 changes: 7 additions & 0 deletions frontend/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"arcanis.vscode-zipfs",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
8 changes: 8 additions & 0 deletions frontend/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"search.exclude": {
"**/.yarn": true,
"**/.pnp.*": true
},
"eslint.nodePath": ".yarn/sdks",
"prettier.prettierPath": ".yarn/sdks/prettier/index.js"
}
20 changes: 20 additions & 0 deletions frontend/.yarn/sdks/eslint/bin/eslint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

const {existsSync} = require(`fs`);
const {createRequire, createRequireFromPath} = require(`module`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.cjs";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);

if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require eslint/bin/eslint.js
require(absPnpApiPath).setup();
}
}

// Defer to the real eslint/bin/eslint.js your application uses
module.exports = absRequire(`eslint/bin/eslint.js`);
20 changes: 20 additions & 0 deletions frontend/.yarn/sdks/eslint/lib/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

const {existsSync} = require(`fs`);
const {createRequire, createRequireFromPath} = require(`module`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../../.pnp.cjs";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);

if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require eslint/lib/api.js
require(absPnpApiPath).setup();
}
}

// Defer to the real eslint/lib/api.js your application uses
module.exports = absRequire(`eslint/lib/api.js`);
6 changes: 6 additions & 0 deletions frontend/.yarn/sdks/eslint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "eslint",
"version": "7.32.0-sdk",
"main": "./lib/api.js",
"type": "commonjs"
}
5 changes: 5 additions & 0 deletions frontend/.yarn/sdks/integrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file is automatically generated by @yarnpkg/sdks.
# Manual changes might be lost!

integrations:
- vscode
20 changes: 20 additions & 0 deletions frontend/.yarn/sdks/prettier/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

const {existsSync} = require(`fs`);
const {createRequire, createRequireFromPath} = require(`module`);
const {resolve} = require(`path`);

const relPnpApiPath = "../../../.pnp.cjs";

const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);

if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require prettier/index.js
require(absPnpApiPath).setup();
}
}

// Defer to the real prettier/index.js your application uses
module.exports = absRequire(`prettier/index.js`);
6 changes: 6 additions & 0 deletions frontend/.yarn/sdks/prettier/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "prettier",
"version": "2.4.1-sdk",
"main": "./index.js",
"type": "commonjs"
}
4 changes: 2 additions & 2 deletions frontend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dev:

.PHONY: test
test:
yarn react-scripts test .
yarn test

.PHONY: build
build:
Expand All @@ -26,7 +26,7 @@ lint:
.PHONY: format
format:
yarn eslint --fix --cache src
yarn prettier --write src/**
yarn prettier --write 'src/**/*.{js,jsx,css,scss,json}'

.PHONY: clean
clean:
Expand Down
Empty file removed frontend/build/empty
Empty file.
Loading