Skip to content

Commit

Permalink
Merge pull request #3104 from balena-io/vipulgupta2048/version
Browse files Browse the repository at this point in the history
Add versioning to CLI docs
  • Loading branch information
flowzone-app[bot] authored Nov 20, 2024
2 parents f7f5c19 + a7823e3 commit 9bb3aff
Show file tree
Hide file tree
Showing 12 changed files with 513 additions and 13 deletions.
1 change: 1 addition & 0 deletions .cspell/balena-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ balena-api
balena-base-ui
balena-build
balena-builder
balenacli
balenahup
balenalib
balenista
Expand Down
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ tmp
.lycheecache

# Ignore external docs that are pulled via tools/fetch-external.sh
pages/reference/cli.md
pages/reference/balena-cli.md

pages/reference/sdk/node-sdk.md
pages/reference/sdk/python-sdk.md

Expand Down Expand Up @@ -45,6 +42,10 @@ pages/reference/base-images/base-images-ref.md
# Ignore dynamic docs created for masterclasses
shared/masterclass

# Ignore dynamic balenaCLI version docs
config/dictionaries/balenacli.json
shared/balena-cli-versions/

# Ignore dynamic assets generated for Getting Started
static/img/device/**
config/dictionaries/device.json
Expand Down
2 changes: 1 addition & 1 deletion config/navigation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Reference
[/reference/api/overview]
Resources[/reference/api/resources/$resource]

CLI[/reference/balena-cli]
CLI[/reference/balena-cli/$balenacli]
SDKs
Node.js SDK[/reference/sdk/node-sdk]
Python SDK[/reference/sdk/python-sdk]
Expand Down
16 changes: 10 additions & 6 deletions config/redirects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@
/deployment/wifi /reference/OS/network/2.x/
/runtime/terminal/ /learn/manage/ssh-access/
/runtime/terminal /learn/manage/ssh-access/
/using/cli/ /reference/balena-cli/
/using/cli /reference/balena-cli/
/using/cli/ /reference/balena-cli/latest/
/using/cli /reference/balena-cli/latest/
/learn/deploy/release-strategy/update-locking/API/ /reference/supervisor/supervisor-api/
/learn/deploy/release-strategy/update-locking/API /reference/supervisor/supervisor-api/
/reference/cli/ /reference/balena-cli/
/reference/cli /reference/balena-cli/
/reference/cli/ /reference/balena-cli/latest/
/reference/cli /reference/balena-cli/latest/
/docs/learn/deploy/release-strategy/update-locking/API/ /reference/supervisor/supervisor-api/
/docs/learn/deploy/release-strategy/update-locking/API /reference/supervisor/supervisor-api/
/learn/more/masterclass/ /learn/more/masterclasses/overview/
Expand Down Expand Up @@ -192,8 +192,8 @@
/runtime/supervisor-api /reference/supervisor/supervisor-api/
/runtime/data-api/ /reference/api/overview/
/runtime/data-api /reference/api/overview/
/tools/cli/ /reference/balena-cli/
/tools/cli /reference/balena-cli/
/tools/cli/ /reference/balena-cli/latest/
/tools/cli /reference/balena-cli/latest/
/tools/sdk/ /reference/sdk/node-sdk/
/tools/sdk /reference/sdk/node-sdk/
/tools/python-sdk/ /reference/sdk/python-sdk/
Expand Down Expand Up @@ -266,6 +266,10 @@
/reference/base-images/base-images/ /reference/base-images/balena-base-images/
/reference/base-images/base-images /reference/base-images/balena-base-images/

# Versioned CLI docs
/reference/balena-cli/ /reference/balena-cli/latest/
/reference/balena-cli /reference/balena-cli/latest/

# Important: keep dynamic redirect below the static redirects
# https://developers.cloudflare.com/pages/platform/redirects/

Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"cspell": "^8.9.1",
"css-loader": "5.2.7",
"file-loader": "6.2.0",
"line-by-line": "^0.1.6",
"mini-css-extract-plugin": "^1.6.2",
"node-html-markdown": "^1.3.0",
"node-jq": "^4.4.0",
Expand Down
14 changes: 14 additions & 0 deletions pages/reference/balena-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: balena CLI Documentation

layout: balena-cli.html

dynamic:
variables: [ $balenacli ]
ref: $original_ref/$balenacli
$switch_text: balena CLI version $balenacli
---

# balena CLI {{ $balenacli.version }} Documentation

{{import "balena-cli-versions"}}
8 changes: 8 additions & 0 deletions templates/balena-cli.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "default.html" %}

{% block dynamicSwitchCustom %}
<p class="dynamic-switch__append">
</p>
{% endblock %}

<div id="output"></div>
3 changes: 3 additions & 0 deletions tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ cd "$SCRIPT_DIR/.."
# Generate Getting Started assets
node ./tools/generate-docs-contracts.js

# Generate versioned balena-cli docs
node ./tools/versioning.js https://github.com/balena-io/balena-cli/blob/master/docs/balena-cli.md

# Generate Masterclasses Dynamically
./tools/build-masterclass.sh

Expand Down
3 changes: 0 additions & 3 deletions tools/fetch-external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ mkdir -p shared/masterclass/debugging/
# Use node-jq if jq is not pre-installed in the environment nor set in path
which jq && JQ="$(which jq)" || JQ="../../node_modules/node-jq/bin/jq"

# get latest CLI docs
curl --fail --show-error -o pages/reference/balena-cli.md -L https://github.com/balena-io/balena-cli/raw/master/docs/balena-cli.md &

# Engine
# get latest balena-engine debugging docs
curl --fail --show-error -o shared/masterclass/debugging/engine.md -L https://github.com/balena-os/balena-engine/raw/master/balena-docs/engine-debugging.md &
Expand Down
173 changes: 173 additions & 0 deletions tools/github-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*!
* parse-github-url <https://github.com/jonschlinkert/parse-github-url>
*
* Copyright (c) 2015-2017, Jon Schlinkert.
* Released under the MIT License.
*/

// GitHub repository URL parser - example
// > ghParser('https://github.com/balena-io/balena-cli/blob/master/docs/balena-cli.md')
// Url {
// protocol: 'https:',
// slashes: true,
// auth: null,
// host: 'github.com',
// port: null,
// hostname: 'github.com',
// hash: null,
// search: null,
// query: null,
// pathname: 'balena-io/balena-cli/blob/master/docs/balena-cli.md',
// path: 'balena-io/balena-cli/blob/master/docs/balena-cli.md',
// href: 'https://github.com/balena-io/balena-cli/blob/master/docs/balena-cli.md',
// filepath: 'docs/balena-cli.md',
// branch: 'master',
// blob: 'master/docs/balena-cli.md',
// owner: 'balena-io',
// name: 'balena-cli',
// repo: 'balena-io/balena-cli',
// repository: 'balena-io/balena-cli'
// }

'use strict';

var url = require('url');
var cache = { __proto__: null };

function isChecksum(str) {
return (/^[a-f0-9]{40}$/i).test(str);
}

function getBranch(str, obj) {
var segs = str.split('#');
var branch;
if (segs.length > 1) {
branch = segs[segs.length - 1];
}
if (!branch && obj.hash && obj.hash.charAt(0) === '#') {
branch = obj.hash.slice(1);
}
return branch || 'master';
}

function trimSlash(path) {
return path.charAt(0) === '/' ? path.slice(1) : path;
}

function name(str) {
return str ? str.replace(/\.git$/, '') : null;
}

function owner(str) {
if (!str) {
return null;
}
var idx = str.indexOf(':');
if (idx > -1) {
return str.slice(idx + 1);
}
return str;
}

function parse(str) {
if (typeof str !== 'string' || !str.length) {
return null;
}

if (str.indexOf('git@gist') !== -1 || str.indexOf('//gist') !== -1) {
return null;
}

// parse the URL
var obj = url.parse(str);
if (typeof obj.path !== 'string' || !obj.path.length || typeof obj.pathname !== 'string' || !obj.pathname.length) {
return null;
}

if (!obj.host && (/^git@/).test(str) === true) {
// return the correct host for git@ URLs
obj.host = url.parse('http://' + str.replace(/git@([^:]+):/, '$1/')).host;
}

obj.path = trimSlash(obj.path);
obj.pathname = trimSlash(obj.pathname);
obj.filepath = null;

if (obj.path.indexOf('repos') === 0) {
obj.path = obj.path.slice(6);
}

var seg = obj.path.split('/').filter(Boolean);
var hasBlob = seg[2] === 'blob';
if (hasBlob && !isChecksum(seg[3])) {
obj.branch = seg[3];
if (seg.length > 4) {
obj.filepath = seg.slice(4).join('/');
}
}

var blob = str.indexOf('blob');
if (hasBlob && blob !== -1) {
obj.blob = str.slice(blob + 5);
}

var hasTree = seg[2] === 'tree';
var tree = str.indexOf('tree');
if (hasTree && tree !== -1) {
var idx = tree + 5;
var branch = str.slice(idx);
var slash = branch.indexOf('/');
if (slash !== -1) {
branch = branch.slice(0, slash);
}
obj.branch = branch;
}

obj.owner = owner(seg[0]);
obj.name = name(seg[1]);

if (seg.length > 1 && obj.owner && obj.name) {
obj.repo = obj.owner + '/' + obj.name;
} else {
var href = obj.href.split(':');
if (href.length === 2 && obj.href.indexOf('//') === -1) {
obj.repo = obj.repo || href[href.length - 1];
var repoSegments = obj.repo.split('/');
obj.owner = repoSegments[0];
obj.name = repoSegments[1];

} else {
var match = obj.href.match(/\/([^/]*)$/);
obj.owner = match ? match[1] : null;
obj.repo = null;
}

if (obj.repo && (!obj.owner || !obj.name)) {
var segs = obj.repo.split('/');
if (segs.length === 2) {
obj.owner = segs[0];
obj.name = segs[1];
}
}
}

if (!obj.branch) {
obj.branch = seg[2] || getBranch(obj.path, obj);
if (seg.length > 3) {
obj.filepath = seg.slice(3).join('/');
}
}

obj.host = obj.host || 'github.com';
obj.owner = obj.owner || null;
obj.name = obj.name || null;
obj.repository = obj.repo;
return obj;
}

module.exports = function parseGithubUrl(str) {
if (!cache[str]) {
cache[str] = parse(str);
}
return cache[str];
};
Loading

0 comments on commit 9bb3aff

Please sign in to comment.