From 87d03702aea2d953917c4e067d3e2cfa4ef8c806 Mon Sep 17 00:00:00 2001 From: Sean Sullivan Date: Thu, 3 Mar 2022 20:04:16 -0800 Subject: [PATCH] update tsconfig --- package.json | 10 ++++++---- src/update-plugins.ts | 39 ++++++++++++++++++++++++--------------- tsconfig.json | 10 ++-------- tsconfig.update.json | 4 ++++ 4 files changed, 36 insertions(+), 27 deletions(-) create mode 100644 tsconfig.update.json diff --git a/package.json b/package.json index 9c863c4f..dc308000 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,9 @@ "test": "tsc --noEmit", "build": "tsc --build", "clean": "rm -rf build", - "update-plugins": "ts-node src/update-plugins.ts" + "preupdate-plugins": "tsc --build tsconfig.update.json", + "update-plugins": "node build/update-plugins.js", + "postupdate-plugins": "npm run clean" }, "repository": { "type": "git", @@ -25,8 +27,8 @@ }, "homepage": "https://github.com/withfig/plugins", "devDependencies": { - "typescript": "^3.5.3", - "node-fetch": "^3.2.1", - "ts-node": "^10.6.0" + "axios": "^0.26.0", + "ts-node": "^10.6.0", + "typescript": "^3.5.3" } } diff --git a/src/update-plugins.ts b/src/update-plugins.ts index 35b30185..f96852ec 100644 --- a/src/update-plugins.ts +++ b/src/update-plugins.ts @@ -1,18 +1,27 @@ -import fetch from "node-fetch"; -import { loadPlugin } from "."; +import axios, { AxiosError } from 'axios'; -const pluginNames = process.argv.slice(2) - .filter(file => file.startsWith("src/plugins/") && file.endsWith(".ts")) - .map(file => file.slice("src/plugins/".length, -".ts".length)); +const plugins = process.argv.slice(2) + .filter(file => file.match(/^src\/plugins\/.*\.ts$/)) + .map(file => { + const js = import(file.replace(/^src/, ".").replace(/\.ts$/, ".js")) + return js.then(plugin => plugin.default) + }); -Promise.all(pluginNames.map(name => loadPlugin(name))).then(plugins => { - fetch("https://api.fig.io/plugins/update", { - method: "POST", - headers: { - Authorization: `Bearer ${process.env.PLUGINS_UPDATE_TOKEN}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({ plugins }) - }).then(res => process.exit(res.ok ? 0 : 1)); +Promise.all(plugins).then(plugins => { + axios.post( + "https://api.fig.io/plugins/update", + { plugins }, + { + headers: { + Authorization: `Bearer ${process.env.PLUGINS_UPDATE_TOKEN}`, + "Content-Type": "application/json" + } + } + ).then((res) => { + console.log("Updated successfully"); + process.exit(0); + }).catch((err: AxiosError) => { + console.log("Failed to update:", err.message); + process.exit(1); + }); }) - diff --git a/tsconfig.json b/tsconfig.json index de6c788e..56c175b9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,17 +1,11 @@ { - "ts-node": { - "transpileOnly": true, - "files": true, - "compilerOptions": { - "module": "commonjs" - } - }, "compilerOptions": { - "moduleResolution": "node", "outDir": "./build", "target": "ES6", "module": "commonjs", "lib": ["ESNext", "DOM"], + "esModuleInterop": true, + "moduleResolution": "node", "strict": true, "allowSyntheticDefaultImports": true, "baseUrl": "./", diff --git a/tsconfig.update.json b/tsconfig.update.json new file mode 100644 index 00000000..074ec7aa --- /dev/null +++ b/tsconfig.update.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["node_modules/"] +}