diff --git a/.env b/.env deleted file mode 100644 index 8555aea0..00000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -PLUTO_APP=true \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1eabe60f..4566a88d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,29 +1,23 @@ -name: CI +name: build on: pull_request: - branches: + branches: - main push: - branches: + branches: - main - jobs: - test: - name: Test + build: runs-on: ubuntu-latest - container: - image: plutolang/pluto steps: - - name: Check out code - uses: actions/checkout@v4 - - name: Install dependencies - run: | - apt update - apt install lsof - npm install - python3 -m pip install -r requirements.txt - python3 -m pip install pytest - - name: Build web - run: cd web && npm install && npm run build - - name: Test - run: ./scripts/test.sh + - name: Git checkout + uses: actions/checkout@v2 + + - name: NPM install + env: + NODE_OPTIONS: "--max_old_space_size=4096" + run: npm install + - name: NPM build + env: + NODE_OPTIONS: "--max_old_space_size=4096" + run: npm run build diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index f8116677..00000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,42 +0,0 @@ -name: Release -on: - push: - tags: - - "v*" -permissions: - contents: write -jobs: - image: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup Docker Buildx - uses: docker/setup-buildx-action@v3 - with: - version: v0.11.2 - install: true - - # <--- Login, build and push image to Docker Hub ---> - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v5 - with: - images: kcllang/pluto-kcl-playground - - name: Build and push Docker image - uses: docker/build-push-action@v6 - with: - context: . - platforms: linux/amd64 - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.gitignore b/.gitignore index dfe7c24b..3b999bbd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,27 +1,198 @@ -*.db -vendor - -*.a -*.o -*.so - -*.exe -*.lib -*.dll - -a.out* -zz_* -/_build* -*.dylib -*.lock -.kclvm - -**/target/ -**/.DS_Store -**/.vscode -node_modules +# Created by https://www.toptal.com/developers/gitignore/api/node +# Edit at https://www.toptal.com/developers/gitignore?templates=node + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* package-lock.json -# pluto -.pluto/**/* -__pycache__ +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# Next.js build output +.next + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# End of https://www.toptal.com/developers/gitignore/api/node + +# Created by https://www.toptal.com/developers/gitignore/api/macos +# Edit at https://www.toptal.com/developers/gitignore?templates=macos + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +# End of https://www.toptal.com/developers/gitignore/api/macos + +# Created by https://www.toptal.com/developers/gitignore/api/windows +# Edit at https://www.toptal.com/developers/gitignore?templates=windows + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/windows + +#Added by cargo + +/target +Cargo.lock + +.pnp.* +.yarn/* +!.yarn/patches +!.yarn/plugins +!.yarn/releases +!.yarn/sdks +!.yarn/versions + +*.node diff --git a/web/.prettierrc b/.prettierrc similarity index 100% rename from web/.prettierrc rename to .prettierrc diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 60c550b7..00000000 --- a/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM plutolang/pluto -WORKDIR / -COPY . . -# Install Pluto and dev dependencies -RUN npm install -# Build frontend web application -RUN cd web && npm install && npm run build -# Install backend dependencies -RUN python3 -m pip install -U -r ./requirements.txt -# Run -CMD ["pluto", "run"] -EXPOSE 8080 -EXPOSE 8000 -EXPOSE 8001 diff --git a/Makefile b/Makefile deleted file mode 100644 index 62ee8d21..00000000 --- a/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -run: - cd web && npm run build - pluto run - -fmt: - python3 -m pip install black && python3 -m black . - -deps: - python3 -m pip install -r requirements - npm install - npm install -g pluto diff --git a/README.md b/README.md index 1fff8ecb..80589cb0 100644 --- a/README.md +++ b/README.md @@ -4,29 +4,24 @@ ## Dependencies -+ Docker -+ Python 3.7+ + Node.js ## Quick Start ```shell -python3 -m pip install -U -r ./requirements.txt npm install -npm install -g pluto -make ``` ## Run ```shell -pluto run +npm run start ``` -## Deploy +## Build ```shell -pluto deploy +npm run build ``` ## Screenshot diff --git a/app/main.py b/app/main.py deleted file mode 100644 index ff1e3d49..00000000 --- a/app/main.py +++ /dev/null @@ -1,74 +0,0 @@ -import json -import re -import tempfile -from pluto_client import ( - Website, - WebsiteOptions, - Router, - RouterOptions, - HttpRequest, - HttpResponse, -) -import kcl_lib.api as kcl_api - -color_pattern = re.compile(r"\x1b\[[0-9;]+m") -api = kcl_api.API() -router = Router("router", RouterOptions(sim_host="0.0.0.0", sim_port="8000")) -website = Website( - "./web/dist", "kcl-playground", WebsiteOptions(sim_host="0.0.0.0", sim_port="8001") -) -website.addEnv("BACKEND_URL", router.url()) - - -def run_code(code: str) -> kcl_api.ExecProgram_Result: - with tempfile.NamedTemporaryFile(suffix=".k") as temp_file: - temp_file.write(code.encode()) - temp_file.seek(0) - args = kcl_api.ExecProgram_Args(k_filename_list=[temp_file.name]) - result = api.exec_program(args) - return result - - -def fmt_code(code: str) -> str: - args = kcl_api.FormatCode_Args(source=code) - result = api.format_code(args) - return str(result.formatted, encoding="utf-8") - - -def compile_handler(req: HttpRequest) -> HttpResponse: - code = req.body["body"] - try: - result = run_code(code) - except Exception as err: - return HttpResponse( - status_code=200, - body=json.dumps( - { - "error": color_pattern.sub("", str(err).removeprefix("ERROR:")), - } - ), - ) - if result.err_message: - return HttpResponse( - status_code=200, - body=json.dumps( - { - "error": color_pattern.sub("", result.err_message), - } - ), - ) - else: - return HttpResponse( - status_code=200, - body=json.dumps({"body": result.log_message + result.yaml_result}), - ) - - -def fmt_handler(req: HttpRequest) -> HttpResponse: - code = req.body["body"] - result = fmt_code(code) - return HttpResponse(status_code=200, body=json.dumps({"body": result})) - - -router.post("/-/play/compile", compile_handler) -router.post("/-/play/fmt", fmt_handler) diff --git a/app/main_test.py b/app/main_test.py deleted file mode 100644 index 4269f04b..00000000 --- a/app/main_test.py +++ /dev/null @@ -1,10 +0,0 @@ -import requests -from main import website, router - - -def test_website(): - assert "8000" in website.url() - - -def test_router(): - assert "8001" in router.url() diff --git a/web/examples/abstration/main.k b/examples/abstration/main.k similarity index 100% rename from web/examples/abstration/main.k rename to examples/abstration/main.k diff --git a/web/examples/kubernetes/main.k b/examples/kubernetes/main.k similarity index 100% rename from web/examples/kubernetes/main.k rename to examples/kubernetes/main.k diff --git a/web/examples/mutation/main.k b/examples/mutation/main.k similarity index 100% rename from web/examples/mutation/main.k rename to examples/mutation/main.k diff --git a/web/examples/validation/main.k b/examples/validation/main.k similarity index 100% rename from web/examples/validation/main.k rename to examples/validation/main.k diff --git a/package.json b/package.json index 1fd52a51..9b714c38 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,37 @@ { - "name": "pluto-kcl-playground", + "name": "kcl-playground", "version": "0.10.0", + "private": true, "scripts": { - "dev": "pluto run", - "test:dev": "pluto test --sim", - "test:prod": "pluto test", - "deploy": "pluto deploy", - "destroy": "pluto destroy" + "start": "webpack serve", + "build": "webpack-cli", + "format": "prettier src/**/*.js src/**/*.css *.config.js --write", + "deploy": "gh-pages -d dist", + "predeploy": "yarn build" }, - "dependencies": {}, + "license": "Apache-2.0", "devDependencies": { - "@plutolang/pluto-infra": "0.4.30", - "@pulumi/pulumi": "^3.88.0", - "@types/node": "^20", - "typescript": "^5.2.2" + "codemirror": "^5.39.2", + "copy-webpack-plugin": "^8.1.1", + "css-loader": "^5.2.4", + "cssnano": "^5.0.1", + "gh-pages": "^3.1.0", + "html-webpack-plugin": "^5.3.1", + "mini-css-extract-plugin": "^1.5.0", + "postcss": "^8.2.10", + "postcss-import": "^14.0.1", + "postcss-loader": "^5.2.0", + "prettier": "^2.2.1", + "webpack": "^5.34.0", + "webpack-cli": "^4.6.0", + "webpack-dev-server": "^3.11.2" }, - "main": "dist/index.js" + "dependencies": { + "@wasmer/wasi": "^1.2.2", + "buffer": "^6.0.3", + "escape-html": "^1.0.3", + "i": "^0.3.7", + "lz-string": "^1.4.4", + "path-browserify": "^1.0.1" + } } diff --git a/pluto.yml b/pluto.yml deleted file mode 100644 index 5a3258e0..00000000 --- a/pluto.yml +++ /dev/null @@ -1,11 +0,0 @@ -current: aws -language: python -stacks: - - configs: {} - name: aws - platformType: AWS - provisionType: Pulumi - -configs: - simulator: - address: "0.0.0.0:8080" diff --git a/web/postcss.config.js b/postcss.config.js similarity index 100% rename from web/postcss.config.js rename to postcss.config.js diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 0a7c9059..00000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -pluto_client -kcl_lib==0.10.0b2 -requests diff --git a/scripts/test.sh b/scripts/test.sh deleted file mode 100755 index 37e4c256..00000000 --- a/scripts/test.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -# Start pluto locally -TMP_OUTPUT_FILE=/tmp/pluto_output.log -pluto run >$TMP_OUTPUT_FILE 2>&1 & -PID1=$! - -# Wait for Pluto to start the project completely -while :; do - if grep -q "Successfully applied!" $TMP_OUTPUT_FILE; then - echo "The project has been successfully started." - break - else - echo "Waiting for Pluto to start the project..." - sleep 1 - fi -done - -# Get the project name from package.json -PROJECT_NAME=$(grep '"name":' package.json | awk -F '"' '{print $4}') -echo "Project name: $PROJECT_NAME" - -# Set environment variables -PORT=8080 -export PLUTO_PROJECT_NAME=$PROJECT_NAME -export PLUTO_STACK_NAME=local_run -export PLUTO_PLATFORM_TYPE=Simulator -export PLUTO_SIMULATOR_URL=http://localhost:$PORT - -# Run tests -print_separator() { - local message=$1 - local message_len=${#message} - - local width=$(tput cols) - local separator=$(printf '=%.0s' $(seq 1 $(((width - message_len - 4) / 2)))) - local bold=$(tput bold) - - printf "\033[34m${bold}${separator}= %s =${separator}\033[0m\n" "$message" -} - -# Output Pluto logs, which might contain useful information -tail -f $TMP_OUTPUT_FILE -n 0 & -PID2=$! - -# Execute tests in the app directory -print_separator "Executing test files in the app directory" -python3 -m pytest -s -q --no-header app - -# Execute tests within the app/main.py file -print_separator "Executing tests within the app/main.py file" -python3 -m pytest -s -q --no-header app/main.py - -# Cleanup -kill $PID1 -wait $PID1 -kill $PID2 diff --git a/web/src/css/base.css b/src/css/base.css similarity index 100% rename from web/src/css/base.css rename to src/css/base.css diff --git a/web/src/css/components/app.css b/src/css/components/app.css similarity index 100% rename from web/src/css/components/app.css rename to src/css/components/app.css diff --git a/web/src/css/components/button.css b/src/css/components/button.css similarity index 100% rename from web/src/css/components/button.css rename to src/css/components/button.css diff --git a/web/src/css/components/console.css b/src/css/components/console.css similarity index 100% rename from web/src/css/components/console.css rename to src/css/components/console.css diff --git a/web/src/css/components/editor.css b/src/css/components/editor.css similarity index 100% rename from web/src/css/components/editor.css rename to src/css/components/editor.css diff --git a/web/src/css/components/footer.css b/src/css/components/footer.css similarity index 100% rename from web/src/css/components/footer.css rename to src/css/components/footer.css diff --git a/web/src/css/components/header.css b/src/css/components/header.css similarity index 100% rename from web/src/css/components/header.css rename to src/css/components/header.css diff --git a/web/src/css/components/select.css b/src/css/components/select.css similarity index 100% rename from web/src/css/components/select.css rename to src/css/components/select.css diff --git a/web/src/css/components/tooltip.css b/src/css/components/tooltip.css similarity index 100% rename from web/src/css/components/tooltip.css rename to src/css/components/tooltip.css diff --git a/web/src/css/style.css b/src/css/style.css similarity index 100% rename from web/src/css/style.css rename to src/css/style.css diff --git a/web/src/css/variables.css b/src/css/variables.css similarity index 100% rename from web/src/css/variables.css rename to src/css/variables.css diff --git a/web/src/favicon.ico b/src/favicon.ico similarity index 100% rename from web/src/favicon.ico rename to src/favicon.ico diff --git a/web/src/index.html b/src/index.html similarity index 53% rename from web/src/index.html rename to src/index.html index 1ec98c32..0a58151c 100644 --- a/web/src/index.html +++ b/src/index.html @@ -1,43 +1,88 @@ +
-