From 175ff0094a864c58015eed4269a6c8d7143f31d9 Mon Sep 17 00:00:00 2001 From: Shane Myrick Date: Tue, 12 Nov 2024 11:26:26 -0800 Subject: [PATCH] Add dist to repo --- .github/workflows/onPushToMain.yml | 37 ++++++------------------------ .gitignore | 1 - dist/commands/mock/index.d.ts | 14 +++++++++++ dist/commands/mock/index.js | 27 ++++++++++++++++++++++ dist/common/server.d.ts | 3 +++ dist/common/server.js | 16 +++++++++++++ dist/index.d.ts | 1 + dist/index.js | 1 + 8 files changed, 69 insertions(+), 31 deletions(-) create mode 100644 dist/commands/mock/index.d.ts create mode 100644 dist/commands/mock/index.js create mode 100644 dist/common/server.d.ts create mode 100644 dist/common/server.js create mode 100644 dist/index.d.ts create mode 100644 dist/index.js diff --git a/.github/workflows/onPushToMain.yml b/.github/workflows/onPushToMain.yml index 3c0caed..24dd4ef 100644 --- a/.github/workflows/onPushToMain.yml +++ b/.github/workflows/onPushToMain.yml @@ -1,5 +1,4 @@ -# test -name: version, tag and github release +name: Build latest and update README on: push: @@ -11,38 +10,16 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 - - name: Check if version already exists - id: version-check - run: | - package_version=$(node -p "require('./package.json').version") - exists=$(gh api repos/${{ github.repository }}/releases/tags/v$package_version >/dev/null 2>&1 && echo "true" || echo "") - - if [ -n "$exists" ]; - then - echo "Version v$package_version already exists" - echo "::warning file=package.json,line=1::Version v$package_version already exists - no release will be created. If you want to create a new release, please update the version in package.json and push again." - echo "skipped=true" >> $GITHUB_OUTPUT - else - echo "Version v$package_version does not exist. Creating release..." - echo "skipped=false" >> $GITHUB_OUTPUT - echo "tag=v$package_version" >> $GITHUB_OUTPUT - fi - env: - GH_TOKEN: ${{ secrets.GH_TOKEN }} - name: Setup git - if: ${{ steps.version-check.outputs.skipped == 'false' }} run: | git config --global user.name "${{ github.actor }}" git config --global user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" - - name: Generate oclif README - if: ${{ steps.version-check.outputs.skipped == 'false' }} - id: oclif-readme + - name: Generate latest build + id: build run: | npm install npm run build - npm exec oclif readme - if [ -n "$(git status --porcelain)" ]; then - git add README.md - git commit -am "chore: update README.md" - git push -u origin ${{ github.ref_name }} - fi + npm run verison + git add . + git commit -am "chore: update build" + git push -u origin ${{ github.ref_name }} diff --git a/.gitignore b/.gitignore index 2d775d5..83d9bcc 100644 --- a/.gitignore +++ b/.gitignore @@ -32,7 +32,6 @@ ehthumbs.db **/.DS_Store # Build -/dist /tmp oclif.manifest.json diff --git a/dist/commands/mock/index.d.ts b/dist/commands/mock/index.d.ts new file mode 100644 index 0000000..ad4c645 --- /dev/null +++ b/dist/commands/mock/index.d.ts @@ -0,0 +1,14 @@ +import { Command } from '@oclif/core'; +export default class Mock extends Command { + static args: { + schema: import("@oclif/core/interfaces").Arg; + }; + static description: string; + static examples: string[]; + static flags: { + port: import("@oclif/core/interfaces").OptionFlag; + }; + run(): Promise; +} diff --git a/dist/commands/mock/index.js b/dist/commands/mock/index.js new file mode 100644 index 0000000..1d04020 --- /dev/null +++ b/dist/commands/mock/index.js @@ -0,0 +1,27 @@ +import { Args, Command, Flags } from '@oclif/core'; +import { readFileSync } from 'node:fs'; +import { startServer } from '../../common/server.js'; +export default class Mock extends Command { + static args = { + schema: Args.file({ description: 'Schema file to mock', required: true }), + }; + static description = 'Start a mock GraphQL server from a file'; + static examples = [ + '<%= config.bin %> <%= command.id %> schema.graphql', + '<%= config.bin %> <%= command.id %> schema.graphql --port 8080', + ]; + static flags = { + port: Flags.integer({ + default: 4000, + description: 'HTTP port for server', + required: false + }) + }; + async run() { + const { args, flags } = await this.parse(Mock); + this.log(`Reading schema file ${args.schema}...`); + const sdl = readFileSync(args.schema, 'utf8'); + const promise = await startServer(sdl, flags.port); + this.log(`🚀 Mock Apollo Server ready at: ${promise.url}`); + } +} diff --git a/dist/common/server.d.ts b/dist/common/server.d.ts new file mode 100644 index 0000000..bc41a2c --- /dev/null +++ b/dist/common/server.d.ts @@ -0,0 +1,3 @@ +export declare const startServer: (sdl: string, port: number) => Promise<{ + url: string; +}>; diff --git a/dist/common/server.js b/dist/common/server.js new file mode 100644 index 0000000..e2054b2 --- /dev/null +++ b/dist/common/server.js @@ -0,0 +1,16 @@ +import { ApolloServer } from '@apollo/server'; +import { startStandaloneServer } from '@apollo/server/standalone'; +import { addMocksToSchema } from '@graphql-tools/mock'; +import { makeExecutableSchema } from '@graphql-tools/schema'; +const getApolloServer = (sdl) => new ApolloServer({ + introspection: true, + schema: addMocksToSchema({ + schema: makeExecutableSchema({ typeDefs: sdl }) + }) +}); +export const startServer = async (sdl, port) => { + const server = getApolloServer(sdl); + return startStandaloneServer(server, { + listen: { port }, + }); +}; diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..d620e70 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1 @@ +export { run } from '@oclif/core'; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..d620e70 --- /dev/null +++ b/dist/index.js @@ -0,0 +1 @@ +export { run } from '@oclif/core';