From 72c08d75da93872d31058b0e2b9288e3e5e63759 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 9 Nov 2022 16:22:28 +0000 Subject: [PATCH] feat: a base for a new web3.storage upload-client (#141) Co-authored-by: Hugo Dias --- .github/release-please-config.json | 1 + .github/workflows/client.yml | 32 +++++++++++ .github/workflows/manual.yml | 23 ++++++++ .github/workflows/release.yml | 21 +++++++- packages/upload-client/package.json | 65 +++++++++++++++++++++++ packages/upload-client/src/index.js | 4 ++ packages/upload-client/test/index.test.js | 8 +++ packages/upload-client/tsconfig.json | 10 ++++ pnpm-lock.yaml | 18 +++++++ 9 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/client.yml create mode 100644 packages/upload-client/package.json create mode 100644 packages/upload-client/src/index.js create mode 100644 packages/upload-client/test/index.test.js create mode 100644 packages/upload-client/tsconfig.json diff --git a/.github/release-please-config.json b/.github/release-please-config.json index ea7d6d554..4959779e8 100644 --- a/.github/release-please-config.json +++ b/.github/release-please-config.json @@ -3,6 +3,7 @@ "packages": { "packages/access": {}, "packages/access-api": {}, + "packages/upload-client": {}, "packages/wallet": {}, "packages/store": {} } diff --git a/.github/workflows/client.yml b/.github/workflows/client.yml new file mode 100644 index 000000000..953d5c8f8 --- /dev/null +++ b/.github/workflows/client.yml @@ -0,0 +1,32 @@ +name: Client +env: + CI: true + FORCE_COLOR: 1 +on: + push: + branches: + - main + paths: + - 'packages/upload-client/**' + - '.github/workflows/client.yml' + - 'pnpm-lock.yaml' + pull_request: + paths: + - 'packages/upload-client/**' + - '.github/workflows/client.yml' + - 'pnpm-lock.yaml' +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v2.2.3 + with: + version: 7 + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'pnpm' + - run: pnpm install + - run: pnpm -r --filter @web3-storage/upload-client run lint + - run: pnpm -r --filter @web3-storage/upload-client run test diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml index a044128d8..6d99b4000 100644 --- a/.github/workflows/manual.yml +++ b/.github/workflows/manual.yml @@ -10,6 +10,7 @@ on: options: - access-api - access + - upload-client - wallet environment: description: 'Environment to deploy' @@ -73,3 +74,25 @@ jobs: - run: pnpm -r --filter @web3-storage/access publish --tag next --access public env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + deploy-upload-client: + runs-on: ubuntu-latest + if: github.event.inputs.package == 'upload-client' + steps: + - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v2.2.3 + with: + version: 7 + - uses: actions/setup-node@v3 + with: + node-version: 18 + registry-url: 'https://registry.npmjs.org' + cache: 'pnpm' + - run: pnpm install + - run: pnpm -r --filter @web3-storage/upload-client build + - run: pnpm -r --filter @web3-storage/upload-client run rc || true # this fails because npm does not support workspace protocol so we force it to exit 0 + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: 'chore(client): Bump client pre release version' + - run: pnpm -r --filter @web3-storage/upload-client publish --tag next --access public + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a91201609..1c387c3ae 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,7 @@ jobs: manifest-file: .github/release-please-manifest.json default-branch: main release-type: node - publish: + publish-access: needs: release if: contains(fromJson(needs.release.outputs.paths_released), 'packages/access') runs-on: ubuntu-latest @@ -40,6 +40,25 @@ jobs: - run: pnpm -r publish env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + publish-upload-client: + needs: release + if: contains(fromJson(needs.release.outputs.paths_released), 'packages/upload-client') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v2.2.3 + with: + version: 7 + - uses: actions/setup-node@v3 + with: + node-version: 18 + registry-url: 'https://registry.npmjs.org' + cache: 'pnpm' + - run: pnpm install + - run: pnpm -r --filter @web3-storage/upload-client build + - run: pnpm -r publish + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} pages: needs: release if: contains(fromJson(needs.release.outputs.paths_released), 'packages/wallet') diff --git a/packages/upload-client/package.json b/packages/upload-client/package.json new file mode 100644 index 000000000..de4b4af80 --- /dev/null +++ b/packages/upload-client/package.json @@ -0,0 +1,65 @@ +{ + "name": "@web3-storage/upload-client", + "version": "0.0.0", + "description": "The web3.storage client", + "homepage": "https://github.com/web3-storage/w3protocol/tree/main/packages/upload-client", + "repository": { + "type": "git", + "url": "https://github.com/web3-storage/w3protocol.git", + "directory": "packages/upload-client" + }, + "author": "Alan Shaw", + "license": "Apache-2.0 OR MIT", + "type": "module", + "types": "dist/src/index.d.ts", + "main": "src/index.js", + "scripts": { + "lint": "tsc && eslint '**/*.{js,ts}' && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore", + "build": "tsc --build", + "test": "npm run test:node && npm run test:browser", + "test:node": "mocha 'test/**/!(*.browser).test.js' -n experimental-vm-modules -n no-warnings", + "test:browser": "playwright-test 'test/**/!(*.node).test.js'", + "rc": "npm version prerelease --preid rc" + }, + "exports": { + ".": "./src/index.js" + }, + "typesVersions": { + "*": { + "*": [ + "dist/*" + ] + } + }, + "files": [ + "src", + "dist/src/**/*.d.ts", + "dist/src/**/*.d.ts.map" + ], + "devDependencies": { + "@types/assert": "^1.5.6", + "@types/mocha": "^10.0.0", + "assert": "^2.0.0", + "hd-scripts": "^3.0.2", + "mocha": "^10.1.0", + "playwright-test": "^8.1.1", + "typescript": "^4.8.4" + }, + "eslintConfig": { + "extends": [ + "./node_modules/hd-scripts/eslint/index.js" + ], + "parserOptions": { + "project": "./tsconfig.json" + }, + "rules": { + "unicorn/prefer-number-properties": "off" + }, + "env": { + "mocha": true + }, + "ignorePatterns": [ + "dist" + ] + } +} diff --git a/packages/upload-client/src/index.js b/packages/upload-client/src/index.js new file mode 100644 index 000000000..8901d0373 --- /dev/null +++ b/packages/upload-client/src/index.js @@ -0,0 +1,4 @@ +class Client {} + +export default Client +export { Client } diff --git a/packages/upload-client/test/index.test.js b/packages/upload-client/test/index.test.js new file mode 100644 index 000000000..bfcd8cc1e --- /dev/null +++ b/packages/upload-client/test/index.test.js @@ -0,0 +1,8 @@ +import assert from 'assert' +import Client from '../src/index.js' + +describe('index', function () { + it('should export a client object', () => { + assert(Client) + }) +}) diff --git a/packages/upload-client/tsconfig.json b/packages/upload-client/tsconfig.json new file mode 100644 index 000000000..180297270 --- /dev/null +++ b/packages/upload-client/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "dist", + "lib": ["ESNext", "DOM"], + "emitDeclarationOnly": true + }, + "include": ["src", "scripts", "test", "package.json"], + "exclude": ["**/node_modules/**"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9c80b3eff..defdcdc0c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -259,6 +259,24 @@ importers: typescript: 4.8.4 wrangler: 2.1.15 + packages/upload-client: + specifiers: + '@types/assert': ^1.5.6 + '@types/mocha': ^10.0.0 + assert: ^2.0.0 + hd-scripts: ^3.0.2 + mocha: ^10.1.0 + playwright-test: ^8.1.1 + typescript: ^4.8.4 + devDependencies: + '@types/assert': 1.5.6 + '@types/mocha': 10.0.0 + assert: 2.0.0 + hd-scripts: 3.0.2 + mocha: 10.1.0 + playwright-test: 8.1.1 + typescript: 4.8.4 + packages/store: specifiers: '@types/chai': ^4.3.0