forked from Superalgos/Superalgos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Superalgos#4523 from Awhiteweb/feature/exporting-docs
Feature/exporting docs
- Loading branch information
Showing
31 changed files
with
7,550 additions
and
1,704 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
}] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**/*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('/') | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.