From c427ac91ee6a3122540e944cd7de4d80c4108235 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sun, 27 Feb 2022 13:38:07 -0600 Subject: [PATCH] Enable saving endpoint data individually --- build-lists.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 2 +- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/build-lists.js b/build-lists.js index 618e5c3..aff0eea 100644 --- a/build-lists.js +++ b/build-lists.js @@ -1,3 +1,5 @@ +import { dirname } from 'path' + import fs from 'fs-extra' import dotenv from 'dotenv' @@ -22,6 +24,9 @@ import { makeSearchableList } from './helpers/searchable-list.js' // Setup dotenv dotenv.config() +const commandArguments = process.argv +const withApi = commandArguments.includes('--with-api') + class BuildLists { @@ -185,6 +190,41 @@ class BuildLists { return } + saveApiEndpoints = async function ( listOptions ) { + // Save each enpoint's data + for ( const listEntry of this.lists[listOptions.name] ) { + + // console.log('listEntry', listEntry) + + const { + // name, + // aliases, + // status, + // bundleIds, + endpoint, + + } = listEntry + + const endpointPath = `./static/api${endpoint}.json` + const endpointDirectory = dirname(endpointPath) + + // Stop if the endpoint is already exists + if (fs.existsSync(endpointPath)) { + console.log(`Path "${endpointPath}" already exists`) + + continue + } + + // console.log(`Saving endpoint "${endpoint}" to "${endpointPath}"`) + + // Ensure the directory exists + await fs.ensureDir( endpointDirectory ) + + // Write the endpoint to JSON + await this.saveToJson( listEntry, endpointPath ) + } + } + // Save app lists to JSON saveAppLists = async function () { @@ -208,8 +248,18 @@ class BuildLists { // Save a searchable list await this.saveToJson( Array.from(searchableList), `./static/${listOptions.name}-list-searchable.json` ) - console.timeEnd(methodName) + + if ( withApi ) { + console.log('Saving individual endpoints...') + + const endpointMethodName = `Saved /${ listOptions.name } endpoints` + console.time(endpointMethodName) + + await this.saveApiEndpoints( listOptions ) + + console.timeEnd(endpointMethodName) + } } console.log('Save lists finished') @@ -223,6 +273,8 @@ class BuildLists { await this.saveAppLists() + + // console.log('appList', appList) // console.log('this.allVideoAppsList', this.allVideoAppsList.length, this.allVideoAppsList[0]) diff --git a/package.json b/package.json index ec7a001..13ce39b 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "test": "ava --timeout=1m --verbose", "dev": "nuxt", "build": "nuxt build", - "build-api": "npm run clone-readme && npm run build-lists", + "build-api": "npm run clone-readme && npm run build-lists -- --with-api", "start": "nuxt start", "generate-dev": "npm run generate && npm test", "generate": "npm run clone-readme && npm run build-lists && npm run generate-nuxt && npm run generate-eleventy",