Skip to content

Commit

Permalink
Convert into monorepo (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
guidanoli authored Jul 13, 2024
1 parent 1ebc612 commit 3f28886
Show file tree
Hide file tree
Showing 32 changed files with 2,107 additions and 616 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-eels-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@guidanoli/cmioc": minor
---

Converted interfaces into types
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
58 changes: 35 additions & 23 deletions .github/workflows/ci.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
name: Release

on:
pull_request:
push:
branches:
- main
tags:
- "v*"

jobs:
test:
nodejs:
name: Node.js
runs-on: ubuntu-latest

outputs:
published: ${{ steps.changeset.outputs.published }}
publishedPackages: ${{ steps.changeset.outputs.publishedPackages }}

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v3
with:
version: 8
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
cache: "pnpm"

- name: Install Node packages
run: pnpm i

- name: Check code format
run: pnpm check-format
- name: Install Node.js dependencies
run: pnpm install

- name: Run tests
run: pnpm test
- name: Create PR or publish packages
id: changeset
uses: changesets/action@v1
with:
publish: pnpm changeset publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

push:
if: ${{ github.event_name != 'pull_request' }}
needs: test
ghcr:
name: GitHub Container Registry
runs-on: ubuntu-latest
needs: nodejs

strategy:
matrix:
package: ${{ fromJson(needs.nodejs.outputs.publishedPackages) }}

if: ${{ needs.nodejs.outputs.published == 'true' && matrix.package.name == '@guidanoli/cmioc-cli' }}

permissions:
packages: write
contents: read
env:
IMAGE_NAME: cmioc

steps:
- uses: actions/checkout@v4

Expand All @@ -51,10 +63,9 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=semver,pattern={{version}},value=${{ matrix.package.version }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand All @@ -68,6 +79,7 @@ jobs:
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
builder: ${{ steps.setup_buildx.outputs.name }}
tags: ${{ steps.extract_metadata.outputs.tags }}
labels: ${{ steps.extract_metadata.lables.labels }}
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Test

on:
pull_request:
push:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v3
with:
version: 8

- uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"

- name: Install Node packages
run: pnpm install

- name: Check code format
run: pnpm run check-format

- name: Run tests
run: pnpm run test
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
pnpm-lock.yaml
README.md
src/*.js
src/*.d.ts
1 change: 0 additions & 1 deletion .prettierrc.yaml

This file was deleted.

9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ RUN pnpm install --prod --frozen-lockfile

FROM base AS build
RUN pnpm install --frozen-lockfile
RUN pnpm run build
RUN pnpm run-s build:core build:cli

FROM base
COPY --from=prod-deps /app/node_modules /app/node_modules
COPY --from=build /app/dist /app/dist
COPY --from=prod-deps /app/packages/core/node_modules /app/packages/core/node_modules
COPY --from=build /app/apps/cli/node_modules /app/apps/cli/node_modules
COPY --from=build /app/packages/core/dist /app/packages/core/dist
COPY --from=build /app/apps/cli/dist /app/apps/cli/dist
EXPOSE 8000
ENTRYPOINT [ "node", "dist/src/cli.js" ]
ENTRYPOINT [ "node", "apps/cli/dist/src/index.js" ]
1 change: 1 addition & 0 deletions apps/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A CLI tool for encoding and decoding, with ease, inputs and outputs for the upcoming Cartesi Rollups SDK v2.
49 changes: 49 additions & 0 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@guidanoli/cmioc-cli",
"version": "0.1.4",
"description": "Cartesi Machine Input/Output Codec CLI",
"keywords": [
"cartesi",
"rollups",
"solidity",
"codec",
"cli"
],
"homepage": "https://github.com/guidanoli/cmioc",
"bugs": {
"url": "https://github.com/guidanoli/cmioc/issues"
},
"license": "GPL-v3-only",
"author": {
"name": "Guilherme Dantas",
"e-mail": "[email protected]",
"url": "https://github.com/guidanoli"
},
"files": [
"dist"
],
"bin": {
"cmioc": "dist/src/index.js"
},
"scripts": {
"build": "tsc",
"clean": "rimraf dist",
"prepack": "run-s build"
},
"dependencies": {
"@commander-js/extra-typings": "^12.0.1",
"@guidanoli/cmioc": "workspace:*",
"commander": "^12.0.0",
"ethers": "^6.11.1",
"viem": "^2.9.2"
},
"devDependencies": {
"@types/node": "^20.14.10",
"rimraf": "^5.0.5",
"ts-node": "^10.9.2",
"tsconfig": "workspace:*"
},
"engines": {
"node": ">=16"
}
}
3 changes: 2 additions & 1 deletion src/cli.ts → apps/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Command, InvalidArgumentError } from "@commander-js/extra-typings";

import {
Address,
BaseError,
Expand All @@ -18,7 +19,7 @@ import {
Notice,
Voucher,
DelegateCallVoucher,
} from ".";
} from "@guidanoli/cmioc";

import { version } from "../package.json";

Expand Down
8 changes: 8 additions & 0 deletions apps/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"outDir": "dist",
"resolveJsonModule": true
},
"extends": "tsconfig/base.json",
"include": ["src", "package.json"]
}
15 changes: 15 additions & 0 deletions apps/site/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "site",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vocs dev",
"build": "vocs build",
"preview": "vocs preview"
},
"devDependencies": {
"@guidanoli/cmioc": "workspace:*",
"vocs": "1.0.0-alpha.52"
}
}
49 changes: 49 additions & 0 deletions apps/site/pages/docs/cli/installation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Installation

## Via package manager

You can install the CLI globally on your machine with your favorite package manager.

:::code-group

```bash [npm]
npm install -g @guidanoli/cmioc
```

```bash [pnpm]
pnpm add -g @guidanoli/cmioc
```

```bash [yarn]
yarn global add @guidanoli/cmioc
```

:::

Once installed, you can execute the CLI directly, like so:

```sh
cmioc [args...]
```

## Via GitHub Container Registry

Alternatively, you can also pull the CLI image from the [GitHub Container Registry].

```sh
docker pull ghcr.io/guidanoli/cmioc
```

Once pulled, you can execute the CLI through Docker, like so:

```sh
docker run ghcr.io/guidanoli/cmioc [args...]
```

If you want to pipe data into the CLI through `stdin`, don't forget the `-i` option.

```sh
cat input.txt | docker run -i ghcr.io/guidanoli/cmioc [args...]
```

[GitHub Container Registry]: https://ghcr.io
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---
title: Getting Started
layout: docs
---
# Getting Started

# Background
## Background

On [Cartesi Rollups SDK v1],
inputs and outputs had a very precise definition.
Expand All @@ -25,7 +22,7 @@ This change allows:
- the Cartesi SDK developers to more easily add new types of executable outputs
- the Cartesi SDK developers to more easily add new types of metadata to inputs

# Purpose
## Purpose

The purpose of `cmioc` is to easily encode and decode,
through a CLI tool and TypeScript library,
Expand Down
27 changes: 27 additions & 0 deletions apps/site/pages/docs/ts/installation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Installation

## Via package manager

You can add the TypeScript package as a dependency to your project with your favorite package manager.

:::code-group

```bash [npm]
npm install @guidanoli/cmioc
```

```bash [pnpm]
pnpm add @guidanoli/cmioc
```

```bash [yarn]
yarn add @guidanoli/cmioc
```

:::

Once installed, you can import definitions from the package like so:

```ts twoslash
import { decodeOutputBlob } from "@guidanoli/cmioc";
```
File renamed without changes.
File renamed without changes
File renamed without changes
3 changes: 2 additions & 1 deletion vocs.config.mts → apps/site/vocs.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig } from "vocs";
export default defineConfig({
title: "cmioc — Cartesi Machine Input/Output Codec",
titleTemplate: "%s — cmioc Documentation",
rootDir: ".",
sidebar: [
{
text: "Getting Started",
Expand Down Expand Up @@ -115,7 +116,7 @@ export default defineConfig({
],
editLink: {
pattern:
"https://github.com/guidanoli/cmioc/edit/main/docs/pages/:path",
"https://github.com/guidanoli/cmioc/edit/main/site/pages/:path",
text: "Edit on GitHub",
},
iconUrl: {
Expand Down
Loading

0 comments on commit 3f28886

Please sign in to comment.