diff --git a/.github/workflows/upload-airtable.yml b/.github/workflows/upload-airtable.yml new file mode 100644 index 0000000..72270cd --- /dev/null +++ b/.github/workflows/upload-airtable.yml @@ -0,0 +1,28 @@ +name: Upload to Airtable + +on: + push: + branches: + - master + +jobs: + csv: + name: Upload CSV to Airtable + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: '20' + - name: Install Node.js dependencies + run: npm ci + - name: Create templates.csv + run: node bin/csv.js + - name: Upload to Airtable + run: | + curl POST ${{ secrets.AIRTABLE_WEBHOOKS_API_ENDPOINT }} \ + -H "Authorization: Bearer ${{ secrets.AIRTABLE_WEBHOOKS_API_KEY }}" \ + -H "Content-Type: text/csv" \ + --data-binary "@bin/templates.csv" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f177099 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bin/templates.csv +node_modules diff --git a/bin/csv.js b/bin/csv.js new file mode 100644 index 0000000..2bb847b --- /dev/null +++ b/bin/csv.js @@ -0,0 +1,48 @@ +const fs = require('fs'); +const path = require('path'); +const yaml = require('yaml'); +const { createObjectCsvWriter } = require('csv-writer'); + +// Define paths to the templates.yml file and the directory containing the template files +const templatesYmlPath = path.join(__dirname, '..', 'templates.yml'); +const templatesDir = path.join(__dirname, '..'); + +// Read and parse the templates.yml file +const templatesYml = fs.readFileSync(templatesYmlPath, 'utf8'); +const templateNames = yaml.parse(templatesYml); + +// Define the CSV writer +const csvWriter = createObjectCsvWriter({ + path: path.join(__dirname, 'templates.csv'), + header: [ + { id: 'name', title: 'Name' }, + { id: 'description', title: 'Description' }, + { id: 'documentationUrl', title: 'Documentation URL' }, + { id: 'format', title: 'Format' }, + ] +}); + +// Function to read and parse each template file +const readTemplateFile = (templateName) => { + const templateFilePath = path.join(templatesDir, `${templateName}.yml`); + const templateYml = fs.readFileSync(templateFilePath, 'utf8'); + const templateData = yaml.parse(templateYml); + let format = templateData.format; + if (format === 'json') { + format = format.toUpperCase(); + } + return { + name: templateData.name, + description: templateData.description, + documentationUrl: templateData['documentation-url'], + format: format, + }; +}; + +// Collect data from each template file +const templatesData = templateNames.map(templateName => readTemplateFile(templateName)); + +// Write data to CSV +csvWriter.writeRecords(templatesData) + .then(() => console.log('Templates data written to templates.csv')) + .catch(err => console.error('Error writing to CSV file', err)); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..e60f794 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,110 @@ +{ + "name": "lorawan-webhook-templates", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "dependencies": { + "csv-writer": "^1.6.0", + "fs": "^0.0.1-security", + "path": "^0.12.7", + "yaml": "^2.4.3" + } + }, + "node_modules/csv-writer": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/csv-writer/-/csv-writer-1.6.0.tgz", + "integrity": "sha512-NOx7YDFWEsM/fTRAJjRpPp8t+MKRVvniAg9wQlUKx20MFrPs73WLJhFf5iteqrxNYnsy924K3Iroh3yNHeYd2g==" + }, + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + }, + "node_modules/inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==" + }, + "node_modules/path": { + "version": "0.12.7", + "resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz", + "integrity": "sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==", + "dependencies": { + "process": "^0.11.1", + "util": "^0.10.3" + } + }, + "node_modules/process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", + "engines": { + "node": ">= 0.6.0" + } + }, + "node_modules/util": { + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", + "integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==", + "dependencies": { + "inherits": "2.0.3" + } + }, + "node_modules/yaml": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.4.3.tgz", + "integrity": "sha512-sntgmxj8o7DE7g/Qi60cqpLBA3HG3STcDA0kO+WfB05jEKhZMbY7umNm2rBpQvsmZ16/lPXCJGW2672dgOUkrg==", + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14" + } + } + }, + "dependencies": { + "csv-writer": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/csv-writer/-/csv-writer-1.6.0.tgz", + "integrity": "sha512-NOx7YDFWEsM/fTRAJjRpPp8t+MKRVvniAg9wQlUKx20MFrPs73WLJhFf5iteqrxNYnsy924K3Iroh3yNHeYd2g==" + }, + "fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==" + }, + "path": { + "version": "0.12.7", + "resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz", + "integrity": "sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==", + "requires": { + "process": "^0.11.1", + "util": "^0.10.3" + } + }, + "process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==" + }, + "util": { + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", + "integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==", + "requires": { + "inherits": "2.0.3" + } + }, + "yaml": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.4.3.tgz", + "integrity": "sha512-sntgmxj8o7DE7g/Qi60cqpLBA3HG3STcDA0kO+WfB05jEKhZMbY7umNm2rBpQvsmZ16/lPXCJGW2672dgOUkrg==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..b307421 --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "csv-writer": "^1.6.0", + "fs": "^0.0.1-security", + "path": "^0.12.7", + "yaml": "^2.4.3" + } +}