code re-use and eslint

This commit is contained in:
LouisLam 2021-08-09 13:49:37 +08:00
parent d0aad3400c
commit bf33f97c9e
6 changed files with 63 additions and 58 deletions

View File

@ -1,19 +1,19 @@
var http = require("http"); let http = require("http");
var options = { let options = {
host: "localhost", host: "localhost",
port: "3001", port: "3001",
timeout: 2000, timeout: 2000,
}; };
var request = http.request(options, (res) => { let request = http.request(options, (res) => {
console.log(`STATUS: ${res.statusCode}`); console.log(`STATUS: ${res.statusCode}`);
if (res.statusCode == 200) { if (res.statusCode == 200) {
process.exit(0); process.exit(0);
} else { } else {
process.exit(1); process.exit(1);
} }
}); });
request.on("error", function (err) { request.on("error", function (err) {
console.log("ERROR"); console.log("ERROR");
process.exit(1); process.exit(1);
}); });
request.end(); request.end();

View File

@ -1,25 +1,9 @@
/** const pkg = require("../package.json");
* String.prototype.replaceAll() polyfill
* https://gomakethings.com/how-to-replace-a-section-of-a-string-with-another-one-with-vanilla-js/
* @author Chris Ferdinandi
* @license MIT
*/
if (!String.prototype.replaceAll) {
String.prototype.replaceAll = function(str, newStr){
// If a regex pattern
if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') {
return this.replace(str, newStr);
}
// If a string
return this.replace(new RegExp(str, 'g'), newStr);
};
}
const pkg = require('../package.json');
const fs = require("fs"); const fs = require("fs");
const util = require("../src/util");
util.polyfill();
const oldVersion = pkg.version const oldVersion = pkg.version
const newVersion = oldVersion + "-nightly" const newVersion = oldVersion + "-nightly"
@ -35,6 +19,6 @@ if (newVersion) {
// Process README.md // Process README.md
if (fs.existsSync("README.md")) { if (fs.existsSync("README.md")) {
fs.writeFileSync("README.md", fs.readFileSync("README.md", 'utf8').replaceAll(oldVersion, newVersion)) fs.writeFileSync("README.md", fs.readFileSync("README.md", "utf8").replaceAll(oldVersion, newVersion))
} }
} }

View File

@ -1,26 +1,10 @@
/**
* String.prototype.replaceAll() polyfill
* https://gomakethings.com/how-to-replace-a-section-of-a-string-with-another-one-with-vanilla-js/
* @author Chris Ferdinandi
* @license MIT
*/
if (!String.prototype.replaceAll) {
String.prototype.replaceAll = function(str, newStr) {
// If a regex pattern
if (Object.prototype.toString.call(str).toLowerCase() === "[object regexp]") {
return this.replace(str, newStr);
}
// If a string
return this.replace(new RegExp(str, "g"), newStr);
};
}
const pkg = require("../package.json"); const pkg = require("../package.json");
const fs = require("fs"); const fs = require("fs");
const child_process = require("child_process"); const child_process = require("child_process");
const util = require("../src/util");
util.polyfill();
const oldVersion = pkg.version; const oldVersion = pkg.version;
const newVersion = process.argv[2]; const newVersion = process.argv[2];

View File

@ -1,6 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.debug = exports.ucfirst = exports.sleep = exports.flipStatus = exports.PENDING = exports.UP = exports.DOWN = exports.appName = void 0; exports.polyfill = exports.debug = exports.ucfirst = exports.sleep = exports.flipStatus = exports.PENDING = exports.UP = exports.DOWN = exports.appName = void 0;
exports.appName = "Uptime Kuma"; exports.appName = "Uptime Kuma";
exports.DOWN = 0; exports.DOWN = 0;
exports.UP = 1; exports.UP = 1;
@ -33,3 +33,14 @@ function debug(msg) {
} }
} }
exports.debug = debug; exports.debug = debug;
function polyfill() {
if (!String.prototype.replaceAll) {
String.prototype.replaceAll = function (str, newStr) {
if (Object.prototype.toString.call(str).toLowerCase() === "[object regexp]") {
return this.replace(str, newStr);
}
return this.replace(new RegExp(str, "g"), newStr);
};
}
}
exports.polyfill = polyfill;

View File

@ -1,3 +1,4 @@
// @ts-nocheck
// Common Util for frontend and backend // Common Util for frontend and backend
// Backend uses the compiled file util.js // Backend uses the compiled file util.js
// Frontend uses util.ts // Frontend uses util.ts
@ -42,3 +43,25 @@ export function debug(msg) {
console.log(msg); console.log(msg);
} }
} }
export function polyfill() {
/**
* String.prototype.replaceAll() polyfill
* https://gomakethings.com/how-to-replace-a-section-of-a-string-with-another-one-with-vanilla-js/
* @author Chris Ferdinandi
* @license MIT
*/
if (!String.prototype.replaceAll) {
String.prototype.replaceAll = function(str, newStr) {
// If a regex pattern
if (Object.prototype.toString.call(str).toLowerCase() === "[object regexp]") {
return this.replace(str, newStr);
}
// If a string
return this.replace(new RegExp(str, "g"), newStr);
};
}
}

View File

@ -1,8 +1,11 @@
{ {
"compileOnSave": true, "compileOnSave": true,
"compilerOptions": { "compilerOptions": {
"target": "ES2018", "target": "es2018",
"module": "commonjs", "module": "commonjs",
"lib": [
"es2020"
],
"removeComments": true, "removeComments": true,
"preserveConstEnums": true, "preserveConstEnums": true,
"sourceMap": false, "sourceMap": false,