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

feat: load components pages to build the doc #62

Merged
merged 15 commits into from
Oct 25, 2022
Merged
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
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