diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml deleted file mode 100644 index 43b6b52..0000000 --- a/.github/workflows/build-and-push.yml +++ /dev/null @@ -1,77 +0,0 @@ -name: Generate development build - -# Don't generate builds for other builds! -on: - push: - branches-ignore: - - "builds/**" - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - - name: Install dependencies - run: | - npm ci - - - name: Build Typescript - run: | - npm run build - - - name: Push build artifacts - if: false - env: - DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} - run: | - # Find current branch name from GITHUB_REF and prepend 'builds/'' - BUILDS_BRANCH_NAME="builds/${GITHUB_REF#refs/heads/}" - echo "Pushing artifacts to branch $BUILDS_BRANCH_NAME" - - # Create another clone of the repository in a temporary directory - git clone "$(git remote get-url origin)" .temp - cd .temp - - # Checkout the builds branch, or create one if it doesn't exist yet - git checkout "$BUILDS_BRANCH_NAME" || git checkout --orphan "$BUILDS_BRANCH_NAME" - - # When creating a new branch, the whole working directory is added by - # default, but we don't want that - git reset - - # We also have to pull changes from the remote if possible - git pull || true - - # Move build artifacts and metadata into this new directory, including - # files always included in npm packages per - # https://docs.npmjs.com/files/package.json#files - cp -r ../dist . - cp ../package.json . - cp ../LICENSE . - cp ../README.md . - - # If we have changes... - if [ -n "$(git status --porcelain)" ]; then - - # Add files to git - git add -f dist/** package.json LICENSE README.md - - # Commit - git config user.name "Build Bot" - git config user.email "bot@github-actions" - git commit -m "Build of ${GITHUB_SHA:0:7}" - - # Convert remote URL from HTTPS to SSH format so we can use our key - git remote set-url origin "$(git remote get-url origin | sed 's#http.*com/#git@github.com:#g')" - - # Push the commit to the origin - eval `ssh-agent -t 60 -s` - echo "$DEPLOY_KEY" | ssh-add - - mkdir -p ~/.ssh/ - ssh-keyscan github.com >> ~/.ssh/known_hosts - git push || git push --set-upstream origin "$BUILDS_BRANCH_NAME" - ssh-agent -k - else - echo "No changes to build output detected" - fi diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..8e99cc1 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,12 @@ +name: Build and test +on: push + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - run: npm ci + - run: npm run fmt:check --workspaces + - run: npm run build:all + - run: npm run test --workspaces diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 18881b6..5f57bdf 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -5,12 +5,6 @@ on: - "v*" workflow_dispatch: -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages -permissions: - contents: read - pages: write - id-token: write - jobs: build: runs-on: ubuntu-latest @@ -19,14 +13,18 @@ jobs: - uses: actions/setup-node@v2 - uses: actions/configure-pages@v3 - run: npm ci + - run: npm run build:all - run: npm run docs - name: Upload Pages artifact uses: actions/upload-pages-artifact@v1 with: path: docs/ - # Deployment job deploy: + # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages + permissions: + pages: write + id-token: write environment: name: docs url: ${{ steps.deployment.outputs.page_url }} diff --git a/.gitignore b/.gitignore index 7b5a7a6..2f063d8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ node_modules .vscode .nyc_output dist +*.tsbuildinfo docs diff --git a/README.md b/README.md index 68f4d72..63c74b9 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,58 @@ -# toolbox-devvit [![npm version](https://img.shields.io/npm/v/toolbox-devvit.svg)](https://www.npmjs.com/package/toolbox-devvit) - -Helpers for working with /r/toolbox data from Devvit community apps. [Read the documentation.](https://toolbox-team.github.io/toolbox-devvit/) - -## Installation - -```bash -npm install --production toolbox-devvit -``` - -## Usage Example - -```ts -import {Devvit} from '@devvit/public-api'; -import {ToolboxClient} from 'toolbox-devvit'; - -Devvit.configure({ - redditAPI: true, - // ... -}); - -// A simple action that creates a usernote on a post's author -Devvit.addMenuItem({ - location: 'post', - label: 'Create Test Usernote', - description: 'Creates a Toolbox usernote for testing', - onPress: async (event, {reddit, ui, postId}) => { - const subredditName = (await reddit.getCurrentSubreddit()).name; - const username = (await reddit.getPostById(postId!)).authorName; - const text = 'Hihi i am a note'; - const wikiRevisionReason = 'Create note via my custom app'; - - const toolbox = new ToolboxClient(reddit); - await toolbox.addUsernote(subredditName, { - username, - text, - }, wikiRevisionReason); - - ui.showToast({ - appearance: 'success', - text: 'Note added!', - }); - }, -}); - -export default Devvit; -``` +# Toolbox Storage Helpers + +A collection of packages for working with /r/toolbox data. + +## Packages + +See the README in each package for more information. + +### [`toolbox-storage`](/packages/toolbox-storage/) [![npm version](https://img.shields.io/npm/v/toolbox-storage.svg)](https://www.npmjs.com/package/toolbox-storage) + +Defines basic helpers classes for reading and manipulating the storage formats. +This package includes no data fetching/API helpers; you'll have to read to/write +from the relevant wiki pages yourself. + +### [`toolbox-devvit`](/packages/toolbox-devvit/) [![npm version](https://img.shields.io/npm/v/toolbox-devvit.svg)](https://www.npmjs.com/package/toolbox-devvit) + +Wraps the basic helpers in a Devvit-specific client class which handles data +fetching for you via Devvit's built-in API client. + +## Development/Contributing + +This project uses [npm workspaces][npm-workspaces]. Run `npm install` from the +root directory in order to install dependencies for all packages and create +`node_modules` symlinks for packages that depend on each other. + +### Package scripts + +Each package defines several scripts for itself, which include: + +- `fmt` formats the package's source code. +- `fmt:check` checks the format without making any changes to files. +- `build` compiles the package and its tests. +- `test` runs the package's tests. Make sure you run `build` first. +- `coverage` compiles and runs tests and generates a test coverage report. + +Each of these scripts can be run in two ways: + +- To run for a single package, run `npm run