Skip to content

Commit

Permalink
Add provider sync script
Browse files Browse the repository at this point in the history
  • Loading branch information
ndaidong committed Jun 25, 2024
1 parent 98b6bc5 commit a586347
Show file tree
Hide file tree
Showing 6 changed files with 7,514 additions and 630 deletions.
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"author": "@extractus",
"license": "MIT",
"tasks": {
"build": "deno run -A ./scripts/build_npm.ts"
"build": "deno run -A ./scripts/build_npm.ts",
"sync": "deno run --allow-net --allow-write --allow-read scripts/sync.ts"
},
"imports": {
"@deno/dnt": "jsr:@deno/dnt@^0.41.2"
Expand Down
49 changes: 49 additions & 0 deletions scripts/sync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env deno run --allow-net --allow-write --allow-read

import { existsSync } from "https://deno.land/std/fs/exists.ts"

import { getJson } from "../utils/retrieve.ts";
import { simplify } from "../utils/provider.ts";

const source = "https://oembed.com/providers.json";
const latest = "./utils/providers.latest.ts";
const prev = "./utils/providers.prev.ts";
const original = "./utils/providers.original.json";

const saveOriginal = (data: any, file: string) => {

};

const sync = async () => {
try {
const result = await getJson(source);
Deno.writeTextFileSync(original, JSON.stringify(result, undefined, 2), { create: true });

const arr = simplify(result);
const data = JSON.stringify(arr, undefined, 2);

// backup previous version
if (existsSync(latest)) {
Deno.copyFileSync(latest, prev);
}

const syncTime = new Date().toISOString();

Deno.writeTextFileSync(
latest,
[
`// provider data, synchronized at ${syncTime}`,
"",
`export const providers = ${data};`,
"",
].join("\n"),
{ create: true }
);

console.log("Providers list has been updated");
} catch (err) {
console.trace(err);
}
};

sync();
File renamed without changes.
Loading

0 comments on commit a586347

Please sign in to comment.