From b3ede487da725de6979179f6f9e7b7d4d1210a4f Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sun, 27 Feb 2022 11:37:04 -0600 Subject: [PATCH 1/5] Add vercel-build and build-api --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 140868e..ec7a001 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "test": "ava --timeout=1m --verbose", "dev": "nuxt", "build": "nuxt build", + "build-api": "npm run clone-readme && npm run build-lists", "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", @@ -29,7 +30,8 @@ "lint:fix": "eslint --fix --ext .js,.vue --ignore-path .gitignore .", "precommit": "npm run lint", "clone-readme": "cp ./README.md README-temp.md", - "cloudflare-deploy": "npm run generate" + "cloudflare-deploy": "npm run generate", + "vercel-build": "npm run build-api" }, "dependencies": { "@11ty/eleventy-assets": "^1.0.5", From a26f1da278424b87f606854d4be02bca0645a738 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sun, 27 Feb 2022 12:53:52 -0600 Subject: [PATCH 2/5] Use fs-extra --- build-lists.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-lists.js b/build-lists.js index cd0e014..618e5c3 100644 --- a/build-lists.js +++ b/build-lists.js @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs' +import fs from 'fs-extra' import dotenv from 'dotenv' import buildAppList from './helpers/build-app-list.js' From d8395fd37d3ed0929f7cc2ef3dd4e55a331172d6 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sun, 27 Feb 2022 13:03:40 -0600 Subject: [PATCH 3/5] Add api directory --- static/api/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 static/api/.gitignore diff --git a/static/api/.gitignore b/static/api/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/static/api/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore From 2280100856e35109dced4119f7e09b8d16883f7c Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sun, 27 Feb 2022 13:07:47 -0600 Subject: [PATCH 4/5] Try setting output directory via vercel.json --- vercel.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vercel.json b/vercel.json index 0cae358..802aff8 100644 --- a/vercel.json +++ b/vercel.json @@ -1,4 +1,11 @@ { + "builds": [ + { + "src": "package.json", + "use": "@vercel/static-build", + "config": { "distDir": "static" } + } + ], "github": { "silent": true } From c427ac91ee6a3122540e944cd7de4d80c4108235 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sun, 27 Feb 2022 13:38:07 -0600 Subject: [PATCH 5/5] 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",