Skip to content

Commit

Permalink
Merge pull request Superalgos#4523 from Awhiteweb/feature/exporting-docs
Browse files Browse the repository at this point in the history
Feature/exporting docs
  • Loading branch information
Luis-Fernando-Molina authored Nov 24, 2022
2 parents 4fe4a4e + 4978bf8 commit 91d21c3
Show file tree
Hide file tree
Showing 31 changed files with 7,550 additions and 1,704 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:

jobs:
publish:
if: github.repository == 'superalgos/superalgos'
name: Publish Image
runs-on: ubuntu-latest
steps:
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Publish stand-alone documentation

on:
push:
branches:
- feature/exporting-docs

jobs:
build:
if: github.repository != 'superalgos/superalgos'
name: Build documentation
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v3
- run: rm -f package-lock.json
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- name: Preparation
id: prep
run: node export-docs -l=_site -r=Superalgos
- name: Build artifact
uses: actions/upload-pages-artifact@v1

deploy:
if: github.repository != 'superalgos/superalgos'
name: Deploy documentation
needs: build
runs-on: ubuntu-latest

permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1

1 change: 1 addition & 0 deletions .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:

jobs:
build-release:
if: github.repository == 'superalgos/superalgos'
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release_build_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

jobs:
create-release:
if: github.repository == 'superalgos/superalgos'
runs-on: ubuntu-latest
steps:
- name: Download a file
Expand All @@ -33,6 +34,7 @@ jobs:
keep_tags: false

build-release:
if: github.repository == 'superalgos/superalgos'
runs-on: ${{ matrix.os }}
needs: create-release
strategy:
Expand Down
36 changes: 36 additions & 0 deletions .vscode/Exports.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"folders": [
{
"path": "/home/pi/trading/Superalgos/.github"
},
{
"path": "/home/pi/trading/Superalgos/My-Data-Storage"
},
{
"path": "/home/pi/trading/Superalgos/Exports"
},
{
"path": "/home/pi/trading/Superalgos/Platform"
},
{
"path": "/home/pi/trading/Superalgos/Projects"
}
],
"settings": {},
"launch": {
"version": "0.2.0",
"configurations": [{
"name": "Debug exports",
"cwd": "/home/pi/trading/Superalgos/",
"program": "export-docs.js",
"args": [
"-r=sa-docs"
],
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
}]
}
}
1 change: 1 addition & 0 deletions Exports/Docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.html
87 changes: 87 additions & 0 deletions Exports/Docs/ExportDocumentationApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const {info} = require('./Scripts/Logger').logger
exports.newExportDocumentationApp = function newExportDocumentationApp() {

let thisObject = {
run: run
}

return thisObject

async function run({project, category}) {
info('Project conversion'.padEnd(20) + ' -> ' + project + ' -> ' + category + ' -> START')
return await triggerPageRendering(project, category)
.then((filePaths) => filePaths.length > 0 ? buildIndexPage(filePaths) : 0)

async function triggerPageRendering(project, category) {
info('Page rendering'.padEnd(20) + ' -> preparing')
const exporter = require('./Scripts/DocumentationExporter')
const filePaths = []
const key = ED.schemas.schemaTypes.find( t => t.category == category).key
const schemaKeys = SCHEMAS_BY_PROJECT.get(project).map[key].keys()
for(let type of schemaKeys) {
info('render'.padEnd(20) + ' -> ' + project + ' -> ' + category + ' -> ' + type)
const exportProcess = exporter.documentationExporter()
exportProcess.currentLanguageCode = ED.DEFAULT_LANGUAGE
exportProcess.currentDocumentBeingRendered = {
project,
category,
type
}

info('Initializing'.padEnd(20) + ' -> ' + project + ' -> ' + category + ' -> ' + type)
exportProcess.initialize()

info('Rendering'.padEnd(20) + ' -> ' + project + ' -> ' + category + ' -> ' + type)
await exportProcess.render().then(() => {
info('Writing'.padEnd(20) + ' -> ' + project + ' -> ' + category + ' -> ' + type)
filePaths.push(exportProcess.write())

info('Finalizing'.padEnd(20) + ' -> ' + project + ' -> ' + category + ' -> ' + type)
exportProcess.finalize()
})
}
return filePaths
}

// TODO: remove section in favour of rendering from json file
/**
* @param {string} filePaths
* @return {number}
*/
function buildIndexPage(filePaths) {
const files = filePaths.map(path => {
const splittedPath = path.split('/')
const name = splittedPath.pop()
return {
path,
name
}
})
let html = '<div>'
for(let i = 0; i < files.length; i++) {
html += '<div class="docs-definition-floating-cells"><a href="' + ED.utilities.normaliseInternalLink(trimLocalPath(files[i].path)) + '">' + files[i].name + '</a></div>'
}
html += '</div>'
const firstPath = trimLocalPath(filePaths[0])
const destination = global.env.PATH_TO_PAGES_DIR + '/' + (firstPath.slice(0,firstPath.length-1).join('/')) + '/index.html'
try {
const dom = new SA.nodeModules.jsDom(SA.nodeModules.fs.readFileSync(ED.indexFile))
dom.window.document.getElementById('docs-content-div').innerHTML = html
SA.nodeModules.fs.writeFileSync(destination, dom.serialize())
}
catch(error) {
error(error)
}
return files.length

/**
* removes the local folder directory for correct browser linking
* @param {string} filePath
* @returns {string}
*/
function trimLocalPath(filePath) {
return filePath.indexOf(global.env.PATH_TO_PAGES_DIR) == 0 ? filePath.slice(global.env.PATH_TO_PAGES_DIR.length+1).split('/') : filePath.splice('/')
}
}
}
}
Loading

0 comments on commit 91d21c3

Please sign in to comment.