diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 3777f5be..98372e94 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -2,9 +2,20 @@ ARG VARIANT="20" FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:${VARIANT} +RUN apt-get update + +RUN apt-get install -y php ruby ruby-dev +RUN gem install standard -v 1.31.0 + +RUN wget https://github.com/mvdan/sh/releases/download/v3.9.0/shfmt_v3.9.0_linux_amd64 -O shfmt \ + && chmod a+x shfmt \ + && mv shfmt /usr/local/bin/shfmt + USER node WORKDIR /home/node +RUN curl -LsSf https://astral.sh/ruff/0.6.3/install.sh | sh + RUN mkdir -p .config/git \ && echo ".vscode/*" >> .config/git/ignore \ && echo "*.code-workspace" >> .config/git/ignore \ diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 21ada2fc..42a4e902 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -12,6 +12,9 @@ "EditorConfig.EditorConfig", "esbenp.prettier-vscode" ], + "remoteEnv": { + "PATH": "${containerEnv:PATH}:${localEnv:HOME}/.cargo/env" + }, "postCreateCommand": "npm install", "remoteUser": "node" } diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml index cf37b61c..9132dcd8 100644 --- a/.github/workflows/generate.yml +++ b/.github/workflows/generate.yml @@ -31,6 +31,21 @@ jobs: uses: ./.github/actions/setup with: install_dependencies: 'false' + - name: Install ruff + run: | + curl -LsSf https://astral.sh/ruff/0.6.3/install.sh | sh + echo "$HOME/.cargo/env" >> $GITHUB_PATH + - name: Install shfmt + run: | + wget https://github.com/mvdan/sh/releases/download/v3.9.0/shfmt_v3.9.0_linux_amd64 -O shfmt + chmod a+x shfmt + mv shfmt /usr/local/bin/shfmt + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + - name: Install standardrb + run: gem install standard -v 1.31.0 - name: Normalize package-lock.json run: npm install - name: Generate docs diff --git a/README.md b/README.md index 1c7abb86..4856a7f5 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,17 @@ $ npm install [npm]: https://www.npmjs.com/ [nvm]: https://github.com/creationix/nvm +### Optional Requirements + +These tools are using to format code during documentation generation. +They are not required for local development: +if they are not installed, the doc generation will simply skip the formatting step. +GitHub actions will automatically ensure the formatting is applied for all pull requests. + +- [shfmt](https://github.com/mvdan/sh) +- [ruff](https://github.com/astral-sh/ruff) +- [standardrb](https://github.com/standardrb/standard) + ## GitHub Actions _GitHub Actions should already be configured: this section is for reference only._ diff --git a/docs/api/acs/systems/list.md b/docs/api/acs/systems/list.md index aebb79fc..09767803 100644 --- a/docs/api/acs/systems/list.md +++ b/docs/api/acs/systems/list.md @@ -14,12 +14,14 @@ response includes all access control systems connected to your workspace. {% tab title="JavaScript" %} ### Request ```javascript - await seam.acs.systems.list({"connected_account_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33"}) + await seam.acs.systems.list({ + connected_account_id: "8d7e0b3a-b889-49a7-9164-4b71a0506a33", +}); ``` ### Response ```javascript - [{"acs_system_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33"}] + [{ acs_system_id: "8d7e0b3a-b889-49a7-9164-4b71a0506a33" }]; ``` {% endtab %} {% tab title="Python" %} @@ -41,19 +43,21 @@ response includes all access control systems connected to your workspace. ### Response ```ruby - [] + [{"acs_system_id" => "8d7e0b3a-b889-49a7-9164-4b71a0506a33"}] ``` {% endtab %} {% tab title="PHP" %} ### Request ```php - $seam->acs->systems->list(connected_account_id:"8d7e0b3a-b889-49a7-9164-4b71a0506a33") + acs->systems->list( + connected_account_id: "8d7e0b3a-b889-49a7-9164-4b71a0506a33" +); ``` ### Response ```php - [{"acs_system_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33"}] + [{ "acs_system_id": "8d7e0b3a-b889-49a7-9164-4b71a0506a33" }] ``` {% endtab %} {% tab title="Seam CLI" %} @@ -64,7 +68,7 @@ acs_system_id="8d7e0b3a-b889-49a7-9164-4b71a0506a33">] ### Response ```seam_cli - [{"acs_system_id":"8d7e0b3a-b889-49a7-9164-4b71a0506a33"}] + [{ "acs_system_id": "8d7e0b3a-b889-49a7-9164-4b71a0506a33" }] ``` {% endtab %} {% endtabs %} diff --git a/package-lock.json b/package-lock.json index 4c1c2f1b..149b6578 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,13 +11,18 @@ "dependencies": { "@metalsmith/layouts": "^2.7.0", "@metalsmith/metadata": "^0.3.0", - "@seamapi/blueprint": "^0.14.2", + "@prettier/plugin-php": "^0.22.2", + "@seamapi/blueprint": "^0.16.0", "change-case": "^5.4.4", + "command-exists": "^1.2.9", + "execa": "^9.3.1", "jstransformer-handlebars": "^1.2.0", - "metalsmith": "^2.6.3" + "metalsmith": "^2.6.3", + "prettier": "^3.0.0" }, "devDependencies": { "@seamapi/types": "^1.229.1", + "@types/command-exists": "^1.2.3", "@types/debug": "^4.1.12", "@types/micromatch": "^4.0.9", "@types/node": "^20.8.10", @@ -27,7 +32,6 @@ "eslint-config-standard-with-typescript": "^43.0.0", "eslint-plugin-simple-import-sort": "^12.0.0", "eslint-plugin-unused-imports": "^3.0.0", - "prettier": "^3.0.0", "tsx": "^4.6.2", "typescript": "~5.3.3" }, @@ -611,10 +615,23 @@ "node": ">= 8" } }, + "node_modules/@prettier/plugin-php": { + "version": "0.22.2", + "resolved": "https://registry.npmjs.org/@prettier/plugin-php/-/plugin-php-0.22.2.tgz", + "integrity": "sha512-md0+7tNbsP0oy+wIP3KZZc6fzx1k1jtWaMjOy/gM8yU9f2BDYEi+iHOc/UNPihYvPI28zFTbjvlhH4QXQjQwNg==", + "license": "MIT", + "dependencies": { + "linguist-languages": "^7.27.0", + "php-parser": "^3.1.5" + }, + "peerDependencies": { + "prettier": "^3.0.0" + } + }, "node_modules/@seamapi/blueprint": { - "version": "0.14.2", - "resolved": "https://registry.npmjs.org/@seamapi/blueprint/-/blueprint-0.14.2.tgz", - "integrity": "sha512-yEO7P6hyMM9EcGPjenw8ofBLbbJcx07xctwVgL/jN4FJLW8kF5flvtF+nVl7zNPsxkuPG9b3wMGHlNe/utXIDg==", + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/@seamapi/blueprint/-/blueprint-0.16.0.tgz", + "integrity": "sha512-bqiF4RonjnaTUXNU/4tNWGx+gOaxNboLCrEYSbpRHmXtladwvI6AN67kLQJZwaD/4BE3VEFrJmMHRfV3jk2jvw==", "license": "MIT", "dependencies": { "change-case": "^5.4.4", @@ -639,12 +656,37 @@ "zod": "^3.21.4" } }, + "node_modules/@sec-ant/readable-stream": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@sec-ant/readable-stream/-/readable-stream-0.4.1.tgz", + "integrity": "sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==", + "license": "MIT" + }, + "node_modules/@sindresorhus/merge-streams": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/merge-streams/-/merge-streams-4.0.0.tgz", + "integrity": "sha512-tlqY9xq5ukxTUZBmoOp+m61cqwQD5pHJtFY3Mn8CA8ps6yghLH/Hw8UPdqg4OLmFW3IFlcXnQNmo/dh8HzXYIQ==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@types/braces": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/@types/braces/-/braces-3.0.4.tgz", "integrity": "sha512-0WR3b8eaISjEW7RpZnclONaLFDf7buaowRHdqLp4vLj54AsSAYWfh3DRbfiYJY9XDxMgx1B4sE1Afw2PGpuHOA==", "dev": true }, + "node_modules/@types/command-exists": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@types/command-exists/-/command-exists-1.2.3.tgz", + "integrity": "sha512-PpbaE2XWLaWYboXD6k70TcXO/OdOyyRFq5TVpmlUELNxdkkmXU9fkImNosmXU1DtsNrqdUgWd/nJQYXgwmtdXQ==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/debug": { "version": "4.1.12", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz", @@ -1293,6 +1335,12 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/command-exists": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", + "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==", + "license": "MIT" + }, "node_modules/commander": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", @@ -1311,7 +1359,6 @@ "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", - "dev": true, "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", @@ -2176,6 +2223,32 @@ "node": ">=0.10.0" } }, + "node_modules/execa": { + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/execa/-/execa-9.3.1.tgz", + "integrity": "sha512-gdhefCCNy/8tpH/2+ajP9IQc14vXchNdd0weyzSJEFURhRMGncQ+zKFxwjAufIewPEJm9BPOaJnvg2UtlH2gPQ==", + "license": "MIT", + "dependencies": { + "@sindresorhus/merge-streams": "^4.0.0", + "cross-spawn": "^7.0.3", + "figures": "^6.1.0", + "get-stream": "^9.0.0", + "human-signals": "^8.0.0", + "is-plain-obj": "^4.1.0", + "is-stream": "^4.0.1", + "npm-run-path": "^5.2.0", + "pretty-ms": "^9.0.0", + "signal-exit": "^4.1.0", + "strip-final-newline": "^4.0.0", + "yoctocolors": "^2.0.0" + }, + "engines": { + "node": "^18.19.0 || >=20.5.0" + }, + "funding": { + "url": "https://github.com/sindresorhus/execa?sponsor=1" + } + }, "node_modules/extend-shallow": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", @@ -2242,6 +2315,21 @@ "reusify": "^1.0.4" } }, + "node_modules/figures": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-6.1.0.tgz", + "integrity": "sha512-d+l3qxjSesT4V7v2fh+QnmFnUWv9lSpjarhShNTgBOfA0ttejbQUAlHLitbjkoRiDulW0OPoQPYIGhIC8ohejg==", + "license": "MIT", + "dependencies": { + "is-unicode-supported": "^2.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -2389,6 +2477,22 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-stream": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-9.0.1.tgz", + "integrity": "sha512-kVCxPF3vQM/N0B1PmoqVUqgHP+EeVjmZSQn+1oCRPxd2P21P2F19lIgbR3HBosbB1PUhOAoctJnfEn2GbN2eZA==", + "license": "MIT", + "dependencies": { + "@sec-ant/readable-stream": "^0.4.1", + "is-stream": "^4.0.1" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/get-symbol-description": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/get-symbol-description/-/get-symbol-description-1.0.2.tgz", @@ -2686,6 +2790,15 @@ "node": ">= 0.4" } }, + "node_modules/human-signals": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-8.0.0.tgz", + "integrity": "sha512-/1/GPCpDUCCYwlERiYjxoczfP0zfvZMU/OWgQPMya9AbAE24vseigFdhAMObpc8Q4lc/kjutPfUddDYyAmejnA==", + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, "node_modules/ignore": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", @@ -2971,6 +3084,18 @@ "node": ">=8" } }, + "node_modules/is-plain-obj": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-4.1.0.tgz", + "integrity": "sha512-+Pgi+vMuUNkJyExiMBt5IlFoMyKnr5zhJ4Uspz58WOhBF5QoIZkFyNHIbBAtHwzVAgk5RtndVNsDRN61/mmDqg==", + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-promise": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz", @@ -3009,6 +3134,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-stream": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-4.0.1.tgz", + "integrity": "sha512-Dnz92NInDqYckGEUJv689RbRiTSEHCQ7wOVeALbkOz999YpqT46yMRIGtSNl2iCL1waAZSx40+h59NV/EwzV/A==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-string": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.7.tgz", @@ -3057,6 +3194,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-unicode-supported": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-2.0.0.tgz", + "integrity": "sha512-FRdAyx5lusK1iHG0TWpVtk9+1i+GjrzRffhDg4ovQ7mcidMQ6mj+MhKPmvh7Xwyv5gIS06ns49CA7Sqg7lC22Q==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-utf8": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz", @@ -3085,8 +3234,7 @@ "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" }, "node_modules/js-yaml": { "version": "4.1.0", @@ -3180,6 +3328,12 @@ "node": ">= 0.8.0" } }, + "node_modules/linguist-languages": { + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/linguist-languages/-/linguist-languages-7.27.0.tgz", + "integrity": "sha512-Wzx/22c5Jsv2ag+uKy+ITanGA5hzvBZngrNGDXLTC7ZjGM6FLCYGgomauTkxNJeP9of353OM0pWqngYA180xgw==", + "license": "MIT" + }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -3297,6 +3451,33 @@ "node": ">=0.10.0" } }, + "node_modules/npm-run-path": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.3.0.tgz", + "integrity": "sha512-ppwTtiJZq0O/ai0z7yfudtBpWIoxM8yE6nHi1X47eFR2EWORqfbu6CnPlNsjeN683eT0qG6H/Pyf9fCcvjnnnQ==", + "license": "MIT", + "dependencies": { + "path-key": "^4.0.0" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/npm-run-path/node_modules/path-key": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz", + "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==", + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/object-inspect": { "version": "1.13.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", @@ -3459,6 +3640,18 @@ "node": ">=6" } }, + "node_modules/parse-ms": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/parse-ms/-/parse-ms-4.0.0.tgz", + "integrity": "sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -3481,7 +3674,6 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", - "dev": true, "engines": { "node": ">=8" } @@ -3502,6 +3694,12 @@ "node": ">=8" } }, + "node_modules/php-parser": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/php-parser/-/php-parser-3.1.5.tgz", + "integrity": "sha512-jEY2DcbgCm5aclzBdfW86GM6VEIWcSlhTBSHN1qhJguVePlYe28GhwS0yoeLYXpM2K8y6wzLwrbq814n2PHSoQ==", + "license": "BSD-3-Clause" + }, "node_modules/picomatch": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", @@ -3536,7 +3734,6 @@ "version": "3.3.3", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", - "dev": true, "bin": { "prettier": "bin/prettier.cjs" }, @@ -3547,6 +3744,21 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/pretty-ms": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-9.1.0.tgz", + "integrity": "sha512-o1piW0n3tgKIKCwk2vpM/vOV13zjJzvP37Ioze54YlTHE06m4tjEbzg9WsKkvTuyYln2DHjo5pY4qrZGI0otpw==", + "license": "MIT", + "dependencies": { + "parse-ms": "^4.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/promise": { "version": "7.3.1", "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz", @@ -3803,7 +4015,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", - "dev": true, "dependencies": { "shebang-regex": "^3.0.0" }, @@ -3815,7 +4026,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", - "dev": true, "engines": { "node": ">=8" } @@ -3839,6 +4049,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "license": "ISC", + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -3951,6 +4173,18 @@ "node": ">=0.10.0" } }, + "node_modules/strip-final-newline": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-4.0.0.tgz", + "integrity": "sha512-aulFJcD6YK8V1G7iRB5tigAP4TsHBZZrOV8pjV++zdUwmeV8uzbY7yn6h9MswN62adStNZFuCIx4haBnRuMDaw==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -4218,7 +4452,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dev": true, "dependencies": { "isexe": "^2.0.0" }, @@ -4306,6 +4539,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/yoctocolors": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/yoctocolors/-/yoctocolors-2.1.1.tgz", + "integrity": "sha512-GQHQqAopRhwU8Kt1DDM8NjibDXHC8eoh1erhGAJPEyveY9qqVeXvVikNKrDz69sHowPMorbPUrH/mx8c50eiBQ==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/zod": { "version": "3.23.8", "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", diff --git a/package.json b/package.json index df4aa44d..e247bdd3 100644 --- a/package.json +++ b/package.json @@ -31,13 +31,18 @@ "dependencies": { "@metalsmith/layouts": "^2.7.0", "@metalsmith/metadata": "^0.3.0", - "@seamapi/blueprint": "^0.14.2", + "@prettier/plugin-php": "^0.22.2", + "@seamapi/blueprint": "^0.16.0", "change-case": "^5.4.4", + "command-exists": "^1.2.9", + "execa": "^9.3.1", "jstransformer-handlebars": "^1.2.0", - "metalsmith": "^2.6.3" + "metalsmith": "^2.6.3", + "prettier": "^3.0.0" }, "devDependencies": { "@seamapi/types": "^1.229.1", + "@types/command-exists": "^1.2.3", "@types/debug": "^4.1.12", "@types/micromatch": "^4.0.9", "@types/node": "^20.8.10", @@ -47,7 +52,6 @@ "eslint-config-standard-with-typescript": "^43.0.0", "eslint-plugin-simple-import-sort": "^12.0.0", "eslint-plugin-unused-imports": "^3.0.0", - "prettier": "^3.0.0", "tsx": "^4.6.2", "typescript": "~5.3.3" } diff --git a/src/lib.d.ts b/src/lib.d.ts new file mode 100644 index 00000000..4751c32d --- /dev/null +++ b/src/lib.d.ts @@ -0,0 +1 @@ +declare module '@prettier/plugin-php/standalone' diff --git a/src/lib/blueprint.ts b/src/lib/blueprint.ts index c252e5d0..ea63b300 100644 --- a/src/lib/blueprint.ts +++ b/src/lib/blueprint.ts @@ -2,18 +2,22 @@ import { createBlueprint, TypesModuleSchema } from '@seamapi/blueprint' import * as types from '@seamapi/types/connect' import type Metalsmith from 'metalsmith' -export const blueprint = ( +import { formatCode } from './format-code.js' + +export const blueprint = async ( _files: Metalsmith.Files, metalsmith: Metalsmith, -): void => { +): Promise => { const metadata = metalsmith.metadata() - if ('codeSampleDefinitions' in metadata) { - const typesModule = TypesModuleSchema.parse({ - ...types, - codeSampleDefinitions: metadata.codeSampleDefinitions, - }) + const codeSampleDefinitions = + 'codeSampleDefinitions' in metadata ? metadata.codeSampleDefinitions : [] + + const typesModule = TypesModuleSchema.parse({ + ...types, + codeSampleDefinitions, + }) - Object.assign(metadata, createBlueprint(typesModule)) - } + const blueprint = await createBlueprint(typesModule, { formatCode }) + Object.assign(metadata, blueprint) } diff --git a/src/lib/format-code.ts b/src/lib/format-code.ts new file mode 100644 index 00000000..65e66cc1 --- /dev/null +++ b/src/lib/format-code.ts @@ -0,0 +1,86 @@ +import * as prettierPluginPhp from '@prettier/plugin-php/standalone' +import type { CodeSampleSyntax } from '@seamapi/blueprint' +import commandExists from 'command-exists' +import { execa } from 'execa' +import { format as prettier } from 'prettier' + +export const formatCode = async ( + content: string, + syntax: CodeSampleSyntax, +): Promise => { + const output = await formatCodeForSyntax(content, syntax) + return output.trim() +} + +export const formatCodeForSyntax = async ( + content: string, + syntax: CodeSampleSyntax, +): Promise => { + switch (syntax) { + case 'javascript': + return await formatJavascript(content) + case 'python': + return await formatPython(content) + case 'ruby': + return await formatRuby(content) + case 'php': + return await formatPhp(content) + case 'bash': + return await formatBash(content) + case 'json': + return await formatJson(content) + default: + return content + } +} + +const formatJavascript = async (content: string): Promise => { + return await prettier(content, { parser: 'typescript' }) +} + +const formatPython = async (content: string): Promise => { + try { + await commandExists('ruff') + } catch (err) { + // eslint-disable-next-line no-console + console.warn('Skipping python formatting: ruff is not installed') + return content + } + const result = await execa({ input: content })`ruff format -` + return result.stdout +} + +const formatRuby = async (content: string): Promise => { + try { + await commandExists('ruff') + } catch { + // eslint-disable-next-line no-console + console.warn('Skipping ruby formatting: standardrb is not installed') + return content + } + const result = await execa({ input: content })`standardrb --stdin --fix -` + return result.stdout.split('\n').slice(1).join('\n') +} + +const formatBash = async (content: string): Promise => { + try { + await commandExists('shfmt') + } catch { + // eslint-disable-next-line no-console + console.warn('Skipping bash formatting: shfmt is not installed') + return content + } + const result = await execa({ input: content })`shfmt -` + return result.stdout +} + +const formatPhp = async (content: string): Promise => { + return await prettier(content, { + parser: 'php', + plugins: [prettierPluginPhp.default], + }) +} + +const formatJson = async (content: string): Promise => { + return await prettier(content, { parser: 'json' }) +}