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

JBook Exercise #5

Merged
merged 41 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d709038
commit progress on jbook exercise
nicholeuf Dec 15, 2023
d91327b
extract preview component
nicholeuf Dec 16, 2023
a29a7f0
refactor and extract bundle logic
nicholeuf Dec 16, 2023
529a06c
Multiple editors as code cell components
nicholeuf Dec 16, 2023
a192ade
code cell has resizable components
nicholeuf Dec 16, 2023
ec75dd8
bug fix for "ResizeObserver loop completed with undelivered notificat…
nicholeuf Dec 16, 2023
df044ce
slight refactor to resizeable (from attempting to debug ResizeObserve…
nicholeuf Dec 17, 2023
6bdf3ea
Automatically bundle code after user stops typing for 1 s
nicholeuf Dec 17, 2023
1fa146e
Give iframe time to initialize message listener by delaying on the po…
nicholeuf Dec 17, 2023
6cdd938
temporarily remove resizeobserver code fix (to see if issue was resol…
nicholeuf Dec 17, 2023
1dce4c7
Error handling use cases (bundler, uncaught errors (from timeout etc))
nicholeuf Dec 17, 2023
2c777d8
Error handling use cases (bundler, uncaught errors (from timeout etc))
nicholeuf Dec 17, 2023
084ac46
text editor implementation
nicholeuf Dec 17, 2023
0fc3d30
Merge branches 'jbook' and 'jbook' of github.com:nicholeuf/udemy into…
nicholeuf Dec 17, 2023
414692c
tweak preview-error styles to more closely match the iframe styles
nicholeuf Dec 17, 2023
4e3d6b2
css tweaks & comments
nicholeuf Dec 18, 2023
ba9743e
fix type of timer
nicholeuf Dec 18, 2023
97ad306
fix eslint warning
nicholeuf Dec 18, 2023
25a2a57
Rough in redux store implementation
nicholeuf Dec 18, 2023
00cfdd5
Merge branch 'main' into jbook
nicholeuf Dec 18, 2023
5b81a53
github action workflow for jbook project w/ README updates
nicholeuf Dec 18, 2023
c78e275
checkin root package lock
nicholeuf Dec 18, 2023
1bb4015
always run workflow?
nicholeuf Dec 18, 2023
0f57b45
cell list & action bar behavior implementation, dev tools hookup
nicholeuf Dec 19, 2023
a1daced
connect bundles in redux
nicholeuf Dec 19, 2023
e177216
cell list has show function available to current cell and accumulates…
nicholeuf Dec 19, 2023
a42cbd8
convert to lerna and implement cli, local api, and hookup client to f…
nicholeuf Dec 21, 2023
bf37d0b
check in project used for testing npm publish flow
nicholeuf Dec 22, 2023
6b5f786
convert to npm organization
nicholeuf Dec 22, 2023
c818fdd
v1.0.0
nicholeuf Dec 22, 2023
caac359
add npmrc
nicholeuf Dec 22, 2023
f53d744
fix typo for NODE_ENV
nicholeuf Dec 22, 2023
a14662c
v1.0.1
nicholeuf Dec 22, 2023
6744fe0
remove npmrc
nicholeuf Dec 22, 2023
1466d64
add a readme
nicholeuf Dec 22, 2023
7ee4344
remove unnecessary bug fix
nicholeuf Dec 22, 2023
4d5bb37
add an nvmrc
nicholeuf Dec 22, 2023
3793eb1
cleanup
nicholeuf Dec 22, 2023
2519c75
v2.0.0
nicholeuf Dec 22, 2023
346d610
README should be in the cli package
nicholeuf Dec 22, 2023
3234e4b
v2.0.1
nicholeuf Dec 22, 2023
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
28 changes: 28 additions & 0 deletions .github/workflows/course-react-ts-portfolio-jbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: course-react-ts-portfolio/jbook CI

on: [push]

defaults:
run:
working-directory: ./course-react-ts-portfolio/jbook

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install --legacy-peer-deps
- run: npx lerna bootstrap
29 changes: 0 additions & 29 deletions .github/workflows/node.js.yml

This file was deleted.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
Udemy course code

1. [React and Typescript: Build a Portfolio Project](https://github.com/nicholeuf/udemy/tree/main/course-react-ts-portfolio)

## Github Workflow Local Setup

This repo can be run locally using the following libraries, which must be installed and run locally:

1. [act](https://github.com/nektos/act)
2. [github-act-cache-server](https://github.com/sp-ricard-valverde/github-act-cache-server)
1 change: 1 addition & 0 deletions course-react-ts-portfolio/jbook/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
13 changes: 13 additions & 0 deletions course-react-ts-portfolio/jbook/lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"packages": [
"packages/*"
],
"version": "2.0.1",
"command": {
"bootstrap": {
"npmClientArgs": [
"--legacy-peer-deps"
]
}
}
}
10 changes: 10 additions & 0 deletions course-react-ts-portfolio/jbook/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "root",
"private": true,
"devDependencies": {
"lerna": "^3.22.1"
},
"scripts": {
"start": "lerna run start --parallel"
}
}
2 changes: 2 additions & 0 deletions course-react-ts-portfolio/jbook/packages/cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
26 changes: 26 additions & 0 deletions course-react-ts-portfolio/jbook/packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# jsnotenlf

Created for Udemy course [React and Typescript: Build a Portfolio Project
](https://www.udemy.com/course/react-and-typescript-build-a-portfolio-project)

The application allows a user to create and edit markdown and javascript code cells directly in the browser. The code cells are bundled and executed automatically, providing instant feedback. The cells can be inserted, reordered, and deleted.

The application will launch a react web client and an api server on the user's local machine. The client fetches a list of cells from the server at startup and any changes to the cells are persisted via the API layer. As of right now, the data is persisted to a file.

Some features of the client-side application include:

- The code cells use the [Monaco](https://github.com/microsoft/monaco-editor) code editor with jsx syntax highlighting
- Node packages referenced in code cells are automatically fetched from [unpkg](https://unpkg.com/).
- Node packages are cached in the browser's IndexedDB using [localForage](https://localforage.github.io/localForage/).
- After the code is bundled with [esbuild](https://esbuild.github.io/), it is executed in an iframe.
- Code entered in previous cells can be referenced in subsequent cells. For instance, a function or variable can be defined in one cell and then used in a later cell.
- A convenience function is available to display content in the iframe. For eexample `show(<h1>hello there</h1)`, will render the provided html in a div element of the iframe.

## Links

- [Github](https://github.com/nicholeuf/udemy) - Navigate to the course-react-ts-portfolio/jbook folder.

## How to run the application

1. On the command line, type `npx jsnotenlf serve`. Optionally, a file can be provided to the serve command and/or the port. Type `npx jsnotenlf serve -h` for additional information.
2. Open the launched client application in your browser. For instance, `http://localhost:4005`.
70 changes: 70 additions & 0 deletions course-react-ts-portfolio/jbook/packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions course-react-ts-portfolio/jbook/packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "jsnotenlf",
"version": "2.0.1",
"description": "",
"bin": "dist/index.js",
"publishConfig": {
"access": "public"
},
"files": [
"dist"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "tsc --watch --preserveWatchOutput",
"prepublishOnly": "esbuild src/index.ts --platform=node --outfile=dist/index.js --bundle --minify --define:process.env.NODE_ENV=\\\"production\\\""
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@jsnotenlf/local-client": "^2.0.0"
},
"devDependencies": {
"@jsnotenlf/local-api": "^2.0.0",
"@types/node": "^20.10.5",
"commander": "^11.1.0",
"esbuild": "0.8.26",
"typescript": "^5.3.3"
}
}
48 changes: 48 additions & 0 deletions course-react-ts-portfolio/jbook/packages/cli/src/commands/serve.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import path from 'path';

import { Command } from 'commander';
import { serve } from '@jsnotenlf/local-api';

interface OptionsParams {
port: string;
}

interface LocalApiError {
code: string;
}

const isLocalApiError = (err: any) => {
return typeof err.code === 'string';
};

const isProduction = process.env.NODE_ENV === 'production';

export const serveCommand = new Command()
// filename is optional value [square brackets]
.command('serve [filename]')
.description('Open a file for editing')
// number is required <angle brackets>
.option('-p, --port <number>', 'port to run server on', '4005')
.action(async (filename = 'notebook.js', options: OptionsParams) => {
try {
const dir = path.join(process.cwd(), path.dirname(filename));
await serve(
parseInt(options.port),
path.basename(filename),
dir,
!isProduction
);
console.log(
`Opened ${filename}. Navigate to http://localhost:${options.port} to edit the file`
);
} catch (err: any) {
if (isLocalApiError(err)) {
if (err.code === 'EADDRINUSE') {
console.error('Port is in use. Try running on a different port.');
}
} else if (err instanceof Error) {
console.log('Heres the problem', err.message);
}
process.exit(1);
}
});
7 changes: 7 additions & 0 deletions course-react-ts-portfolio/jbook/packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node
import { program } from 'commander';
import { serveCommand } from './commands/serve';

program.addCommand(serveCommand);

program.parse(process.argv);
Loading