diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 0000000..bc35c70 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,46 @@ +name: Deploy static content to Pages + +on: + # Runs on pushes targeting the default branch + push: + branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Single deploy job since we're just deploying + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Pages + uses: actions/configure-pages@v5 + - name: Dereference files + run: | + npm install && \ + npm run dereference + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + # Upload entire repository + path: '.' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/dereference.js b/dereference.js new file mode 100644 index 0000000..c2600fb --- /dev/null +++ b/dereference.js @@ -0,0 +1,39 @@ +const $RefParser = require("@apidevtools/json-schema-ref-parser"); +const fs = require("fs"); +const path = require("path"); + +function getFilesAtDepth(directory, depth = 1, currentDepth = 0, files = []) { + const items = fs.readdirSync(directory); + + items.forEach((item) => { + const itemPath = "./" + path.join(directory, item); + const stats = fs.statSync(itemPath); + + // Check if item is a directory or a file + if (stats.isDirectory()) { + // Traverse deeper if it's a directory + getFilesAtDepth(itemPath, depth, currentDepth + 1, files); + } else if (currentDepth >= depth) { + // Add file to list if it's at the required depth + files.push(itemPath); + } + }); + + return files; +} + +const relativePath = "./schemas"; +const depthRequirement = 1; // Minimum depth for files to be included +getFilesAtDepth(relativePath, depthRequirement).forEach(async (file) => { + try { + const deref = await $RefParser.dereference(`./${file}`); + fs.writeFile(file, JSON.stringify(deref), (err) => { + if (err) console.log(err); + else { + console.log(`File written successfully: ${file}`); + } + }); + } catch (err) { + console.error(err); + } +}); diff --git a/package-lock.json b/package-lock.json index 5a3c9f7..ce53687 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0-rc.2", "license": "ISC", "dependencies": { + "@apidevtools/json-schema-ref-parser": "^11.7.2", "fs-extra": "^11.1.1", "image-size": "^1.0.2", "stac-node-validator": "2.0.0-beta.12" @@ -17,6 +18,22 @@ "open-science-catalog-validation": "bin/cli.js" } }, + "node_modules/@apidevtools/json-schema-ref-parser": { + "version": "11.7.2", + "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-11.7.2.tgz", + "integrity": "sha512-4gY54eEGEstClvEkGnwVkTkrx0sqwemEFG5OSRRn3tD91XH0+Q8XIkYIfo7IwEWPpJZwILb9GUXeShtplRc/eA==", + "dependencies": { + "@jsdevtools/ono": "^7.1.3", + "@types/json-schema": "^7.0.15", + "js-yaml": "^4.1.0" + }, + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://github.com/sponsors/philsturgeon" + } + }, "node_modules/@jest/schemas": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", @@ -28,6 +45,11 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/@jsdevtools/ono": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz", + "integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==" + }, "node_modules/@multiformats/base-x": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@multiformats/base-x/-/base-x-4.0.1.tgz", @@ -56,6 +78,11 @@ "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", "integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==" }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==" + }, "node_modules/@zxing/text-encoding": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/@zxing/text-encoding/-/text-encoding-0.9.0.tgz", @@ -115,6 +142,11 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + }, "node_modules/assert": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/assert/-/assert-2.1.0.tgz", @@ -565,6 +597,17 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, "node_modules/json-schema-traverse": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", diff --git a/package.json b/package.json index c92c0c4..37a9931 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,13 @@ "license": "ISC", "bin": "./bin/cli.js", "dependencies": { + "@apidevtools/json-schema-ref-parser": "^11.7.2", "fs-extra": "^11.1.1", "image-size": "^1.0.2", "stac-node-validator": "2.0.0-beta.12" }, "scripts": { + "dereference": "node ./dereference.js", "test": "stac-node-validator --config config.json" } }