Skip to content

Commit 2195c5b

Browse files
jaslongCopybara
authored and
Copybara
committed
Merge "Upload API doc model to S3 postpublish"
GitOrigin-RevId: 8d5b1ce68e068cdf47f9fddc1731b9ee269c650e
1 parent 897c4c0 commit 2195c5b

File tree

16 files changed

+62
-3
lines changed

16 files changed

+62
-3
lines changed

build.mjs

+9-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ async function buildBundle({
212212
* this script multiple times for multiple entry points, which would result in
213213
* duplicative `tsc` runs.
214214
*/
215-
function extractApi({ name, dtsRollupPath }) {
215+
function extractApi({ name, dtsRollupPath, docModelPath }) {
216+
// Excluding non-index entry points for now since we can't handle multiple entry points.
217+
// TODO: https://linear.app/plasmic/issue/PLA-10114
218+
const docModelEnabled = name === "index";
219+
216220
const extractorConfig = ExtractorConfig.prepare({
217221
configObject: {
218222
apiReport: {
@@ -224,6 +228,10 @@ function extractApi({ name, dtsRollupPath }) {
224228
compiler: {
225229
tsconfigFilePath: path.resolve("./tsconfig.json"),
226230
},
231+
docModel: {
232+
enabled: docModelEnabled,
233+
apiJsonFilePath: path.resolve(`./api/temp/${name}.api.json`),
234+
},
227235
dtsRollup: {
228236
enabled: true,
229237
untrimmedFilePath: path.resolve(dtsRollupPath),

packages/auth-api/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"test": "yarn --cwd=../.. test --passWithNoTests",
2525
"lint": "eslint",
2626
"prepublishOnly": "npm run build",
27+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
2728
"size": "size-limit",
2829
"analyze": "size-limit --why"
2930
},

packages/auth-react/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"test": "yarn --cwd=../.. test",
2525
"lint": "eslint",
2626
"prepublishOnly": "npm run build",
27+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
2728
"size": "size-limit",
2829
"analyze": "size-limit --why"
2930
},

packages/data-sources-context/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"test": "yarn --cwd=../.. test --passWithNoTests",
2525
"lint": "eslint",
2626
"prepublishOnly": "npm run build",
27+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
2728
"size": "size-limit",
2829
"analyze": "size-limit --why"
2930
},

packages/data-sources/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"test": "yarn --cwd=../.. test --passWithNoTests",
2525
"lint": "eslint",
2626
"prepublishOnly": "npm run build",
27+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
2728
"size": "size-limit",
2829
"analyze": "size-limit --why"
2930
},

packages/loader-core/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"test": "yarn --cwd=../.. test",
2626
"lint": "eslint",
2727
"prepublishOnly": "npm run build",
28+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
2829
"size": "size-limit",
2930
"analyze": "size-limit --why"
3031
},

packages/loader-edge/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"coverage": "yarn --cwd=../.. test --coverage --passWithNoTests",
2727
"lint": "eslint",
2828
"prepublishOnly": "npm run build",
29+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
2930
"size": "size-limit",
3031
"analyze": "size-limit --why"
3132
},

packages/loader-fetcher/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"test": "yarn --cwd=../.. test",
2626
"lint": "eslint",
2727
"prepublishOnly": "npm run build",
28+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
2829
"size": "size-limit",
2930
"analyze": "size-limit --why"
3031
},

packages/loader-gatsby/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"build:gatsby-node": "node ../../build.mjs src/gatsby-node.ts --no-esm",
3232
"build:gatsby-ssr": "node ../../build.mjs src/gatsby-ssr.ts --no-esm",
3333
"yalcp": "yalc publish --push",
34-
"prepublishOnly": "npm run build"
34+
"prepublishOnly": "npm run build",
35+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh"
3536
},
3637
"keywords": [
3738
"gatsby",

packages/loader-nextjs/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"coverage": "yarn test --coverage",
5454
"lint": "eslint",
5555
"prepublishOnly": "npm run build",
56+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
5657
"size": "size-limit",
5758
"analyze": "size-limit --why"
5859
},

packages/loader-react/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"coverage": "yarn --cwd=../.. test --coverage --passWithNoTests",
4848
"lint": "eslint",
4949
"prepublishOnly": "npm run build",
50+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
5051
"size": "size-limit",
5152
"analyze": "size-limit --why"
5253
},

packages/loader-splits/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"coverage": "yarn --cwd=../.. test --coverage --passWithNoTests",
2727
"lint": "eslint",
2828
"prepublishOnly": "npm run build",
29+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
2930
"size": "size-limit",
3031
"analyze": "size-limit --why"
3132
},

packages/loader-vue/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"build": "yarn build:types && yarn build:index",
1616
"build:types": "yarn tsc",
1717
"build:index": "node ../../build.mjs src/index.ts",
18-
"prepublishOnly": "npm run build"
18+
"prepublishOnly": "npm run build",
19+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh"
1920
},
2021
"files": [
2122
"dist"

packages/query/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"test": "yarn --cwd=../.. test --passWithNoTests",
2525
"lint": "eslint",
2626
"prepublishOnly": "npm run build",
27+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
2728
"size": "size-limit",
2829
"analyze": "size-limit --why"
2930
},

packages/watcher/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"test": "yarn --cwd=../.. test",
2626
"lint": "eslint",
2727
"prepublishOnly": "npm run build",
28+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh",
2829
"size": "size-limit",
2930
"analyze": "size-limit --why"
3031
},

scripts/publish-api-doc-model.sh

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
function read_json_object_field() {
4+
file=$1
5+
key=$2
6+
7+
# -m 1 returns only first match
8+
# -o returns only matched text
9+
10+
# first match the sequence "<key>": "<value> (no closing quote)
11+
grep -m 1 -o '"'"$key"'": "[^"]*' $file | \
12+
# then match the last part without quotes
13+
grep -o '[^"]*$'
14+
}
15+
16+
package_name=$(read_json_object_field ./package.json name)
17+
package_version=$(read_json_object_field ./package.json version)
18+
19+
# Check that the cicd.bash wasn't publishing to Verdaccio
20+
# NPM_REGISTRY in the start_verdaccio function
21+
if [ -n "$NPM_REGISTRY" ]; then
22+
echo "We were probably publishing to Verdaccio because the NPM_REGISTRY flag was set to $NPM_REGISTRY. "\
23+
"Not publishing API doc model for $package_name@$package_version."
24+
exit 0
25+
fi;
26+
27+
# Sanity check that the package has already been published to NPM
28+
npm_version=$(npm --no-workspaces view $package_name version | tr -d '\n')
29+
if [ "$npm_version" != "$package_version" ]; then
30+
echo "Current latest version on NPM is $npm_version. "\
31+
"Not publishing API doc model for $package_name@$package_version."
32+
exit 0
33+
fi
34+
35+
s3_dest="s3://api-doc-model/$package_name/$package_version"
36+
aws s3 sync "./api/temp" $s3_dest
37+
echo "Published API doc model for $package_name@$package_version to $s3_dest."

0 commit comments

Comments
 (0)