From 4300c092cff2987de60bdb81a65c1a88e48edeb7 Mon Sep 17 00:00:00 2001 From: uwap Date: Tue, 20 Dec 2022 09:13:21 +0100 Subject: [PATCH] add upload script --- .gitignore | 3 ++- package.json | 4 +++- upload.js | 25 +++++++++++++++++++++++++ yarn.lock | 5 +++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 upload.js diff --git a/.gitignore b/.gitignore index 763301f..5c84119 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ dist/ -node_modules/ \ No newline at end of file +node_modules/ +.env \ No newline at end of file diff --git a/package.json b/package.json index d7003bc..8c7833b 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "build": "npx spack", "lint": "npx eslint src/", "prepare": "husky install", - "test": "yarn lint" + "test": "yarn lint", + "push": "node ./upload.js" }, "dependencies": { "@types/screeps": "^3.3.0" @@ -18,6 +19,7 @@ "@swc/core": "^1.3.23", "@typescript-eslint/eslint-plugin": "^5.47.0", "@typescript-eslint/parser": "^5.47.0", + "dotenv": "^16.0.3", "eslint": "^8.30.0", "husky": "^8.0.0", "typescript": "^4.9.4" diff --git a/upload.js b/upload.js new file mode 100644 index 0000000..5010bbc --- /dev/null +++ b/upload.js @@ -0,0 +1,25 @@ + +require('dotenv').config(); +const fs = require('fs'); +var https = require('https'); + +var data = { + branch: 'world', + modules: { + main: fs.readFileSync('./dist/screeps.js', 'utf-8').toString(), + } +}; + +var req = https.request({ + hostname: 'screeps.com', + port: 443, + path: '/api/user/code', + method: 'POST', + headers: { + 'Content-Type': 'application/json; charset=utf-8', + 'X-Token': process.env.SCREEPS_API_TOKEN + } +}); + +req.write(JSON.stringify(data)); +req.end(); \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 0d2451d..54bbd7f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -363,6 +363,11 @@ doctrine@^3.0.0: dependencies: esutils "^2.0.2" +dotenv@^16.0.3: + version "16.0.3" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07" + integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ== + escape-string-regexp@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34"