Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use npm root instead of cd'ing into the node_modules directory to run commands #62

Merged
merged 13 commits into from
Dec 16, 2022
Merged
2 changes: 2 additions & 0 deletions addLinks.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

const fs = require('fs');
const readline = require('readline');

Expand Down
2 changes: 2 additions & 0 deletions deleteBaseClasses.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

const fs = require('fs');
const readline = require('readline');

Expand Down
11 changes: 5 additions & 6 deletions generate-devsite-base-classes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@
mkdir -p ./etc


cp node_modules/@google-cloud/cloud-rad/api-extractor.json .
cp "$(npm root)/@google-cloud/cloud-rad/api-extractor.json" .
npx @microsoft/api-extractor run --local
npx @googleapis/api-documenter@^7 yaml --input-folder=temp
echo "node $(npm root)/@googleapis/api-documenter/bin/api-documenter yaml --input-folder=temp"
node "$(npm root)/@googleapis/api-documenter/bin/api-documenter" yaml --input-folder=temp

# replace markdown code examples with html, see b/204924531
dir="$(cd "$(dirname "$0")"; pwd)"
node "$dir/../@google-cloud/cloud-rad/prettyPrint.js"
node "$(npm root)/@google-cloud/cloud-rad/prettyPrint.js"

# remove interfaces from toc
dir="$(cd "$(dirname "$0")"; pwd)"
node "$dir/../@google-cloud/cloud-rad/removeInterface.js"
node "$(npm root)/@google-cloud/cloud-rad/removeInterface.js"

# Clean up TOC
# Delete SharePoint item, see https://github.com/microsoft/rushstack/issues/1229
Expand Down
42 changes: 27 additions & 15 deletions generate-devsite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,39 @@
# When running locally, run `docfx --serve` in ./yaml/ after this script


echo "mkdir -p ./etc"
mkdir -p ./etc


cp node_modules/@google-cloud/cloud-rad/api-extractor.json .
echo "cp $(npm root)/@google-cloud/cloud-rad/api-extractor.json ."
cp "$(npm root)/@google-cloud/cloud-rad/api-extractor.json" .
echo "npx @microsoft/api-extractor run --local"
npx @microsoft/api-extractor run --local

# copy the common.api.json file as it is used as a base class
# If cloud-rad is running for common, the copied file will be overwritten by api-extractor
cp node_modules/@google-cloud/cloud-rad/api-extractor-configs/common.api.json temp
cp node_modules/@google-cloud/cloud-rad/api-extractor-configs/google-auth-library.api.json temp
echo "cp $(npm root)/@google-cloud/cloud-rad/api-extractor-configs/common.api.json temp"
cp "$(npm root)/@google-cloud/cloud-rad/api-extractor-configs/common.api.json" temp
echo "cp $(npm root)/@google-cloud/cloud-rad/api-extractor-configs/google-auth-library.api.json temp"
cp "$(npm root)/@google-cloud/cloud-rad/api-extractor-configs/google-auth-library.api.json" temp

npx @googleapis/api-documenter@^7 yaml --input-folder=temp
echo "node $(npm root)/@googleapis/api-documenter/bin/api-documenter yaml --input-folder=temp"
node "$(npm root)/@googleapis/api-documenter/bin/api-documenter" yaml --input-folder=temp

# replace markdown code examples with html, see b/204924531
dir="$(cd "$(dirname "$0")"; pwd)"
node "$dir/../@google-cloud/cloud-rad/prettyPrint.js"
echo "node $(npm root)/@google-cloud/cloud-rad/prettyPrint.js"
node "$(npm root)/@google-cloud/cloud-rad/prettyPrint.js"

# remove common and auth from toc
dir="$(cd "$(dirname "$0")"; pwd)"
node "$dir/../@google-cloud/cloud-rad/deleteBaseClasses.js"
echo "node $(npm root)/@google-cloud/cloud-rad/deleteBaseClasses.js"
node "$(npm root)/@google-cloud/cloud-rad/deleteBaseClasses.js"

# remove interfaces from toc
dir="$(cd "$(dirname "$0")"; pwd)"
node "$dir/../@google-cloud/cloud-rad/removeInterface.js"
echo "node $(npm root)/@google-cloud/cloud-rad/removeInterface.js"
node "$(npm root)/@google-cloud/cloud-rad/removeInterface.js"

# remove protos from toc
dir="$(cd "$(dirname "$0")"; pwd)"
node "$dir/../@google-cloud/cloud-rad/removeProtos.js"
echo "node $(npm root)/@google-cloud/cloud-rad/removeProtos.js"
node "$(npm root)/@google-cloud/cloud-rad/removeProtos.js"

# Clean up TOC
# Delete SharePoint item, see https://github.com/microsoft/rushstack/issues/1229
Expand Down Expand Up @@ -83,24 +88,31 @@ sed -i -e '7a\
# be two files in temp. Otherwise, delete common.api.json and auth.
numberOfFiles=$(ls temp | wc -l)
if [[ $numberOfFiles -ge 3 ]]; then
echo "rm temp/common.api.json"
rm temp/common.api.json
rm temp/google-auth-library.api.json
fi

# add href for external classes, see b/195674809
dir="$(cd "$(dirname "$0")"; pwd)"
node "$dir/../@google-cloud/cloud-rad/addLinks.js"
echo "node $(npm root)/@google-cloud/cloud-rad/removeProtos.js"
node "$(npm root)/@google-cloud/cloud-rad/addLinks.js"

NAME=$(ls temp | sed s/.api.json*//)
## Copy everything to devsite
echo "mkdir -p ./_devsite"
mkdir -p ./_devsite
echo "mkdir -p ./_devsite/$NAME"
mkdir -p ./_devsite/$NAME

echo "cp ./yaml/$NAME/* ./_devsite/$NAME || :"
cp ./yaml/$NAME/* ./_devsite/$NAME || :
echo "cp ./yaml/toc.yml ./_devsite/toc.yml"
cp ./yaml/toc.yml ./_devsite/toc.yml

## Rename the default overview page,
echo "mv ./yaml/$NAME.yml ./_devsite/overview.yml"
mv ./yaml/$NAME.yml ./_devsite/overview.yml

## readme is not allowed as filename
echo "cp ./README.md ./_devsite/index.md"
cp ./README.md ./_devsite/index.md
15 changes: 6 additions & 9 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ if [[ -z "$CREDENTIALS" ]]; then
# and don't set NPM_CONFIG_PREFIX.
export NPM_CONFIG_PREFIX=${HOME}/.npm-global
export PATH="$PATH:${NPM_CONFIG_PREFIX}/bin"
cd $(dirname $0)/../..
fi

if [[ -n "$MONO_REPO_CWD" ]]; then
cd $MONO_REPO_CWD
fi

if [[ -n "$VERSION" ]]; then
Expand All @@ -40,13 +35,15 @@ npm i [email protected] -g
name=$(cat package.json | json name | sed 's/^.*\///')

# Generate the data for the devsite tarball
dir="$(cd "$(dirname "$0")"; pwd)"
if [ "$name" == "common" ]; then
. "$dir/../@google-cloud/cloud-rad/generate-devsite-base-classes.sh"
echo ". $(npm root)/@google-cloud/cloud-rad/generate-devsite-base-classes.sh"
. "$(npm root)/@google-cloud/cloud-rad/generate-devsite-base-classes.sh"
elif [ "$name" == "google-auth-library" ]; then
. "$dir/../@google-cloud/cloud-rad/generate-devsite-base-classes.sh"
echo ". $(npm root)/@google-cloud/cloud-rad/generate-devsite-base-classes.sh"
. "$(npm root)/@google-cloud/cloud-rad/generate-devsite-base-classes.sh"
else
. "$dir/../@google-cloud/cloud-rad/generate-devsite.sh"
echo ". generate-devsite"
. "$(npm root)/@google-cloud/cloud-rad/generate-devsite.sh"
fi

if [[ -n "$NO_UPLOAD" ]]; then
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{
"name": "@google-cloud/cloud-rad",
"version": "0.2.19",
"version": "0.3.1",
"description": "",
"main": "index.js",
"repository": "googleapis/cloud-rad",
"bin": {
"cloud-rad": "./main.sh"
},
"scripts": {
"test": "env NO_UPLOAD=1 mocha"
"test": "env NO_UPLOAD=1 mocha --timeout=5000"
},
"author": "Google Inc",
"license": "Apache-2.0",
"dependencies": {
"@googleapis/api-documenter": "~7.13.0",
"@microsoft/api-extractor": "~7.19.0"
"@microsoft/api-extractor": "~7.19.0",
"glob": "^8.0.3"
},
"engines": {
"node": ">=12.0.0"
Expand Down
2 changes: 2 additions & 0 deletions prettyPrint.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

const fs = require('fs');
const readline = require('readline');

Expand Down
2 changes: 2 additions & 0 deletions removeInterface.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

const fs = require('fs');
const readline = require('readline');

Expand Down
2 changes: 2 additions & 0 deletions removeProtos.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

const fs = require('fs');
const readline = require('readline');

Expand Down
6 changes: 5 additions & 1 deletion test/generateYamlTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ before(function () {
// Copy over nodejs-deploy library from Github
executeCmd("git clone --branch release-v1.0.0 https://github.com/googleapis/nodejs-deploy.git " + nodejsDeployDir)
// Install local version of cloud-rad command and generate yaml.
executeCmd("cd " + nodejsDeployDir + "; npm i; npm i ../..; npx @google-cloud/cloud-rad")
executeCmd("cd " + nodejsDeployDir + "; npm i; npm run compile; npm install --no-save @google-cloud/cloud-rad;npx @google-cloud/cloud-rad . cloud-rad")
})

after(function () {
executeCmd(`rm -rf ${nodejsDeployDir}`);
})

describe('cloud-rad docfx generator', () => {
Expand Down