Skip to content

Commit

Permalink
Merge "Upload API doc model to S3 postpublish"
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 8d5b1ce68e068cdf47f9fddc1731b9ee269c650e
  • Loading branch information
jaslong authored and Copybara committed Nov 10, 2023
1 parent 897c4c0 commit 2195c5b
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 3 deletions.
10 changes: 9 additions & 1 deletion build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ async function buildBundle({
* this script multiple times for multiple entry points, which would result in
* duplicative `tsc` runs.
*/
function extractApi({ name, dtsRollupPath }) {
function extractApi({ name, dtsRollupPath, docModelPath }) {
// Excluding non-index entry points for now since we can't handle multiple entry points.
// TODO: https://linear.app/plasmic/issue/PLA-10114
const docModelEnabled = name === "index";

const extractorConfig = ExtractorConfig.prepare({
configObject: {
apiReport: {
Expand All @@ -224,6 +228,10 @@ function extractApi({ name, dtsRollupPath }) {
compiler: {
tsconfigFilePath: path.resolve("./tsconfig.json"),
},
docModel: {
enabled: docModelEnabled,
apiJsonFilePath: path.resolve(`./api/temp/${name}.api.json`),
},
dtsRollup: {
enabled: true,
untrimmedFilePath: path.resolve(dtsRollupPath),
Expand Down
1 change: 1 addition & 0 deletions packages/auth-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"test": "yarn --cwd=../.. test --passWithNoTests",
"lint": "eslint",
"prepublishOnly": "npm run build",
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
"size": "size-limit",
"analyze": "size-limit --why"
},
Expand Down
1 change: 1 addition & 0 deletions packages/auth-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"test": "yarn --cwd=../.. test",
"lint": "eslint",
"prepublishOnly": "npm run build",
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
"size": "size-limit",
"analyze": "size-limit --why"
},
Expand Down
1 change: 1 addition & 0 deletions packages/data-sources-context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"test": "yarn --cwd=../.. test --passWithNoTests",
"lint": "eslint",
"prepublishOnly": "npm run build",
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
"size": "size-limit",
"analyze": "size-limit --why"
},
Expand Down
1 change: 1 addition & 0 deletions packages/data-sources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"test": "yarn --cwd=../.. test --passWithNoTests",
"lint": "eslint",
"prepublishOnly": "npm run build",
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
"size": "size-limit",
"analyze": "size-limit --why"
},
Expand Down
1 change: 1 addition & 0 deletions packages/loader-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"test": "yarn --cwd=../.. test",
"lint": "eslint",
"prepublishOnly": "npm run build",
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
"size": "size-limit",
"analyze": "size-limit --why"
},
Expand Down
1 change: 1 addition & 0 deletions packages/loader-edge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"coverage": "yarn --cwd=../.. test --coverage --passWithNoTests",
"lint": "eslint",
"prepublishOnly": "npm run build",
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
"size": "size-limit",
"analyze": "size-limit --why"
},
Expand Down
1 change: 1 addition & 0 deletions packages/loader-fetcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"test": "yarn --cwd=../.. test",
"lint": "eslint",
"prepublishOnly": "npm run build",
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
"size": "size-limit",
"analyze": "size-limit --why"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/loader-gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"build:gatsby-node": "node ../../build.mjs src/gatsby-node.ts --no-esm",
"build:gatsby-ssr": "node ../../build.mjs src/gatsby-ssr.ts --no-esm",
"yalcp": "yalc publish --push",
"prepublishOnly": "npm run build"
"prepublishOnly": "npm run build",
"postpublish": "bash ../../scripts/publish-api-doc-model.sh"
},
"keywords": [
"gatsby",
Expand Down
1 change: 1 addition & 0 deletions packages/loader-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"coverage": "yarn test --coverage",
"lint": "eslint",
"prepublishOnly": "npm run build",
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
"size": "size-limit",
"analyze": "size-limit --why"
},
Expand Down
1 change: 1 addition & 0 deletions packages/loader-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"coverage": "yarn --cwd=../.. test --coverage --passWithNoTests",
"lint": "eslint",
"prepublishOnly": "npm run build",
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
"size": "size-limit",
"analyze": "size-limit --why"
},
Expand Down
1 change: 1 addition & 0 deletions packages/loader-splits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"coverage": "yarn --cwd=../.. test --coverage --passWithNoTests",
"lint": "eslint",
"prepublishOnly": "npm run build",
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
"size": "size-limit",
"analyze": "size-limit --why"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/loader-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"build": "yarn build:types && yarn build:index",
"build:types": "yarn tsc",
"build:index": "node ../../build.mjs src/index.ts",
"prepublishOnly": "npm run build"
"prepublishOnly": "npm run build",
"postpublish": "bash ../../scripts/publish-api-doc-model.sh"
},
"files": [
"dist"
Expand Down
1 change: 1 addition & 0 deletions packages/query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"test": "yarn --cwd=../.. test --passWithNoTests",
"lint": "eslint",
"prepublishOnly": "npm run build",
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
"size": "size-limit",
"analyze": "size-limit --why"
},
Expand Down
1 change: 1 addition & 0 deletions packages/watcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"test": "yarn --cwd=../.. test",
"lint": "eslint",
"prepublishOnly": "npm run build",
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
"size": "size-limit",
"analyze": "size-limit --why"
},
Expand Down
37 changes: 37 additions & 0 deletions scripts/publish-api-doc-model.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

function read_json_object_field() {
file=$1
key=$2

# -m 1 returns only first match
# -o returns only matched text

# first match the sequence "<key>": "<value> (no closing quote)
grep -m 1 -o '"'"$key"'": "[^"]*' $file | \
# then match the last part without quotes
grep -o '[^"]*$'
}

package_name=$(read_json_object_field ./package.json name)
package_version=$(read_json_object_field ./package.json version)

# Check that the cicd.bash wasn't publishing to Verdaccio
# NPM_REGISTRY in the start_verdaccio function
if [ -n "$NPM_REGISTRY" ]; then
echo "We were probably publishing to Verdaccio because the NPM_REGISTRY flag was set to $NPM_REGISTRY. "\
"Not publishing API doc model for $package_name@$package_version."
exit 0
fi;

# Sanity check that the package has already been published to NPM
npm_version=$(npm --no-workspaces view $package_name version | tr -d '\n')
if [ "$npm_version" != "$package_version" ]; then
echo "Current latest version on NPM is $npm_version. "\
"Not publishing API doc model for $package_name@$package_version."
exit 0
fi

s3_dest="s3://api-doc-model/$package_name/$package_version"
aws s3 sync "./api/temp" $s3_dest
echo "Published API doc model for $package_name@$package_version to $s3_dest."

0 comments on commit 2195c5b

Please sign in to comment.