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

feat: add Connector docs to LB4 docs #863

Merged
merged 1 commit into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ node_modules
.jekyll-metadata
vendor
.bundle
package-lock.json
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@
},
"license": "MIT",
"author": "IBM Corp.",
"dependencies": {}
"dependencies": {
"js-yaml": "^3.13.1"
}
}
32 changes: 32 additions & 0 deletions update-lb4-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@

const fs = require('fs-extra');
const path = require('path');
const yaml = require('js-yaml');

const srcDocs = path.resolve(__dirname,'node_modules/@loopback/docs/site');
const destDocs = path.resolve(__dirname, 'pages/en/lb4');
const srcSidebars = path.resolve(srcDocs, 'sidebars');
const destSidebars= path.resolve(__dirname, '_data/sidebars');
const lb4Sidebar = yaml.safeLoad(fs.readFileSync(__dirname + '/_data/sidebars/lb4_sidebar.yml', 'utf8'));
let connectorsReference;
for (let i = 0; i < lb4Sidebar.children.length; i++) {
const child = lb4Sidebar.children[i];
if (child.title === 'Connectors reference') {
connectorsReference = child;
break;
}
}

/**
* Utility function to remove a directory.
Expand Down Expand Up @@ -49,6 +59,28 @@ copyDocs(srcDocs, destDocs);
//copy over sidebar for LoopBack 4
copyDocs(srcSidebars, destSidebars);

function copyFile(input) {
if (input) {
const lb3Path = __dirname + '/pages/en/lb3/' + input.url.replace(/\.html$/, '.md');
const lb4Path = __dirname + '/pages/en/lb4/' + input.url.replace(/\.html$/, '.md');
// Copy only if the file does not exist in the lb4 dir
if (!fs.existsSync(lb4Path)) {
let fc = fs.readFileSync(lb3Path, 'utf8');
fc = fc.replace('/lb3/', '/lb4/').replace('lb3_sidebar', 'lb4_sidebar');
fs.writeFileSync(lb4Path, fc);
}

if (input.children) {
input.children.forEach(function(child) {
copyFile(child);
});
}
}
}

// Most of the connector doc files are in the lb3 dir, copy them for lb4
copyFile(connectorsReference);

const fileToUpdate = path.resolve(destDocs, 'Testing-the-API.md');

// bug in `jekyll-relative-links` plugin; probably safe to remove when
Expand Down
7 changes: 7 additions & 0 deletions update-readmes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# from the given github repo. If that branch is NOT master, then the
# branch name will be appended to the local readme file name.
(cat <<LIST_END
strongloop loopback-connector-mysql master
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: strongloop loopback-connector-couchdb2 master is also supported

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add it after this one lands.

strongloop loopback-connector-cassandra master
strongloop loopback-connector-cloudant master
strongloop loopback-connector-dashdb master
Expand Down Expand Up @@ -82,6 +83,9 @@ LIST_END
# No branch means latest release, so fetch from npmjs.org
echo "fetching $org/$repo from latest npmjs.org release..."
curl -s $NPMURL | jq -r '.readme|rtrimstr("\n")' > $DEST
LB4DEST=${DEST/\/lb3\//\/lb4\/}
echo "copying $DEST to $LB4DEST"
cp $DEST $LB4DEST
else
# The loopback-example-database repo contains a separate branch for each
# actual example project, so we need to add the branch name to the readme
Expand All @@ -91,5 +95,8 @@ LIST_END
fi
echo "fetching $org/$repo/$branch from GitHub's raw content domain..."
curl -s $GHURL > $DEST
LB4DEST=${DEST/\/lb3\//\/lb4\/}
echo "copying $DEST to $LB4DEST"
cp $DEST $LB4DEST
fi
done