diff --git a/.github/workflows/main-branch-workflow.yml b/.github/workflows/main-branch-workflow.yml new file mode 100644 index 0000000..538a4c1 --- /dev/null +++ b/.github/workflows/main-branch-workflow.yml @@ -0,0 +1,30 @@ +name: Main Branch + +on: + push: + branches: + - main + +jobs: + publish-release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: EndBug/latest-tag@latest + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + - name: Install dependencies + shell: bash + run: npm install + - name: Build Entries + shell: bash + run: npm run build:entries + - name: Compress Entries + shell: bash + run: tar -czvf dynamo-entries.tgz ./dynamo-entries + - uses: softprops/action-gh-release@v2 + with: + tag_name: latest + files: dynamo-entries.tgz \ No newline at end of file diff --git a/package.json b/package.json index 987d995..6bdce83 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "ts-node src/index.ts" + "start": "ts-node src/index.ts", + "build:entries": "ts-node src/scripts/create-dynamo-entries.ts" }, "keywords": [], "author": "", diff --git a/src/scripts/create-dynamo-entries.ts b/src/scripts/create-dynamo-entries.ts new file mode 100644 index 0000000..544357a --- /dev/null +++ b/src/scripts/create-dynamo-entries.ts @@ -0,0 +1,30 @@ +import fs from 'fs'; +import path from 'path'; +import { mapFieldNames } from '../utils/mapping.utils'; + +const inputDir = path.resolve(__dirname, '../constants/Home_Energy_Data'); +const outputDIr = path.resolve(__dirname, '../../dynamo-entries'); + +(async () => { + try { + const constantsFiles = await fs.promises.readdir(inputDir); + await fs.promises.mkdir(outputDIr); + for (let file of constantsFiles) { + const filePath = `${inputDir}/${file}` + try { + const entries = JSON.parse(await fs.promises.readFile(filePath, { encoding: 'utf-8' })); + await fs.promises.writeFile( + `${outputDIr}/${file}`, + JSON.stringify(entries.map(mapFieldNames), null, 2), + { flag: 'wx', encoding: 'utf-8' } + ) + } catch(e) { + console.error(`Failed processing "${filePath}": ${e}`); + continue; + } + } + } catch (e) { + console.error(`Failed generating Dynamo entries: ${e}`) + process.exit(1); + } +})() \ No newline at end of file