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

[WIP]init sks #111

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion cloudtower-api-doc/docs/getting-started/how-to.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 如何阅读 API 参考
title: 如何阅读 CloudTower API 参考
sidebar_position: 13
---

Expand Down
2 changes: 1 addition & 1 deletion cloudtower-api-doc/docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ CloudTower API 可以用于调用 CloudTower 内所管理的各类资源。我

## 更多

我们提供了较多常见且丰富的 SDK 调用示例,您可以到 `案例演示` 该章节下进一步熟悉。同时,具体的 API 接口、字段说明等可以查看 [API 参考](https://code.smartx.com/api/) 页面。
我们提供了较多常见且丰富的 SDK 调用示例,您可以到 `案例演示` 该章节下进一步熟悉。同时,具体的 API 接口、字段说明等可以查看 [CloudTower API 参考](https://code.smartx.com/api/) 页面。

感谢您选择 CloudTower API。如果您有任何疑问或需要帮助,请随时联系我们。
6 changes: 5 additions & 1 deletion cloudtower-api-doc/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ const config = {
},
{
to: "/api",
label: "API 参考",
label: "CloudTower API 参考",
},
{
to: "/sks-api",
label: "SKS API 参考",
},
{
type: "docsVersionDropdown",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"item.label.API 参考": {
"message": "API Reference"
"item.label.CloudTower API 参考": {
"message": "CloudTower API Reference"
},
"item.label.SKS API 参考": {
"message": "SKS API Reference"
},
"item.label.下载": {
"message": "Download"
Expand Down
67 changes: 26 additions & 41 deletions cloudtower-api-doc/scripts/create-new-api-doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
getLocalesFile,
} = require("./describe");

const versions = [
const towerVersions = [
'4.0.0',
'3.4.0',
"3.3.0",
Expand All @@ -29,63 +29,48 @@ const versions = [
'1.8.0'
];

const sksVersions = [
'1.4.0'
]

const versionMap = {
sks: sksVersions,
tower: towerVersions
}
yargsInteractive()
.usage("$0 <command> [args]")
.help("help")
.alias("help", "h")
.interactive({
interactive: { default: true },
product: {
description: "Provide which product you want to create, sks or tower",
type: "input"
},
version: {
description: "Provide swagger json file version",
type: "input",
},
})
.then((result) => {
const { version } = result;
createNewApiLocales(version);
// createNewApiDoc(version);
const { version, product } = result;
createNewApiLocales(version, product);
});


const getPrevVersion = (v) => {
if(versions.indexOf(v) < 0) {
return versions[0]
}
return versions[versions.indexOf(v) + 1];
}
const getSwaggerPath = (v) =>

const getSwaggerPath = (v, prefix) =>
nodePath.resolve(
process.cwd(),
nodePath.join('cloudtower-api-doc', 'static', 'specs', `${v}-swagger.json`)
nodePath.join('cloudtower-api-doc', 'static', `${prefix}specs`, `${v}-swagger.json`)
);

const getVersionedPath =(version, isEn) => {
let versionedPath = nodePath.join('versioned_docs', `version-${version}`);
if(isEn) {
versionedPath = nodePath.join('i18n', 'en', 'docusaurus-plugin-content-docs', `version-${version}`)
}
return nodePath.resolve(process.cwd(), nodePath.join('cloudtower-api-doc', versionedPath))
}

const createNewApiDoc = async (version) => {
const prevVersion = getPrevVersion(version);
const pMap = (await import("p-map")).default;
await pMap(['zh', 'en'], async (lng) => {
const versiondPath = getVersionedPath(version, lng === 'en');
const prevVersionPath = getVersionedPath(prevVersion, lng === 'en');
fsExtra.copySync(prevVersionPath, versiondPath);
fsExtra.readdirSync(versiondPath).forEach(file => {
if(file === 'download.md') {
const completePath = nodePath.join(versiondPath, file);
fsExtra.writeFileSync(completePath, fsExtra.readFileSync(completePath, 'utf-8').replaceAll(prevVersion, version), 'utf-8')
}
})
})
}

const createNewApiLocales = async (version) => {
const createNewApiLocales = async (version, product) => {
const prefix = product === 'tower' ? '' : `${product}-`
const traverPreviousVersion = async (current_version, onGetDiffSpec) => {
let early_break = false;
const versions = versionMap[product];
let versionIndex = versions.findIndex((v) => v === current_version) + 1;
versionIndex = versions.findIndex((v) => v === current_version) + 1;
while (!early_break && versionIndex < versions.length) {
Expand All @@ -95,7 +80,7 @@ const createNewApiLocales = async (version) => {
}
};

const specAbsolutePath = getSwaggerPath(version);
const specAbsolutePath = getSwaggerPath(version, prefix);
const pMap = (await import("p-map")).default;
if (!fsExtra.statSync(specAbsolutePath).isFile()) {
throw new Error(
Expand All @@ -108,7 +93,7 @@ const createNewApiLocales = async (version) => {
const spec = require(specAbsolutePath);
const { paths, components } = spec;
const tags = new Set();
const outputLocalesPath = getLocalesFile(lng, version);
const outputLocalesPath = getLocalesFile(lng, `${prefix}${version}`);
const locales = fsExtra.existsSync(outputLocalesPath) ? require(outputLocalesPath) : {
schemas: {},
tags: [],
Expand All @@ -118,7 +103,7 @@ const createNewApiLocales = async (version) => {
let diffSchema;
let previousVersion;
await traverPreviousVersion(version, async (previous) => {
const previousLocales = require(getLocalesFile(lng, previous));
const previousLocales = require(getLocalesFile(lng, `${prefix}${previous}`));
diffSchema = previousLocales.schemas[schemaName]
if(diffSchema) {
previousVersion = previous;
Expand Down Expand Up @@ -149,7 +134,7 @@ const createNewApiLocales = async (version) => {
}
let diffContent;
await traverPreviousVersion(version, async (previous) => {
const previousLocales = require(getLocalesFile(lng, previous));
const previousLocales = require(getLocalesFile(lng, `${prefix}${previous}`));
diffContent = previousLocales.paths[api];
return diffContent;
});
Expand All @@ -162,7 +147,7 @@ const createNewApiLocales = async (version) => {
};
});
await traverPreviousVersion(version, async (previous) => {
const previousSpec = require(getSwaggerPath(previous));
const previousSpec = require(getSwaggerPath(previous, prefix));
await pMap(Object.keys(previousSpec.paths), async (api) => {
const tagList = _.get(previousSpec, ['paths', api, 'post', 'tags'])
tagList &&
Expand Down
2 changes: 1 addition & 1 deletion cloudtower-api-doc/src/pages/api.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: API 参考
title: CloudTower API 参考
hide_table_of_contents: true
---

Expand Down
8 changes: 8 additions & 0 deletions cloudtower-api-doc/src/pages/sks-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: SKS API 参考
hide_table_of_contents: true
---

import App from '../../swagger/SKS-App';

<App />
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
import clsx from 'clsx';
import i18next from '../../../swagger/i18n';
import { specMap } from '../../../swagger/utils/swagger';
import { specMap, sksSpecMap } from '../../../swagger/utils/swagger';
import styles from './styles.module.scss'
import { useLocation } from '@docusaurus/router';

Expand All @@ -17,20 +17,22 @@ export default function DocsVersionDropdownNavbarItem({
...props
}) {
const versions = Object.keys(specMap);
const sksVersions = Object.keys(sksSpecMap);
const [ active, setActive ] = useState(false)
const { search, pathname, hash } = useLocation();
const searchParams = new URLSearchParams(search);
const currentVersion = searchParams.get('version') || versions[0];
const versionLinks = useMemo(() => {
return versions.map((version) => {
const vs = pathname === '/api' ? versions : sksVersions
return vs.map((version) => {
searchParams.set('version', version);
return {
label: version,
to: `${pathname}?${searchParams.toString()}${hash}`,
isActive: () => version === currentVersion,
};
})
}, [ versions, currentVersion]);
}, [ versions,, sksVersions, currentVersion]);

const items = [
...dropdownItemsBefore,
Expand All @@ -42,8 +44,8 @@ export default function DocsVersionDropdownNavbarItem({
<DefaultNavbarItem
{...props}
mobile={mobile}
label={"dropdown-label"}
to={"xx"}
label={i18next.t('components.version_icu', {version: items[0].label})}
to={items[0].to}
isActive={dropdownActiveClassDisabled ? () => false : undefined}
/>
);
Expand Down
Loading
Loading