Skip to content

Commit

Permalink
Documentation is now in Github first
Browse files Browse the repository at this point in the history
  • Loading branch information
Plopix committed Jan 7, 2023
1 parent e5090d9 commit b845548
Show file tree
Hide file tree
Showing 15 changed files with 2,950 additions and 1,385 deletions.
35 changes: 33 additions & 2 deletions .github/workflows/main-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
needs: [lint]
strategy:
matrix:
node: [14, 16, 18]
node: [16, 18]
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
needs: [lint]
strategy:
matrix:
node: [14, 16, 18]
node: [16, 18]
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
Expand Down Expand Up @@ -87,3 +87,34 @@ jobs:
echo ::endgroup::
fi
done
sync:
name: 🍿 Sync Doc to Crystallize
if: github.event_name == 'push' && github.ref_name == 'main'
runs-on: ubuntu-latest
needs: [lint, test, builds]
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.10.0

- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 16

- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: 📥 Download deps
run: yarn install && yarn build

- name: 🚀 Sync it!
env:
MARKDOWN_TO_CRYSTALLIZE_SHARED_KEY: ${{ secrets.MARKDOWN_TO_CRYSTALLIZE_SHARED_KEY }}
run: |
for COMPONENT in `ls components`; do
if [ -d "components/${COMPONENT}" ]; then
echo ::group::..:: ${COMPONENT} ::..
node apps/doc2crystallize/build/index.js components/${COMPONENT}/README.md
echo ::endgroup::
fi
done
2 changes: 2 additions & 0 deletions apps/doc2crystallize/build/fs-utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare function isFileExists(path: string): boolean;
export declare function loadFile(path: string): Promise<any>;
21 changes: 21 additions & 0 deletions apps/doc2crystallize/build/fs-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import fs from 'fs';
export function isFileExists(path) {
return fs.existsSync(path);
}
export function loadFile(path) {
return new Promise((resolve, reject) => {
fs.readFile(path, 'utf8', (err, content) => {
if (err) {
reject(err);
}
else {
try {
resolve(content);
}
catch (err) {
reject(err);
}
}
});
});
}
1 change: 1 addition & 0 deletions apps/doc2crystallize/build/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
30 changes: 30 additions & 0 deletions apps/doc2crystallize/build/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { isFileExists, loadFile } from './fs-utils.js';
import md5 from 'md5';
import fetch from 'node-fetch';
const bossmanEndpoint = 'https://bossman.crystallize.com/md2crystal';
async function main(markdownFilePath) {
if (!isFileExists(markdownFilePath)) {
console.error(`File ${markdownFilePath} does not exist`);
process.exit(1);
}
const markdown = await loadFile(markdownFilePath);
const now = Math.floor(Date.now() / 1000);
const key = md5(`${now}-X-${process.env.MARKDOWN_TO_CRYSTALLIZE_SHARED_KEY}`);
const response = await fetch(bossmanEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'text/plain',
'X-Secure-Value': now.toFixed(0),
'X-Secure-Signature': key,
},
body: markdown,
});
const result = await response.json();
if (result.status === 'ok') {
console.log(`Publish to Crystallize: https://app.crystallize.com/@${result.tenantIdentifier}/en/catalogue/${result.type}/${result.objectId}`);
}
else {
console.error(`File was not correctly published to Crystallize`);
}
}
main(process.argv[2]).catch(console.error);
30 changes: 30 additions & 0 deletions apps/doc2crystallize/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "module",
"name": "@crystallize/doc2crystallize",
"version": "0.0.1",
"engines": {
"node": ">=16.0"
},
"scripts": {
"start": "node -r dotenv/config build/index.js",
"watch": "tsc -W",
"build": "tsc"
},
"private": true,
"volta": {
"node": "16.14.2",
"yarn": "1.22.18"
},
"dependencies": {
"dotenv": "^16.0.1",
"md5": "^2.3.0",
"node-fetch": "^3.3.0",
"path": "^0.12.7"
},
"devDependencies": {
"@tsconfig/node16": "^1",
"@types/md5": "^2.3.2",
"@types/node": "^18.0.6",
"typescript": "^4.7.4"
}
}
21 changes: 21 additions & 0 deletions apps/doc2crystallize/src/fs-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import fs from 'fs';

export function isFileExists(path: string): boolean {
return fs.existsSync(path);
}

export function loadFile(path: string): Promise<any> {
return new Promise((resolve, reject) => {
fs.readFile(path, 'utf8', (err, content) => {
if (err) {
reject(err);
} else {
try {
resolve(content);
} catch (err) {
reject(err);
}
}
});
});
}
33 changes: 33 additions & 0 deletions apps/doc2crystallize/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { isFileExists, loadFile } from './fs-utils.js';
import md5 from 'md5';
import fetch from 'node-fetch';

const bossmanEndpoint = 'https://bossman.crystallize.com/md2crystal';

async function main(markdownFilePath: string) {
if (!isFileExists(markdownFilePath)) {
console.error(`File ${markdownFilePath} does not exist`);
process.exit(1);
}
const markdown = await loadFile(markdownFilePath);
const now = Math.floor(Date.now() / 1000);
const key = md5(`${now}-X-${process.env.MARKDOWN_TO_CRYSTALLIZE_SHARED_KEY}`);
const response = await fetch(bossmanEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'text/plain',
'X-Secure-Value': now.toFixed(0),
'X-Secure-Signature': key,
},
body: markdown,
});
const result: any = await response.json();
if (result.status === 'ok') {
console.log(
`Publish to Crystallize: https://app.crystallize.com/@${result.tenantIdentifier}/en/catalogue/${result.type}/${result.objectId}`,
);
} else {
console.error(`File was not correctly published to Crystallize`);
}
}
main(process.argv[2]).catch(console.error);
10 changes: 10 additions & 0 deletions apps/doc2crystallize/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@tsconfig/node16/tsconfig.json",
"compilerOptions": {
"outDir": "./build",
"declaration": true,
"module": "ES2020",
"moduleResolution": "node"
},
"include": ["src/**/*.ts", "src/**/*.tsx"]
}
Loading

0 comments on commit b845548

Please sign in to comment.