Skip to content

Commit

Permalink
feat: load components pages to build the doc (#62)
Browse files Browse the repository at this point in the history
* feat: allow to load multiple api from components.yml file

Signed-off-by: shiipou <shiishii@nocturlab.fr>

* fix: separate component name and release file name

Signed-off-by: shiipou <shiishii@nocturlab.fr>

* fix: load pages from html
TODO: I need to find info in the .json for title, etc when it got fixed

Signed-off-by: shiipou <shiishii@nocturlab.fr>

* feat: read .html file to generate the doc instead of component-api json

Signed-off-by: shiipou <shiishii@nocturlab.fr>

* fix: filter dotted files

Signed-off-by: shiipou <shiishii@nocturlab.fr>

* feat: restore markdown file loading

Signed-off-by: shiipou <shiishii@nocturlab.fr>

* better like this

Signed-off-by: shiipou <shiishii@nocturlab.fr>

* feat: add static markdowns load

Signed-off-by: shiipou <shiishii@nocturlab.fr>

* fix: add link in CLI repository

Signed-off-by: shiipou <shiishii@nocturlab.fr>

* fix: add Capitalize to menu items

Signed-off-by: shiipou <shiishii@nocturlab.fr>

* build: rename `doc-deps.yml`

Signed-off-by: shiipou <shiishii@nocturlab.fr>

* Update src/utils/views.js

* build: update components-api version

Signed-off-by: shiipou <shiishii@nocturlab.fr>

* build(deps): update components-api to beta.63

Signed-off-by: shiipou <shiishii@nocturlab.fr>

Signed-off-by: shiipou <shiishii@nocturlab.fr>
Co-authored-by: Jonas Martinez <36544012+jonas-martinez@users.noreply.github.com>
  • Loading branch information
shiipou and jonas-martinez authored Oct 25, 2022
1 parent 8187822 commit 18b66f9
Show file tree
Hide file tree
Showing 39 changed files with 531 additions and 1,573 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/semantic_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ jobs:
run: |
sudo chown $USER:$USER .github/release.sh
sudo chmod +x .github/release.sh
npx -p conventional-changelog-conventionalcommits@4 -p @semantic-release/exec -p @semantic-release/git -p semantic-release@18 semantic-release
npx -p conventional-changelog-conventionalcommits@4 \
-p @semantic-release/exec \
-p @semantic-release/git \
-p semantic-release@18 \
semantic-release
5 changes: 5 additions & 0 deletions .scripts/doc-deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
components:
- name: components-api
url: https://github.com/lenra-io/components-api
version: v1.0.0-beta.63
file: lenra-api-docs-v1.0.0-beta.63.zip
62 changes: 55 additions & 7 deletions .scripts/load-api.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,64 @@
const { exec } = require('child_process');
const Path = require('path');
const fs = require('fs-extra');
const yaml = require('yaml');
const https = require('https'); // or 'http' for http:// URLs
const jszip = require('jszip');
const { default: js } = require('minify/lib/js');

const srcPath = Path.join(__dirname, '..', 'src');
const apiPath = Path.join(srcPath, 'api');

let cloneApi = true;
const components_yaml = yaml.parse(fs.readFileSync(Path.join(__dirname, 'doc-deps.yml')).toString())

if (fs.existsSync(apiPath)) {
exec('git pull', {cwd: apiPath});
}
for (const component of components_yaml.components) {
const component_path = Path.join(apiPath, component.name)
const component_version_file = Path.join(component_path, '.version')

if (!fs.existsSync(component_version_file) || fs.readFileSync(component_version_file).toString() != component.version) {
if(fs.existsSync(component_path))
fs.rmSync(component_path, { recursive: true})

fs.mkdirSync(component_path, { recursive: true })

const file_path = Path.join(component_path, component.file)
const downloaded_stream = fs.createWriteStream(file_path);

const url = `${component.url}/releases/download/${component.version}/${component.file}`
const download_zip = function (response) {
response.pipe(downloaded_stream)

if (cloneApi) {
exec('git clone https://github.com/lenra-io/components-api.git api', {cwd: srcPath});
}
// after download completed close filestream
downloaded_stream.on("finish", async () => {
downloaded_stream.close()

console.log(`Download of ${component.name} (${downloaded_stream.bytesWritten} bytes) Completed`)

console.log(`Unzip ${Path.basename(file_path)} ...`)
const file_content = fs.readFileSync(file_path)
const jszip_instance = new jszip()
const result = await jszip_instance.loadAsync(file_content)
for(key of Object.keys(result.files)) {
const item = result.files[key];
if (item.dir) {
fs.mkdirSync(Path.join(component_path, item.name))
} else {
fs.writeFileSync(Path.join(component_path, item.name), Buffer.from(await item.async('arrayBuffer')))
}
}
fs.rmSync(file_path)
fs.writeFileSync(component_version_file, component.version)
})
}
https.get(url, (response) => {
console.log(`Downloading ${url} ...`)

if (response.statusCode == 200) {
download_zip(response)
} else if (response.statusCode == 302) {
console.log(`Redirecting to ${response.headers.location}`)
https.get(response.headers.location, download_zip)
}
})
}
}
Loading

0 comments on commit 18b66f9

Please sign in to comment.